# ko.sh 20240310_1900	apps
# ko.sh 20240225_1230	"$1" == "items" "$1" == "items2db"
# ko.sh 20240225_1230	if fi # labels
# ko.sh 20240225_930	items
# ko.sh 20240223_0930	csv2json json2csv
# ko.sh 20240223_0930	kolists0.sh b64s0.sh
# ko.sh 20240222_0900	todos todos todo todo_db todo_fs todo_tx awks fors   kolists bs4 b64 
# ko.sh 20240130_2100	mvs
# ko.sh 20230525_0230	ssk <usr><domain><fmt>
# ko.sh 20230525_0230	ssk <usr><domain><fmt>
# ko.sh 20230520_1530	https://cpanel-cli.readthedocs.io/en/latest/reference/mysql.html
# ko.sh	20230218_1800	items2sl items2leds
# ko.sh	20230218_0510	items2sl items2leds
# ko.sh	20230218_0500	dirs2html
# ko.sh	20230202_1000	dirs2fb
# ko.sh	20230131_1000	find2tbl find2fb
# ko.sh	20230131_0300	jsk2 gjw kofeeshop kitiworks
# ko.sh 20221106_0000	psv
# ko.sh 20220930_1730	sql3 <sel|up>	
# ko.sh 20220930_1630	uapi email <list|create>
# ko.sh 20220928_1230	pb 
# ko.sh 20220928_1230	vi notes 
# ko.sh 20220922_0500	md move dirs
# ko.sh 20220919_1300	mv snapndrag snap_yyyymmdd
# ko.sh 20220911_0230	md mv vi
# ka.sh	20220908_0730	mkdir nasa_yyyymmdd
# ka.sh	20220119_1930	db3
# ka.sh	20220119_1145	db3
# ka.sh	20220118_1830	db3
# ka.sh	20211009_1900

# if [ "$UID" -eq 0 -o "$EUID" -eq 0 ]; then
#    command
# else
#    sudo command
# fi

# printf "bash version ${BASH_VERSION}\n";
# printf "bash version ${BASH_VERSION}\n";
# printf "bash version ${BASH_VERSION}\n";

# etchosts_ka12=`cat /etc/hosts | grep "ka0" | grep -v "#"`
# if [ "$etchosts_ka12" == "" ]; then
# 	printf "cat '# 10.5.50.112 ka12 ka0' >> /etc/hosts\n";
# #	sudo cat '# 10.5.50.112 ka12 ka0' >> /etc/hosts

# 	cat /etc/hosts | grep "ka0"
# 	printf "# 10.5.50.112 ka12 ka0\n" >> /etc/hosts
# 	cat /etc/hosts | grep "ka0"
# 	exit;
# else
# 	printf "ping ka12\n";
# 	ping ka12
# 	exit;
# 	fi
# exit;


#	tl_b64s = `ls b*.txt`
progid="ko"
hostname=`hostname`
dttm=`date +"%Y%m%d_%H%M%S"`
yyyymmdd=`date +"%Y%m%d"`
if [ "$2" != "" ] && [ "$2" != "psv" ]; then yyyymmdd=$2; fi

logfil="$progid.log"
db3="../tl.db3";
tbl="tl";
tbls="fb tl mp4 mp3 pdf jpg txt";

ids="iperms";
ids="jtfdc jtfdcr jtfinc"
ids="konet";
ids="konet jtfdc jtfdcr jtfinc iperms";
ids="bookusb"
ids="jtfdc nasa kb snap"

function random_int() {
	max=$1
	min=$2
	idx=$(($min + $RANDOM % $max))
	printf $idx;
	}
function ko1() {
	dttm=`date +"%Y%m%d_%H%M%S"`
	txtout="ko1 $dttm args1=$1";
	printf "$txtout\n";
	}

ko2() {
	dttm=`date +"%Y%m%d_%H%M%S"`
	txtout="ko2 $dttm args1=$1";
	printf "$txtout\n";
	}


# =================================================
# echo "$progid $dttm BUGS_070 1=$1 2=$2 3=$3 4=$4"
#	echo "$progid $dttm books=$books"
#	if [ "$1" == "vi." ] || [ "$1" == "vi." ];  then
#		vi $progid.sh; 
#		exit; 
#		fi

ht="../ht";
db3s="/ko/ko.db3 /ko/tl.db3 /ko/leds.db3";
psvdir="/ko/psv";
sl_items_html="/ko/ko_sl_items.html";
leds_items_html="/ko/ko_leds_items.html";
fdir="$ht/fb/jtfdcr";
tdir="$ht/law";
htmlfile="/law/jtfdcr_links.html"
ht_htmlfile="$ht/law/jtfdcr_links.html"

jsonfile="../ht/ko/randomusers.json"
db3fil="../ht/ko.db3"
tbl="contacts";


usrcmd="";
i=0; j=0; k=0;
function kludge() {
	printf "BUGS_100 kludge args=$args\n"
	return $args ;
	}
function kludge1() {
	printf "BUGS_121 kludge1 args=$args\n"
	return $args ;
	}
function kludge2() {
	printf "BUGS_102 kludge args=$args\n"
	for value in "$@"; do # You want to use "$@" here, not "$*" !!!!!
		let j=j+1
		printf "BUGS_102 kludge2 j=$j value=$value args=$args\n"
		:
		done
	return $args ;
	}
function ko_finds {
 	args="args"
 	printf "BUGS_130 KO_FINDS args=$args\n"
 	return 0;
 	}

function ko_selects {
	args="args";
	printf "BUGS_140 KO_SELECTS args=$args\n"
	return 0 ;
	}


function linearSearch () {
# 	linearSearch $someStringValue "${someArray[@]}"
	local myVar="$1"
	shift 1 # Removes $1 from the parameter list
	for value in "$@"; do # Represents the remaining parameters.
		if [[ $value == $myVar ]]; then
			echo -e "Found it!\t... after a while."
			return 0
			fi
		done
	return 1
	}
function callingSomeFunction () {
# callingSomeFunction myArray # No $ in front of the argument. You pass by name, not expansion / value.
	local -n someArray=$1 # also ${1:?} to make the parameter mandatory.
	for value in "${someArray[@]}"; do # Nice!
		:
		done
	}
function example1 { args : string firstName , string lastName , integer age } {
	echo "My name is ${firstName} ${lastName} and I am ${age} years old."
	}
function example2 {
	args
	: @required string firstName
	: string lastName
	: integer age
	: string[] ...favoriteHobbies

	echo "My name is ${firstName} ${lastName} and I am ${age} years old."
	echo "My favorite hobbies include: ${favoriteHobbies[*]}"
	}

shopt -s expand_aliases

function assignTrap {
# alias args='local __previousTrap=$(trap -p DEBUG); trap "eval \"\$(assignTrap \$BASH_COMMAND)\";" DEBUG;'
	local evalString
	local -i paramIndex=${__paramIndex-0}
	local initialCommand="${1-}"

	if [[ "$initialCommand" != ":" ]]
	then
		echo "trap - DEBUG; eval \"${__previousTrap}\"; unset __previousTrap; unset __paramIndex;"
		return
		fi

	while [[ "${1-}" == "," || "${1-}" == "${initialCommand}" ]] || [[ "${#@}" -gt 0 && "$paramIndex" -eq 0 ]]
	do
		shift # First colon ":" or next parameter's comma ","
		paramIndex+=1
		local -a decorators=()
		while [[ "${1-}" == "@"* ]]
		do
			decorators+=( "$1" )
			shift
			done

		local declaration=
		local wrapLeft='"'
		local wrapRight='"'
		local nextType="$1"
		local length=1

		case ${nextType} in
			string | boolean) declaration="local " ;;
			integer) declaration="local -i" ;;
			reference) declaration="local -n" ;;
			arrayDeclaration) declaration="local -a"; wrapLeft= ; wrapRight= ;;
			assocDeclaration) declaration="local -A"; wrapLeft= ; wrapRight= ;;
			"string["*"]") declaration="local -a"; length="${nextType//[a-z\[\]]}" ;;
			"integer["*"]") declaration="local -ai"; length="${nextType//[a-z\[\]]}" ;;
			esac

		if [[ "${declaration}" != "" ]]
		then
			shift
			local nextName="$1"

      for decorator in "${decorators[@]}"
      do
        case ${decorator} in
          @readonly) declaration+="r" ;;
          @required) evalString+="[[ ! -z \$${paramIndex} ]] || echo \"Parameter '$nextName' ($nextType) is marked as required by '${FUNCNAME[1]}' function.\"; " >&2 ;;
          @global) declaration+="g" ;;
        esac
      done



		local paramRange="$paramIndex"

		if [[ -z "$length" ]]
		then
# ...rest
			paramRange="{@:$paramIndex}"
# trim leading ...
			nextName="${nextName//\./}"
			if [[ "${#@}" -gt 1 ]]
			then
				echo "Unexpected arguments after a rest array ($nextName) in '${FUNCNAME[1]}' function." >&2
				fi
			elif [[ "$length" -gt 1 ]]
			then
				paramRange="{@:$paramIndex:$length}"
				paramIndex+=$((length - 1))
				fi

			evalString+="${declaration} ${nextName}=${wrapLeft}\$${paramRange}${wrapRight}; "

# Continue to the next parameter:
			shift
			fi
		done
	echo "${evalString} local -i __paramIndex=${paramIndex};"
	}

# echo "parameterized function example"
# function print_param_value() {
# print_param_value "6" "4" # Space-separated value
#	value1="${1}" # $1 represent first argument
#	value2="${2}" # $2 represent second argument
#	echo "param 1 is  ${value1}" # As string
#	echo "param 2 is ${value2}"
#	sum=$(($value1+$value2)) # Process them as number
#	echo "The sum of two value is ${sum}"
#	}
# print_param_value "6" "4" # Space-separated value


# You can also pass parameters during executing the script
# print_param_value "$1" "$2" # Parameter $1 and $2 during execution
# Suppose our script name is "param_example".
# Call it like this:
# ./param_example 5 5
# Now the parameters will be $1=5 and $2=5
# read -p "Enter the first  value: " x
# read -p "Enter the second value: " y
# add(){
#     arg1=$1 # arg1 gets to be the first  assigned argument (note there are no spaces)
#       arg2=$2 # arg2 gets to be the second assigned argument (note there are no spaces)
# 
#     echo $(($arg1 + $arg2))
# }
# 
# add x y # Feeding the arguments

	if [ "$1" == "tbl2psv" ] || [ "$1" == "tbl2psv" ]; then
			db3="ko.db3"; tbl=""; j=0; k=0;
			tbls=`sqlite3 $db3 ".tables"`
			for tbl in $tbls; do
				let k=k+1
				psvfil="./psv/$tbl.psv"
				printf "$progid $dttm BUGS_280 tbl2psv $j,$k tbl=$fsrc\n";

				sql="select * from $tbl"
				sqlcmd="sqlite3 $db3 \"$sql\""
				printf "$progid $dttm $j,$k id=$id  BUGS_382 FINDS GO $fsrc $tsrc sqlcmd=$sqlcmd id=$id type=$type item=$item lincnt=$lincnt linend=$linend lincnt=$lincnt descr=$descr  sqlcmd=$sqlcmd > $psvfil  ==================\n";
				if [ "$usrcmd" != "g" ]; then
					read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
					if [ "$usrcmd" == "q" ]; then exit; fi
					if [ "$usrcmd" == "s" ]; then continue; fi
					if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
					if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
					fi

				if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
#					printf "$progid $dttm $j,$k BUGS_390 FINDS GO id=$id ofile=$ofile linbeg=$linbeg linend=$linend item=$item ==================\n";
					if [ -f $db3 ]; then
						printf "BUGS_430 INSERT db3=$db3 sqlcmd=$sqlcmd\n";
						sqlite3  $db3 -header "$sql" > $psvfil
						fi
					fi

				done




			exit;
			fi # if [ "$1" == "tbl2psv" ] || [ "$1" == "tbl2psv" ]; then

	if [ "$1" == "finds" ] || [ "$1" == "finds" ]; then
# function finds() {
		htmout=""; j=0; k=0;

		db3="ko.db3"; tbl="bs4";
		tbl="bs4fil";
# .ko.sh finds <"ko.php ko.html ko.py ko.sh">
# ./ko.sh finds ko.php <tsrcs>
# ./ko.sh finds ko.php <todo>
# ./ko.sh finds ko.php 
# ./ko.sh finds ko.php

# fsrcs="ko.sh ko.py ko.php ko.html"
fsrcs="ko.php ko.py ko.html"
fsrcs="ko.html"
todos="id2tbl id2fil id2b64"
type="";


		for fsrc in $fsrcs; do
			dttm=`date +"%Y%m%d_%H%M%S"`

			if [ ! -f $fsrc ]; then
				printf "$progid $dttm BUGS_280 finds NOTFOUND $j,$k fsrc=$fsrc\n";
				continue;
				fi

#			type=`printf $fsrc | awk -F"." '{ print $2 }'`
			let j=j+1

			if [ "$type" == "html" ]; then
				headmark="<script";
				tailmark="</script";
#  				`cat index.html | awk '/<script/ { print $1"|"$2"|"$0"|"NR }' | cut -c 1-80 | sed -e "s:\t::g" | tr -d '\t' > finds_html_script.psv`
#				`cat index.html | awk '/<style/ { print $1"|"$2"|"$0"|"NR }' | cut -c 1-80 | sed -e "s:\t::g" | tr -d '\t' > finds_html_style.psv`
#				`cat index.html | awk '/<div/ { print $1"|"$2"|"$0"|"NR }' | cut -c 1-80 | sed -e "s:\t::g" | tr -d '\t' > finds_html_div.psv`

#				items=`cat $fsrc | awk '/$headmark/ { print $1"|"NR"|"$2"|"$0 }'`
#				items=`cat finds_html_div.psv`
#				items=`cat finds_html_style.psv`
#				items=`cat finds_html_script.psv`
				fi
			if [ "$type" == "php" ]; then
				headmark="^function";
				tailmark="^function";
#				items=`cat $fsrc | awk '/$headmark/ { print $1"|"NR"|"$2"|"$0 }'`
#				`cat ko.php | awk '/^function/ { print $1"|"$2"|"$0"|"NR }' | cut -c 1-80 | sed -e "s:\t::g" | tr -d '\t' > finds_phps.psv`
#				items=`cat finds_php.psv`
				fi
			if [ "$type" == "py" ]; then
				headmark="^def";
				tailmark="^def";
#				items=`cat $fsrc | awk '/$headmark/ { print $1"|"NR"|"$2"|"$0 }'`
#				`cat ko.py | awk '/^def/ { print $1"|"$2"|"$0"|"NR }' | cut -c 1-80 | sed -e "s:\t::g" | tr -d '\t' > finds_phps.psv`
#				items=`cat finds_py.psv`
				fi
			if [ "$type" == "sh" ]; then
				headmark="\"\$1\" ==";
				tailmark="\"\$1\"";
#				items=`cat $fsrc | awk '/$headmark/ { print $1"|"NR"|"$2"|"$0 }'`
#				`cat ko.py | awk '/"$1" ==/ { print $1"|"$2"|"$0"|"NR }' | cut -c 1-80 | sed -e "s:\t::g" | tr -d '\t' > finds_shs.psv`
#				items=`cat finds_sh.psv`
				fi

		
#			printf "BUGS_350 function finds j=$j id=$id item=$item type=$type fsrc=$fsrc tsrc=$tsrc type=$type \n";
#			find_cmd="cat $fsrc | awk '/$headmark/ { print \$1\"|\"NR\"|\"\$2\"|\"\$0 }'"
			
#			ilim=`echo $items | wc -l | awk '{ print $1}'`	
#			printf "BUGS_351 function finds $j,$k ilim=$ilim type=$type  items=$items\n";
#			continue


# pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq

			items=`find ./htm -type f -name "*.htm"`
			headmark=""; tailmark=""; id=""; sort=""; 
			fsrc=""; tsrc=""; status=""; label="";
			linbeg=""; linend=""; lincnt=""
			for item in $items; do
				dttm=`date +"%Y%m%d_%H%M%S"`
				let k=k+1
				htmfil=$item;
				id=`printf $htmfil | sed -e "s:/htm::" | sed -e "s:.htm::" | sed -e "s:./::"`
				b64fil=`printf $htmfil | sed -e "s:htm/:b64/b64_:"| sed -e "s:.htm:.txt:"`
#				txtfil=`printf $b64fil | sed -e "s:.txt:.htm:" | sed -e "s:/b64/b64_:/b64/txt_:" | sed -e "s:.txt:.htm:"`
				txtfil=`printf $b64fil |  sed -e "s:/b64/b64_:/b64/txt_:" | sed -e "s:.txt$:.htm:"`
				b64htm=`printf $b64fil |  sed -e "s:/b64/b64_:/b64/b64_:" | sed -e "s:.txt$:.htm:"`
				linbeg=1; 
				if [ -f $htmfil ]; then lincnt=`cat $htmfil | wc -l | awk '{ print $1 }'`; fi
				linend=$lincnt;
# <script id="fb_extras_jquery_min_17_js" src='data:/text/plain;base64,LyohIGpRdWVyeSB2MS43IGpxdWVyeS5jb20gfCBqcXVlcnkub3
				b64="_b64_";
				if [ -f $htmfil ]; then
					b64=`cat $htmfil | base64`
					fi
				printf "BUGS_381 $j,$k ITEM=$item ID=$id\n";
				printf "BUGS_382 $j,$k htmfil=$htmfil\n";
#				printf "BUGS_383 $j,$k b64=$b64\n";
				printf "BUGS_383 $j,$k b64fil=$b64fil\n";
				printf "BUGS_383 $j,$k txtfil=$txtfil\n";
				printf "BUGS_384 $j,$k b64htm=$b64htm\n";
				printf "BUGS_384 $j,$k linbeg=$linbeg linend=$linend lincnt=$lincnt\n";
				printf "BUGS_385 $j,$k ----------------------------------------------\n";
#				headmark=`printf $item | awk -F"|" '{ print $1 }'| sed -e "s:id=::g" | sed -e "s:\"::g" | awk -F"(" '{ print $1 }'`
#				id=`printf $item | awk -F"|" '{ print $2 }'| sed -e "s:id=::g" | sed -e "s:\"::g" | awk -F"(" '{ print $1 }'`
#				id=`printf | sed -e "s:>::g" | sed -e "s:(::g"`

				if [ "$id" == "" ]; then 
					printf "BUGS_350 SKIP id=$id item=$item\n";
					continue;
					fi

#				descr=`printf $item | awk -F"|" '{ print $4 }'`
#				linend=0; lincnt=1
#				let linend=linbeg+1
				printf "BUGS_360 $j,$k headmark=$headmark  id=$id linbeg=$linbeg desc=$desr ITEM=$item\n";
#				if [ $k -gt 10 ]; then exit; fi
#				if [ "$k" == "10" ]; then exit; fi


# linend=`cat $fsrc | awk -v linbeg=$linbeg -v lenend=$linend '/<script/ && NR>linbeg && NR<=linend { print $0 }' | head -1 | awk -F"|" '{ print $1 }'`

				if [ "$type" == "sh" ]; then tsrc="./sh/function_$id.sh"; fi
				if [ "$type" == "py" ]; then tsrc="./py/def_$id.py"; fi
				if [ "$type" == "php" ]; then tsrc="./php/function_$id.php"; fi
				if [ "$type" == "html" ]; then tsrc="./htm/div_$id.htm"; fi
				if [ "$type" == "html" ]; then tsrc="./htm/style_$id.htm"; fi
				if [ "$type" == "html" ]; then tsrc="./htm/script_$id.htm"; fi

				status="status"; sort=$k; 
printf "BUGS_370 id=$id type=$type fsrc=$fsrc tsrc=$tsrc linbeg=$linbeg linend=$linend lincnt=$lincnt\n";

				fsrc=$htmfil;
				tsrc=`printf $fsrc | sed -e "s:../ht/::"`

#				sql="insert into $tbl (id,status,type,sort,linbeg,linend,lincnt,fsrc,tsrc,descr) values ('$id','$status','$type','$sort','$linbeg','$linend','$lincnt','$fsrc','$tsrc','$descr')"

				b64="_b64_"
				if [ -f $htmfil ]; then
					b64=`cat $htmfil | base64`
					fi
				b64cut=`printf $b64 | cut -c 1-40`
				sql="update $tbl set b64='$b64cut'";
				sqlcmd="sqlite3 $db3 \"$sql\""

				printf "BUGS_390 pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n";
				printf "BUGS_390 $j $k ID=$id \n";
				printf "BUGS_390 $j $k id=$id sqlcmd=$sqlcmd\n";
				printf "BUGS_390 bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n";

					
#				printf "$progid $dttm $j,$k id=$id id1=$id1 id2=id2 BUGS_381 FINDS GO $ item=$item \n";
#				printf "$progid $dttm $j,$k id=$id  BUGS_382 FINDS GO $fsrc $tsrc sqlcmd=$sqlcmd id=$id type=$type item=$item lincnt=$lincnt linend=$linend lincnt=$lincnt descr=$descr  ==================\n";
				if [ "$usrcmd" != "g" ]; then
					read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
					if [ "$usrcmd" == "q" ]; then exit; fi
					if [ "$usrcmd" == "s" ]; then continue; fi
					if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
					if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
					fi
				if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
#					printf "$progid $dttm $j,$k BUGS_390 FINDS GO id=$id ofile=$ofile linbeg=$linbeg linend=$linend item=$item ==================\n";
					b64="_b64_";
					if [ -f $htmfil ]; then
						b64=`cat $htmfil | base64`
						fi

					b64cut=`print $b64`
					sql="update $tbl set b64='$b64' where id=='$id'"
					sqlcmd="sqlite3 $db3 \"$sql\"";
					printf "BUGS_430 INSERT sqlcmd=$sqlcmd\n";
					if [ -f $db3 ]; then
						printf "BUGS_431 INSERT db3=$db3 sqlcmd=$sqlcmd\n";
						sqlite3 $db3 "$sql"
						fi

b64htm="./b64/htm_b64_$id.htm";
tsthtm="./b64/tst_$id.htm"
b64=`sqlite3 $db3 "select b64 from $tbl where id='"+id+"'"`
b64html="<script id=script_"+id+" src='data:/text/plain;base64,"+b64+"></script id=script_"+id+"_end>";
printf $b64html > $tsthtm
					continue;

					if [ ! -f $b64fil ]; then
						printf "BUGS_430 cat $htmfil | base64 > $b64fil\n";
						`cat $htmfil | base64 > $b64fil`
						fi

					if [ ! -f $txtfil ]; then
						printf "BUGS_430 cat $htmfil | base64 > $b64fil\n";
						`cat $b64fil | base64 -d > $txtfil`
						fi

					if [ -f $b64fil ]; then
						b64=`cat $b64fil`
						sql="update $tbl set b64='$b64' where id=='$id'";
						sqlcmd="sqlite3 $db3 \"$sql\"";
						printf "BUGS_440 sqlcmd=$sqlcmd\n";
						`$sqlcmd`
						fi




#					if [ -f $fsrc ]; then				
#  cat $fsrc | cut -c 1-80 | awk -v linbeg=336 -v linend=2000 '/<script/ && NR>linbeg && NR<linend { print NR"|"$0 }' | head -1 > $ofile
#						printf "BUGS_390\n";
#						fi
					fi

				done
			sqlite3 $db3 -header "select tsrc,type,id,linbeg,linend,lincnt,descr from $tbl"
			printf "$progid $dttm $j,$k BUGS_302 FINDS __ item=$item ==================\n";
			continue;
			done


#			db3="./ko.db3"; tbl="divs"; sql=""; fdir="../ht/ko/htm"; tdir="../ht/ko/htm"
#			find_names="*.htm"; find_path="../ht/ko/htm" maxdepth=1; type="f";
#			find_cmd="find $find_path -type f -maxdepth $maxdept -name  \"$find_names\""
#			select_cmd="sqlite3 $db3 \"select * from $tbl\""
#			printf "BUGS_294 function finds\n";
#			j=0; k=0; htmout=0; id=""
#			if [ "$2" != "go" ] && [ "$2" != "" ]; then 
#				id=$2; 
#				find_cmd="find $find_path -type f -maxdepth $maxdept -name  \"$id\""
#				select_cmd="sqlite3 $db3 \"select * from $tbl where id like '$id'\""
#				fi
#		
#		//	find_items=`$find_cmd`
#		//	select_items=`$select_cmd`
#			printf "$progid $dttm BUGS_300 FINDS find_cmd=$find_cmd\n";
#			printf "$progid $dttm BUGS_300 FINDS select_cmd=$select_cmd\n";
#			printf "$progid $dttm BUGS_309 FINDS id=$id db3=$db3 tbl=$tbl sql=$sql fdir=$fdir tdir=$tdir\n";
#			for item in $find_items; do
#				let j=j+1;
#				b64fil=`printf $item | sed -e "s:^:b64_:" | sed -e "s:.htm:.txt"`
#				id=`printf $item | sed -e "s:.htm::"`
#		
#				printf "$progid $dttm $j,$k BUGS_301 FINDS item=$item id=$id b64fil=$b64fil  ------------------\n";
#				if [ "$usrcmd" != "g" ]; then
#					read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
#					if [ "$usrcmd" == "q" ]; then exit; fi
#					if [ "$usrcmd" == "s" ]; then continue; fi
#					if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
#					if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
#					fi
#				if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
#					printf "$progid $dttm $j,$k BUGS_302 FINDS item=$item ==================\n";
#		
#					fi
#		
#				done
#			done

		printf "BUGS_390 FINDS_END\n";
		printf "$progid $dttm $j,$k BUGS_304 FINDS item=$item ==================\n";
		exit;
		fi # if [ "$1" == "finds" ] || [ "$1" == "finds" ]; then

	if [ "$1" == "go" ] || [ "$1" == "go" ]; then 
		printf "MSG_000 $progid $dttm $j,$k GO a1=$1 a2=$2 a3=$3  a4=GO \n"
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "go" ]; then 

	if [ "$1" == "go0" ] || [ "$1" == "go0" ]; then 
		printf "MSG_100 $progid $dttm $j,$k GO0 a1=$1 a2=$2 a3=$3 a4=$a4\n"
		exit;
		fi # if [ "$1" == "go0" ] || [ "$1" == "go0" ]; then 

	if [ "$1" == "go1" ] || [ "$1" == "go1" ]; then 
		printf "MSG_101 $progid $dttm $j,$k GO1 a1=$1 a2=$2 a3=$3 a4=$a4\n"
		exit;
		fi # if [ "$1" == "go1" ] || [ "$1" == "go1" ]; then 

	if [ "$1" == "go2" ] || [ "$1" == "go2" ]; then 
		printf "MSG_102 $progid $dttm $j,$k GO2 a1=$1 a2=$2 a3=$3 a4=$a4\n"
		exit;
		fi # if [ "$1" == "go2" ] || [ "$1" == "go2" ]; then  


	if [ "$1" == "apps" ] || [ "$1" == "app" ]; then 
		id=$2; file=$3;
		db3="ko.db3"; tbl="apps";
		printf "MSG_1010 $progid $dttm $j,$k APPS a1=$1 a2=$2 a3=$3 a4=$a4\n"
		if [ ! -f $db3 ]; then
			printf "MSG_1012 $progid $dttm $goflag $j,$k APPS NOTFOUND db3='$db3'\n"
			exit;
			fi
		if [ "$id" == "" ]; then
			printf "MSG_1011 $progid $dttm $goflag $j,$k APPS NOTFOUND id='$id'\n"
			sql="select * from $tbl"
			sqlite3 $db3 -header "$sql"
			exit;
			fi

		sql="select link from $tbl where id=='$id'"
		link=`sqlite3 $db3 "$sql"`
		if [ "$link" == "" ]; then
			printf "MSG_1012 $progid $dttm $goflag $j,$k APPS NOTFIND link=$link sql=$sql\n"
			exit
			fi

		printf "MSG_1012 $progid $dttm $goflag $j,$k APPS link=$link sql=$sql\n"

		syscmd_app="open $file -a \"$link\""
		printf "MSG_1013 $progid $dttm $goflag $j,$k APPS syscmd_app=$syscmd_app\n"
		if [ "$goflag" == "go" ]; then
			$syscmd_app
			exit;
			fi
		exit;
		fi # if [ "$1" == "apps" ] || [ "$1" == "app" ]; neht  


	if [ "$1" == "dls" ] || [ "$1" == "go" ]; then
		logfil="ko_dls.log";
		wlfil="ko_dls.wl"
		wlfil="../ht/yt/txt/ytlist_$yyyymmdd.psv"
		if [ ! -f $wlfil ]; then
			if [ ! -d $wlfil ]; then printf "$progid $dttm BUGS_100 NOTFOUND wlfil=$wlfil\n"; exit; fi
			exit;
			fi
		j=0; k=0;
	
	items_done="
	yt_georgrainalter_dominik_plangger_dont_you_take_it_too_bad|https://www.youtube.com/watch?v=TzxkPtydz5Y
	"
	items="
	yt_georgrainalter_dominik_plangger_speed_of_the_sound_of_loneliness_john_prine_cover_fenzl|https://www.youtube.com/watch?v=aPMoMmETUQ4
	yt_georgrainalter_dominik_plangger_save_the_last_dance_for_me_live2016|https://www.youtube.com/watch?v=gwaPaKR3SkE
	yt_georgrainalter_dominik_plangger_snowin_on_raton_cover_fenzl|https://www.youtube.com/watch?v=wQ3bszHO5jc
	yt_georgrainalter_dominik_plangger_fruhling|https://www.youtube.com/watch?v=hkTsySotahs&list=PLtw-cGZsmpqdXq3eQxjmVcsJZcToFPpd2
	yt_georgrainalter_dominik_plangger_operator_jim_crocer_cover_fenzl|https://www.youtube.com/watch?v=sLGbyEgYWGM
	yt_georgrainalter_dominik_plangger_if_i_needed_you
	yt_georgrainalter_dominik_plangger_i_remember_everything_douglas_linton_john_prine_cover|https://www.youtube.com/watch?v=qihTbqMRArE
	yt_georgrainalter_dominik_plangger_heimatland_balcontytv|https://www.youtube.com/watch?v=BxJG8586aJ0
	yt_georgrainalter_dominik_plangger_mai_maadele_mai_tschuurale_live_2017|https://www.youtube.com/watch?v=dBOaGAkPX9k
	"
	items=`cat $wlfil`;
		printf "$progid $dttm BUGS_100 HEAD $j,$k items_psv=$items_psv\n";
		for item in $items; do
			let j=j+1;
			grp=`printf $item | awk -F"|" '{ print $2 }'`	
			dt=`printf $item | awk -F"|" '{ print $3 }'`	
			url=`printf $item | awk -F"|" '{ print $4 }'`	
			syscmd="media-downloader -l \"$url\""
	
			printf "$progid $dttm BUGS_101 $j,$k ITEM=$item desc=$descr \nurl=$url \nsyscmd=$syscmd\n"
			printf "$progid $dttm BUGS_102 $j,$k syscmd=$syscmd ==================\n";
			if [ "$usrcmd" != "g" ]; then
				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
				if [ "$usrcmd" == "q" ]; then exit; fi
				if [ "$usrcmd" == "s" ]; then continue; fi
				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
				fi
	
			if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
				printf "$progid $dttm BUGS_102 GO $j,$k syscmd=$syscmd ==================\n";
				printf "$progid $dttm BUGS_102 GO $j,$k syscmd=$syscmd ==================\n" >> $logfil;
				media-downloader -l "$url"
	#			$syscmd
	#			if [ -f $db3 ]; then
	#				printf "BUGS_430 INSERT db3=$db3 sqlcmd=$sqlcmd\n";
	#				sqlite3  $db3 -header "$sql" > $psvfil
	#				fi
				fi
			done
		printf "$progid $dttm BUGS_103 TAIL $j,$k item=$item ==================\n";
		fi # [ "$1" == "dls" ] || [ "$1" == "go" ]; neht
	
	
	
		if [ "$1" == "mvs" ] || [ "$1" == "go" ]; then
			fdir="/Users/konet/Downloads"
			tdir="mp4/mp4_$yyyymmdd"
			tdir_mp4="mp4/mp4_$yyyymmdd"
			tdir_mp3="mp3/mp3_$yyyymmdd"
	
	
	
			printf "" >dls_cp.sh
			printf "" >dls_mp3.sh
			printf "" >dls_rm.sh
	
			printf "" >dls_cp_.sh
			printf "" >dls_mp3_.sh
			printf "" >dls_rm_.sh
	
			printf "" > dls_cp_go.sh
			printf "" >dls_mp3_go.sh
			printf "" >dls_rm_go.sh
	
	
	
	
			if [ ! -d $fdir ]; then printf "$progid $dttm BUGS_100 NOTFOUND fdir=$fdir\n"; exit; fi
			if [ ! -d $tdir_mp4 ]; then 
				printf "$progid $dttm BUGS_102 NOTFOUND tdir_mp4=$tdir_mp4\n"; 
				syscmd="mkdir $tdir_mp4"
				if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ]; then
					printf "$progid $dttm BUGS_103 GO MKDIR syscmd=$syscmd\n"; 
					$syscmd
					fi
				fi
			if [ ! -d $tdir_mp3 ]; then 
				printf "$progid $dttm BUGS_102 NOTFOUND tdir_mp3=$tdir_mp3\n"; 
				syscmd="mkdir $tdir_mp3"
				if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ]; then
					printf "$progid $dttm BUGS_103 GO MKDIR syscmd=$syscmd\n"; 
					$syscmd
					fi
				fi
	
	#		IFS='\n'
	#		syscmd_find="find $fdir -type f -name "*.mp4"
	#		fnams=`$syscmd_find`
	#		fnams=`find $fdir -name "*.mp4"`
	#		fnams=`find /Users/konet/Downloads -name "*.mp4" | sed -e "s:$:\n:"`
	# 		fnams="line1 line2 line3"
	#		fnams=`find /Users/konet/Downloads -name "*.mp4"`
	#		wlfil="dls_wl0.txt"
			wlfil="dls_wl.txt"
			fnams=`cat $wlfil`
	#		printf "BUGS_99 wlfil=$wlfil fnams=$fnams\n";
	
	# fnams_cnt=${#fnams[@]}
	# fnam0=${fnams[$j]}
	# fnam1=${fnams[1]}
	# fnam2=${fnams[2]}
	# printf "BUGS_100 fnams_cnt=$fnams_cnt fnams=$fnams\n"; 
	# printf "BUGS_101 fnams_cnt=$fnams_cnt\n"; 
	# printf "BUGS_102 fnam0=$fnam0\n"; 
	# printf "BUGS_101 fnam1=$fnam1\n"; 
	# printf "BUGS_102 fnam2=$fnam2\n"; 
	
	# for ((j = 0; j < ${#fnams[@]}; j++)); do
	# for fnam in $fnams; do
	# for fnam  in ${fnams[*]}; do
	# while [ $j -lt ${#fnams[#]} ]; do
#	fname=${fnams[$j]}
#	echo "BUGS_121 $j,$k FNAM=$fnam";
#	echo "BUGS_122 $j,$k FNAME=$fname";
#	let j=j+1
#	((j++))
#	done

#		read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
#			fnam=${fnams[$j]}
#			read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd


			j=0;k=0;n=0; usrcmd=""; last_usrcmd="" jlim=0;
# UGS_07 fnams=/Users/konet/Downloads/Suzy Morgan - Stuff that Works (Guy Clark cover) - Suzy & the Sissies.mp4=
#		for(( j=0; j<${#fnams[@]}; j++)); do
#			fnam=${fnams[$j]}


			dls_todo_sh="dls_todo.sh"; printf "" >> $dls_todo_sh;
			logfil="dls.log";
	
			jlim=`cat fnams | wc -l | awk '{ print $1 }'`
			wlfile="dls_wl.txt";
			fdir="/Users/konet/Downloads"; name="*.mp4"; 
			printf "BUGS_130 wlfile=$wlfile fdir=$fdir name=$name\n";
			if [ ! -d $fdir ]; then printf "BUGS_131 NOTFOUND fdir=$fdir\n"; exit; fi
	
	#		OLDIFS=$IFS; IFS='\n'
			OLDIFS=$IFS; IFS='|'
	
	#		fnams=`find $fdir -type f -name "$name" | sed -e "s:$:|\n:" > $wlfile`
			find $fdir -type f -name "$name" | sed -e "s:$:|:" > $wlfile
			fnams=`cat $wlfile`
			jlim=`cat $fnams |  wc -l | awk '{ print $1 }'`
	
	
	#		jlim=${#fnams[@]}
	#		linnum=0; f0=`awk -v linnum="$linnum" 'NR == linnum {print $0}' $wlfile`
	#		linnum=1; f1=`awk -v linnum="$linnum" 'NR == linnum {print $0}' $wlfile`
	#		linnum=2; f2=`awk -v linnum="$linnum" 'NR == linnum {print $0}' $wlfile`
	#		f0=${#fnams[0]}
	#		f1=${#fnams[1]}
	#		f2=${#fnams[2]}
	#		printf "BUGS_140 fnams=$fnams\n jlim=$jlim\n";
	#		printf "BUGS_140 f0=$f0\n jlim=$jlim\n";
	#		printf "BUGS_141 f1=$f1\n jlim=$jlim\n";
	#		printf "BUGS_142 f2=$f2\n jlim=$jlim\n";
	
			j=0; k=0; n=0; linnum=0; fnam="_fnam_"; tnam="_tnam_";
			logfil="dls.log"; dls_todo_sh="dls_todo.sh";
	
			for fnam in $fnams; do
				dttm=`date +"%Y%m%d_%H%M%X"`
				let j=j+1; 
				let k=k+1;
				fname="${fnam#"${fnam%%[![:space:]]*}"}"
	#			fnam=`awk -v linnum="$linnum" -F"|" 'NR == linnum {print $1 }' $wlfile`
	#			linnum=0; f0=`awk -v linnum="$linnum" 'NR == linnum {print $0}' $wlfile`
	
				tnam=$fnam;
				tnam=`printf $tnam | sed -e "s: :_:g"`
				tnam=`printf $tnam | sed -e "s:$fdir:$tdir:g"`
				tnam=`printf $tnam | tr -d '&' | tr -d '(' | tr -d ')' | tr -d ',' | tr -d "'"`
				tnam=`printf $tnam | tr -d '.'`
				tnam=`printf $tnam | sed -e "s:mp4$:.mp4:"`
				tnam=`printf $tnam | tr -d '⧸'`
				tnam=`printf $tnam | tr -d '＂'`
	
				tnam=`printf $tnam | sed -e "s:__:_:g"`
				tnam=`printf $tnam | sed -e "s:_-_:-:g"`
				tnam=`printf $tnam | tr 'A-Z' 'a-z'`
				fnam="${fnam#"${fnam%%[![:space:]]*}"}"
				tnam="${tnam#"${tnam%%[![:space:]]*}"}"
	
				tnam_mp4=$tnam;
				tnam_mp3=`printf $tnam_mp4 | sed -e "s:mp4:mp3:g"`
	
				printf "BUGS_188 fnam=$fnam\n";
				printf "BUGS_189 tnam=$tnam\n";
	# _⧸_j
	# _＂i
	# remove leading whitespace characters
	# var="${var#"${var%%[![:space:]]*}"}"
	# remove trailing whitespace characters
	# var="${var%"${var##*[![:space:]]}"}"   
	
	# \3f  \22 0d 0a
	#			tnam=`printf $tnam | xargs`
#			tnam=`printf $tnam | sed -e "s/ *$//`
#			fnam="${tnam#"${tnam%%[![:space:]]*}"}"
#			tnam="${tnam#"${tnam%%[![:space:]]*}"}"



				dls_todo_sh="dls_todo.sh"
				syscmd_mv="mv \"$fnam\" $tnam_mp4\n"
				syscmd_cp="cp \"$fnam\" $tnam_mp4\n"
				syscmd_mp3="ffmpeg -i \"$tnam_mp4\" $tnam_mp3\n"
				syscmd_rm="rm \"$fnam\"\n"
	
				printf "$syscmd_cp\n" >> $dls_todo_sh
				printf "$syscmd_mp3\n" >> $dls_todo_sh
				printf "# $syscmd_rm\n" >> $dls_todo_sh
	
	#			printf "BUGS_180 $j,$k,$n jlim=$jlim FNAM=$fnam\nTNAM=$tnam ========================\n"
				printf "BUGS_181 $j,$k,$n jlim=$jlim FNAM=$fnam ========================\n"
				printf "BUGS_181 $j,$k,$n jlim=$jlim FNAME=$fnam3 ========================\n"
				printf "BUGS_182 $j,$k,$n jlim=$jlim TNAM_MP4=$tnam_mp4 ========================\n"
				printf "BUGS_183 $j,$k,$n jlim=$jlim TNAM_MP3=$tnam_mp3 ========================\n"
	
	#			printf "BUGS_191 $j,$k,$n syscmd_mv=$syscmd_mv\n";
				printf "BUGS_192 $j,$k,$n syscmd_cp=$syscmd_cp\n";
				printf "BUGS_193 $j,$k,$n syscmd_mp3=$syscmd_mp3\n";
				printf "BUGS_194 $j,$k,$n syscmd_rm=$syscmd_rm\n";
	
				printf "$syscmd_cp\n" >> dls_cp.sh;
				printf "$syscmd_mp3\n" >> dls_mp3.sh;
				printf "$syscmd_rm\n" >> dls_rm.sh;
	
	# ffmpeg -i filename.mp4 filename.mp3
	# ffmpeg -i video.mp4 -b:a 192K -vn music.mp3
	
	
	#			syscmd_mp3="ffmpeg -i $tnam $tnam_mp3"
	#			printf "$progid $dtmm BUGS_150 $j,$k fnam=$fnam tnam=$tnam tnam_mp3=$tnam_mp3\n";
				printf "$progid $dtmm BUGS_150 $j,$k n=$n jlim=$jlim usrcmd=$usrcmd last_usrcmd=$last_usrcmd\n";
				if [ "$usrcmd" != "g" ]; then
					last_usrcmd=$usrcmd
					read -e -p "+n -n :n .n q=quit s=skip g=go enter=continue:  " usrcmd
					printf "BUGS_150 $j,$k, n=$n jlim=$jlim usrcmd=$usrcmd last_usrcmd=$last_usrcmd\n";
					if [ "$usrcmd" == "q" ]; then exit; fi
					if [ "$usrcmd" == "s" ]; then continue; fi
					if [ "$usrcmd" == "g" ]; then usrcmd="g"; fi
					if [[ "$usrcmd" == "+"* ]]; then
						n=`echo "$usrcmd" |  sed -e "s:+::";`
						if [ "$n" == "" ]; then n=1; fi
						let k=k+n;
						if [ "$k" -gt "$jlim" ]; then k=0; fi
						printf "BUGS_151 +n $j,$k n=$n jlim=$jlim usrcmd=$usrcmd last_usrcmd=$last_usrcmd\n";
#						continue;
						fi
					if [[ "$usrcmd" == "-"* ]]; then
#						n=`printf "$usrcmd" | cut -c 2-40`
#						n=`echo "$usrcmd" |  sed -e "s:-::";`
						printf "BUGS_170 $j,$k usrcmd=$usrcmd N=$n\n"
#						if [ "$n" == "" ]; then n=1; fi
						let k=k-n;
						printf "BUGS_171 $j,$k usrcmd=$usrcmd N=$n\n"
						if [ "$k" -lt "0" ]; then k=$jlim; fi
						printf "BUGS_172 -n $j,$k n=-$n jlim=$jlim usrcmd=$usrcmd last_usrcmd=$last_usrcmd\n";
#						continue;
						fi
					if [[ "$usrcmd" == ":"* ]]; then
#						n=`printf $usrcmd | cut -c 2-40`
						n=`echo "$usrcmd" |  sed -e "s/://";`
						if [ "$n" == "" ]; then n=1; fi
						if [ "$n" == "" ]; then n=1; fi
						if [ "$n" -gt "$jlim" ]; then n=0; fi
						if [ "$n" -lt "0" ]; then n=$jlim; fi
						j=$n
						printf "BUGS_153 :n $j,$k n=$n jlim=$jlim usrcmd=$usrcmd last_usrcmd=$last_usrcmd\n";
#						continue;
						fi
	
					if [[ "$usrcmd" == "."* ]]; then
#						n=`printf $usrcmd | cut -c 2-40`
#						n=`echo "$usrcmd" |  sed -e "s/://";`
						if [ "$n" == "" ]; then n=1; fi
						k=$j
						if [ "$k" -gt $jlim ]; then k=0; fi
						printf "BUGS_154 . $j,$k n=$n jlim=$jlim usrcmd=$usrcmd last_usrcmd=$last_usrcmd\n";
#						continue;
						fi
	
#					if [[ "$usrcmd" =~ "+"* ]]; then
#						n=`printf $usrcmd | cut -c 2-40`
#						n=`echo "$usrcmd" |  sed -e "s/+//";`
#						if [ "$n" == "" ]; then n=1; fi
#						let k=k+n;
#						if [ "$k" -gt $jlim ]; then k=0; fi
#						printf "BUGS_161 ~ +n $j,$k n=$n jlim=$jlim usrcmd=$usrcmd last_usrcmd=$last_usrcmd\n";
#						continue;
#						fi
	
#					if [[ "$usrcmd" =~ "-"* ]]; then
#						n=`printf $usrcmd | cut -c 2-40`
#						n=`echo "$usrcmd" |  sed -e "s/-//";`
#						if [ "$n" == "" ]; then n=1; fi
#						let k=k-n;
#						if [ "$k" -gt "$jlim" ]; then k=0; fi
#						printf "BUGS_162 ~ -n $j,$k n=$n jlim=$jlim usrcmd=$usrcmd last_usrcmd=$last_usrcmd\n";
#						continue;
#						fi
	
#					if [[ "$usrcmd" =~ ":"* ]]; then
#						n=`printf $usrcmd | cut -c 2-40`
#						n=`echo "$usrcmd" |  sed -e "s/://";`
#						if [ "$n" == "" ]; then n=1; fi
#						let k=n;
#						if [ "$k" -gt "$jlim" ]; then k=0; fi
#						if [ "$k" -lt "0" ]; then k=$jlim; fi
#						printf "BUGS_163 ~ :n $j,$k n=$n jlim=$jlim usrcmd=$usrcmd last_usrcmd=$last_usrcmd\n";
#						continue;
#						fi
	
	
#					if [ "$usrcmd" == "" ]; then 
#						usrcmd="prompt"; 
#						usrcmt=$last_usrcmd;
#						fi
					fi
	
	
	
				if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
#					printf "$progid $dttm BUGS_310 GO_MV $j,$k n=$n  syscmd_mv=$syscmd_mv ==================\n" >> $logfil
#					echo "$syscmd_mv\n" >> dls_gomv.sh
#					$syscmd_mv
	
	
	
	
	
					printf "$progid $dttm BUGS_311 GO_CP $j,$k n=$n syscmd_cp=$syscmd_cp pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqp\n"
	
					printf "$syscmd_cp" >> dls_cp_go.sh
					$syscmd_cp
	
	
	
					printf "$progid $dttm BUGS_312 GO_MP3 $j,$k n=$n syscmd_mp3=$syscmd_mp3 pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqp\n"
					printf "$syscmd_mp3\n" >> dls_mp3_go.sh
					$syscmd_mp3
	
	
#					printf "$progid $dttm BUGS_313 GO_RM $j,$k n=$n syscmd_rm=$syscmd_rm pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqp\n"
#					printf "$syscmd_rm\n" >> dls_rm_go.sh
#					$syscmd_rm
	
	
#					if [ -f $db3 ]; then
#						printf "BUGS_430 INSERT db3=$db3 sqlcmd=$sqlcmd\n";
#						sqlite3  $db3 -header "$sql" > $psvfil
#						fi
					fi
				done
	
			chmod 755 dls_cp_go.sh
			chmod 755 dls_mp3_go.sh
			chmod 755 dls_rm_go.sh
	
			chmod 755 dls_cp.sh
			chmod 755 dls_mp3.sh
			chmod 755 dls_rm.sh
	
			chmod 755 dls_cp_.sh
			chmod 755 dls_mp3_.sh
			chmod 755 dls_rm_.sh
	
			./dls_cp_go.sh
			./dls_mp3_go.sh
	
			vi $dls_todo_sh
			ls -lat $tdir_mp4/*.mp4
			ls -lat $tdir_mp3/*.mp3
	
			printf "$progid $dttm BUGS_103 TAIL $j,$k item=$item ==================\n";
			fi # [ "$1" == "mvs" ] || [ "$1" == "go" ]; neht
	

	if [ "$1" == "items" ] || [ "$1" == "go" ]; then
		j=0; k=0; n=0; fsrc=""; db3="ko.db3" tbl="items"; sql="select * from $tbl";
		fsrcs="../ht/ko/ko.php ../ht/index.html ../ht/ko/wz.html"
		fsrcs="ko.sh ko.py ../ht/ko/ko.php ../ht/index.html ../ht/ko/index.html ../ht/ko/wz.html ../ht/kd/index.html"

skip_types="
py|^def |^def |kludge_py
sh|if \[ \"\$1\" == |fi # \[ \"\$1\" == |kludge_sh
"
types_psv="
type|headmark|tailmark|kludge
php|^function |^function |kludge_php
style|<style |</style |kludge_style
script|<script |</script |kludge_script
div|<div |</div |kludge_div
list|\` = |\`; |kludge_list
"


		fsrc="_fsrc"; type="_type_"; mask="_mask_"; linbeg="0"; linend="99999";
		awkfil="items_awk_$dttm.txt"; 
		headmark=""; tailmark="";

		fsrc="_fsrc_"; type="_type_"
		printf "" > $awkfil;
		for fsrc in $fsrcs; do
			if [ ! -f $fsrc ]; then printf "BUGS_31 NOTFOUND fsrc=$fsrc\n"; continue; fi
			if [ "$fsrc" == "fsrc" ]; then printf "BUGS_32 LABEL fsrc=$fsrc\n"; continue; fi

			let j=j+1; k=0;
			suffix=`printf $fsrc | awk -F"." '{ print $3 }'`

			printf "$progid $dttm BUGS_100 $j,$k FSRC=$fsrc TYPE=$type mask=$mask ================\n";
			for type_psv in $types_psv; do
				let k=k+1;
				type=`printf $type_psv | awk -F"|" '{ print $1 }'`
				if [ "$type" == "" ]; then continue; fi
				if [ "$type" == "" ]; then printf "BUGS_33 TYPE_BLANK type=$type\n"; continue; fi
				if [ "$type" == "type" ]; then printf "BUGS_34 TYPETYPE type=$type\n"; continue; fi

				headmark=`printf $type_psv | awk -F"|" '{ print $2 }'`
				tailmark=`printf $type_psv | awk -F"|" '{ print $3 }'`
				kludge=`printf $type_psv | awk -F"|" '{ print $4 }'`
				mask=$headmark;	


#				if [[ "$type" == "#"* ]]; then 
#					printf "$progid $dttm BUGS_41 SKIPTYPE1 type=$type\n";
#					continue; 
#					fi
#				if [[ "$type" =~ "^#" ]]; then
#					printf "$progid $dttm BUGS_42 SKIPTYPE2 type=$type\n";
#					continue
#					fi

				if [ "$suffix" == "py" ] && [ "$type" != "py" ]; then continue; fi
				if [ "$suffix" == "sh" ] && [ "$type" != "sh" ]; then continue; fi
				if [ "$suffix" == "php" ] && [ "$type" != "php" ]; then continue; fi

#				if [ "$suffix" == "py" ] && [ "$type" == "py" ]; then continue; fi
#				if [ "$suffix" == "sh" ] && [ "$type" == "sh" ]; then continue; fi
#				if [ "$suffix" == "html" ] && [ "$type" == "style" ]; then continue; fi
#				if [ "$suffix" == "html" ] && [ "$type" == "script" ]; then continue; fi
#				if [ "$suffix" == "html" ] && [ "$type" == "div" ]; then continue; fi
#				if [ "$suffix" == "html" ] && [ "$type" == "div" ]; then continue; fi

				
				printf "$progid $dttm BUGS_70 $j,$k FSRC=$fsrc TYPE=$type mask=$mask suffix=$suffix\n";


				cat $fsrc | awk -v fsrc="$fsrc" -v mask="$mask" -v linbeg="$linbeg" -v linend="$linend" '/mask/ && NR>linbeg && NR<=linend { print NR"|"$0"|"fsrc"|"mask"|"linbeg"|"linend }' >> $awkfil


				awktxt=`cat $fsrc | awk -v fsrc="$fsrc" -v mask="$mask" -v linbeg="$linbeg" -v linend="$linend" '/mask/ && NR>linbeg && NR<=linend { print NR"|"$0"|"fsrc"|"mask"|"linbeg"|"linend }'`

				printf "$progid $dttm BUGS_80 $j,$k FSRC=$fsrc TYPE=$type mask=$mask awktxt=$awktxt\n";
				done
			done 

		head -5 $awkfil
		tail -5 $awkfil
		wc -l $awkfil

		
#		fsrc="ko.sh"; searchtext="if [ \"\$1\" == " awkfil="awkout.txt"
#		mask="mvs"; linbeg=0; linend=99999;
		awkcnt=`cat $awktxt | wc -l | awk '{ print $1 }'`
		printf "BUGS_70 FSRC=$fsrc MASK=$mask awktxt=\n$awktxt\n";
	
		exit;
		fi


	if [ "$1" == "items2db" ] || [ "$1" == "go" ]; then
		itemsfile="items_awk_20240301_085532.txt"
		j=0; k=0; n=0;
		if [ ! -f $itemsfile ]; then 
			printf "$progid $dttm BUGS_81 $j,$k items2db NOTFOUND itemsfile=$itemsfile\n"; 
			exit; 
			fi

		printf "$progid $dttm BUGS_82 $j,$k items2db ___FOUND itemsfile=$itemsfile\n"; 

#		printf "BUGS_91 itemsfile=$itemsfile\n";
#		head -5 $itemsfile
#		tail -5 $itemsfile
#		printf "BUGS_92 itemsfile=$itemsfile\n";

#		OLDIFS=$IFS; IFS='\n';
		items=`awk '{print $0}' $itemsfile`
		awk '{print  $0}' $itemsfile > "items_awk0.txt"
		items=`cat items_awk0.txt`
#		itemslen=`awk 'END{print NR}' $items`
		itemsflen=`awk 'END{print NR}' $itemsfile`
		itemslen=${#items[@]}
		item0=${#items[0]}
		item1=${#items[1]}
		item2=${#items[2]}
		printf "$progid $dttm BUGS_100 $j,$k items2db itemslen=$itemslen itemsflen=$itemsflen itemsfile=$itemsfile\n";
		printf "BUGS_110 item0=$item0\n";
		printf "BUGS_111 item1=$item1\n";
		printf "BUGS_112 item2=$item2\n";
		printf "BUGS_113 itemslen=$itemslen\n";
		printf "BUGS_114 itemsfilelen=$itemsfilelen\n";



#		exit;
#		OLDIFS=$IFS; IFS='\n';
#		for [ rowid=0; rowid< $itemslim; rowid++ ];  do
		rowid=0;
		if [ ! -f $itemsfile ]; then printf "BUGS_200 NOTFOUND itemsfile=$itemsfile\n"; exit; fi

#
#		while rowid -ge 0 && rowid -le $itemsfilelen; do
		yyyymmdd_hh=`date +"%Y%m%d_%H"`
		awkfil="items_awk_$yyyymmdd_hh.txt"
		printf "" > $awkfil
		items=`cat $itemsfile`
		for itemdata in $items;  do
			awk -v rowid="$rowid" 'NR == rowid { print $0 }' $itemsfile
			awk -v rowid="$rowid" 'NR == rowid { print $0 }' $itemsfile >> $awkfil
			awk -v rowid="$rowid" -F"|" 'NR == rowid { print $1 }' $itemsfile
			awk -v rowid="$rowid" -F"|" 'NR == rowid { print $1 }' $itemsfile >> $awkfil
			itemline=`awk -v rowid="$rowid" 'NR == rowid { print $0 }' $itemsfile`
			linbeg=`awk -v rowid="$rowid" -F"|" 'NR == rowid { print $1 }' $itemsfile`
			headmark=`awk -v rowid="$rowid" -F"|" 'NR == rowid { print $2 }' $itemsfile`
			fsrc=`awk -v rowid="$rowid" -F"|" 'NR == rowid { print $3 }' $itemsfile`
			item=`awk -v rowid="$rowid" -F"|" 'NR == rowid { print $4 }' $itemsfile`

			if [ "$linbeg" == "" ]; then printf "BUGS_155 SKIP_LINBEG $j,$k, rowid=$rowid linbeg=$linbeg"; continue; fi
			if [ "$fsrc" == "" ]; then printf "BUGS_156 SKIP_FSRC $j,$k, rowid=$rowid linbeg=$linbeg"; continue; fi


			printf "$progid $dttm BUGS_201 $j,$k rowid=$rowid items2db db3=$db3 tbl=$tbl $rowid ITEM=$item fsrc=$fsrc linbeg=$linbeg headmark=$headmark\n"
			sql="insert or replace into $tbl (item,fsrc,headmark,linbeg) values ('$item','$fsrc','$headmark','$linbeg');"

			printf "BUGS_202 $progid $dttm $j,$k rowid=$rowid item=$item itemline=$itemline\n";
			printf "BUGS_203 $progid $dttm $j,$k rowid=$rowid db3=$db3 itemdata=$itemdata\n";
			printf "BUGS_204 $progid $dttm $j,$k rowid=$rowid db3=$db3 fsrc=$fsrc\n";
			printf "BUGS_205 $progid $dttm $j,$k rowid=$rowid db3=$db3 linbeg=$linbeg\n";
			printf "BUGS_206 $progid $dttm $j,$k rowid=$rowid db3=$db3 item=$item\n";
			printf "BUGS_207 $progid $dttm $j,$k rowid=$rowid db3=$db3 sql=$sql\n";
			if [ "$usrcmd" != "g" ]; then
				read -e -p "q=quit s=skip g=go enter=continue +-.:  " usrcmd
				if [ "$usrcmd" == "q" ]; then exit; fi
				if [ "$usrcmd" == "s" ]; then continue; fi
				if [ "$usrcmd" == "g" ]; then usrcmd="g"; fi
				if [[ "$usrcmd" == "+"* ]]; then
					n=$usrcmd;
					if [ $n -gt $itemslim ]; then n=0; fi
					let rowid=rowid$n
					continue
					fi
				if [[ "$usrcmd" == "-"* ]]; then
					n=$n;
					if [ $n -lt 0 ]; then n=$itemslim; fi
					let rowid=rowid$n
					continue
					fi
				if [[ "$usrcmd" == ":"* ]]; then
					n=`printf $usrcmd | tr -d ':'`
					if [ $n -lt 0 ]; then n=$itemslim; fi
					if [ $n -gt $itemslim ]; then n=0; fi
					let rowid=$n
					continue
					fi
				if [[ "$usrcmd" == "."* ]]; then
					rowid=rowid-1
					continue
					fi
				if [[ "$usrcmd" =~ "jk"* ]]; then
					printf "BUGS_231 JK $progid $dttm $j,$k  =~ rowid=$rowid usrcmd=$usrcmd\n";
					read -e -p "q=quit s=skip enter=continue:  " usrcmd1
					if [ "$usrcmd1" == "q" ]; then exit; fi
					if [ "$usrcmd1" == "g" ]; then
						printf "BUGS_232 JK $progid $dttm $j,$k rowid=$rowid DOSOMETHING4jk\n";
						continue;
						fi
					if [ "$usrcmd1" == "s" ]; then
						printf "BUGS_233 JK $progid $dttm $j,$k rowid=$rowid SKIP\n";
						continue;
						fi
					printf "BUGS_234 JK $progid $dttm $j,$k rowid=$rowid skip\n";
					continue;
					fi
				if [[ "$usrcmd" =~ "sk"* ]]; then
					printf "BUGS_241 SK $progid $dttm $j,$k rowid=$rowid  =~ rowid=$rowid usrcmd=$usrcmd\n";
					read -e -p "q=quit s=skip enter=continue:  " usrcmd1
					if [ "$usrcmd1" == "q" ]; then exit; fi
					if [ "$usrcmd1" == "g" ]; then
						printf "BUGS_242 SK $progid $dttm $j,$k rowid=$rowid DOSOMETHING4sk\n";
						continue;
						fi
					if [ "$usrcmd1" == "s" ]; then
						printf "BUGS_243 SK $progid $dttm $j,$k rowid=$rowid SKIP\n";
						continue;
						fi
					printf "BUGS_244 SK $progid $dttm $j,$k rowid=$rowid skip\n";
					continue;
					fi

				if [ "$usrcmd" == "" ]; then 
#					usrcmd="prompt"; 
					let rowid=rowid+1
					let j=j+1
					continue
					fi
				fi



			if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ]; then
				printf "BUGS_202 $progid $dttm $j,$k rowid=$rowid items2db GO_SQL db3=$db3 sql=$sql\n"
				sqlite3 $db3 "$sql"
				fi
			printf "BUGS_220 $progid $dttm $j,$k rowid=$rowid items2db ITEM=$item\n";

			let rowid=rowid+1
			let j=j+1;
			let k=k+1;
			done

		sqlite3 $db3 -header "select * from $tbls"
		printf "BUGS_230 $progid $dttm $j,$k rowid=$rowid items2db\n";
		exit;

		fi # [ "$1" == "items" ] || [ "$1" == "go" ]; neht






	if [ "$1" == "db3s" ] || [ "$1" == "go" ]; then
#		db3s=`cat find_db3s.txt | head -10`
		db3s=`cat find_db3s.txt`
		db3mstr="/Volumes/ka1tbr2/pj/ko.db3"
		if [ ! -f $db3mstr ]; then
			printf "BUGS_100 $progid $dttm NOTFOUND db3mstr=$db3mstr\n";
			exit;
			fi
	
		db3="_db3_"; tbl="_tbl_"; label="_label_", lincnt=0;
		j=0; k=0;
		for db3 in $db3s; do
			if [ ! -f $db3mstr ]; then
				printf "BUGS_200 $progid $dttm NOTFOUND db3=$db3\n";
				continue;
				fi
			let j=j+1
			printf "BUGS_100 $j,$k db3=$db3\n";
	#		tbls=`sqlite3 $db3 ".tables" | awk '-v db3="$db3" -v tbl="$1" { print "insert into db3 (id,item) values("db3"|"$1" )'"`
			tbls=`sqlite3 $db3 ".tables" | awk '{ print $1}'`
			for tbl in $tbls; do
				let k=k+1;
				printf "BUGS_101 $j,$k db3=$db3 tbl=$tbl\n";
				tblflds=`sqlite3 $db3 -header "select * from $tbl limit 1" | head -1`
				tblcnt=`sqlite3 $db3 -header "select count(*)  from $tbl"`
				sqlins="insert or replace into db3s (db3,tbl,label,lincnt) values ('$db3','$tbl','$tblflds','$tblcnt')";
	
	
				if [ "$usrcmd" != "g" ]; then
					read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
					if [ "$usrcmd" == "q" ]; then exit; fi
					if [ "$usrcmd" == "s" ]; then continue; fi
					if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
					if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
					fi
	
				if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
	#				printf "$progid $dttm $j,$k BUGS_390 FINDS GO id=$id ofile=$ofile linbeg=$linbeg linend=$linend item=$item ==================\n";
					if [ -f $db3 ]; then
						printf "BUGS_430 INSERT db3=$db3 sqlcmd=$sqlcmd\n";
	#					sqlite3  $db3 -header "$sql" > $psvfil
						sqlite3 $db3mstr "$sqlins"
	#					sqlite3 $db3mstr -header "select * from db3s"
						fi
					fi
				done
			done
		sqlite3 $db3mstr -header "select * from db3s"
		fi # [ "$1" == "db3s" ] || [ "$1" == "go" ]; neht
	
	if [ "$1" == "todos" ] || [ "$1" == "todos" ]; then 
		printf "MSG_201 $progid $dttm $j,$k TODOS a1=$1 a2=$2 a3=$3 a4=$a4\n"
		db3="ko.db3"; tbl="ko"; htmout=""; i=0; j=0; k=0;
		options=""; usrcmd=""; syscmd=""; sqlcmd=""; dbcmd=""; fscmd=""; txcmd=""
		fsrc="fsrc.txt"; tsrc="tsrc.txt";
		src=""; dir=""; nam=""; txt=""; tbl="";
		fsrc=""; fdir=""; fnam=""; ftxt=""; ftbl="";
		tsrc=""; tdir=""; tnam=""; ttxt=""; ttbl="";
		if [ "$2" != "" ] & [ "$2" != "go" ]; then options=$2; fi

		if [ ! -f $db3 ]; then printf "ERR_101 $progid $dttm $j,$k TODOS NOTFOUND db3=$db3\n"; exit; fi
		if [ ! -f $fsrc ]; then printf "ERR_101 $progid $dttm $j,$k TODOS NOTFOUND fsrc=$fsrc\n"; exit; fi

		if [ ! -f $tsrc ]; then printf "ERR_101 $progid $dttm $j,$k TODOS NOTFOUND tsrc=$tsrc\n"; exit; fi
		tbl="files" 
		tbl="kolists";
#		tbl_status=`sqlite3 $db3 ".tables" | awk '/$tbl/ { print $1 }'`
#		if [ ! $tbl_status ]; then 
#			printf "ERR_101 $progid $dttm $j,$k TODOS db3=$db3 NOTFOUND_TBL tbl=$tbl tbl_status=$tbl_status\n"; 
#			exit;
#			fi
#		else
#			printf "MSG_101 $progid $dttm $j,$k TODOS db3=$db3 ___FOUND_TBL tbl=$tbl tbl_status=$tbl_status\n"; 
#			fi

flds_psv="id|fsrc|tsrc|txt|kludge"
items_psv="
id|fsrc|tsrc|txt
id1|fsrc1|tsrc1|txt
id2|fsrc2|tsrc2|txt
id3|fsrc3|tsrc3|txt
"
flds="id,fsrc,tsrc,txt,kludge"; 
vals="'$id','$fsrc','$tsrc','$txt','$kludge'"

options="itemstx"
options="itemsfs"
options="itemsdb"; 
options="itemsfs"
tmpfil="ko.tmp";
		itemsdb="_itemsdb_" itemsfs="_itemsfs_" itemstx="_itemstx_"
		if [ "$options" == "itemsdb" ]; then
			sql="select * from $tbl"
			sqlcmd="sqlite3 $db3 -header \"$sql\""
#			sqlite3 $db3 "$sql" > $tmpfil
#			itemsdb=`cat $tmpfil`
			itemsdb=`sqlite3 $db3 "$sql"`
			printf "BUGS_201 sqlcmd=sqlite3 $db3 \"$sql\" itemsdb=$itemsdb\n";
			itemsdb_len=0;
			if [ "$itemsdb_len" != "" ]; then itemsdb_len=`printf $itemsdb | awk -F"\n" '{print NR}'`; fi
			items=$itemsdb; items_len=$itemsdb_len;
			printf "BUGS_201 $progid $dttn $j,$j TODOS ITEMSDB db3=$db3 tbl=$tbl itemdb_len=$itemdb_len itemdb=$itemdb\n"
			fi
		if [ "$options" == "itemsfs" ]; then
			dir="./htm"; nam="*.htm";
			itemsfs=`find $dir -type f -maxdepth 1 -name "$nam"`
			printf "BUGS_202 itemsfs=$itemsfs\n"
			itemsfs_len=`cat $itemsfs | awk '{ print NR}'`
			items=$itemsfs; items_len=$itemsfs_len;
			printf "BUGS_202 $progid $dttn $j,$j TODOS ITEMSDB dir=$dir nam=$nam itemfs_len=$itemfs_len itemfs=$itemfs\n"
			fi
		printf "BUGS_203 $progid $dttn $j,$j TODOS ITEMSDB db3=$db3 tbl=$tbl items_len=$items_len items=$items\n"
		printf "BUGS_203 $progid $dttn $j,$j TODOS ITEMSDB db3=$db3 tbl=$tbl items_len=$items_len\n"
		printf "BUGS_203 $progid $dttn $j,$j TODOS ITEMSFS dir=$dir nam=$nam items_len=$items_len items=$items\n"
		printf "BUGS_203 $progid $dttn $j,$j TODOS ITEMSFS dir=$dir nam=$nam items_len=$items_len\n"

		id="ID"; fsrc="fsrc.txt"; tsrc="tsrc.txt"; txt="_TEXT_"; kludge="_KLUDGE_"; rowid=0
		syscmd_ls="ls -lat $fdir"; syscmd_find="find $fdir -type f -name '$fnam'"
		syscmd=$syscmd_find
		sql_sel="select from $tbl"
		sql_ins="insert or replace into $tbl ($flds) values ($vals)"
		sql_upd="update $tbl set id='$id' where rowid='$rowid'"
		sql_del="delete from $tbl where rowid='$rowid'"
		sql=$sql_sel
		sqlcmd="sqlite3 $db3 \"$sql\""

		for item in $items; do
			let j=j+1
			if [ j -gt 100 ]; then break; fi
			id=`printf $item | awk -F"|" '{ print $1 }'`
			fsrc=`printf $item | awk -F"|" '{ print $2 }'`
			tsrc=`printf $item | awk -F"|" '{ print $3 }'`
			txt=`printf $item | awk -F"|" '{ print $4 }'`
			kludge=`printf $item | awk -F"|" '{ print $5 }'`

			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen ========================================\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen ----------------------------------------\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen ID=$id FSRC=$fsrc TSRC=$tsrc TXT=$txt kludge=$kludge\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen ITEM=$item\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen flds_psv=$flds_psv\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen ----------------------------------------\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen src=$src dir=$dir nam=$nam txt=$txt\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen fsrc=$fsrc fdir=$fdir fnam=$fnam ftxt=$ftxt\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen tsrc=$tsrc tdir=$tdir tnam=$tnam ttxt=$ttxt\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen ----------------------------------------\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen syscmd=$syscmd\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen ----------------------------------------\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen sqlcmd=$sqlcmd\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen sql_sel=$sql_sel\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen sql_ins=$sql_ins\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen sql_upd=$sql_upd\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen sql_del=$sql_del\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen ----------------------------------------\n"
			printf "$progid $dttm $j,$k MSG_100 TODOS ilen=$ilen bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"
			if [ "$usrcmd" != "g" ]; then
					read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
					if [ "$usrcmd" == "q" ]; then exit; fi
					if [ "$usrcmd" == "s" ]; then continue; fi
					if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
					if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
					fi
			if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
				printf "$progid $dttm $j,$k MSG_300 TODOS GO ilen=$ilen pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
				printf "$progid $dttm $j,$k MSG_301 TODOS GO SQLCMD sqlcmd=$sqlcmd ========================================\n"
				`$sqlcmd`;
				printf "$progid $dttm $j,$k MSG_302 TODOS GO SYSCMD ----------------------------------------\n"


				printf "$progid $dttm $j,$k MSG_302 TODOS GO SYSCMD syscmd=$syscmd ========================================\n"
				`$syscmd`;
				printf "$progid $dttm $j,$k MSG_302 TODOS GO SYSCMD ----------------------------------------\n"
				printf "$progid $dttm $j,$k MSG_300 TODOS GO ilen=$ilen bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"
				fi
			done	
		printf "$progid $dttm $j,$k MSG_300 TODOS GO ilen=$ilen bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"
		exit;
		fi # if [ "$1" == "todos" ] || [ "$1" == "todos" ]; then 

	if [ "$1" == "todo" ] || [ "$1" == "todo" ]; then 
		printf "MSG_202 $progid $dttm $j,$k TODO a1=$1 a2=$2 a3=$3 a4=$a4 \n"
		exit;
		fi # if [ "$1" == "todo" ] || [ "$1" == "todo" ]; then 

	if [ "$1" == "tododb" ] || [ "$1" == "tododb" ]; then 
		printf "MSG_203 $progid $dttm $j,$k TODODB a1=$1 a2=$2 a3=$3 a4=$a4 \n"
		exit;
		fi # if [ "$1" == "tododb" ] || [ "$1" == "tododb" ]; then 

	if [ "$1" == "todofs" ] || [ "$1" == "todofs" ]; then 
		printf "MSG_204 $progid $dttm $j,$k TODOFS a1=$1 a2=$2 a3=$3 a4=$a4 \n"
		exit;
		fi # if [ "$1" == "todofs" ] || [ "$1" == "todofs" ]; then 

	if [ "$1" == "todotx" ] || [ "$1" == "todotx" ]; then 
		printf "MSG_205 $progid $dttm $j,$k TODOTX a1=$1 a2=$2 a3=$3 a4=$a4\n"
		exit;
		fi # if [ "$1" == "todotx" ] || [ "$1" == "todotx" ]; then 

	if [ "$1" == "awks" ] || [ "$1" == "awks" ]; then 
		printf "MSG_206 $progid $dttm $j,$k AWKS a1=$1 a2=$2 a3=$3 a4=$a4\n"
		exit;
		fi # if [ "$1" == "awks" ] || [ "$1" == "awks" ]; then 

	if [ "$1" == "fors" ] || [ "$1" == "fors" ]; then 
		printf "MSG_207 $progid $dttm $j,$k FORS a1=$1 a2=$2 a3=$3 a4=$a4 \n"
		exit;
		fi # if [ "$1" == "fors" ] || [ "$1" == "fors" ]; then 

	if [ "$1" == "b64s" ] || [ "$1" == "b64s" ]; then 
		printf "MSG_208 $progid $dttm $j,$k B64S a1=$1 a2=$2 a3=$3 a4=$a4\n"
		exit;
		fi # if [ "$1" == "b64s" ] || [ "$1" == "b64s" ]; then 

	if [ "$1" == "bs4" ] || [ "$1" == "bs4" ]; then 
		printf "MSG_209 $progid $dttm $j,$k BS4 a1=$1 a2=$2 a3=$3 a4=$a4\n"
		exit;
		fi # if [ "$1" == "bs4" ] || [ "$1" == "bs4" ]; then 


	if [ "$1" == "csv2jsn" ] || [ "$1" == "csv2jsn" ]; then
		csvfil="ko.csv"; jsnfil="ko.json";
		if [ "$2" != "" ]; then csvfil=$2; fi
		if [ "$3" != "" ]; then jsnfil=$3; fi
		printf "$progid $dttm CSV2JSON csvfil=$csvfl jsnfil=$jsnfil\n"
		if [ ! -f $csvfil ]; then printf "$progid $dttm CSV2JSON NOTFOUND csvfil=$csvfl\n"; exit; fi
		if [ -f $jsnfil ]; then printf "$progid $dttm CSV2JSON ___FOUND jsnfil=$jsnfil\n"; exit; fi

		cat $csvfil | python -c 'import csv, json, sys; print(json.dumps([dict(r) for r in csv.DictReader(sys.stdin)]))' > $jsnfil
		if [ -f $jsnfil ]; then vi $jsnfil; printf "vi $jsnfil\n"; fi
		exit;
		fi # if [ "$1" == "csv2jsn" ] || [ "$1" == "csv2jsn" ]; then

	if [ "$1" == "jsn2csv" ] || [ "$1" == "jsn2csv" ]; then
		jsnfil="ko.json"; csvfil="ko.csv"; 
		if [ "$2" != "" ]; then jsnfil=$2; fi
		if [ "$3" != "" ]; then csvfil=$3; fi
		printf "$progid $dttm JSN2CSV jsnfil=$jsnfil csvfil=$csvfil\n"
		if [ ! -f $jsnfil ]; then printf "$progid $dttm JSN2CSV NOTFOUND jsnfil=$jsnfil\n"; exit; fi
		if [ -f $csvfil ]; then printf "$progid $dttm JSN2CSV ___FOUND csvfil=$csvfil\n"; exit; fi

		cat $jsnfil | jq '.[]| join(",")' > $csvfil
		vi $csvfil


#		cat $csvfil | python -c 'import csv, json, sys; print(json.dumps([dict(r) for r in csv.DictReader(sys.stdin)]))' > $jsnfil
		if [ -f $csvfil ]; then vi $csvfil; printf "vi $csvfil\n"; fi
		exit;
		fi # [ "$1" == "jsn2csv" ] || [ "$1" == "jsn2csv" ]; then

	if [ "$1" == "items" ] || [ "$1" == "items" ]; then
		fsrcs="ko.sh ko.py ../ht/ko/ko.php ../ht/index.html ../ht/ko/index.html ../ht/kd/index.html ../ht/ko/wz.html kludge.sh";
		types="div script style def function sh list type_kludge"


#		OLDIFS=$IFS; IFS=$'\n'
		db3="ko.db3"; tbl="items"; fsrc="ko.sh"; tsrc="new_ko.sh"
		sqlfil="items.sql"; psvfil="items.psv"; txtfil="items.txt";
		printf "" > $sqlfil; printf "" > $psvfil; printf "" > $txtfil;
		htmout=""; j=0; k=0; 

		printf "BUGS_800 db3=$db3 tbl=$tbl fsrc=$fsrc tsrc=$tsrc\n";
		printf "BUGS_801 fsrcs=$fsrcs\n";
		printf "BUGS_802 types=$types\n";

		if [ ! -f $db3 ]; then printf "BUGS_831 kolists NOTFOUND db3=$db3\n"; exit; fi
		tblstatus=`sqlite3 $db3 ".tables" | awk '{ print $1}'`
		if [ "$tblstatus" == "" ]; then 
			printf "BUGS_832 items NOTFOUND tbl=$tbl\n"; 
			exit; 
			fi

#		printf "BUGS_841 items FOUND db3=$db3\n"; 
#		printf "BUGS_842 items FOUND tbl=$tbl\n"; 

		for fsrc in $fsrcs; do
			let j=j+1
			filesuffix=`print $fsrc | awk -F"." '{ print $2 }'`
			if [ ! -f $fsrc ]; then 
				printf "BUGS_851 $j,$k db3=$db3 tbl=$tbl items NOTFOUND FSRC=$fsrc type=$type\n";
			else
				printf "BUGS_852 $j,$k db3=$db3 tbl=$tbl items ___FOUND FSRC=$fsrc type=$type\n";
				fi

			for type in $types; do
				let k=k+1
 # tick "=`" "^`;"
				if [ "$type" == "div" ]; then headmark="<div"; tailmark="</div"; fi
				if [ "$type" == "script" ]; then headmark="<script"; tailmark="</script"; fi
				if [ "$type" == "style" ]; then headmark="<script"; tailmark="</style"; fi
				if [ "$type" == "def" ]; then headmark="^def "; tailmark="^def "; fi
				if [ "$type" == "function" ]; then headmark="^function "; tailmark="^function "; fi
				if [ "$type" == "sh" ]; then headmark="\"\$1\" == "; tailmark="\"\$1\" == "; fi
				if [ "$type" == "list" ]; then headmark="=`"; tailmark="^`;"; fi

				if [ "$filesuffix" == "sh" ]; then
					if [ "$type" == "div" ]; then continue; fi
					if [ "$type" == "script" ]; then continue; fi
					if [ "$type" == "style" ]; then continue; fi
					if [ "$type" == "def" ]; then continue; fi
					if [ "$type" == "function" ]; then continue; fi
#					if [ "$type" == "sh" ]; then continue; fi
					if [ "$type" == "list" ]; then continue; fi
					fi
				if [ "$filesuffix" == "php" ]; then
					if [ "$type" == "div" ]; then continue; fi
					if [ "$type" == "script" ]; then continue; fi
					if [ "$type" == "style" ]; then continue; fi
					if [ "$type" == "def" ]; then continue; fi
#					if [ "$type" == "function" ]; then continue; fi
					if [ "$type" == "sh" ]; then continue; fi
					if [ "$type" == "list" ]; then continue; fi
					fi
				if [ "$filesuffix" == "py" ]; then
					if [ "$type" == "div" ]; then continue; fi
					if [ "$type" == "script" ]; then continue; fi
					if [ "$type" == "style" ]; then continue; fi
#					if [ "$type" == "def" ]; then continue; fi
					if [ "$type" == "function" ]; then continue; fi
					if [ "$type" == "sh" ]; then continue; fi
					if [ "$type" == "list" ]; then continue; fi
					fi
				if [ "$filesuffix" == "html" ] || [ "$filesuffix" == "htm" ]; then
#					if [ "$type" == "div" ]; then continue; fi
# 					if [ "$type" == "script" ]; then continue; fi
# 					if [ "$type" == "style" ]; then continue; fi
 					if [ "$type" == "def" ]; then continue; fi
 					if [ "$type" == "function" ]; then continue; fi
# 					if [ "$type" == "sh" ]; then continue; fi
# 					if [ "$type" == "list" ]; then continue; fi
					fi


				printf "BUGS_851 $j,$k db3=$db3 pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
				printf "BUGS_852 $j,$k db3=$db3 tbl=$tbl items $j,$k  fsrc=$fsrc TYPE=$type\n";
				printf "BUGS_853 $j,$k db3=$db3 tbl=$tbl items $j,$k  fsrc=$fsrc TYPE=$type headmark=$headmark tailmark=$tailmark\n";

				mark=$headmark;linbeg=0; linend=99999;
				awk -v fsrc="$fsrc" -v type="$type" -v mark=$mark -v linbeg=$linbeg -v linend=$linend '/mark/ { print fsrc"|"type"|"mark"|"linbeg"|"linend"|"NR"|"$0 }' $fsrc

				awktxt=`awk -v fsrc="$fsrc" -v type="$type" -v mark=$mark -v linbeg=$linbeg -v linend=$linend '/mark/ { print fsrc"|"type"|"mark"|"linbeg"|"linend"|"NR"|"$0 }' $fsrc`

				awk -v fsrc="$fsrc" -v type="$type" -v mark=$mark -v linbeg=$linbeg -v linend=$linend '/mark/ { print fsrc"|"type"|"mark"|"linbeg"|"linend"|"NR"|"$0 }' $fsrc > $psvfil
awkpsv=`cat $psvfil`

				printf "BUGS_854 $j,$k db3=$db3 tbl=$tbl items $j,$k  fsrc=$fsrc TYPE=$type mark=$mark awkpsv=$awkpsv\n";
				printf "BUGS_855 $j,$k db3=$db3 tbl=$tbl items $j,$k  fsrc=$fsrc TYPE=$type mark=$mark awktxt=$awktxt\n";
				printf "BUGS_856 $j,$k db3=$db3 tbl=$tbl items $j,$k  fsrc=$fsrc TYPE=$type headmark=$headmark tailmark=$tailmark\n";


				sql="insert or replace into $tbl (id,fsrc,type,headmark,linbeg) values ('$id','$fsrc','$type','$headmark','linbeg','$item');"
				sqlcmd="sqlite3 $db3 \"$sql\""

				echo $awkpsv >> $psvfil
				echo $awktxt | sed -e "s:$:\n:" >> $txtfil
				echo "$sqlcmd" | sed -e "s:$:\n:" >> $sqlfil

				printf "BUGS_873 $j,$k db3=$db3 tbl=$tbl ITEMS SQLCMD=$sqlcmd\n";
				printf "BUGS_874 $j,$k db3=$db3 bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"

				if [ "$usrcmd" != "g" ]; then
					read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
					if [ "$usrcmd" == "q" ]; then exit; fi
					if [ "$usrcmd" == "s" ]; then continue; fi
					if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
					if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
					fi

				if [ "$2" == "go" ] || [ "$2" == "go" ] || [ "$2" == "go" ]; then

					printf "BUGS_880 $j,$k db3=$db3 tbl=$tbl ITEMS_GO sqlcmd=$sqlcmd\n";
					sqlite3 $db3 "$sql"

					fi




				done
			done
#		vi $psvfil
#		vi $txtfil
#		vi $sqlfil
		sql="select * from $tbl"
		sqlite3 $db3 -header "$sql"

		wc -l items.*
		exit;
		fi # if [ "$1" == "items" ] || [ "$1" == "items" ]; then
		
	if [ "$1" == "kolists" ] || [ "$1" == "kolists" ]; then
		printf "MSG_200 $progid $dttm $j,$k KOLISTS a1=$1 a2=$2 a3=$3 a4=$a4 \n"
		OLDIFS=$IFS; IFS=$'\n'
		db3="../ht/ko/kolists/kolists.db3"; tbl="kolists";
		fsrc="../ht/ko/kolists/kolists.htm";
		if [ ! -f $db3 ]; then printf "BUGS_601 kolists NOTFOUND db3=$db3\n"; exit; fi
		if [ ! -f $fsrc ]; then printf "BUGS_602 kolists NOTFOUND fsrc=$fsrc\n"; exit; fi
		
		j=0; k=0;
		items=`sqlite3 $db3 -header "select id,linbeg,linend from $tbl"`
		ilen=`sqlite3 $db3 -header "select count(*) from $tbl"`
		printf "BUGS_602 ilen=$ilen items=$items\n";
		for item in $items; do
			let j=j+1
			id=`printf $item | awk -F"|" '{ printf $1 }'`
			done
		exit;
		fi # if [ "$1" == "kolists" ] || [ "$1" == "kolists" ]; then



# KOLISTS0 pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq
	if [ "$1" == "kolists0" ]; then
		printf "KOLISTS0 $progid $dttm pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n";
		# update kolists_psv set txt=rownum, rownun=""
		db3="ko.db3"; tbl="kolists"; j=0; k=0;
		items=`sqlite3 $db3 "select * from kolists"`
		ids=`sqlite3 $db3 "select id from kolists"`
		printf "BUGS_items=$items\n"
		dttm=`date +"%Y%m%d_%H%M%S"`
		datetag=`date +"%Y%m%d_%H%M"`
		
		lists="min min100 min1000 max"
		for list in $lists; do
		#	htmfil="kolists_min_$datetag.htm"
		#	limit=99999; htmfil="kolists_max_$datetag.htm";
		#	if [ "$list" == "max" ]; then htmfil="kolists_max_$datetag.htm"; limit=99999; fi
		#	if [ "$list" == "min" ]; then htmfil="kolists_min_$datetag.htm"; limit=10; fi
		
			if [ "$list" == "min" ]; then htmfil="kolists_min.htm"; limit=10; fi
			if [ "$list" == "min100" ]; then htmfil="kolists_min100.htm"; limit=100; fi
			if [ "$list" == "min1000" ]; then htmfil="kolists_min1000.htm"; limit=1000; fi
			if [ "$list" == "max" ]; then htmfil="kolists_max.htm"; limit=99999; fi
		
			printf "<script id=script_kolists_$list""_$datetag>\n" 		> $htmfil
			printf "	function kolists(id) {\n" 				>> $htmfil
			for id in $ids; do
				printf "kolist[\'$id\'] = \`\n"					>> $htmfil
				let j=j+1
				printf "BUGS_102 $j id=$id\n"
			#	sql="select txt from kolists_psv where id='$id'" 		>> $htmfil
				sql="select txt from kolists_psv where id='$id' limit $limit" 		>> $htmfil
			#	sqlite3 $db3 "select txt from kolists_psv where id='$id' limit 100" 	>> $htmfil
			#	sqlite3 $db3 "$sql"
				sqlite3 $db3 "$sql"						>> $htmfil
				printf "\`;\n" 							>> $htmfil
				printf "\n" 							>> $htmfil
				done
			printf "	return(kolists[id]);\n"			>> $htmfil
			printf "	}\n" 						>> $htmfil
			printf "	</script id=script_kolists_$list""_$datetag""_end>\n"	>> $htmfil
			done
		
		
		
		vi $htmfil
		wc -l $htmfil
		exit
		
		
			if [ "$1" != "go" ]; then
				printf "BUGS_100 ./$progid.sh go\n"
				printf "BUGS_101 db3=$db3 tbl=$tbl \n"
				printf "BUGS_101 db3=$db3 tbl=$tbl item=$item \n"
				exit
				fi
		
		# rownum|id|status|type|sort|lin|linbeg|lincnt|linend|linlim|label|headmark|tailmark|x|y|z|h|w|dx|dy|dz|dh|dw|xmin|ymin|zmin|hmin|wmin|xmax|ymax|zmax|hmax|wmax|color|fsrc|tsrc|descr|txt|b64|kludge
		
		ofile="kolists_psv.psv"
		printf "" > $ofile
		for item in $items; do
			let j=j+1
			txt=`printf $item | awk -F"|" '{ print $1 }'`
			id=`printf $item | awk -F"|" '{ print $2 }'`
			status=`printf $item | awk -F"|" '{ print $3 }'`
			type=`printf $item | awk -F"|" '{ print $4 }'`
			sort=`printf $item | awk -F"|" '{ print $5 }'`
			linbeg=`printf $item | awk -F"|" '{ print $7 }'`
			linend=`printf $item | awk -F"|" '{ print $9 }'`
		
		
			sql="update kolists_htm set id='$id',linbeg=$linbeg, linend=$linend where rowid>$linbeg and rowid<$linend"
			sqlite3 ko.db3 "$sql"
			sql="update kolists_psv set id='$id',linbeg=$linbeg, linend=$linend where rowid>$linbeg and rowid<$linend"
			sqlite3 ko.db3 "$sql"
			printf "BUGS_102 sqlite3 ko.db3 \"$sql\"\n"
			continue
			sql="select '$id',txt from kolists_htm where rowid > $linbeg and rowid < $linend"	
		#	sqlite3 $db3 "$sql" | awk -v id=$id -v l1=$linbeg -v l2=$linend '{ print NR"|"id"|status|type|sort|lin|"l1"||"l2"|_label_||||||kolists.htm|_tsrc_|_descr_|"$0"|b64|_kludge_" }' >> $ofile
			sqlite3 $db3 "$sql" | awk -v id=$id -v l1=$linbeg -v l2=$linend '{ print NR"|"id"|status|type|sort|lin|"l1"||"l2"|_label_||||||kolists.htm|_tsrc_|_descr_|"$0"|b64|_kludge_" }' > $ofile
			cat $ofile | awk '{ print NR"|"$0 }'
			
		
		
			if [ "$usrcmd" != "g" ]; then
				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
				if [ "$usrcmd" == "q" ]; then exit; fi
				if [ "$usrcmd" == "s" ]; then continue; fi
				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
				fi
		
			printf "BUGS_100 j=$j id=$id status=$status type=$type linbeg=$linbeg linend=$linend\n"
			printf "BUGS_100 j=$j id=$id sql=$sql\n"
			done
		
		sqlite3 $db3 "delete from kolists_psv"
		sqlite3 $db3 ".import $ofile kolists_psv"
		sqlite3 $db3 -header "select * from kolists_psv" | more
		
			vi $ofile
			wc -l $ofile
		printf "KOLISTS0 $progid $dttm bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"
		fi # [ "$1" == "kolists0" ]; end

	if [ "$1" == "b64s0" ]; then
		printf "B64S0 $progid $dttm pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
		printf "BUGS_100 B64S0 go\n"

		j=0;k=0;
		items=`find b64 -name "b64_*.txt"`
		db3="ko.db3"; tbl="b64";
		printf "" > b64s.sql
		printf "" > b64s.psv
		for item in $items; do
			let j=j+1
			id=`printf $item | sed -e "s:b64/b64_::" | sed -e "s:.txt::" | sed -e "s:./htm/::" | sed -e "s:.htm::"`
			fsrc=`printf $item | sed -e "s:b64/b64_:./htm/:" | sed -e "s:.txt:.htm:"`
			b64=`cat $item`
		# rowid|rownum|id|status|type|sort|lin|linbeg|lincnt|linend|linlim|label|headmark|tailmark|x|y|z|h|w|dx|dy|dz|dh|dw|xmin|ymin|zmin|hmin|wmin|xmax|ymax|zmax|hmax|wmax|color|fsrc|tsrc|descr|txt|b64|kludge
			printf "txt|$id|status|type|sort||linbeg|lincnt|linend|linlim|label|headmark|tailmark|||||||||||||||||||||color|$fsrc|tsrc|descr|txt|$b64|kludge" >> b64s.psv
		
			printf "$id|$fsrc|$b64\n" >> b64s.psv
			printf "BUGS_100 j=$j item=$item ID=$id FSRC=$fsrc\n"
		
			b64htm=`printf $item | sed -e "s:.txt:.htm:"`
			continue
		#	printf "\n<!-- $item -->\n<script id=script_$id src='data:/text/plain;base64,$b64'></script id=script_$id""_end>\n\n" > $b64htm
		#	printf "BUGS_100 j=$j b64htm=$b64htm item=$item\n";
			
			sql="insert or replace into $tbl (id,fsrc,b64) values ('$id','$fsrc','$b64');"
			printf "$sql" >> b64s.sql
		#	sqlite3 $db3 "$sql"
		#	sql="insert or replace into $tbl (id,fsrc,b64) values ('$id','$fsrc','b64');"
		#	printf "BUGS_101 sql=$sql\n"
			done
		
		# vi b64s.sql
		# sqlite3 $db3 -header "select rowid,id,fsrc from $tbl"
		# sqlite3 $db3 -header "select * from $tbl"
		
		# ls -lat b64/b64*.htm
		printf "B64S0 $progid $dttm bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"
		fi # [ "$1" != "b64s0" ]; end

	if [ "$1" == "todo" ] || [ "$1" == "todo" ]; then 
		printf "MSG_202 $progid $dttm $j,$k TODO a1=$1 a2=$2 a3=$3 a4=$a4 \n"
		exit;
		fi # if [ "$1" == "todo" ] || [ "$1" == "todo" ]; then 

	if [ "$1" == "tododb" ] || [ "$1" == "tododb" ]; then 
		printf "MSG_203 $progid $dttm $j,$k TODODB a1=$1 a2=$2 a3=$3 a4=$a4 \n"
		exit;
		fi # if [ "$1" == "tododb" ] || [ "$1" == "tododb" ]; then 

	if [ "$1" == "todofs" ] || [ "$1" == "todofs" ]; then 
		printf "MSG_204 $progid $dttm $j,$k TODOFS a1=$1 a2=$2 a3=$3 a4=$a4 \n"
		exit;
		fi # if [ "$1" == "todofs" ] || [ "$1" == "todofs" ]; then 

	if [ "$1" == "todotx" ] || [ "$1" == "todotx" ]; then 
		printf "MSG_205 $progid $dttm $j,$k TODOTX a1=$1 a2=$2 a3=$3 a4=$a4\n"
		exit;
		fi # if [ "$1" == "todotx" ] || [ "$1" == "todotx" ]; then 

	if [ "$1" == "awks" ] || [ "$1" == "awks" ]; then 
		printf "MSG_206 $progid $dttm $j,$k AWKS a1=$1 a2=$2 a3=$3 a4=$a4\n"
		exit;
		fi # if [ "$1" == "awks" ] || [ "$1" == "awks" ]; then 

	if [ "$1" == "fors" ] || [ "$1" == "fors" ]; then 
		printf "MSG_207 $progid $dttm $j,$k FORS a1=$1 a2=$2 a3=$3 a4=$a4 \n"
		exit;
		fi # if [ "$1" == "fors" ] || [ "$1" == "fors" ]; then 

	if [ "$1" == "b64s" ] || [ "$1" == "b64s" ]; then 
		printf "MSG_208 $progid $dttm $j,$k B64S a1=$1 a2=$2 a3=$3 a4=$a4\n"
		exit;
		fi # if [ "$1" == "b64s" ] || [ "$1" == "b64s" ]; then 

	if [ "$1" == "bs4" ] || [ "$1" == "bs4" ]; then 
		printf "MSG_209 $progid $dttm $j,$k BS4 a1=$1 a2=$2 a3=$3 a4=$a4\n"
		exit;
		fi # if [ "$1" == "bs4" ] || [ "$1" == "bs4" ]; then 


	if [ "$1" == "kolists" ] || [ "$1" == "kolists" ]; then
		printf "MSG_200 $progid $dttm $j,$k KOLISTS a1=$1 a2=$2 a3=$3 a4=$a4 \n"
		OLDIFS=$IFS; IFS=$'\n'
		db3="../ht/ko/kolists/kolists.db3"; tbl="kolists";
		fsrc="../ht/ko/kolists/kolists.htm";
		if [ ! -f $db3 ]; then printf "BUGS_601 kolists NOTFOUND db3=$db3\n"; exit; fi
		if [ ! -f $fsrc ]; then printf "BUGS_602 kolists NOTFOUND fsrc=$fsrc\n"; exit; fi
		
		j=0; k=0;
		items=`sqlite3 $db3 -header "select id,linbeg,linend from $tbl"`
		ilen=`sqlite3 $db3 -header "select count(*) from $tbl"`
		printf "BUGS_602 ilen=$ilen items=$items\n";
		for item in $items; do
			let j=j+1
			id=`printf $item | awk -F"|" '{ printf $1 }'`
		db3="ko.db3"; tbl="kolists";  
		id="id"; fsrc="fsrc.txt"; tsrc="tsrc.txt"; txt="_txt_"; kludge="_kludge_";
		flds="id,fsrc,tsrc,txt,kludge"

		sql_sel="select * from $tbl"; 
		sql_ins="insert into $tbl ($flds) values ($vals)"
		sql_upd="update $tbl set id='$id' where rowid='$rowid'"
			linbeg=`printf $item | awk -F"|" '{ printf $2 }'`
			linend=`printf $item | awk -F"|" '{ printf $3 }'`
			psvfil="../ht/ko/kolists/kolist_$id.psv"
			htmfil="../ht/ko/kolists/kolist_$id.htm"
			printf "BUGS_603 $j,$k ID=$id LINBEG=$linbeg LINEND=$linend item=$item\n";

			printf "BUGS_671 $j,$k pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
			printf "BUGS_672 $j,$k $db3 $tbl $fsrc ilen=$ilen $psvfil ID=$id HEAD_MARK=$headmark\n";
			printf "BUGS_673 $j,$k ID=$id HEADMARK=$headmark linbeg=$linbeg linend=$linend\n";
			printf "BUGS_674 $j,$k ITEM=$item \n";
			printf "BUGS_675 $j,$k SQL=$sql \n";
			printf "BUGS_676 $j,$k ====================================================\n"
printf "cat $fsrc | awk -v id=\"$id\" -v linbeg=$linbeg -v linend=$linend '{ print $0 }'\n"
			printf "BUGS_676 $j,$k bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"
			if [ "$usrcmd" != "g" ]; then
					read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
					if [ "$usrcmd" == "q" ]; then exit; fi
					if [ "$usrcmd" == "s" ]; then continue; fi
					if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
					if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
					fi
			if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
				printf "BUGS_675 $j,$k SQL=$sql \n";

printf "<script id=script_$id>\n" > $htmfil
printf "kolists['$id'] = `\n"; >> $htmfil
cat $fsrc | awk -v id="$id" -v linbeg=$linbeg -v linend=$linend '{ print $0 }' >> $htmfil
printf "`;" >> $htmfil
printf "<script id=script_$id>\n" >> $htmfil

cat $fsrc | awk -v id="$id" -v linbeg=$linbeg -v linend=$linend '{ print $0 }' >> $psv

				fi







			done
		exit;
		fi # if [ "$1" == "kolists" ] || [ "$1" == "kolists" ]; then

	if [ "$1" == "kolists1" ] || [ "$1" == "kolists1" ]; then
		OLDIFS=$IFS; IFS=$'\n'
		db3="../ht/ko/kolists/kolists.db3"; tbl="kolists";
		fsrc="../ht/ko/kolists/kolists.htm";
		items=`cat $fsrc | awk '/^kolists/ { print NR"|"$0 }' | awk 'FS="=" { print $1 }' | tr -d '`' | tr -d '=' | tr -d ';'`
		ilen=`cat $items | wc -l | awk '{ print $1 }'`

#		printf "BUGS_600 KOLISTS items=$items\n";
		printf "BUGS_601 KOLISTS ilen=$ilen db3=$db3 tbl=$tbl fsrc=$fsrc\n";
		printf "BUGS_671 $j,$k pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
		printf "BUGS_672 $j,$k $db3 $tbl $fsrc ilen=$ilen $psvfil ID=$id HEAD_MARK=$headmark\n";
		printf "BUGS_673 $j,$k ID=$id HEADMARK=$headmark linbeg=$linbeg linend=$linend\n";
		printf "BUGS_674 $j,$k ITEM=$item \n";
		printf "BUGS_675 $j,$k SQL=$sql \n";
		printf "BUGS_676 $j,$k bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"
		if [ "$usrcmd" != "g" ]; then
				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
				if [ "$usrcmd" == "q" ]; then exit; fi
				if [ "$usrcmd" == "s" ]; then continue; fi
				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
				fi
			if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
				printf "BUGS_675 $j,$k SQL=$sql \n";
				fi
			done
		exit;
		fi # if [ "$1" == "kolists1" ] || [ "$1" == "kolists1" ]; then

	if [ "$1" == "kolists0" ] || [ "$1" == "kolists0" ]; then
		printf "BUGS_500 KOLISTS\n";
		
# function kolists() {
		db3="../ht/ko/kolists/kolists.db3"; tbl="kolists_all"; sql=""; fdir="../ht/ko/kolists"; tdir="../ht/ko/kolists"
fsrcs="index.html ko.php ko.py ko.sh"
fsrcs="../ht/ko/kolists/kolists.psv"
fsrcs="../ht/ko/kolists/kolists_ids.psv"
fsrc="../ht/ko/kolists/kolists.htm";

# awk: FILENAME FNR_recno NF_numflds NR_numrec RLENGTH
# $ awk 'BEGIN {
# >        for (i = 0; i < ARGC; i++) 
# >            print ARGV[i] 
# >      }' inventory-shipped BBS-list
# -| awk
# -| inventory-shipped
# -| BBS-list

# BEGIN {
#     for (i = 1; i < ARGC; i++) {
#         if (ARGV[i] == "-v")
#             verbose = 1
#         else if (ARGV[i] == "-d")
#             debug = 1
#         else if (ARGV[i] ~ /^-?/) {
#             e = sprintf("%s: unrecognized option -- %c",
#                     ARGV[0], substr(ARGV[i], 1, ,1))
#             print e > "/dev/stderr"
#         } else
#             break
#         delete ARGV[i]
#     }
# }

# s="the quick red fox jumped over the lazy brown dogs"; printf "slen=${#s}\n" 
# n=${#s}
# o create an array:
# arr=("value1" value2 $value3)
# To print an array:
# echo ${arr[@]}
# To print length of an array:
# echo ${#arr[@]}
# Using indices (index starts from 0):
# echo ${arr[index]}
# ${string:position}  --> returns a substring starting from $position till end
# ${string:position:length} --> returns a substring of $length characters starting from $position.
## n=`expr "$str" : '.*'`
# To delete the shortest substring match from front of $string:
# ${string#substring}
# To delete the shortest substring match from back of $string:
# ${string%substring}
# To delete the longest substring match from front of $string:
# ${string##substring}
# To delete the shortest substring match from back of $string of $string:
# ${string%%substring}
# for i in $(ls *.pdf); do mv $i $(basename $i .pdf)_$(date +%Y%m%d).pdf done
# $ for i in web{0..10};do scp somefile.txt ${i}:;done;
# for i in web{0..10} db{0..2} balance_{a..c};do echo $i;done
# for i in $(ls FILE*.txt);do mv $i `echo $i | sed s/FILE/TEXT/`;done
# ${string:position:length}	

		OLDIFS=$IFS; IFS=$'\n'
		db3="../ht/ko/kolists/kolists.db3"; tbl="kolists";
		if [ ! -f $fsrc ]; then printf "BUGS_601 NOTFOUND fsrc=$fsrc\n"; exit; fi

		items=`cat $fsrc | awk '/^kolist/ { print NR"|"$0 }' | awk 'FS="=" { print $1 }'| awk 'FS="\`" { print $1 }' | head -2`
		ilen=`cat $items | wc -l | awk '{ print $1 }'`
#		ilen=`cat $fsrc | wc -l | awk '{ print $1 }'`
		j=0; k=0; psvfil=""; headmark=""; id=""; linbeg=0; linend=0; lincnt=0; txt=""

		for item in $items; do
			let j=j+1
			id=`print $item | awk 'FS="'" { print $2 }'
			linbeg=`print $item | awk 'FS="|" { print $1 }'
			headmark=`print $item | awk 'FS="|" { print $2 }'
			printf "BUGS_601 kolists id=$id linbeg=linbeg headmark=$headmark ilen=$ilen \n";
			exit;
			linend=`cat $fsrc | awk -v id=$id -v linbeg=$linbeg 'NR>linbeg && /\`/ { print NR }' | awk'{ print $1 }' | head -1`
			sql="insert into $tbl (id,linbeg,linend,headmark) values ('$id','$linbeg','$linend','$headmark' );"
			printf "BUGS_671 $j,$k pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
#			printf "BUGS_672 $j,$k $db3 $tbl $fsrc ilen=$ilen $psvfil ID=$id HEAD_MARK=$headmark\n";
#			printf "BUGS_673 $j,$k ID=$id HEADMARK=$headmark linbeg=$linbeg linend=$linend\n";
#			printf "BUGS_674 $j,$k ITEM=$item \n";
#			printf "BUGS_675 $j,$k SQL=$sql \n";
			printf "BUGS_676 $j,$k bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"
			if [ "$usrcmd" != "g" ]; then
				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
				if [ "$usrcmd" == "q" ]; then exit; fi
				if [ "$usrcmd" == "s" ]; then continue; fi
				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
				fi
			if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
				printf "$progid $dttm kolists: SQL  sqlite3 $db3 \"$sql\"\n";
				sqlite3 $db3 "$sql"
				fi
			printf "BUGS_610 kolists id=$id linbeg=linbeg headmark=$headmark ilen=$ilen \n";
			done
		printf "BUGS_611 kolists id=$id linbeg=linbeg headmark=$headmark ilen=$ilen \n";
		exit;

		for j in {1.10}; do
			printf "BUGS_700 j=$j \n";
			printf "BUGS_701 $j,$k pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
			printf "BUGS_702 $j,$k $db3 $tbl $fsrc $psvfil ID=$id HEAD_MARK=$headmark\n";
			printf "BUGS_703 $j,$k $id linbeg $headmark\n";
#			printf "BUGS_704 $j,$k ITEM=$item \n";
			printf "BUGS_705 $j,$k SQL=$sql \n";
			printf "BUGS_706 $j,$k bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"
			if [ "$usrcmd" != "g" ]; then
				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
				if [ "$usrcmd" == "q" ]; then exit; fi
				if [ "$usrcmd" == "s" ]; then continue; fi
				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
				fi
			if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
				printf "$progid $dttm kolists:  sqlite3 $db3 \"$sql\"\n";
				sqlite3 $db3 "$sql"
				fi
			done
		exit;
			
		ids=`cat $fsrc | awk '/^kolist/ { print NR"|"$0 }'`
		for id_ in $ids; do
			if [ "$id_" == "\`;" ]; then continue; fi
			linbeg=""; linend=""; lincnt="";
#			linbeg=`printf $id_ | awk -F"|" '{ print $1 }';
#			headmark=`printf $id_ | awd -F"`" '{ print $1 }'`
#			id=`printf $id_ | awd -F"'" '{ print $2 }'`

linend=`cat $fsrc | awk -v id="$id" -v linbeg=$linbeg -v linend=$linend '/\`/ && NR >linbeg { print NR"|"$0 }'`
			let j=j+1
			printf "BUGS_601 $j,$k $db3 $tbl ID=$id HEADMARK=$headmark linbeg=$linbeg linend=$linend" ;
			sql="insert into $tbl (rowid,id,linbeg,linend,lincnt,headmark,label) values ('$j','$id','$linbeg','$linend','$lincnt','$headmark','label' );"


			printf "BUGS_730 $j,$k pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
			printf "BUGS_731 $j,$k $db3 $tbl $fsrc $psvfil ID=$id HEAD_MARK=$headmark\n";
			printf "BUGS_732 $j,$k $id linbeg $headmark\n";
#			printf "BUGS_733 $j,$k ITEM=$item \n";
			printf "BUGS_733 $j,$k SQL=$sql \n";
			printf "BUGS_734 $j,$k bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"
			if [ "$usrcmd" != "g" ]; then
				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
				if [ "$usrcmd" == "q" ]; then exit; fi
				if [ "$usrcmd" == "s" ]; then continue; fi
				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
				fi
			if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
				printf "$progid $dttm kolists:  sqlite3 $db3 \"$sql\"\n";
				sqlite3 $db3 "$sql"
				fi
			done
		exit;
			

		for fsrc in $fsrcs; do
			let k=k+1
#			items=`sqlite3 $db3 "select rowid,id,type,linbeg,fsrc from $tbl where fsrc='$fsrc'"`
			items=`cat $fsrcs`;
			j=0;
			for item in $items; do
				let j=j+1
				linbeg=0; linend=0; lincnt=0;

				id=`printf $item | awk -F"|" '{ print $1 }' | awk -F"'" '{ print $2 }'`
				headmark=`printf $item | awk -F"|" '{ print $2 }'`
				linbeg=`printf $item | awk -F"|" '{ print $3 }'`
				psvfil="../ht/ko/kolists/kolist_$id.psv";


#				linend=`printf $item | awk -F"|" '{ print $4 }'`
#				lincnt=`printf $item | awk -F"|" '{ print $5 }'`
#				status=`printf $item | awk -F"|" '{ print $6 }'`
#				txt=`printf $item | awk -F"|" '{ print $6 }'`
#				rowid=`printf $item | awk -F"|" '{ print $1 }'`
#				type=`printf $item | awk -F"|" '{ print $3 }'`

#				if [ "$linbeg" == "" ]; then printf "BUGS_491 SKIP $j,$k ITEM=$item linbeg=$linbeg\n"; continue; fi
#				if [ linbeg -lt 3 ]; then printf "BUGS_492 SKIP_LINBEG0 $j,$k ITEM=$item linbeg=$linbeg\n"; fi
				sql="insert into $tbl (id,headmark,linbeg,txt ) values ('$id','$headmark','$linbeg','$txt' );"
				printf "BUGS_780 $j,$k pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
				printf "BUGS_781 $j,$k $db3 $tbl $fsrc $psvfil ID=$id HEAD_MARK=$headmark\n";
				printf "BUGS_782 $j,$k $id linbeg $headmark\n";
				printf "BUGS_783 $j,$k ITEM=$item \n";
				printf "BUGS_783 $j,$k SQL=$sql \n";
				printf "BUGS_784 $j,$k bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"
				if [ "$usrcmd" != "g" ]; then
					read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
					if [ "$usrcmd" == "q" ]; then exit; fi
					if [ "$usrcmd" == "s" ]; then continue; fi
					if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
					if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
					fi

				if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
#					printf "$progid $dttm $j,$k BUGS_402 SELS_GO item=$item id=$id htmfil=$htmfil  ------------------\n";
	
					printf "BUGS_640 $j,$k rowid=$rowid $id, sqlite3 $db3 \"update bs4 set linend='$linend' where rowid='$rowid'\"\n"
					fsrc="../ht/ko/kolists/kolists_all.psv";
					txt="_txt_";
					cat $fsrc | awk  -v id id=$id -v headmark=$headmark -v linbeg=$linbeg -v linend=$linend -v fsrc="kolists_all.psv" -v txt=$txt 'NR>=linbeg && NR<linend { print $j"|"id"|||||"linbeg"|lincnt"linend"|linlim|label|"headmark"|||||||||||||||||||||||"fsrc"|||"txt"||" }' > $psvfil;

					sqlite3 $db3 "update bs4 set linend='$linend' where rowid='$rowid'"
					sql="insert into $tbl (id,headmark,linbeg,txt,fsrc,label ) values ('$id','$headmark','$linbeg','$txt','$fsrc','$label' );"
					sqlite3 $db3 "$sql"
					fi
#	
				done
			done

		items=`sqlite3 $db3 "select rowid,id,linbeg from $tbl"`
		printf "BUGS_580 selects items=$items\n";
		exit;
#		find_names="*.htm"; find_path="../ht/ko/htm" maxdepth=1; type="f";
#		find_cmd="find $find_path -type f -maxdepth $maxdept -name  \"$find_names\""
#		select_cmd="sqlite3 $db3 \""select * from $tbl\""
#		find_items=`$find_cmd`
#		select_items=`$select_cmd`
#		j=0; k=0; htmout=0;
#	
#		if [ "$2" != "go" ] && [ "$2" != "" ]; then 
#			id=$2; 
#			find_cmd="find $find_path -type f -maxdepth $maxdept -name  \"$id\""
#			select_cmd="sqlite3 $db3 \"select * from $tbl where id like '$id'\""
#			fi
#		find_items=`$find_cmd`
#		select_items=`$select_cmd`
#		printf "$progid $dttm BUGS_401 FINDS find_cmd=$find_cmd\n";
#		printf "$progid $dttm BUGS_402 FINDS select_cmd=$select_cmd\n";
#		printf "$progid $dttm BUGS_403 FINDS id=$id db3=$db3 tbl=$tbl sql=$sql fdir=$fdir tdir=$tdir\n";
#	
#		for item in $select_items; do
#			let j=j+1;
#			id=item
#			htmfil="$tdir/$id.htm"
#	
#			printf "$progid $dttm $j,$k BUGS_401 FINDS item=$item id=$id htmfil=$htmfil  ------------------\n";
#			if [ "$usrcmd" != "g" ]; then
#				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
#				if [ "$usrcmd" == "q" ]; then exit; fi
#				if [ "$usrcmd" == "s" ]; then continue; fi
#				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
#				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
#				fi
#			if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
#				printf "$progid $dttm $j,$k BUGS_402 FINDS item=$item id=$id htmfil=$htmfil  ------------------\n";
#	
#				fi
#	
#			done
#		printf "BUGS_379 SELECTS_END\n";
#		exit;
		fi # if [ "$1" == "kolists0" ] || [ "$1" == "kolists0" ]; then
	
	if [ "$1" == "selects" ] || [ "$1" == "sels" ]; then
		printf "BUGS_400 SELECTS_BEG\n";
		
# function selects() {
		db3="./ko.db3"; tbl="bs4"; sql=""; fdir="../ht/ko/htm"; tdir="../ht/ko/htm"
fsrcs="index.html ko.php ko.py ko.sh"

		for fsrc in $fsrcs; do
			let k=k+1
			items=`sqlite3 $db3 "select rowid,id,type,linbeg,fsrc from $tbl where fsrc='$fsrc'"`
			j=0;
			for item in $items; do
				let j=j+1
				rowid=`printf $item | awk -F"|" '{ print $1 }'`
				id=`printf $item | awk -F"|" '{ print $2 }'`
				type=`printf $item | awk -F"|" '{ print $3 }'`
				linbeg=`printf $item | awk -F"|" '{ print $4 }'`
				linend=0;
				lincnt=0;

#				if [ "$linbeg" == "" ]; then printf "BUGS_491 SKIP $j,$k ITEM=$item linbeg=$linbeg\n"; continue; fi
#				if [ linbeg -lt 3 ]; then printf "BUGS_492 SKIP_LINBEG0 $j,$k ITEM=$item linbeg=$linbeg\n"; fi
				printf "BUGS_490 $j, $k $id $tsrc $item -------------------------------------------\n";
				if [ "$type" == "py" ]; then
					printf "BUGS_491 PY\n";
					tsrc="../py/$id.py"
#					linend=`cat $fsrc | awk -v linbeg=$linbeg 'NR>$linbeg && /^def / { print NR"|"$0 }' | tail -1 | awk -F"|" '{ print $1 }'`
linend=`cat $fsrc | awk -v linbeg=$linbeg '/^def/ && NR > linbeg { print NR"|"$0 }' | head -2 | tail -1`

					fi	
				if [ "$type" == "php" ]; then
					printf "BUGS_491 PHP\n";
					tsrc="../php/$id.php"
#					linend=`cat $fsrc | awk -v linbeg=$linbeg 'NR>$linbeg && /^function / { print NR"|"$0 }' | tail -1`
linend=`cat $fsrc | awk -v linbeg=$linbeg '/^function/ && NR > linbeg { print NR"|"$0 }' | head -2 | tail -1 | awk -F"|" '{ print $1 }'`
					fi	
				if [ "$type" == "sh" ]; then
					printf "BUGS_491 SH\n";
					tsrc="../sh/$id.sh"
#					linend=`cat $fsrc | awk -v linbeg=$linbeg 'NR>$linbeg && /"\$1" ==/ { print NR"|"$0 }' | tail -1`
linend=`cat $fsrc | awk -v linbeg=$linbeg '/"\$1" ==/ && NR > linbeg { print NR"|"$0 }' | head -2 | tail -1 | awk -F"|" '{ print $1 }'`
					fi	
				if [ "$type" == "div" ]; then
					printf "BUGS_491 DIV\n";
					tsrc="../htm/$id.htm"
					linend=`cat $fsrc | awk -v linbeg=$linbeg 'NR>$linbeg && /<div/ { print NR"|"$0 }' | tail -1 | awk -F"|" '{ print $1 }'`
linend=`cat $fsrc | awk -v linbeg=$linbeg '/<div/ && NR > linbeg { print NR"|"$0 }' | head -2 | tail -1`
					fi	
				if [ "$type" == "style" ]; then
					printf "BUGS_491 STYLE\n";
					tsrc="../htm/$id.htm"
#					linend=`cat $fsrc | awk -v linbeg=$linbeg 'NR>$linbeg && /<style/ { print NR"|"$0 }' | tail -1 | awk -F"|" '{ print $1 }'`
linend=`cat $fsrc | awk -v linbeg=$linbeg '/<style/ && NR > linbeg { print NR"|"$0 }' | head -2 | tail -1`
					fi	
				if [ "$type" == "js" ]; then
					printf "BUGS_491 JS\n";
					tsrc="../htm/$id.htm"
					linend=`cat $fsrc | awk -v linbeg=$linbeg 'NR>$linbeg && /<script/ { print NR"|"$0 }' | tail -1 | awk -F"|" '{ print $1 }'`
linend=`cat $fsrc | awk -v linbeg=$linbeg '/<script/ && NR > linbeg { print NR"|"$0 }' | head -2 | tail -1`
					fi	

				printf "BUGS_490 $j,$k SELS___ $rowid type=$type id=$id linbeg=$linbeg linend=$linend fsrc=$fsrc tsrc=$tsrc ITEM=$item \n";

				if [ "$usrcmd" != "g" ]; then
					read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
					if [ "$usrcmd" == "q" ]; then exit; fi
					if [ "$usrcmd" == "s" ]; then continue; fi
					if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
					if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
					fi

				if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
					printf "$progid $dttm $j,$k BUGS_402 SELS_GO item=$item id=$id htmfil=$htmfil  ------------------\n";
	
					printf "BUGS_530 $j,$k rowid=$rowid $id, sqlite3 $db3 \"update bs4 set linend='$linend' where rowid='$rowid'\"\n"
					sqlite3 $db3 "update bs4 set linend='$linend' where rowid='$rowid'"
					fi
#	
				done
			done

		items=`sqlite3 $db3 "select rowid,id,linbeg from $tbl where fsrc='index.html'"`
		printf "BUGS_580 selects items=$items\n";
		exit;
#		find_names="*.htm"; find_path="../ht/ko/htm" maxdepth=1; type="f";
#		find_cmd="find $find_path -type f -maxdepth $maxdept -name  \"$find_names\""
#		select_cmd="sqlite3 $db3 \""select * from $tbl\""
#		find_items=`$find_cmd`
#		select_items=`$select_cmd`
#		j=0; k=0; htmout=0;
#	
#		if [ "$2" != "go" ] && [ "$2" != "" ]; then 
#			id=$2; 
#			find_cmd="find $find_path -type f -maxdepth $maxdept -name  \"$id\""
#			select_cmd="sqlite3 $db3 \"select * from $tbl where id like '$id'\""
#			fi
#		find_items=`$find_cmd`
#		select_items=`$select_cmd`
#		printf "$progid $dttm BUGS_401 FINDS find_cmd=$find_cmd\n";
#		printf "$progid $dttm BUGS_402 FINDS select_cmd=$select_cmd\n";
#		printf "$progid $dttm BUGS_403 FINDS id=$id db3=$db3 tbl=$tbl sql=$sql fdir=$fdir tdir=$tdir\n";
#	
#		for item in $select_items; do
#			let j=j+1;
#			id=item
#			htmfil="$tdir/$id.htm"
#	
#			printf "$progid $dttm $j,$k BUGS_401 FINDS item=$item id=$id htmfil=$htmfil  ------------------\n";
#			if [ "$usrcmd" != "g" ]; then
#				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
#				if [ "$usrcmd" == "q" ]; then exit; fi
#				if [ "$usrcmd" == "s" ]; then continue; fi
#				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
#				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
#				fi
#			if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
#				printf "$progid $dttm $j,$k BUGS_402 FINDS item=$item id=$id htmfil=$htmfil  ------------------\n";
#	
#				fi
#	
#			done
#		printf "BUGS_379 SELECTS_END\n";
#		exit;
		fi # if [ "$1" == "selects" ] || [ "$1" == "sels" ]; then
	
#	if [ "$1" == "finds" ] || [ "$1" == "finds" ]; then 
#		printf "BUGS_311 FINDS 1=$1 2=$2 3=$3 4=$4 \n"	
#		status=finds
#		printf "BUGS_312 FINDS status=$status \n"	
#		exit;
#		fi #	if [ "$1" == "finds" ] || [ "$1" == "finds" ]; then 

#	if [ "$1" == "sels" ] || [ "$1" == "selects" ]; then 
#		printf "BUGS_321 SELs 1=$1 2=$2 3=$3 4=$4 \n"	
#		status=selects
#		printf "BUGS_322 SELs status=$status \n"	
#		exit;
#		fi #	if [ "$1" == "sels" ] || [ "$1" == "selects" ]; then 

	if [ "$1" == "kludge" ] || [ "$1" == "kludge" ]; then 
		args=$2
		status=kludge;
		printf "BUGS_200 kludge status=$status\n";
		exit;
		fi # if [ "$1" == "kludge" ] || [ "$1" == "kludge" ]; then 

	if [ "$1" == "kludge1" ] || [ "$1" == "kludge1" ]; then 
		args=$2
		status=kludge1;
# 		kludge "${someArray[@]}" # Expands to all array elements.
		printf "BUGS_201 kludge1 status=$status\n";
		exit;
		fi # if [ "$1" == "kludge1" ] || [ "$1" == "kludge1" ]; then 

	if [ "$1" == "kludge2" ] || [ "$1" == "kludge2" ]; then 
		args=$2
		status=kludge2;
		printf "BUGS_202 kludge2 status=$status\n";
		exit;
		fi

	if [ "$1" == "finds" ] || [ "$1" == "finds" ]; then 
		args=$2
		status="_STATUS:finds";
		status=finds;
		printf "BUGS_420 finds status=$status\n";
		exit;
		fi # if [ "$1" == "finds" ] || [ "$1" == "finds" ]; then 

	if [ "$1" == "selects" ] || [ "$1" == "sels" ]; then 
		args=$2
		status="_STATUS:selects";
		status=selects;
		printf "BUGS_202 selects status=$status\n";
		exit;
		fi # if [ "$1" == "selects" ] || [ "$1" == "sels" ]; then 

	if [ "$1" == "go" ] || [ "$1" == "go" ]; then 
		printf "BUGS_100 GO \n"
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "go" ]; then 


	if [ "$1" == "koarrays" ] || [ "$1" == "koarrays" ]; then 
		printf "BUGS_101 KOARRAYS \n"
# IFS=$IFS#
# printf "%q" "$IFS"
ids=()
id_txt="Hello World of Linux the quick red fox jumped over the lazy brown dogs"
id_psv="Hello|World|of|Linux|the|quick|red|fox|jumped|over|the|lazy|brown|dogs"
gifs_txt="
/imgs/gif/orbs/orbs1.gif
/imgs/gif/orbs/orbs2.gif
/imgs/gif/orbs/orbs3.gif
/imgs/gif/orbs/orbs4.gif
/imgs/gif/orbs/orbs5.gif
"
printf "BUGS_102 id_txt=$id_txt id_psv=$id_psv\n";

# for id in $id_psv; do 
# for id in $id_txt; do 
for id in $gifs_txt; do 
	ids+=($id) ; 
	printf "BUGS_200 j=$j id=$id ids=$ids\n" ;
	done

for id in ${ids[@]}; do let j=j+1; printf "BUGS_201 j=$j id=$id\n" ; done

val1=${ids[1]}
val2=${ids[2]}
val3=${ids[3]}
len=${#ids[@]}
printf "BUGS_300 len=$len\n val1=$val1\n val2=$val2\n val3=$val3\n";

# IFS='|';echo "${ids[*]// /|}";IFS=$' \t\n'
# a|b|c|d|e|f
exit

# LinuxIFS="${IFS:0:3}"
#printf '%q' "${IFS}"
# ' \t\n'

words=()
read -a words
Hello World of Linux the quick red fox jumped over the lazy brown dogs
for word in ${words[@]}; do echo $word ; done
		exit;
		fi # if [ "$1" == "koarrays" ] || [ "$1" == "koarrays" ]; then 


	if [ "$1" == "wz" ] || [ "$1" == "wz" ]; then 
dttm=`date +"%Y%m%d_%H%M%S"`
divids_cord="div_sailboat div_leds div_ledsover div_display div_bugs div_toggles div_controls"
divids="kd_jenna kd_skwii kd_jkwii kd_usa kd_snowday kd_fans kd_players kd_stables kd_horses kd_cards kd_dice kd_trackline kd_tracoval kd_bugs"

htmout=""; j=0; k=0;
wz_html="../ht/ko/wz_sh.html"
# gifs=`find ../../imgs/gif/orbs -name "*.gif"`

# j=5; src=`cat gifs.txt | awk -v j="$j" 'NR == j { print $1 }'`; 
# gif=`echo $gifs | awk 'NR==$j { print $1 }'`
# gif=${ $gifs[$j] }
# printf "BUGS_101 gif=$gif\n";

gifs="
/leds/imgs/gif
/leds/imgs/gif/applewait.gif
/leds/imgs/gif/dragon_cube.gif
/leds/imgs/gif/dragon_gosquare.gif
/leds/imgs/gif/dragon_orb2.gif
/leds/imgs/gif/dragon_orb3.gif
/leds/imgs/gif/dragon_orb4.gif
/leds/imgs/gif/dragon_orb5.gif
/leds/imgs/gif/dragon_orb6.gif
/leds/imgs/gif/dragon_orb7.gif
/leds/imgs/gif/fish.gif
/leds/imgs/gif/giphy._eyeball_glossygif.gif
/leds/imgs/gif/giphy_birds.gif
/leds/imgs/gif/giphy_eagle_bw.gif
/leds/imgs/gif/giphy_eggs_01.gif
/leds/imgs/gif/giphy_eggs_10_kiti.gif
/leds/imgs/gif/giphy_eggs_11.gif
/leds/imgs/gif/giphy_eggs_20.gif
/leds/imgs/gif/giphy_eggs_30.gif
/leds/imgs/gif/giphy_eggs_31.gif
/leds/imgs/gif/giphy_eggs_33.gif
/leds/imgs/gif/giphy_eggs_34.gif
/leds/imgs/gif/giphy_eggs_36.gif
/leds/imgs/gif/giphy_eggs_37.gif
/leds/imgs/gif/giphy_eggs_38.gif
/leds/imgs/gif/giphy_eggs_39.gif
/leds/imgs/gif/giphy_eggs_54.gif
/leds/imgs/gif/giphy_exclaimation01.gif
/leds/imgs/gif/giphy_eyes_linedraw.gif
/leds/imgs/gif/giphy_jbird.gif
/leds/imgs/gif/giphy_kbird.gif
/leds/imgs/gif/giphy_ko01.gif
/leds/imgs/gif/giphy_ko11.gif
/leds/imgs/gif/giphy_law_notguilty.gif
/leds/imgs/gif/giphy_law_scales01.gif
/leds/imgs/gif/giphy_neuz02.gif
/leds/imgs/gif/giphy_onoff21.gif
/leds/imgs/gif/giphy_orb_drips.gif
/leds/imgs/gif/giphy_orb_hary.gif
/leds/imgs/gif/giphy_orb_in_cube.gif
/leds/imgs/gif/giphy_orbwave.gif
/leds/imgs/gif/giphy_radar.gif
/leds/imgs/gif/giphy_shades.gif
/leds/imgs/gif/giphy_spinner2.gif
/leds/imgs/gif/giphy_spinner3.gif
/leds/imgs/gif/giphy_spinner8.gif
/leds/imgs/gif/giphy_spinner_disk.gif
/leds/imgs/gif/giphy_spinner_sumi.gif
/leds/imgs/gif/giphy_spiral.gif
/leds/imgs/gif/giphy_tetertotter.gif
/leds/imgs/gif/giphy_undulate2.gif
/leds/imgs/gif/giphy_wave_cbs.gif
/leds/imgs/gif/giphy_waveup.gif
/leds/imgs/gif/lit2.gif
/leds/imgs/gif/litecrystle.gif
/leds/imgs/gif/octopus.gif
/leds/imgs/gif/photonorb.gif
/leds/imgs/gif/photons.gif
/leds/imgs/gif/spinning-arrow-right.gif
"

# IFS=', ' read -r -a array <<< "$string"
# echo "${array[0]}"
# for element in "${array[@]}"; do echo "$element"; done
# for index in "${!array[@]}"; do echo "$index ${array[index]}"; done
# unset "array[1]"; array[42]=Earth
# last=echo "${array[-1]}"
# cnt=echo "${#array[@]}"
# IFS=', ' eval 'array=($divids)';
# printf "BUGS_array=$array\n";

# IFS=', ' eval 'array=($string)'; ## $IFS does not outlive the eval command, but $array does
# IFS=', ' read -ra a <<<$divids; declare -p a;
# IFS=', ' read -ra a <<<'Los Angeles, United States, North America'; declare -p a;
## declare -a a=([0]="Los" [1]="Angeles" [2]="United" [3]="States" [4]="North" [5]="America")








#	for i in ${!myArray[@]}; do
#		echo "element $i is ${myArray[$i]}"
#		done
#	for i in ${!gifs[@]}; do
#		echo "BUGS_000 ============== element $i is ${gifs[$i]}"
#		done
#	i=1; gif=${gifs[$i]};
#	printf " BUGS_001 i=$i gif=$gif ${gifs[$i]} \n";
#	i=10; gif=$gifs[$i];
#	printf " BUGS_001 i=$i gif=$gif ${gifs[$i]} \n";
#	i=50; gif=${gifs[$i]};
#	printf " BUGS_001 i=$i gif=$gif ${gifs[$i]} \n";

#	for gif in $gifs; do
#		let j=j+1
#		printf "BUGS_100 j=$j gif=$gif\n"
#		done

#	for j in {1..10}; do
#		src=`cat gifs.txt | awk -v j="$j" 'NR == j { print $1 }'`; 
#		gif=`cat gifs.txt | awk 'NR == $j { print $1 }'`
#		printf "BUGS_101 j=$j src=$src\n";
#		done
#	j=0;
#	for gif in ${$gifs[@]}; do
#		done

			if [ "$1" == "go" ] || [ "$1" == "wz" ]; then
				j=0;
				printf "<html><head><title>wx.html $dttm</title><head>\n" >> $wz_html
				printf "<body bgcolor=linen>\n" >> $wz_html
				printf "<script id=script_wz src=/js/wz/wz_dragdrop.js ></script>\n" >> $wz_html

				for divid in $divids; do
					let j=j+1
					left=600; top=600; width=1100; height=800;
					x=$left; y=$top; w="$width"; h="$height";
					let dx=10*j; let dy=1000*j; 
					let x=x+dx; let y=y+dy ;
//					src=`cat gifs.txt | awk -v j="$j" 'NR == j { print $1 }'`; 

					k=0;
					gif="/imgs/btn/koeye_handhither.gif"
					for gif in $gifs; do
						let k=k+1;
						if [ j == k ]; then break; fi
						done
					printf "BUGS_200 j=$j k=$k gif=$gif\n";



					printf "\n" >> $wz_html
					printf "\n" >> $wz_html
					printf "<!-- $divid  $j ================= HEAD ===================== $divid END -->\n" >> $wz_html
					printf "       <style id=\"style_div_$divid\" > \n" >> $wz_html
					printf "                #div_$divid { \n" >> $wz_html
					printf "                        position:absolute; \n" >> $wz_html
					printf "                        left:$x""px; top:$y""px; width:$w""px; height=$h""px; \n" >> $wz_html
					printf "                        border:1px solid #000099; \n" >> $wz_html
					printf "                        background:#eeeeee; \n" >> $wz_html
					printf "                        layer-background-color:#eeeeee; \n" >> $wz_html
					printf "                        overflow:hidden; \n" >> $wz_html
					printf "//                      visibility:hidden; \n" >> $wz_html
					printf "                        } \n" >> $wz_html
					printf "                </style id=\"style_div_$divid""_end\" > \n" >> $wz_html

					printf "\n" >> $wz_html

					printf "		\n" >> $wz_html	
					printf "		\n" >> $wz_html	
#					printf "	<div id=\"layer_$divid\" >\n" >> $wz_html
#					printf "		<h1>layer_$divid</h1>\n" >> $wz_html
					printf "		<div id=\"div_$divid\" >\n" >> $wz_html
					printf "			<h2>div_$divid</h2>\n" >> $wz_html
					printf "			<div id=\"div_$divid""_body\" >\n" >> $wz_html


#					printf "<img src=/gm/kd/imgs/koeye.png title=\"          $divid\" height=50px width=100px border=0>$divid\n"

					printf "<hr color=black>\n" >> $wz_html
					printf "<hr color=white>\n" >> $wz_html
					printf "<img src=/imgs/btn/koeye.png title=\"          $divid $src\" onclick=\"$divid('""$divid""'); return false;\" height=50px width=100px border=0>$divid\n" >> $wz_html
					printf "<hr color=white>\n" >> $wz_html
					printf "<hr color=black>\n" >> $wz_html
					printf "\n" >> $wz_html
					printf "				<h3>div_$divid</h3>\n" >> $wz_html
printf "<img id=img_$divid src=$src title=\"          $divid\" onclick=\"$divid('""$divid""'); return false;\" 
 height=500px width=500px border=0>\n" >> $wz_html
					printf "				</div id=\"div_$divid""body_end\" >\n" >> $wz_html
					printf "			</div id=\"div_$divid""_end\" >\n" >> $wz_html
#					printf "		</div id=\"layer_ko_$divid""_end\" >\n" >> $wz_html
					printf "\n" >> $wz_html
					printf "<script id=script_$divid>\n" >> $wz_html
					printf "	function $divid(args) {\n" >> $wz_html
					printf "		alert( \"BUGS_$j $divid args=\"+args )\n" >> $wz_html
					printf "		return(args); \n" >> $wz_html
					printf "		}\n" >> $wz_html
					printf "	</script id=script_$divid""_end>\n" >> $wz_html
					printf "<!-- $divid  $j ----------------- TAIL --------------------- $divid END -->\n" >> $wz_html
					printf "\n" >> $wz_html
					printf "\n" >> $wz_html

					done

divids0="div_sailboat div_leds div_ledsover div_display div_bugs div_toggles div_controls"
divids="kd_jenna kd_skwii kd_jkwii kd_usa kd_snowday kd_fans kd_players kd_stables kd_horses kd_cards kd_dice kd_trackline kd_tracoval kd_bugs"

				printf "\n" >> $wz_html
				printf "<script id=script_set_dhtml>\n" >> $wz_html
				printf "SET_DHTML(\n" >> $wz_html
				for divid0 in $divids0; do
					printf "\"div_$divid0\"+RESIZABLE+TRANSPARENT,\n" >> $wz_html
					done
				for divid in $divids; do
					printf "\"div_$divid\"+RESIZABLE+TRANSPARENT,\n" >> $wz_html
					done
				printf "\"div_kludge\"+RESIZABLE+TRANSPARENT\n" >> $wz_html

				printf "	);\n" >> $wz_html
				printf "	</script id=script_set_dhtml_end>\n" >> $wz_html
				printf "	</body></html\n" >> $wz_html
					
#				vi $divs_html
#				vi $dhtml_html
#				printf "vi $divs_html\n";
#				printf "vi $dhtml_html\n";
#				cp wz.htm wz.html
#				vi wz.html +3020



				vi $wz_html

				exit;
				fi



			printf "$progid $dttm pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n";
			printf "\n";
			printf "divids=$divids\n"
			printf "\n";
			printf "./$progid go		\n";
			printf "./$progid wz		\n";
			printf "$progid $dttm bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n";
		exit;
		fi # if [ "$1" == "wz" ] || [ "$1" == "wz" ]; then 

	if [ "$1" == "sql" ] || [ "$1" == "sql" ]; then 
		db3="/Volumes/ka2tbr1/ht/ko/kd.db3"
		db3="../ht/ko/ko.db3";
		if [ ! -f $db3 ]; then 
			printf "BUGS_123 SQL NOTFOUND db3=$db3\n"; 
			exit;
		else 
			printf "BUGS_123 SQL ___FOUND db3=$db3\n"; 
			fi
		printf "BUGS_201 SQL db3=$db3 \n"
		tbls=`sqlite3 $db3 ".tables"`
		printf "BUGS_202 SQL tbls=$tbls\n";
		for tbl in $tbls; do
			printf "$j item=$item\n";
			printf "$hostname $dttm $j,$k p0=$p0 tbl=$tbl item=$item pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
			if [ "$usrcmd" != "g" ]; then
				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
				if [ "$usrcmd" == "q" ]; then exit; fi
				if [ "$usrcmd" == "s" ]; then continue; fi
				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
				fi

			printf "$hostname $dttm gO $j,$k p0=$p0 tbl=$tbl item=$item ==========================================\n"
#			printf "sqlite3 $db3 -header \"select * from $tbl\" > $tbl.psv\n"
			if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ]; then
				printf "$hostname $dttm GO $j,$k p0=$p0 tbl=$tbl item=$item ==========================================\n"
				printf "SQL sqlite3 $db3 -header \"select * from $tbl\" > $tbl.psv\n"
#				sqlite3 $db3 -header "select * from $tbl" > $tbl.psv
#				flds=`head -1 $tbl.psv`
#				sqlite3 $db3 'insert into flds (id,label) values ("$tbl","$flds")'
#				sqlite3 $db3 -header "select rowid,* from flds where id==$tbl"
				
				if [ "$2" == "drop" ]; then
					printf "SQL_DROP $j,$k tbl=$tbl\n"
					printf "sqlite3 $db3 \"drop table $tbl;\"\n";
					sqlite3 $db3 "drop table $tbl;"
					fi
				if [ "$2" == "cr" ]; then
					printf "SQL_CR $j,$k tbl=$tbl\n"
					printf "sqlite3 $db3 < cr_$tbl.sql\n"
					sqlite3 $db3 < cr_$tbl.sql
					fi
				if [ "$2" == "exp" ]; then
					printf "SQL_EXP $j,$k tbl=$tbl\n"
					printf "sqlite3 $db3 -header \"select * from $tbl\" > ./psv/$tbl.psv\n";
					sqlite3 $db3 -header "select * from $tbl" > ./psv/$tbl.psv
					fi
				if [ "$2" == "imp" ]; then
					printf "SQL_IMP $j,$k tbl=$tbl\n"
					printf "sqlite3 $db3 \".import ../ht/ko/psv/$tbl.psv $tbl\"\n";
					sqlite3 $db3 ".import ../ht/ko/psv/$tbl.psv $tbl"
					fi
				if [ "$2" == "del" ]; then
					printf "SQL_DEL $j,$k tbl=$tbl\n"
					printf "sqlite3 $db3 \"delete from $tbl\"\n";
					sqlite3 $db3 "delete from $tbl"
					fi
				if [ "$2" == "sel" ]; then
					printf "SQL_DEL $j,$k tbl=$tbl\n"
					printf "sqlite3 $db3 -header \"select rowid,* from $tbl\""
					sqlite3 $db3 -header "select rowid,* from $tbl"
					fi
				if [ "$2" == "ins" ]; then
					$db3="/Volume/ka2tbr1/ht/ko/kd.db3"
					printf "SQL_INS $j,$k tbl=$tbl\n"
					flds=`cat ../ht/ko/psv/$tlb.psv | head -1`
					printf "sqlite3 $db3 \"insert into tbls (id,label) values ('$tbl','$flds')\"\n";
					sqlite3 $db3 "insert into tbls (id,label) values ('$tbl','$flds')"
					fi
				fi
			printf "$hostname $dttm $db3 $j,$k item=$item bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"
			done
		exit;
		fi # if [ "$1" == "sql" ] || [ "$1" == "sql" ]; then 

	if [ "$1" == "scp" ] || [ "$1" == "scp" ]; then
		if [ "$2" == "k1" ] || [ "$3" == "k1" ]; then hosts="konet@ka2:/Volumes/ka2tbr1/ht/gm/kd"; fi
		if [ "$2" == "k0" ] || [ "$3" == "k0" ]; then hosts="kozerus@ko0.us:~/public_html/gm/kd"; fi
		if [ "$2" == "k2" ] || [ "$3" == "k2" ]; then hosts="kotwous@ko2.us:~/public_html/gm/kd"; fi
		if [ "$2" == "k" ] || [ "$3" == "k" ]; then 
			hosts="konet@ka2:/Volumes/ka2tbr1/ht/gm/kd kozerus@ko0.us:~/public_html/gm/kd kotwous@ko2.us:~/public_html/gm/kd";
			fi


		for host in $hosts; do
			let j=j+1;
			printf "$j,$k host=$host\n";
#			printf "scp index.htm* $host\n";	
#			printf "scp kd.htm* $host\n";	
			printf "scp *.* $host\n";	
			if [ "$2" == "go" ] || [ "$3" == "go" ];  then
#				scp index.htm* $host
#				scp kd*.* $host
				scp wz*.* $host
				fi
			done		
		exit;
		fi # if [ "$1" == "scp" ] || [ "$1" == "scp" ]; then


	if [ "$2" != "" ] && [ "$2" != "psv" ]; then yyyymmdd=$2; fi # if [ "$2" != "" ] && [ "$2" != "psv" ]; then 

	if [ "$1" == "go" ] || [ "$1" == "kd" ]; then
		printf "$progid $dttm GO\n";
		printf "db3=$db3 tbl=$tbl\n"; psvfil="kd_contenders.psv"
		j=0; k=0; htmout=0; i=0; ilen=0;
#		contenders=`sqlite3 $db3 "select * from contenders"`;
#		contenders_len=`cat $contenders | wc -l`;

#		OLDIFS=$IFS; IFS=$'\n'
#		contenders=`($(sqlite3 $db3 "select * from contenders" ))`
#		contenders=($(cat $psvfil ))
#		contenders=`head $psvfil`
#		ilen=`cat $contenders | wc -l`
#		printf "BUGS_100 ilen=$ilen contenders=$contenders\n=======\n ilen=$ilen";

		OLDIFS=$IFS
		IFS=$'\n'
		for contenders in $(sqlite3 kd.db3 "select * from contenders limit 5")
		do
			printf "contenders=$contenders"
			done
		IFS=$OLDIFS
		exit;
		
	

	
		exit;

		contenders=`sqlite3 $db3 "select * from contenders limit 5"`;

#		IFS=$OLDIFS
		IFS='\n'
		ilen=${#contenders[@]}
#		for (( i=0; i<${ilen}; i++ )); do
		i=0
		for contender in $contenders; do
			contender="${contenders[$i]}"
			printf "BUGS_101 i=$i ilen=$ilen contender=$contender\n";
			let i=i+1;	
			done	
#		printf "BUGS_101 ilen=$ilen contenders=$contenders\n";
		printf "BUGS_102 ilen=$ilen\n";
		exit;
		
#		items=`cat $jsonfile | tr -d '[' | tr -d ']' | tr -d '{' | tr -d '}' | sed -e "s:,:|:g" | awk -F"\n" '{ print $1 }'`
		ilen=${#items[@]}
		printf "BUGS_104 items=$items ilen=$ilen\n";
		for (( i=0; i<${ilen}; i++ )); do
			item="${items[$i]}"
#			pathfile=`echo $item | awk -F"|" '{ print $1 }'`
#			desc=`echo $item | awk -F"|" '{ print $2 }'`

			printf "$j item=$item\n";
			printf "$hostname $dttm $j,$k p0=$p0 item=$item pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
			if [ "$usrcmd" != "g" ]; then
				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
				if [ "$usrcmd" == "q" ]; then exit; fi
				if [ "$usrcmd" == "s" ]; then continue; fi
				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
				fi
			printf "$hostname $dttm $db3 $j,$k item=$item bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"
			done
		IFS=$OLDIFS'\n'
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "kd" ]; then

	if [ "$1" == "mvs" ] || [ "$1" == "mvs" ]; then # move dated directories
		fdir="../i"; 
		prefixs="nasa";
		prefixs="snap";
		prefixs="kb";
		prefixs="jtfdc nasa kb snap";
		printf "$progid $dttm"
		for prefix in $prefixs; do
			let j=j+1
			printf "$progid $dttm BUGS_100 $j,$k prefix=$prefix ===========================\n";
	
			tdir="$fdir/$prefix";
	#		todir="$tdir/$prefix";
			if [ ! -d $fdir ]; then
				printf "$progid $dttm BUGS_101 NOTFOUND $j,$k fdir=$fdir\n";
				continue;
				fi
			if [ ! -d $tdir ]; then
				printf "$progid $dttm BUGS_102 NOTFOUND tdir=$tdir\n";
				continue;
				fi
			dirs=`find $fdir -type d -maxdepth 1 -name "$prefix""_*"`
			dircnt=`find $fdir -type d -maxdepth 1 -name "$prefix""_*" | wc -l`
			printf "$progid $dttm $j,$k prefix=$prefix dircnt=$dircnt \n";
	#		printf "$progid $dttm $j,$k dirs=$dirs\n";
	#		continue;
			k=0;
			for dir in $dirs; do
				let k=k+1
				todaydir="$fdir/$prefix""_$today";
				printf "$progid $dttm $j,$k BUGS_200 dir=$dir tdir=$tdir  todaydir=$todaydir ------------\n";
	#			continue;
				if [ ! -d $tdir ]; then
					printf "$progid $dttm BUGS_201 NOTFOUND tdir=$tdir\n";
					continue;
					fi
				if [ ! -d $dir ]; then
					printf "$progid $dttm BUGS_202 NOTFOUND dir=$dir\n";
					continue;
					fi
				if [ "$dir" == "$todaydir" ]; then
					printf "$progid $dttm BUGS_401 SKIPTODAY todaydir=$todaydir\n";
					continue;
					fi
				printf "$progid $dttm BUGS_300 MV $dir $tdir\n";
	#			printf "mv $dir $tdir\n"
	
	
				if [ "$usrcmd" != "g" ]; then
					read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
					if [ "$usrcmd" == "q" ]; then exit; fi
					if [ "$usrcmd" == "s" ]; then continue; fi
					if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
					if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
		                        fi
	
	
	
				if [ "$2" == "go" ]; then
					printf "$progid $dttm BUGS_301 mv $dir $tdir\n";
					mv $dir $tdir
					fi
	
				done
			done
		exit;
		fi # if [ "$1" == "mvs" ] || [ "$1" == "mvs" ]; then # move dated directories
	
	if [ "$1" == "ssk" ] || [ "$1" == "ssk" ]; then
		tbl="ssk"
		db3fil="~/.ssk/ssk.db3"
		db3fil="/Users/konet/.ssk/ssk.db3"
		printf "$progid $dttm $hostname ssk db3fil=$db3fil tbl=$tbl  ==================\n";
		if [ ! -f $db3fil ]; then
			printf "$progid $dttm $hostname BUGS_100 NOTFOUND db3fil=$db3fil\n";
#			exit;
			fi

		printf "BUGS_101 \$0=$0 1=$1 2=$2 3=$3 4=$4\n" 
		printf "sqlite3 -header $db3fil \"select * from ssk\"\n" 
		sqlite3 -header $db3fil "select * from ssk"
		printf "BUGS_102 ZZZZZZZZZZZZZZZZZZZZZZZZZZ\n"
		exit;
		fi # if [ "$1" == "ssk" ] || [ "$1" == "ssk" ]; then

	if [ "$1" == "go" ] || [ "$1" == "json2db3" ]; then
		printf "$progid $dttm $hostname json2db3 jsonfile=$jsonfile db3fil=$db3fil tbl=$tbl  ==================\n";
		if [ ! -f $jsonfile ]; then
			printf "$progid $dttm $hostname BUGS_101 NOTFOUND jsonfile=$jsonfile\n";
			exit;
			fi
		if [ ! -f $db3fil ]; then
			printf "$progid $dttm $hostname BUGS_101 NOTFOUND db3fil=$db3fil\n";
			exit;
			fi

		OLDIFS=$IFS; IFS=$'\n'
#		items=`($(cat $jsonfile ))`
		items=`cat $jsonfile | tr -d '[' | tr -d ']' | tr -d '{' | tr -d '}' | sed -e "s:,:|:g" | awk -F"\n" '{ print $1 }'`
		ilen=${#items[@]}
		printf "BUGS_104 jsonfile=$jsonfile ilen=$ilen\n";
#		printf "BUGS_105 ilen=$ilen items=$items\n";
		exit;
		for (( i=0; i<${ilen}; i++ )); do
			item="${items[$i]}"
#			pathfile=`echo $item | awk -F"|" '{ print $1 }'`
#			desc=`echo $item | awk -F"|" '{ print $2 }'`
			printf "($i,$j,$k) item=$item\n";

			fldvals=`echo $item | awk -F"|" '{ print $1 }'`
			for fldval in $fldvals; do
				let j=j+1;
				printf "BUGS_110 ($i,$j,$k) fldval=$fldval\n-------------------\n";
				continue;
				fld=`echo $fldval | awk -F":" '{ print $1 }'`
				val=`echo $fldval | awk -F":" '{ print $2 }'`
				printf "BUGS_120 ($i,$j,$k) fld=$fld val=$val\n";
				done
			done
		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "json2db3" ]; then

	if [ "$1" == "awk_vars" ] || [ "$1" == "awk_vars" ]; then
		printf "$progid $dttm go ==================\n";
#			echo | awk -v variable='This is variable!' 'END{print variable}'
		exit;
		fi # if [ "$1" == "awk_vars" ] || [ "$1" == "awk_vars" ]; then

	if [ "$1" == "items2leds" ] || [ "$1" == "items2leds" ]; then
		printf "$progid $dttm go ==================\n";
		db3="../ht/ko/ko.db3"
		tbl="leds_jtfdcr"

# 		led_id|led_id|led_status|led_code|led_name|led_dttm|led_color|led_speed|led_type|led_date|led_cmd|led_cmdout|led_desc|led_misc|led_city|led_bldg|led_loc_code|led_floor|led_group|led_orgs|led_title|led_published|led_width|led_height|led_comment|led_filename|led_user|led_user_ip|led_referer|led_remote_port|led_viewrole|led_user_agent|led_unique_id|led_err|led_fix|led_os

		printf "$progid $dttm items2leds $db3 tbl=$tbl  ==================\n";
		sqlite3 $db3 "create table if not exists $tbl as select * from leds limit 1;"
		sqlite3 $db3 "delete from $tbl";
		sqlite3 $db3 ".tables"
		sqlite3 $db3 "select * from $tbl"




		htmlfile="/ko/items2leds.html"
		ht_htmlfile="../ht/ko/items2leds.html"
		ht_ko_leds_head_html="../ht/ko/ko_leds_head.html"
		ht_ko_leds_content_html="../ht/ko/ko_leds_content.html"
		ht_ko_leds_body_html="../ht/ko/ko_leds_body.html"
		ht_ko_leds_links_html="../ht/ko/ko_leds_links.html"
		ht_ko_leds_tail_html="../ht/ko/ko_leds_tail.html"

		ht_ko_leds_head_b64="../ht/ko/ko_leds_head.b64"
		ht_ko_leds_content_b64="../ht/ko/ko_leds_content.b64"
		ht_ko_leds_body_b64="../ht/ko/ko_leds_body.b64"
		ht_ko_leds_links_b64="../ht/ko/ko_leds_links.b64"
		ht_ko_leds_tail_b64="../ht/ko/ko_leds_tail.b64"


		printf "" > $ht_htmlfile_html
		printf "" > $ht_ko_leds_head_html
		printf "" > $ht_ko_leds_content_html
		printf "" > $ht_ko_leds_body_html
		printf "" > $ht_ko_leds_links_html
		printf "" > $ht_ko_leds_tail_html

		printf "" > $ht_htmlfile_b64
		printf "" > $ht_ko_leds_head_b64
		printf "" > $ht_ko_leds_content_b64
		printf "" > $ht_ko_leds_body_b64
		printf "" > $ht_ko_leds_links_b64
		printf "" > $ht_ko_leds_tail_b64

		cat ../ht/ko/leds.html | awk 'NR<25 { print $0 }' >> $ht_htmlfile
		cat ../ht/ko/leds.html | awk 'NR<25 { print $0 }' >> $ht_ko_leds_head_html

		k=0;
		links=""; content="";
#		ks="0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16";
#		for k in $ks; do
		items=`cat ../ht/ko/lists_items.txt | head -100`
		items=`cat ../ht/ko/lists_items.txt `


		for item in $items; do
			let k=k+1
			src=`echo $item | awk '{ print $1 }'`
			desc=`echo $item | awk '{ print $2 }'`
			if [ "$desc" == "" ]; then
				desc=`echo $src | awk -F"." '{ print $1 }'`
				fi
			imgid="img_leds_$k";
			printf "BUGS_123 k=$k src=$src desc=$desc\n";

			txt=""
			txtfil=`echo $src | sed -e "s:jpg$:txt:"`
			if [ -f $txtfil ]; then
				txt=`cat $txtfil`
				fi
			ext=`echo $src | awk -F"." '{ print $2 }'`
			tn="/leds/imgs/hal/hald_red.gif";
			if [ "$ext" == "jpg" ]; then tn=$src; fi
			if [ "$ext" == "png" ]; then tn=$src; fi
			if [ "$ext" == "gif" ]; then tn=$src; fi
	
			content=""
			content="$content""content[$k]='";
			content="$content""<h1>$desc</h1>";
			content="$content""$txt"
			content="$content""<hr color=white>";
#			content="$content""<img src=$src border=0 onclick=\"open('$src'); return false;\">\n";
			content="$content""<img src=$src border=0 height=600>";
			printf "$content" >> $ht_htmlfile
			printf "$content" >> ../ht/ko/leds_content.html
			printf "$content" >> ../ht/ko/ko_leds_content.html
	
#			printf "BUGS_131 k=$k src=$src tn=$tn desc=$desc\n";
#			printf "BUGS_130 desc=$desc content=$content\n";
			done

		cat ../ht/ko/leds.html | awk 'NR>80 && NR <150 { print $0 }' >> $ht_htmlfile
	
#		for k in $ks; do
		k=0;
		for item in $items; do
			let k=k+1;
			src=`echo $item | awk -F"|" '{ print $1 }'`
			desc=`echo $item | awk -F"|" '{ print $2 }'`

			if [ "$desc" == "" ]; then
				desc=`echo $src | awk -F"." '{ print $1 }'`
				fi

			ext="jpg";
			ext=`echo $src | awk -F"." '{ print $2 }'`

			tn="/leds/imgs/hal/hald_red.gif";
			if [ "$ext" == "jpg" ]; then tn=$src; fi
			if [ "$ext" == "png" ]; then tn=$src; fi
			if [ "$ext" == "gif" ]; then tn=$src; fi
			if [ "$ext" == "pdf" ]; then tn="/imgs/btn/koeye_pdf.png"; fi
			if [ "$ext" == "mp3" ]; then tn="/imgs/btn/koeye_mp3.png"; fi
			if [ "$ext" == "mp4" ]; then tn="/imgs/btn/koeye_mp4.png"; fi
			if [ "$ext" == "txt" ]; then tn="/imgs/btn/koeye_txt.png"; fi
			imgid="img_leds_$k";
	
			links=""
			links="$links""<a href=$src onMouseover=\"changetext(content[$k])\">\n"
			links="$links""	<img id=$imgid title=\"          $imgid\" src=$src ";
			links="$links""onclick=\"";
			links="$links""leds('$src'); return false;\" "
#			links="$links""window.open('$src'); return false;\" "
#			links="$links""$htmlfile?ledid=$imgid'); return false;\" ";

			links="$links""onMouseover=\"changetext(content["$k"])\" ";
			links="$links""onMouseout=\"tipout(); return false;\" ";
			links="$links""height=50 border=0>\n";
			links="$links""</a>\n";
			printf "$links" >> $ht_htmlfile
			printf "$links" >> $ht_ko_leds_links_html
#			printf "BUGS_140  links=$links\n";

			flds="'led_id','led_misc', 'led_filename', 'led_bldg', 'led_code', 'led_name', 'led_dttm', 'led_type', 'led_color', 'led_speed', 'led_group', 'led_orgs', 'led_desc'";
			led_id=$imgid;
			led_misc=$pathfile;
			led_filename=$pathfile;
			led_bldg="jtf00";
			led_code=$imgid;
			led_name=$desc;
			led_dttm=$dttm;
			led_type="hals";
			led_color="red";
			led_speed="1";
			led_group="jtfdcr";
			led_orgs="jtfdcr";
			led_desc=$desc;	



			vals="'$led_id', '$led_misc', '$led_filename', '$led_bldg', '$led_code', '$led_name', '$led_dttm', '$led_type', '$led_color', '$led_speed', '$led_group', '$led_orgs', '$led_desc'";


			sql_insert="insert into $tbl ( $flds ) values ( $vals );"


			printf "sqlite3 $db3 \"$sql_insert\"\n"
			sqlite3 $db3 "$sql_insert"
			done

		cat ../ht/ko/leds.html | awk 'NR >220 { print $0 }' 	>> $ht_htmlfile
		cat ../ht/ko/leds.html | awk 'NR >220 { print $0 }' 	>> $ht_ko_leds_tail_html

		printf "	<script id=script_ko_leds_head \n";	 	> $ht_ko_leds_head_b64
		printf "		src='data:/text/plain;base64,"		>> $ht_ko_leds_head_b64
		base64 $ht_ko_leds_head_html 					>> $ht_ko_leds_head_b64
		printf "'>\n"							>> $ht_ko_leds_head_b64
		printf "		</script id=script_ko_leds_head_end>\n"	>> $ht_ko_leds_head_b64

		printf "	<script id=script_ko_leds_content \n";			 > $ht_ko_leds_content_b64
		printf "		src='data:/text/plain;base64,"			>> $ht_ko_leds_content_b64
		base64 $ht_ko_leds_content_html 					>> $ht_ko_leds_content_b64
		printf "'>\n"								>> $ht_ko_leds_content_b64
		printf "		</script id=script_ko_leds_content_end>\n"	>> $ht_ko_leds_content_b64


		printf "	<script id=script_ko_leds_body \n";		> $ht_ko_leds_body_b64
		printf "		src='data:/text/plain;base64,"		>> $ht_ko_leds_body_b64
		base64 $ht_ko_leds_body 					>> $ht_ko_leds_body_b64
		printf "'>\n"							>> $ht_ko_leds_body_b64
		printf "		</script id=script_ko_leds_body_end>\n"	>> $ht_ko_leds_body_b64

		printf "	<script id=script_ko_leds_links \n";		 > $ht_ko_leds_links_b64
		printf "		src='data:/text/plain;base64,"		>> $ht_ko_leds_links_b64
		base64 $ht_ko_leds_links_html				 	>> $ht_ko_leds_links_b64
		printf "'>\n"							>> $ht_ko_leds_links_b64
		printf "		</script id=script_ko_leds_links_end>\n">> $ht_ko_leds_links_b64

		printf "	<script id=script_ko_leds_tail \n";		 > $ht_ko_leds_tail_b64
		printf "		src='data:/text/plain;base64,"		>> $ht_ko_leds_tail_b64
		base64 $ht_ko_leds_tail_html 					>> $ht_ko_leds_tail_b64
		printf "'>\n"							>> $ht_ko_leds_tail_b64
		printf "		</script id=script_ko_leds_tail_end>\n"	>> $ht_ko_leds_tail_b64

		vi $ht_ko_leds_head_b64
		vi $ht_ko_leds_content_b64
		vi $ht_ko_leds_body
		vi $ht_ko_leds_links
		vi $ht_ko_leds_tail

		open http://ka12$htmlfile
		vi $ht_htmlfile +80
		exit
		fi # if [ "$1" == "items2leds" ] || [ "$1" == "items2leds" ]; then

	if [ "$1" == "awk" ] || [ "$1" == "awk" ]; then
		path=../ht/ko
		items=`find $path -name "ko_??.html"`
		j=0;
		for item in $items; do
			let j=j+1;
#			printf "item=$item\n";
			nr=`cat $item | awk -F"\n" '/script_toggles/ { print N$" "$0 }'`
			printf "BUGS_120 awk item=$item nr=$nr\n";
			done
		exit;
		printf "$progid $dttm awk path=$path  ==================\n";
#		echo | awk -v variable='This is variable!' 'END{print variable}'
		pattern=$2
		if [ "$pattern" == "" ]; then
			echo "Enter the matching pattern"
			IFS= read -r pattern
			fi
		printf "$progid $dttm BUGS_110 awk path=$path\n";
		if [ ! -d $path ]; then
			printf "$progid $dttm BUGS_110 awk NOTFOUND path=$path\n";
			exit;
			fi
# FS	file separator
# OFS	output file separator
# RS
# ORS
# NR		number records
# NF		number fields
# FILENAME
# FNR
# BEGIN {}
# END {}
# BEGIN{FS="|";}

#		awk 'NR==FNR{a[$1];next}$1 in a{print $1}' file1 file2


#		cd "$path" || exit
#		awk -v pattern="$pattern" '$0 ~ pattern{for (i=1; i<=10; i++) {getline;print}}' filename
#		cat $path/*.html | awk -v pattern="$pattern" '$0 ~ pattern{for (i=1; i<=10; i++) {getline;print}}' 
#		cat *.html | awk -v pattern="$pattern" '$0 ~ pattern{for (i=1; i<=10; i++) {getline;print}}' 

		exit;
		fi # if [ "$1" == "awk" ] || [ "$1" == "awk" ]; then

	if [ "$1" == "db3s2psv" ] || [ "$1" == "db3s2psv" ]; then
		printf "$progid $dttm db3s2psv ==================\n";
		db3s="../ht/ko/ko.db3"
		db3s="../ht/ko/ko.db3 ../ht/ko/tl.db3 ../ht/ko/leds.db3"
		tblmatch="items";
		tbls="files contacts letter items"
		if [ "$2" != "" ]; then tbls=$2; fi
		j=0; k=0
		for db3 in $db3s; do
			if [ ! -f $db3 ]; then printf "BUGS_200 NOTFOUND db3=$db3\n"; continue; fi
			let j=j+1
			psvfil=`echo $db3 | sed -e "s:db3$:psv:"`
#			printf "BUGS_201 j=$j db3=$db3 psvfil=$psvfil\n"
			sqltbls="";
			if [ "$2" == "" ]; then 
				tbls=`sqlite3 $db3 .tables | tr -s ' ' | tr -d '\n'`
			else
				tbls=$2; 
				fi
#			printf "BUGS_202 j=$j db3=$db3 tbls=$tbls\n"

			k=0;
			db3bak=`echo $db3 | sed -e "s:.db3$:_$dttm.db3:"`
#			printf "cp $db3 $db3bak";
#			cp $db3 $db3bak
			for tbl in $tbls; do
				let k=k+1
				psvfil=`echo $db3 | sed -e "s:.db3$:_$tbl.psv:"`
				if [ -f $psvfil ]; then
					wc=`cat $psvfil | wc -l | awk '{print $1}'`
					if [ "$wc" == "0" ]; then
						printf "BUGS_201 ($j,$k) $db3 wc=$wc RM psvfil=$psvfil\n";
						rm $psvfil
#					else
#						printf "BUGS_202 ($j,$k) $db3 WC=$wc __ psvfil=$psvfil\n";
						fi
					fi


				tblcheck=`sqlite3 $db3 .tables | grep "$tbl"`
				if [ "$tblcheck" == "" ]; then
					printf "BUGS_201 ($j,$k) $db3 NOTFOUND TBL=$tbl\n";
					if [ -f $psvfil ]; then 
						printf "BUGS_201 ($j,$k) db3=$db3 REMOVE psvfil=$psvfil\n";
						rm $psvfil; 
						fi
					continue;
				else
					printf "BUGS_212 ($j,$k) $db3 ___FOUND tbl=$tbl\n";
					fi

#				printf "BUGS_210 j=$j _______ $db3 tbl=$tbl\n";
#				printf "BUGS_211 j=$j db3=$db3 psvfil_tbl=$psvfil\n"
#				printf "BUGS_212 j=$j sqlite3 -header $db3 \"select * from $tbl\" > $psvfil\n";
#				printf "BUGS_203 ($j,$k) $db3 tbl=$tbl\n";



				printf "BUGS_204 ($j,$k) $db3 sqlite3 -header $db3 \"select * from $tbl\" > $psvfil\n";
				sqlite3 -header $db3 "select * from $tbl" > $psvfil




#				printf "BUGS_204 j=$j sqlite3 $db3 \"delete  from $tbl\"\n";
#				printf "BUGS_205 j=$j sqlite3 $db3 \"vacuum\"\n";
#				printf "BUGS_206 j=$j sqlite3 $db3 \".import $psvfil $tbl\"\n";
#				head $psvfil
				wc=""
				if [ -f $psvfil ]; then
					wc=`cat $psvfil | wc -l | awk '{print $1}'`
	
					if [ "$wc" == "0" ]; then
						printf "BUGS_221head ($j,$k) $db3 wc=$wc RM psvfil=$psvfil\n";
						rm $psvfil
						wc -l $psvfil
						printf "BUGS_221tail ($j,$k) $db3 wc=$wc RM psvfil=$psvfil\n";
						exit;
					else
						printf "BUGS_222 ($j,$k) $db3 WC=$wc __ psvfil=$psvfil\n";
						fi
				else
					printf "BUGS_220 ($j,$k) $db3 WC=$wc __ NOTFOUND psvfil=$psvfil\n";
					fi
				done
			
			done
#		wc -l ../ht/ko/*.psv
		exit;
		fi # if [ "$1" == "db3s2psv" ] || [ "$1" == "db3s2psv" ]; then

	if [ "$1" == "awk" ] || [ "$1" == "awk" ]; then
		path=../ht/ko
		items=`find $path -name "ko_??.html"`
		j=0;
		for item in $items; do
			let j=j+1;
#			printf "item=$item\n";
			nr=`cat $item | awk -F"\n" '/script_toggles/ { print N$" "$0 }'`
			printf "BUGS_120 awk item=$item nr=$nr\n";
			done
		exit;
		printf "$progid $dttm awk path=$path  ==================\n";
#		echo | awk -v variable='This is variable!' 'END{print variable}'
		pattern=$2
		if [ "$pattern" == "" ]; then
			echo "Enter the matching pattern"
			IFS= read -r pattern
			fi
		printf "$progid $dttm BUGS_110 awk path=$path\n";
		if [ ! -d $path ]; then
			printf "$progid $dttm BUGS_110 awk NOTFOUND path=$path\n";
			exit;
			fi
# FS	file separator
# OFS	output file separator
# RS
# ORS
# NR		number records
# NF		number fields
# FILENAME
# FNR
# BEGIN {}
# END {}
# BEGIN{FS="|";}

#		awk 'NR==FNR{a[$1];next}$1 in a{print $1}' file1 file2


#		cd "$path" || exit
#		awk -v pattern="$pattern" '$0 ~ pattern\{for (i=1; i<=10; i++) \{getline;print\}\}' filename
#		cat $path/*.html | awk -v pattern="$pattern" '$0 ~ pattern{for (i=1; i<=10; i++) {getline;print}}' 
#		cat *.html | awk -v pattern="$pattern" '$0 ~ pattern{for (i=1; i<=10; i++) {getline;print}}' 

		exit;
		fi # if [ "$1" == "awk" ] || [ "$1" == "awk" ]; then

	if [ "$1" == "dirs2html" ] || [ "$1" == "dirs2html" ]; then
#		htmlfile="$ht/ko/jtfdcr_links.html"
		printf "$progid $dttm dirs2html ==================\n";
		printf "$progid $dttm dirs2html fdir=$fdir tdir=$tdir ht=$ht htmlfile=$htmlfile ht_htmlfile=$ht_htmlfile\n";
#		if [ -d $fdir ]; then printf "BUGS_101 ___FOUND  fdir=$fdir\n"; fi
#		if [ -d $tdir ]; then printf "BUGS_101 ___FOUND  tdir=$tdir\n"; fi
		if [ ! -d $fdir ]; then printf "BUGS_101 NOTFOUND  fdir=$fdir\n"; exit; fi
		if [ ! -d $tdir ]; then printf "BUGS_102 NOTFOUND  tdir=$tdir\n"; exit; fi
		items=`find $fdir -type f -name "*.html" | grep "gojs" `
		j=0; k=0;
		htmout=""
		htmout="$htmout""\n<html>\n<head>\n	<title>$htmlfile $dttm</title>\n	</head>\n" 
		htmout="$htmout""<body bgcolor=linen>\n"; 
		htmout="$htmout""	<h1>$htmlfile $dttm</h1>\n" 
		htmout="$htmout""	<hr color=black>\n";
		htmout="$htmout""	<div id=div_html>\n";
		htmout="$htmout""	<h2>div_html</h2>\n";
		htmout="$htmout""	<table id=table_html>\n";
		htmout="$htmout""	<tr><td>num</td><td>link</td><td>item</td></tr>\n";
		printf "BUGS_140 htmout=$htmout\n"
		for item in $items; do
			let j=j+1
			link="<a href=$item target=_blank>"
			link="$link""<img src=/imgs/btn/brdb.png height=50>"
			link="$link""</a>"
			htmout="$htmout""<tr>\n"
			htmout="$htmout""<td>$j</td><td>$link</td><td>$item</a></td>\n"
			htmout="$htmout""</tr>\n"
			done
		htmout="$htmout""		</table id=table_html_end>\n"
		htmout="$htmout""		</div id=div_html_end>\n"
		htmout="$htmout""		<hr color=white>\n"
		printf "$htmout" >> $ht_htmlfile

		items=`find $fdir  -type f -name "*.png"`
		j=0; k=0;
		
		htmout="$htmout""	<div id=div_png>\n"
		htmout="$htmout""	<h2>div_png></h2>\n"
		htmout="$htmout""	<table id=table_png>\n" 
		htmout="$htmout""	<tr><td>num</td><td>link</td><td>item</td></tr>\n"
		for item in $items; do
			let k=k+1
			link="<a href=$item target=_blank>"
			link="$link""<img src=$item height=50>"
			link="$link""</a>"
			htmout="$htmout""<tr>\n";
			htmout="$htmout""<td>$k</td><td>$link</td><td>$item</a></td>" 
			htmout="$htmout""</tr>\n"
			done
		htmout="$htmout""		</table id=table_png_end>\n"
		htmout="$htmout""		</div id=div_png_end>\n"
		htmout="$htmout""		<hr color=black>\n"
#		printf $htmout
		printf $htmout >> $ht_htmlfile
#		open http://ka12/$htmlfile
		vi $ht_htmlfile
		printf "vi $ht_htmlfile\n";
		printf "http://ka12$htmlfile";
		exit;
		fi # if [ "$1" == "dirs2html" ] || [ "$1" == "dirs2html" ]; then

	if [ "$1" == "go" ] || [ "$1" == "db2leds" ]; then
		content=""; links=""; htmout=""; j=0; k=0;
		src="/fb/konet/pages/1.jpg";
		led="/imgs/leds/hal/hal000.gif";
		db3="../ht/ko/ko.db3";
		tbl="items";
		sql="select rowid,pathfile,path,file,base,ext,desc from $tbl"
		leds_content="leds_content.txt";
		leds_links="leds_links.txt";
		printf "" > $leds_content
		printf "" > $leds_links

		printf "BUGS_123 leds db3=$db3 tbl=$tbl sql=$sql \n";
		items=`sqlite3 $db3 "$sql"`
		for item in $items; do
			let j=j+1;
			rowid=`echo $item | awk -F"|" '{ print $1 }'`
			pathfile=`echo $item | awk -F"|" '{ print $2 }'`
			path=`echo $item | awk -F"|" '{ print $3 }'`
			file=`echo $item | awk -F"|" '{ print $4 }'`
			base=`echo $item | awk -F"|" '{ print $5 }'`
			ext=`echo $item | awk -F"|" '{ print $6 }'`
			desc=`echo $item | awk -F"|" '{ print $7 }'`
			led="/imgs/leds/hal/hal000.gif"
			src=$pathfile;
			printf "BUGS_124 j=$j rowid=$rowid pathfile=$pathfile base=$base ext=$ext desc=$desc\n";
			content="$content""content[$j]='<br><big><b>$desc</b></big><br>$desc<hr color=white><img id=img_led_$j title=\"          led_$j\" src=$src height=400 border=>'\n"

			links="$links"""
			links="$links""<img id=img_led_$j title=\"          led_$j\"";
			links="$links"" src=$led ";
			links="$links"" onclick=\"window.open('$src'); return false;\" ";
			links="$links"" onMouseover=\"changetext(content[$j])\" height=10 border=0>";
			links="$links"" height=10 border=0>\n";
			if [ $j -gt 10 ]; then break; fi
			done

		printf "$content" > $leds_content
		printf "$links" > $leds_links
		vi $leds_content
		vi $leds_links
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "db2leds" ]; then

	if [ "$1" == "go" ] || [ "$1" == "png2gif" ]; then
		ht="../ht/imgs/leds/hal"
		j=0; k=0; speed=10;
bg="$ht/hal_bg.png"
bg0="$ht/hal_bg0.png"
hues="000"
delays="1 50 100 200 300 500 1000";
hues="000 050 100 110 120 150 190"
		for hue in $hues; do
			png="$ht/hal$hue.png"
			gif="$ht/hal$hue.gif"
#			printf "CONVERT $bg0 $png $bg $gif\n";
			if [ "$2" == "go" ]; then
				printf "convert $bg0 $png $bg $gif\n";
				convert $bg0 $png $bg $gif
				if [ -f $gif ]; then
					for delay in $delays; do
						printf "convert $gif -delay $delay $gif2\n";
						gif2="$ht/hal$hue""_$delay.gif";
						convert $gif -delay $delay $gif2
						done
					fi
				fi
			done
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "png2gif" ]; then

	if [ "$1" == "go" ] || [ "$1" == "items2db3" ]; then
# read file line by line
#		while IFS= read -r line; do
#			if [[ "$line" == *"apt"* ]]; then
#				printf '%s\n' "$line"
#				fi
#			done < distros.txt

tbls="items contacts letter postturtles coffee floods monkeytraps"
tbls="items"
tbls="contacts letter postturtles coffee floods monkeytraps"
db3="../ht/ko/ko.db3";
db3bak="../ht/ko/ko_$dttm.db3"
ht="../ht";
#		if [ -f $db3 ]; then printf "BUGS_100 cp $db3 $db3bak\n"; cp $db3 $db3bak; ls -lat $db3bak; exit; fi
		j=0; k=0; i=0;
		for tbl in $tbls; do
			let j=j+1;
			txtfil="../ht/ko/lists_$tbl.txt"
			if [ ! -f $txtfil ]; then
				printf "BUGS_102 NOTFOUND db3=$db3 tbl=$tbl txt=$txt \n";
				continue;
				fi



#			printf "sqlite3 $db3 \"CREATE table if not exists $tbl as select * from files limit 1\" \n"
#			if [ "$2" == "go" ]; then
#				printf "sqlite3 $db3 \"create table if not exists $tbl as select * from files limit 1\" \n"
#				sqlite3 $db3 "create table if not exists $tbl as select * from files limit 1"
#				fi
#			sqlite3 $db3 ".tables";
#			continue;

			k=0;
			items=`cat $txtfil`
			items_len=`cat $txtfil | wc -l`


			OLDIFS=$IFS; IFS=$'\n'
			items=($(cat $txtfil  ))
			items_len=${#items[@]}
#			printf "BUGS_104 txtfil=$txtfil items_len=$items_len\n";
			for (( f=0; f<${items_len}; f++ )); do
				item="${items[$f]}"
				pathfile=`echo $item | awk -F"|" '{ print $1 }'`
				desc=`echo $item | awk -F"|" '{ print $2 }'`
				if [ ! -f $ht/$pathfile ]; then
					printf "BUGS_201 NOTFOUND pathfile=$pathfile\n";
					continue;
					fi
				dirname=`dirname $pathfile`
				basename=`basename $pathfile`
				dirbase=`basename $dirname`
				file=$basename
				base=`echo $file | awk -F"." '{ print $1 }'`
				ext=`echo $file | awk -F"." '{ print $2 }'`
				exif_dt=`exiftool $ht/$pathfile | grep "Create" | head -1 | cut -c35-54 | sed -e "s/:/,/g" `
				exif_tm=`exiftool $ht/$pathfile | grep "Create" | head -1 |cut -c46-53 `
				desc=$pathfile
				headline=$pathfile;

				printf "BUGS_212 ($j,$k,$items_len) txtfil=$txtfil pathfile=$pathfile dirbase=$dirbase file=$file ext=$ext exif_dt=$exit_dt exif_tm=$exif_tm\n";
flds="'pathfile','path','file','base','ext','dttm','exif_dt','exif_tm','desc','headline'"
vals="'$pathfile','$path','$file','$base','$ext','$dttm','$exif_dt','$exif_tm','$desc','$headline'"
				printf "sqlite3 $db3 \"INSERT into $tbl ( $flds ) values ( $vals );\"\n";
				if [ "$2" == "go" ]; then
					printf "sqlite3 $db3 \"insert into $tbl ( $flds ) values ( $vals );\"\n";
					sqlite3 $db3 "insert into $tbl ( $flds ) values ( $vals )";
					fi

				let k=k+1;
				done

			printf "sqlite3 $db3 \"select count(*) from $tbl\"\n";
			sqlite3 $db3 "select count(*) from $tbl"
			IFS=$OLDIFS;
			done
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "items2db3" ]; then

	if [ "$1" == "go" ] || [ "$1" == "go" ]; then
		printf "$progid $dttm GO $db3 $tbl tbls=$tbls\n";
		fdir="../ht/byrdbellvjk/imgs";
		tdir="../ht/byrdbellvjk/";
		ht="../ht";
		name="*.*"
		imgtxt="$fdir/imgs.txt";
		imgpdf="$fdir/imgs.pdf";

		
		if [ "$2" == "vi" ]; then flag_vi="vi"; fi
		if [ "$2" == "scp" ]; then flag_scp="scp"; fi
		if [ "$2" == "rm" ]; then flag_rm="rm"; fi
		if [ "$2" == "mkdir" ]; then flag_mkdir="mkdir"; fi

#		flag_scp="scp";
		flag_vi="vi";
		flag_mkdir="mkdir"
		flag_convert="convert"

		if [ ! -d $fdir ]; then
			printf "$progid $dttm NOTFOUND_FDIR fdir=$fdir name=$name\n";
			exit;
		else
			printf "$progid $dttm ___FOUND_FDIR $fdir/pages\n";
			fi

		if [ ! -d $tdir/pages ]; then
			printf "$progid $dttm NOTFOUND_PG fdir=$fdir name=$name\n";
			if [ "$flag_mkdir" == "mkdir" ]; then mkdir $tdir/pages; fi
		else
			printf "$progid $dttm ___FOUND_PG $tdir/pages\n";
#			p0=`find $tdir/pages -maxdepth 1 -type f -name "*.jpg" | sed -e "s:.jpg$::" | head -1`
			p0=`find $tdir -type f -maxdepth 1 -name "*.*" | awk '{ print NR }' | tail -1`
			fi

		if [ ! -d $tdir/pages/zn ]; then
			printf "$progid $dttm NOTFOUND_ZN fdir=$fdir name=$name\n";
			if [ "$flag_mkdir" == "mkdir" ]; then mkdir $tdir/pages/zn; fi
		else
			printf "$progid $dttm ___FOUND_TN $tdir/pages/zn\n";
			fi

		if [ ! -d $tdir/pages/tn ]; then
			printf "$progid $dttm NOTFOUND_TN fdir=$fdir name=$name\n";
			if [ "$flag_mkdir" == "mkdir" ]; then mkdir $tdir/pages/tn; fi
		else
			printf "$progid $dttm ___FOUND_TN $tdir/pages/tn\n";
			fi

#		if [  -f $imgtxt ]; then rm $imgtxt; exit; fi
		if [ "$flag_rm" == "rm" ]; then 
			if [ -f $imgtxt ]; then
				rm $imgtxt; 
				exit; 
				fi
			fi
		if [ ! -f $imgtxt ]; then
			printf "$progid $dttm NOTFOUND_IMGTXT imgtxt=$imgtxt\n";
#			`find $fdir -type f -name "*.*" > $imgtxt`
#			`find $fdir -type f -name "*.*" | awk '{ printf "grp|id|$1|$1" }'> $imgtxt`
			`find ../ht/byrdbellvjk/pages -maxdepth 1 -type f -name "*.jpg" | awk '{ print NR"|grp|id"NR"|"$1"|"$1 }' | sed -e "s:.jpg$::" | sed -e "s:../ht::g" > $imgtxt`
			if [ -f $imgtxt ]; then
				if [ "$flag_vi" == "vi" ]; then
					vi $imgtxt
					fi
				fi
			printf "$progid $dttm NOTFOUND_IMGTXT imgtxt=$imgtxt\n";
		else
			printf "$progid $dttm ___FOUND imgtxt=$imgtxt\n";
			printf "$progid $dttm VI imgtxt=$imgtxt\n";
			vi $imgtxt
			fi

		printf "$hostname $dttm ($j,$k) p0=$p0 item=$item imgtxt=$imgtxt pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
		if [ "$usrcmd" != "g" ]; then
			read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
			if [ "$usrcmd" == "q" ]; then exit; fi
			if [ "$usrcmd" == "s" ]; then continue; fi
			if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
			if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
			fi
		printf "$hostname $dttm $db3 ($j,$k) item=$item imgtxt$imgtxt bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"




		items=`cat $imgtxt`

		htmout=""; i=0; p=0;
		ht="../ht";
		for item in $items; do
			let i=i+1
			let p=p0+i;
			num=`printf $item | awk -F"|" '{ print $1 }'`
			grp=`printf $item | awk -F"|" '{ print $2 }'`
			id=`printf $item | awk -F"|" '{ print $3 }'`
			pathfile=`printf $item | awk -F"|" '{ print $4 }'`
			desc=`printf $item | awk -F"|" '{ print $5 }' | sed -e "s:$ht::"`
			if [ "$id" == "" ] || [ "$id" == "id" ]; then
				id="id$p"
				fi

			printf "BUGS_850 $i,$p num=$num grp=$grp id=$id pathfile=$pathfile desc=$desc\n";
			if [ $i -gt 10 ]; then exit; fi
			continue;

			dirname=`dirname $item`
			basename=`basename $item`
			file=`echo $basename | awk -F"." '{ print $1 }'`
			ext=`echo $basename | awk -F"." '{ print $2 }'`

			if [ ! -d $dirname/pages ]; then
				printf "$prodid $dttm MK_PAGES mkdir $dirname/pages\n";
				fi
			if [ ! -d $dirname/pages/zn ]; then
				printf "$prodid $dttm MK_ZN mkdir $dirname/pages/zn\n";
				fi
			if [ ! -d $dirname/pages/tn ]; then
				printf "$prodid $dttm MK_TN mkdir $dirname/pages/tn\n";
				fi


			pg="$dirname/pages/$p.jpg"
			zn="$dirname/pages/zn/zn_$p.jpg"
			tn="$dirname/pages/tn/tn_$p.png"
			if [ ! -f $zn ]; then 
				printf "CONVERT_ZN convert $ht$item -resize 1100x $ht$zn\n";
				if [ "$flag_convert" == "convert" ]; then
					convert $ht$item -resize 1100x $ht$zn; 
					fi
				fi
			if [ ! -f $pg ]; then 
				printf "CONVERT_PG convert $ht$item -resize 650x $ht$pg\n";
				if [ "$flag_convert" == "convert" ]; then
					convert $ht$item -resize 650x $ht$pg; 
					fi
				fi
			if [ ! -f $tn ]; then 
				printf "CONVERT_TN $ht$item -resize 400x $ht$tn\n"
				if [ "$flag_convert" == "convert" ]; then
					convert $ht$item -resize 400x $ht$tn; 
					fi
				fi
			done

		if [ "$flag_scp" == "scp" ]; then
hosts="
kotowus@ko2.us:~/public_html
kotowus@ko2.us:~/public_html
ka2:/Volumes/ka2tbr1/ht
ka1:/Volumes/ka1tbr2/ht
"

			cp ../ht/law/help.html ../ht/law/help.htm
			cp ../ht/law/help.html ../ht/law/help_best.html
			cp ../ht/law/help.html ../ht/law/help_$dttm.html
			j=0;
			for host in $hosts;do
				hostsname=`echo $host | awk -F":" '{ printf $1 }'`
				if [ "$hostname" == "$hostsname" ] ; then continue; fi

				let j=j+1;
				printf "scp ../ht/law/help.htm* $host/law/\n";
#				scp ../ht/law/help.htm* $host/law/
				done


			fi


		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "go" ]; then

	if [ "$1" == "go" ] || [ "$1" == "go" ]; then
		printf "$progid $dttm GO $db3 $tbl tbls=$tbls\n";
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "go" ]; then

	if [ "$1" == "txt2txt" ] || [ "$1" == "txt2txt" ]; then
#		cp ../ht/law/index.html ../ht/law/index.htm
#		cp ../ht/law/index.html ../ht/law/index_best.html
#		cp ../ht/law/index.html ../ht/law/index_20230405_2100.html
#		scp ../ht/law/index.htm* kotwous@ko2.us:~/public_html/law/
#		scp ../ht/law/law_media.html kotwous@ko2.us:~/public_html/law/
#		scp ../ht/law/index.htm* kozerus@ko0.us:~/public_html/law/
#		scp ../ht/law/law_media.html kozerus@ko0.us:~/public_html/law/
#		scp ../ht/law/index.htm* ka2:/Volumes/ka2tbr1/ht/law/
#		scp ../ht/law/law_media.html ka2:/Volumes/ka2tbr1/ht/law/
#	exit;
		wlfile="txt2txt.txt"
		dir="../ht/byrdbellvjk/mp4"
		name="*_201*_*.mp4"
		type="f"
		printf "$progid $dttm wlfile=$wlfile dir=$dir name=$name\n";
#		printf "find $dir -type $type -name \"$name\" > $wlfile\n";
#		find $dir -type d -name "$name" > $wlfile

		if [ ! -f $wlfile ]; then
			printf "BUGS_105 NOTFOUND wlfile=$wlfile\n";
			exit;
		else
			items=`cat $wlfile`;
			wc=`wc -l $wlfile`
			fi
		printf "BUGS_106 $progid $dttm cat $wlfile\n";
		printf "BUGS_107 $progid $dttm wc=$wc items=$items\n";

		notefile="../ht/notes.html"
		notefile="../ht/notes.txt"
		htmlfile="../ht/law/law_media.html";
		htmout="";
		htmout="$htmout<html>\n";
		htmout="$htmout<head>\n";
		htmout="$htmout<title>/law/law_media.html 20230205_1830</title>\n"
		htmout="$htmout	</head>\n";
		htmout="$htmout<body bgcolor=linen>\n";

		htmout="$htmout<div id=div_media>\n";
		htmout="$htmout<h1>div_media</h1>\n";
		htmout="$htmout<table id=table_media>\n";
		htmout="$htmout<tr>";
		htmout="$htmout<td width=50>num</td>";
		htmout="$htmout<td width=100>date</td>";
		htmout="$htmout<td width=400>desc</td>";
		htmout="$htmout<td width=100>mp4</td>";
		htmout="$htmout<td width=50>mp4size</td>";
		htmout="$htmout<td width=100>mp3</td>";
		htmout="$htmout<td width=50>mp3size</td>";
		htmout="$htmout<td width=100>txt</td>";
		htmout="$htmout<td width=50>txtsize</td>";
		htmout="$htmout<td width=50>wc</td>";
		htmout="$htmout<td width=50>pdf</td>";
		htmout="$htmout<td width=50>pdfsize</td>";
		htmout="$htmout	</tr>\n";

		if [ ! -f $notefile ]; then
			printf "BUGS_125 NOTFOUND notefile=$notefile\n";
			exit;
			fi

		j=0; k=0; i=0; l=0;
		for item in $items; do
			if [ "$item" == "" ]; then continue; fi
			if [ "$item" == " " ]; then continue; fi

			mask=`echo $item | awk -F"|" '{ print $1 }'`
			path=`echo $item | awk -F"|" '{ print $2 }'`
			base=`echo $item | awk -F"|" '{ print $3 }'`
			file=`echo $base | awk -F"." '{ print $1 }'`
			ext=`echo $base | awk -F"|" '{ print $2 }'`

			if [ "$mask" == "" ]; then continue; fi

			let j=j+1;
#			printf "BUGS_101 $progid $dttm j=$j mask=$mask path=$path base=$base file=$file ext=$ext\n";
			mp4="/byrdbellvjk/mp4/$base.mp4";
			mp3="/byrdbellvjk/mp3/$base.mp3";
			pdf="/byrdbellvjk/pdf/$base.pdf";
			txt="/byrdbellvjk/txt/$base.txt";
			jpg="/byrdbellvjk/mp4/$base.jpg";
			tn="./byrdbellvjk/mp4/tn_$base.png";
			txtfil="../ht/byrdbellvjk/txt/$base.txt";

#			if [ ! -f $txtfil ]; then
#				printf "BUGS_151 NOTFOUND txtfil=$txtfil\n";
#				continue;
#			else
#				wc=`wc -l $txtfil | awk -F" " '{ print $1 }' | sed -e "s: ::g" `
##				printf "BUGS_152 ___FOUND wc=$wc txtfil=$txtfil\n";
#				
#				fi

#			if [ '$wc' != "1" ]; then continue; fi
#			if [ $wc -gt 2 ]; then continue; fi
#			`cat $notefile | grep \"$mask\" > $txtfil`


#			wc=`wc -l $txtfil | awk -F" " '{ print $1 }' | sed -e "s: ::g" `
#			printf "BUGS_160 $progid $dttm j=$j wc=$wc cat $notefile | grep \"$mask\" >> $txtfil\n";
#			if [ $wc -le 2 ]; then continue; fi
			

		printf "$hostname $dttm ($j,$k) wc=$wc txtfil=$txtfil pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
		if [ "$usrcmd" != "g" ]; then
			read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
			if [ "$usrcmd" == "q" ]; then exit; fi
			if [ "$usrcmd" == "s" ]; then continue; fi
			if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
			if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
			fi
		printf "$hostname $dttm $db3 ($j,$k) wc=$wc txtfil$txtfil bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"

#			if [ -f $txtfil ]; then
#				cat $txtfil
#				printf "BUGS_170 cat $txtfil\n";
#				fi

			height=40;
			href_mp4="";
			if [ -f ../ht/byrdbellvjk/mp4/$base.mp4 ]; then
				if [ -f ../ht/byrdbellvjk/mp4/$base.jpg ]; then 
					height=100;
					href_mp4="$href_mp4<a href=/byrdbellvjk/mp4/$base.mp4 target=_blank>"
					href_mp4="$href_mp4<img src=/byrdbellvjk/mp4/$base.jpg height=$height border=0></a>"
				else
					height=40;
convert ../ht/byrdbellvjk/mp4/jtfdc_20160530_1916_byrd_threat.jpg -resize 100x ../ht/byrdbellvjk/mp4/$base.jpg
					href_mp4="$href_mp4<a href=/byrdbellvjk/mp4/$base.mp4 target=_blank>"
					href_mp4="$href_mp4<img src=/byrdbellvjk/mp4/jtfdc_20160530_1916_byrd_threat.jpg height=$height border=0></a>"
					fi

				fi

			height=20;
			href_mp3="";
			if [ -f ../ht/byrdbellvjk/mp3/$base.mp3 ]; then 
				height=40
				href_mp3="$href_mp3<a href=/byrdbellvjk/mp3/$base.mp3 target=_blank>"
				href_mp3="$href_mp3<img src=/imgs/btn/koeye_mp3.png height=$height border=0>"
				href_mp3="$href_mp3</a>";
			else
#				cp ../ht/byredbellvjk/mp3/jtfdc_20190516_0830_1m23-1m33.mp3 ../ht/byrdbellvjk/mp3/$base.mp3
				href_mp3="$href_mp3<a href=/byrdbellvjk/mp3/$base.mp3 target=_blank>"
				href_mp3="$href_mp3<img src=/imgs/btn/koeye_mp3.png height=$height border=0>"
				href_mp3="$href_mp3</a>";
				fi

			height=20;
			href_txt="";
			printf "cp $notefile ../ht/byrdbellvjk/txt/$base.txt\n";
#			cp $notefile ../ht/byrdbellvjk/txt/$base.txt;
			printf "/byrdbellvjk/txt/$base.txt =================================\n" > ../ht/byrdbellvjk/txt/$base.txt

#			cat $notefile | grep "$mask" >> ../ht/byrdbellvjk/txt/$base.txt

			if [ -f ../ht/byrdbellvjk/txt/$base.txt ]; then 
				height=40
				href_txt="$href_txt<a href=/byrdbellvjk/txt/$base.txt target=_blank>"
				href_txt="$href_txt<img src=/imgs/btn/koeye_txt.png height=$height border=0>"
				href_txt="$href_txt</a>";
			else
				printf "/byrdbellvjk/txt/$base.txt\n" >> ../ht/byrdbellvjk/txt/$base.txt
				href_txt="$href_txt<a href=/byrdbellvjk/txt/$base.txt target=_blank>"
				href_txt="$href_txt<img src=/imgs/btn/koeye_txt.png height=$height border=0>"
				href_txt="$href_txt</a>";
				fi

			height=20;
			href_pdf="";
			if [ -f ../ht/byrdbellvjk/pdf/$base.pdf ]; then 
				height=40;
				href_pdf="$href_pdf<a href=/pdf/web/viewer.html?file=/byrdbellvjk/pdf/$base.pdf target=_blank>"
				href_pdf="$href_pdf<img src=/imgs/btn/btn_pdf1.png height=$height border=0>"
				href_pdf="$href_pdf</a>";
			else
#				cp ../ht/byrdbellvjk/byrdbellvjk.pdf ../ht/byrdbellvjk/pdf/$base.pdf
				href_pdf="$href_pdf<a href=/pdf/web/viewer.html?file=/byrdbellvjk/pdf/$base.pdf target=_blank>"
				href_pdf="$href_pdf<img src=/imgs/btn/btn_pdf1.png height=$height border=0>"
				href_pdf="$href_pdf</a>";
				fi

			
#			mp4size=`du -k ../ht/byrdbellvjk/mp4/$base.mp4 | awk -F" " '{ print $5 }'`
#			mp3size=`du -k ../ht/byrdbellvjk/mp3/$base.mp3 | awk -F" " '{ print $5 }'`
#			pdfsize=`du -k ../ht/byrdbellvjk/pdf/$base.pdf | awk -F" " '{ print $5 }'`

			mp4size=`stat -f %z ../ht/byrdbellvjk/mp4/$base.mp4 | awk -F" " '{ print $5 }'`
			mp3size=`stat -f %z ../ht/byrdbellvjk/mp3/$base.mp3 | awk -F" " '{ print $5 }'`
			pdfsize=`stat -f %z ../ht/byrdbellvjk/pdf/$base.pdf | awk -F" " '{ print $5 }'`

printf "BUGS_270 base=$base\n";
			mp4duh=`du -h ../ht/byrdbellvjk/mp4/$base.mp4 | awk '{ print $1}'`
			mp3duh=`du -h ../ht/byrdbellvjk/mp3/$base.mp3 | awk '{ print $1}'`
			pdfduh=`du -h ../ht/byrdbellvjk/pdf/$base.pdf | awk '{ print $1}'`
			txtduh=`du -h ../ht/byrdbellvjk/txt/$base.txt | awk '{ print $1}'`
#			txtwc=`ls -lat ../ht/byrdbellvjk/txt/$base.txt | awk '{ print $1 }'`
			txtwc=`wc -l ../ht/byrdbellvjk/txt/$base.txt | awk '{ print $1 }'`

#			printf "BUGS_281 mp4duh=$mp4duh base=$base\n";
#			printf "BUGS_282 mp3duh=$mp3duh base=$base\n";
#			printf "BUGS_283 pdfduh=$pdfduh base=$base\n";
#			printf "BUGS_284 txtduh=$txtduh base=$base\n";
#			printf "BUGS_285 txtwc=$txtwc base=$base\n";

#			du -h .
#			SIZE=$(du -B 1 /path/to/directory | cut -f 1 -d "   ")    
#			2GB = 2147483648 bytes
#			10GB = 10737418240 bytes
# 			if [[ $SIZE -gt 2147483648 && $SIZE -lt 10737418240 ]]; then printf "$SIZE 2GB-10GB\n"; fi





			htmout="$htmout<tr>\n";
			
			htmout="$htmout<td>$j</td>\n"
			htmout="$htmout<td><b><font style=\"font-size:20\">$mask</b></font></td>\n"
			htmout="$htmout<td><b><font style=\"font-size:16\">$base</b></font></td>\n"
			htmout="$htmout<td>$href_mp4</td>\n"
			htmout="$htmout<td>$mp4duh</td>\n"
			htmout="$htmout<td>$href_mp3</td>\n"
			htmout="$htmout<td>$mp3duh</td>\n"
			htmout="$htmout<td>$href_txt</td>\n"
			htmout="$htmout<td><b>$txtduh</b></td>\n"
			htmout="$htmout<td><b>$txtwc</b></td>\n"
			htmout="$htmout<td>$href_pdf</td>\n"
			htmout="$htmout<td>$pdfduh</td>\n"
			htmout="$htmout</tr>\n"

			
			continue;

#			`cat $notefile | grep "$mask" `

			done

		htmout="$htmout	</table id=table_media_end>\n";
		htmout="$htmout	</div id=div_media_end>\n";
		printf "$htmout" > $htmlfile;

		printf "htmlfile=$htmlfile\n";
#		vi $htmlfile

#		printf "vi $wlfile"
#		wc -l $wlfile
		exit;
		fi # if [ "$1" == "txt2txt" ] || [ "$1" == "txt2txt" ]; then
	
	if [ "$1" == "go" ] || [ "$1" == "go" ]; then
		db3="../tl.db3";
		tbls="tl mp4 mp3 pdf jpg txt";
		tbl="tl";
		j=0; k=0;
		exts="pdf mp3 mp4 txt jpg";
		printf "$progid $dttm GO $db3 $tbl\n";
		for tbl in $tbls; do
			printf "$progid $dttm GO $db3 $tbl tbl=$tbl\n";


			done
			if [ "$usrcmd" != "g" ]; then
				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
				if [ "$usrcmd" == "q" ]; then exit; fi
				if [ "$usrcmd" == "s" ]; then continue; fi
				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
				fi

			printf "$dttm $j $file pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"

		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "go" ]; then

	if [ "$1" == "ssk" ] || [ "$1" == "ssk" ]; then
		ssk="~/.ssk/kibble.txt";
		if [ -f ~/.ssk/kibble.txt ]; then
			printf "$progid $dttm ___FOUND ssk=$ssk\n";
			printf "cat $ssk\n";
			cat ~/.ssk/kibble.txt
		else
			printf "$progid $dttm NOTFOUND ssk=$ssk\n";
			fi

		if [ "$2"  == "go" ]; then
			printf "vi $ssk\n";
			vi $ssk
			fi
		exit;
		fi # if [ "$1" == "ssk" ] || [ "$1" == "ssk" ]; then

	if [ "$1" == "bugs" ] || [ "$1" == "bg" ]; then
		db3fil="../ht/birds/ko.db3"
		tbl="bugs";
		if [ ! -f $db3fil ]; then
			printf "BUGS_100 $progid $dttm $hostname NOTFOUND db3fil=$db3fil";
			exit;
			fi

#		if [ "$2" == "" ]; then
			printf "$progid $dttm $hostname db3fil=$db3fil tbl=$tbl\n";
#			sqlite3 -header $db3fil "select rowid,* from $tbl" | limit -10
#			exit;
#			fi


		bugfil="../ht/birds/bugs.txt";
		dttm=`date +"%Y%m%d_%H%M%S"`
		id="paco"
		dt=`date +"%Y%m%d"`
		tm=`date +"%H%M%S"`
		bugs=""; go="";

		if [ "$2" != "" ]; then bugs=$2; fi
		if [ "$3" != "" ]; then tm=$2; bugs=$3; fi
		if [ "$4" != "" ]; then dt=$2 tm=$3; bugs=$4; fi
		if [ "$5" != "" ]; then dt=$2 tm=$3; bugs=$4; go="g"; fi

		yyyy=`echo $dt | cut -c1-4`
		mm=`echo $dt | cut -c5-6`
		dd=`echo $dt | cut -c7-8`
		hh=`echo $tm | cut -c1-2`
		mn=`echo $tm | cut -c2-3`
		dt="$yyyy-$mm-$dd"
		tm="$hh:$mn:00"

		tot=`echo $bugs |  awk  '{ print length($0) }'`
		totc=`echo $bugs |  sed -e "s:m::gi" | sed -e "s:w::gi" | awk  '{ print length($0) }'`
		totm=`echo $bugs |  sed -e "s:c::gi" | sed -e "s:w::gi" | awk  '{ print length($0) }'`
		totw=`echo $bugs |  sed -e "s:m::gi" | sed -e "s:c::gi" | awk  '{ print length($0) }'`

		flds="'id','dt','tm','tot','totc','totm','totw','bugs'";
		vals="'$id','$dt','$tm','$tot','$totc','$totm','totw','$bugs'";
		

		printf "$hostname $progid $dttm bugs=$dt|$tm|$bugs\n";
		if [ "$2" == "go" ] || [ "$3" == "go" ] || [ "$4" == "go" ] || [ "$5" == "go" ]; then
			printf "sqlite3 $db3fil \"insert into $tbl ( $flds ) values ( $vals );\""
			sqlite3 $db3fil "insert into $tbl ( $flds ) values ( $vals );"
#			printf "$bugs\n" >> $bugfil;
#			printf "vi $bugfil\n";
#			vi $bugfil
			fi
		
		sqlite3 -header $db3fil "select rowid,* from $tbl" | tail -5
		if [ "$2" == "scp" ] || [ "$3" == "scp" ] || [ "$4" == "scp" ] || [ "$5" == "scp" ]; then
hosts="kozerus@ko0.us:~/public_html kotwous@ko2.us:~/public_html ka2:/Volumes/ka2tbr1/ht ka1:/Volumes/ka1tbr2/ht"
			for host in $hosts; do
				let j=j+1;
				localhost=`echo $host | grep "$hostname"`
				if [ "$localhost" != "" ]; then 
					printf "BUGS_105 SKIP localhost=$localhost\n";
					continue; 
					fi
				printf "scp ../ht/birds/ko.db3 $host/birds\n"

				scp ../ht/birds/ko.db3 $host/birds
				done
			fi
		exit;
		fi # if [ "$1" == "bugs" ] || [ "$1" == "bg" ]; then

	if [ "$1" == "scp" ] || [ "$1" == "scp" ]; then
hosts="ka1:/Volumes/ka1tbr2/ht";
hosts="ka2:/Volumes/ka2tbr1/ht";
hosts="kotwous@ko2.us:~/public_html";
hosts="ka2:/Volumes/ka2tbr1/ht kotwous@ko2.us:~/public_html kozerus@ko0.us:~/public_html";
dirs="law med byrdbellvjk ka ko1 konet iperms jtfdc jtfdcr jtfinc kofe newz"

		for host in $hosts; do
			for dir in $dirs; do
				printf "SCP ../ht/law/help.htm*  $host/$dir\n";
				if [ "$2" == "go" ]; then
					printf "scp ../ht/law/help.htm*  $host/$dir\n";
#
					scp ../ht/law/help.htm*  $host/$dir
					fi


				done
			done	




#			printf "scp ../ht/law/help.htm*  $host/law\n";
#			printf "scp ../ht/law/help.htm*  $host/med\n";
#			printf "scp ../ht/law/help.htm*  $host/byrdbellvjk\n";
#			printf "scp ../ht/law/help.htm*  $host/ka\n";
#			printf "scp ../ht/law/help.htm*  $host/ko1\n";
#			printf "scp ../ht/law/help.htm*  $host/konet\n";
#			printf "scp ../ht/law/help.htm*  $host/iperms\n";
#			printf "scp ../ht/law/help.htm*  $host/jtfdc\n";
#			printf "scp ../ht/law/help.htm*  $host/jtfdcr\n";
###			printf "scp ../ht/law/help.htm*  $host/jtfinc\n";
#			printf "scp ../ht/law/help.htm*  $host/kofe\n";
#			printf "scp ../ht/law/help.htm*  $host/newz\n";

#			printf "scp ../ht/brydbellvjk/tl.* $host/ka/\n";
#			printf "scp ../ht/brydbellvjk/tl.* $host/med/\n";
#			printf "scp ../ht/brydbellvjk/tl.* $host/law/\n";
#			printf "scp ../ht/brydbellvjk/tl.* $host/kofeshop/\n";
#			printf "scp ../ht/brydbellvjk/tl.* $host/byrdbellvjk/\n";
#			printf "scp ../ht/brydbellvjk/tl.* $host/konet/\n";
#			printf "scp ../ht/brydbellvjk/tl.* $host/ko1/\n";
#			printf "scp ../ht/brydbellvjk/tl.* $host/iperms/\n";
#
#
##			printf "scp ../ht/ka/index.ht* $host/ka/\n";

#			printf "scp ../*tl*.* $host/byrdbellvjk/\n";
#			printf "scp ??.sh $host/byrdbellvjk/pj/\n";
#			printf "scp ../help.* $host/byrdbellvjk/\n";
#			printf "scp ../todo.* $host/byrdbellvjk/\n";

#			printf "scp -r ../ht/ka/fb/jsk2 $host/ka/fb/\n"
#			printf "scp -r ../ht/ka/fb/gjw $host/ka/fb/\n"
#			printf "scp -r ../ht/ka/fb/kofeshop $host/ka/fb/\n"


#			printf "scp  ../ht/ka/pdf/jsk2.pdf $host/ka/pdf/\n"
#			printf "scp  ../ht/ka/pdf/jsk2_emilia.pdf $host/ka/pdf/\n"
#			printf "scp  ../ht/ka/pdf/gjw_wed_prep.pdf $host/ka/pdf/\n"
#			printf "scp  ../ht/ka/pdf/kofeshop.pdf $host/ka/pdf/\n"
#			printf "scp  ../ht/ka/pdf/kitiworks.pdf $host/ka/pdf/\n"


#			cp ../ht/ko/ko_fb.html ../ht/ka/fb/index.html
#			cp ../ht/ko/ko_fb.html ../ht/ka/fb/index.htm
#			cp ../ht/ka/fb/index.htm* ../ht/ka/fb/jsk2/
#			cp ../ht/ka/fb/index.htm* ../ht/ka/fb/jsk2/emilia/
#			cp ../ht/ka/fb/index.htm* ../ht/ka/fb/gjw/
#			cp ../ht/ka/fb/index.htm* ../ht/ka/fb/gjw/wed
#			cp ../ht/ka/fb/index.htm* ../ht/ka/fb/gjw/wed/wed_prep

#			if [ "$2" == "go" ]; then
#				printf "scp ../ht/law/help.htm*  $host/$dir\n";
#				scp ../ht/law/help.htm*  $host/$dir
#				done
#				printf "scp -r ../ht/leds $host/\n";
#				scp -r ../ht/leds $host/
	
#			scp ../ht/byrdbellvjk/index.htm* $host/byrdbellvjk/
#			scp ../ht/ka/index.htm* $host/ka/
#			scp ../ht/ko/index.htm* $host/ko/
#			scp ../ht/law/index.htm* $host/law/
#			scp ../ht/med/index.htm* $host/med/
#
#			scp ../ht/byrdbellvjk/index.htm* $host/byrdbellvjk/
#			scp ../ht/law/index.htm* $host/law/
#			scp ../ht/byrdbellvjk/index.htm* $host/ko/
#			scp ../ht/byrdbellvjk/tl.* $host/ka/
#			scp ../ht/byrdbellvjk/tl.* $host/med/
#			scp ../ht/byrdbellvjk/tl.* $host/law/
#			scp ../ht/byrdbellvjk/tl.* $host/kofeshop/
#			scp ../ht/byrdbellvjk/tl.* $host/byrdbellvjk/
#			scp ../ht/byrdbellvjk/tl.* $host/konet/
#			scp ../ht/byrdbellvjk/tl.* $host/ko1/
#			scp ../ht/brydbellvjk/tl.* $host/iperms/

#				printf "CMD_301: scp ../ht/ka/index.htm* $host/ka/\n";
#				scp ../ht/ka/index.htm* $host/ka/
#
#				scp ../ht/ka/fb/index.htm* $host/ka/fb/
#				scp ../ht/ka/fb/index.htm* $host/ka/fb/jsk2
#				scp ../ht/ka/fb/index.htm* $host/ka/fb/jsk2/emilia
#				scp ../ht/ka/fb/index.htm* $host/ka/fb/gjw
#				scp ../ht/ka/fb/index.htm* $host/ka/fb/gjw/wed
#				scp ../ht/ka/fb/index.htm* $host/ka/fb/gjw/wed/wed_prep
#				scp ../ht/ka/pdf/gjw*.pdf $host/ka/pdf
#				scp ../ht/ka/pdf/jsk2*.pdf $host/ka/pdf





#				scp -r ../ht/ka/fb/jsk2 $host/ka/fb/
#				scp -r ../ht/ka/fb/gjw $host/ka/fb/
#				scp -r ../ht/ka/fb/kofeshop $host/ka/fb/
#
#				scp  ../ht/ka/pdf/jsk2.pdf $host/ka/pdf/
#				scp  ../ht/ka/pdf/jsk2_emilia.pdf $host/ka/pdf/
#				scp  ../ht/ka/pdf/gjw_wed_prep.pdf $host/ka/pdf/
#				scp  ../ht/ka/pdf/kofeshop.pdf $host/ka/pdf/
#				scp  ../ht/ka/pdf/kitiworks.pdf $host/ka/pdf/

##				printf "scp ??.sh $host/byrdbellvjk/pj/\n";
#				scp ??.sh $host/byrdbellvjk/pj/
#				scp ??.sh $host/ka/pj/
#				scp ??.sh $host/law/pj/
#				scp ??.sh $host/pj/

#				printf "scp help.* $host/byrdbellvjk/\n";
#				scp ../help.* $host/byrdbellvjk/
#				scp ../help.* $host/law/

#				printf "scp todo.* $host/byrdbellvjk/\n";
#				scp ../todo.* $host/byrdbellvjk/
#				scp ../todo.* $host/law/

#				printf "scp ../*tl*.* $host/byrdbellvjk/\n";
#				scp ../*tl*.* $host/byrdbellvjk/
#				fi
#			done


		exit;
		fi # if [ "$1" == "scp" ] || [ "$1" == "scp" ]; then


	if [ "$1" == "dirs2fb" ] || [ "$1" == "dirs2fb" ]; then
		from_fb="../ht/fb/comics";
		to_fb="../ht/newz/fb/comics";
		to_pdf="../ht/newz/pdf/comics";
	
		from_fb="../ht/fb/weds"
		to_fb="../ht/newz/fb/weds"
		to_pdf="../ht/newz/pdf/weds";
		if [ ! -d $to_fb ]; then 
			printf "BUGS_271 NOTFOUND to_fb=$to_fb\n";
			if [ "$2" == "go" ]; then mkdir $to_fb; fi
			fi
		if [ ! -d $to_pdf ]; then 
			printf "BUGS_272 NOTFOUND to_pdf=$to_pdf\n";
			if [ "$2" == "go" ]; then mkdir $to_pdf; fi
			fi

#		items=`find $from_fb -type f -name "1.jpg" | sed -e "s:/1.jpg::" | head`
		items=`find $from_fb -type f -name "1.jpg" | sed -e "s:/1.jpg::"`
		for item in $items; do
			dirname=`dirname $item`
			basename=`basename $item`
			dirnam=`echo $dirname | sed -e "s:\.\./ht/fb/::" | sed -e "s:/pages::"`
			let j=j+1
			basename=`basename $from_fb`
			dirname=`dirname $from_fb`
			dirs=`echo $dirnam | sed -e "s:$basename/::" | sed -e "s:/: :g"`
			printf "BUGS_280 $j,$k item=$item =============================\n";
#			printf "BUGS_281 $j,$k basename=$basename \n";
#			printf "BUGS_281 $j,$k dirname=$dirname \n";
#			printf "BUGS_281 $j,$k dirs=$dirs \n";

			k=0; subdir=""; pdfnam="";
			for dir in $dirs; do
				let k=k+1
				if [ $k -eq 0 ]; then continue; fi
				subdir="$subdir/$dir";
#				printf "BUGS_281 $j,$k dir=$dir from_fb=$from_fb  to_fb=$to_fb subdir=$subdir\n";
#				printf "BUGS_282 $j,$k ISDIRCHECK $to_fb$subdir\n";

				if [ ! -d $to_fb$subdir ]; then
					printf "BUGS_283 $j,$k MKDIR NOTFOUND dir=$dir $to_fb$subdir\n";
					if [ "$2" == "go" ]; then
						printf "BUGS_284 $j,$k mkdir $to_fb$subdir\n";
						mkdir $to_fb$subdir
						fi
#				else
#					printf "BUGS_285 $j,$k MKDIR ___FOUND $to_fb$subdir\n";
					fi
				done

			pdfnam=`echo $item | sed -e "s:../ht/fb/::" |  sed -e "s:/pages:.pdf:" | sed -e "s:/:_:g"`
			dirnam=`dirname $from_fb`;


			printf "BUGS_320 $j,$k item=$item ----------------------\n";
			printf "BUGS_320 $j,$k from_fb=$from_fb to_fb=$to_fb\n";
			printf "BUGS_321 $j,$k CP $item/?.jpg $to_fb$subdir/pages\n";
			printf "BUGS_322 $j,$k CP $item/zn/zn_?.jpg $to_fb$subdir/pages/zn\n";
			printf "BUGS_323 $j,$k CP $item/tn/tn_?.png $to_fb$subdir/pages/tn\n";

			printf "BUGS_327 $j,$k item=$item\n";
			printf "BUGS_327 $j,$k to_pdf=$to_pdf\n";
			printf "BUGS_327 $j,$k pdfnam=$pdfnam\n";
#			printf "BUGS_324 $j,$k CONVERT $items/\*.jpg $to_pdf$subdir/$pdfnam\n";
			printf "BUGS_325 $j,$k CONVERT $item/.jpg $to_pdf/$pdfnam\n";


			if [ "$usrcmd" != "g" ]; then
				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
				if [ "$usrcmd" == "q" ]; then exit; fi
				if [ "$usrcmd" == "s" ]; then continue; fi
				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
				fi

			if [ "$2" == "go" ]; then

				if [ ! -d $to_fb$subdir/pages ]; then
					printf "BUGS_311 $j,$k mkdir $to_fb$subdir/pages\n";
					mkdir $to_fb$subdir/pages
					fi
				if [ ! -d $to_fb$subdir/pages/zn ]; then
					printf "BUGS_312 $j,$k mkdir $to_fb$subdir/pages/zn\n";
					mkdir $to_fb$subdir/pages/zn
					fi
				if [ ! -d $to_fb$subdir/pages/tn ]; then
					printf "BUGS_313 $j,$k mkdir $to_fb$subdir/pages/tn\n";
					mkdir $to_fb$subdir/pages/tn
					fi


				if [ -f $from_fb$subdir/pages/1.jpg ]; then
#					printf "BUGS_340 $j,$k item=$item\n";
#					printf "BUGS_340 $j,$k from_fb=$from_fb\n";
#					printf "BUGS_340 $j,$k to_fb=$to_fb\n";
#					printf "BUGS_340 $j,$k subdir=$subdir\n";
#					printf "BUGS_340 $j,$k item=$item\n";
#					printf "----------------------------------------------------\n";
#					printf "BUGS_341 $j,$k cp $item/?.jpg $to_fb$subdir/pages\n";
					printf "BUGS_342 $j,$k cp $item/zn/zn_?.jpg $to_fb$subdir/pages/zn\n";
					printf "BUGS_343 $j,$k cp $item/tn/tn_?.jpg $to_fb$subdir/pages/tn\n";
#					cp $item/?.jpg $to_fb$subdir/pages
#					cp $item/zn/zn_?.jpg $to_fb$subdir/pages/zn
#					cp $item/tn/tn_?.jpg $to_fb$subdir/pages/tn
#
					printf "BUGS_370 $j,$k convert $to_fb$subdir/pages/*.jpg $to_pdf$subdir/$pdfnam\n";
					printf "BUGS_325 $j,$k CONVERT $item/.jpg $to_pdf/$pdfnam\n";
#					convert $item/?.jpg $to_pdf/$pdfnam;
					convert $item/*.jpg $to_pdf/$pdfnam;
					
					to_fbitem=`echo $item | sed -e "s:pages/::"`
					printf "BUGS_336 $j,$k cp ../ht/ko/ko_fb.html  $to_fbitem\n";

					cp ../ht/ko/ko_fb.html  $to_fb_item

					to_pdfdir=`echo $to_pdf | sed -e "s:\.\./ht::"`
					to_fbdir=`echo $to_pdf | sed -e "s:\.\./ht::"`

printf "<a href=/pdf/web/viewer.html?file=$to_pdfdir/$pdfnam target=_blank>" >> ../ht/newz/pdfs.html
printf "<img title=\"       $pdfnam\" src=/imgs/btn/btn_pdf1.png height=20 border=0 alt=$pdfnam></a>\n" >> ../ht/newz/pdfs.html

printf "<a href=$to_fbdir target=_blank>" >> ../ht/newz/pdfs.html
printf "<img title=\"       $to_fbitem\" src=$item/pages/1.jpg height=100 border=0 alt=$pdfnam></a>" >> ../ht/newz/pdfs.html
printf "<br>\n" >> ../ht/newz/pdfs.html



printf "<a href=/pdf/web/viewer.html?file=$to_pdfdir/$pdfnam target=_blank>\n" >> ../ht/newz/fbs.html
printf "<img title=\"       $pdfnam\" src=/imgs/btn/btn_pdf1.png height=20 border=0 alt=$pdfnam></a>\n" >> ../ht/newz/fbs.html
printf "<a href=$to_fbitem target=_blank>" >> ../ht/newz/fbs.html
printf "<img title=\"       $to_fbitem\" src=$item/pages/1.jpg height=100 border=0 alt=$pdfnam></a>\n" >> ../ht/newz/fbs.html
printf "<br>\n" >> ../ht/newz/fbs.html






					fi


				fi
			done
		exit;
		fi # if [ "$1" == "dirs2fb" ] || [ "$1" == "dirs2fb" ]; then

	if [ "$1" == "go" ] || [ "$1" == "go1" ]; then
#		ids=`find imgs -type d -name "*"`
		ids=`find imgs -type d -name "*" | sed -e "s.imgs/.."`
#		ids=`find imgs -type d -name "*" | sed -e "s.imgs/.." | head -1`
		j=0; k=0; p=0;
		for id in $ids; do
			let j=j+1;
			printf "$progid $dttm j=$j id=$id ===========================\n";

			if [ ! -d fb/$id ]; then printf "mkdir fb/$id\n"; mkdir fb/$id; fi 
			if [ ! -d fb/$id/pages ]; then printf "mkdir fb/$id/pages\n"; mkdir fb/$id/pages; fi
			if [ ! -d fb/$id/pages/zn ]; then printf "mkdir fb/$id/pages/zn\n"; mkdir fb/$id/pages/zn; fi
			if [ ! -d fb/$id/pages/tn ]; then printf "mkdir fb/$id/pages/tn\n"; mkdir fb/$id/pages/tn; fi
			if [ ! -d fb/$id/index.html ]; then 
				printf "cp ko_fb.html fb/$id/index.html\n"; 
				cp ko_fb.html fb/$id/index.html
				cp ko_fb.html fb/$id/index.htm
				fi

			imgs=`find imgs/$id -type f -name "*.*"`
			p=9;
			for img in $imgs; do
				dttm=`date +"%Y%m%d_%H%M%S"`

				let p=p+1;
				printf "$progid $dttm j=$j id=$id p=$p img=$img ---------------\n";
				if [ ! -f fb/$id/pages/zn/zn_$p.jpg ]; then
					printf "convert $img -resize 1100x fb/$id/pages/zn/zn_$p.jpg\n";
					convert $img -resize 1100x fb/$id/pages/zn/zn_$p.jpg;
					fi
				if [ ! -f fb/$id/pages/$p.jpg ]; then
					printf "convert $img -resize 650x fb/$id/pages/$p.jpg\n";
					convert $img -resize 650x fb/$id/pages/$p.jpg;
					fi
				if [ ! -f fb/$id/pages/tn/tn_$p.png ]; then
					printf "convert $img -resize 400x fb/$id/pages/tn/tn_$p.png\n";
					convert $img -resize 400x fb/$id/pages/tn/tn_$p.png;
					fi
				done

			if [ ! -f pdf/$id.pdf ]; then
				printf "convert fb/$id/zn/zn_*.jpg pdf/$id.pdf\n";
				convert fb/$id/zn/zn_*.jpg pdf/$id.pdf;
				fi

			if [ ! -f fb/$id/1.jpg ]; then 
				if [ -f fb/$id/10.jpg ]; then 
					printf "cp fb/$id/10.jpg fb/$id/1.jpg\n";
					cp fb/$id/10.jpg fb/$id/1.jpg; 
					fi
				fi


			printf "<a href=fb/$id target=_blank>" >> fb/index.html
			printf "<img src=fb/$id/pages/1.jpg height=100 border=0>" >> fb/index.html
			printf "</a><br>\n" >> fb/index.html

			printf "<a href=/pdf/web/viewer.html?file=/byrdbellvjk/pdf/$id.pdf target=_blank>" >> pdf/index.html
			printf "	<img src=/imgs/btn/btn_pdf1.png height=10 border=0>\n" >> pdf/index.html
			printf "	<img src=fb/$id/pages/1.jpg height=100 border=0>\n" >> pdf/index.html
			printf "	</a><br>\n" >> pdf/index.html
			done

		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "go1" ]; then

	if [ "$1" == "find2fb" ] || [ "$1" == "find2tbl" ]; then
		j=0; k=0;
		fbid="jsk2_emilia"
		fb_path="/ka/fb/jsk2/emilia"
		pdf="../ht/ka/pdf/$fbid.pdf"
		fbid="gjw";
		fb_path="/ka/fb/gjw"
		pdf="../ht/ka/pdf/$fbid.pdf"

#		mp4s=`find ../mp4 -type f -name "*.mp4"`
# 		mp4s=`cat find_mp4_jtf.txt`
#		mp4s=`sqlite3 $db3 "select rowid,ext,pathfile,tn from $tbl where ext like "mp%"`
		printf "\n";
		imglist="../ht$fb_path/imgs/imgs.txt"
		if [ ! -f $imglist ]; then
			printf "BUGS_334 NOTFOUND imglist=$imglist\n";
			find ../ht$fb_path/imgs -type f -name "*.*" > $imglist
			fi

		printf "\n";
		printf " vi imglist=$imglist\n";
		if [ "$usrcmd" != "g" ]; then
			read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
			if [ "$usrcmd" == "q" ]; then exit; fi
			if [ "$usrcmd" == "s" ]; then continue; fi
			if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
			if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
			fi



		if [ "$usrcmd" != "s" ]; then
			printf "vi $imglist"
			vi $imglist
			fi

		if [ -f $imglist ]; then items=`cat $imglist` fi
		else 
			printf "ERR_371: NOTFOUND imglist=$imglist\n";
			exit;
			fi


		printf "$hostname $dttm $db3 ($j,$k) $tbl pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
		if [ "$usrcmd" != "g" ]; then
			read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
			if [ "$usrcmd" == "q" ]; then exit; fi
			if [ "$usrcmd" == "s" ]; then continue; fi
			if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
			if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
			fi
		printf "$hostname $dttm $db3 ($j,$k) $tbl bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"


		for item in $items; do
			let j=j+1
			if [ ! -f $item ]; then
				printf "ERR_337 NOTFOUND item=$item\n";
				exit;
				fi

			if [ ! -d ../ht$fb_path/pages ]; then
				if [ "$2" == "go" ]; then
					mkdir ../ht$fb_path/pages
					mkdir ../ht$fb_path/pages/zn
					mkdir ../ht$fb_path/pages/tn
					fi
				fi

			pg="../ht$fb_path/pages/$j.jpg";
			zn="../ht$fb_path/pages/zn/zn_$j.jpg";
			tn="../ht$fb_path/pages/tn/tn_$j.png";
			printf "$j item=$item\n";
			printf "convert $item -resize 650x $pg\n";
			printf "convert $item -resize 1100x $zn\n";
			printf "convert $item -resize 400x $tn\n";
			if [ "$2" == "go" ]; then
				if [ -f $item ]; then
					convert $item -resize 650x $pg
					convert $item -resize 1100x $zn
					convert $item -resize 400x $tn
				else
					printf "ERR_339 NOTFOUND item=$item\n";
					fi
				fi
			done

		printf "BUGS_300 find2fb items=$items\n";
		if [ "$2" == "go" ]; then
			convert ../ht$fb_path/pages/?.jpg pdf1.pdf
			convert ../ht$fb_path/pages/??.jpg pdf2.pdf
			convert ../ht$fb_path/pages/???.jpg pdf3.pdf
			convert pdf1.pdf pdf2.pdf pdf3.pdf $pdf
			rm pdf1.pdf
			rm pdf2.pdf
			rm pdf3.pdf
			if [ ! -f ../ht/$fb_path/index.html ]; then
				cp ../ht/ka/ko_fb.html ../ht/$fb_path/index.html
				cp ../ht/ka/ko_fb.html ../ht/$fb_path/index.htm
				fi
			fi
		if [  -f $pdf ]; then
			open $pdf;
		else
			printf "ERR_338 NOTFOUND pdf=$pdf\n";
			fi
		exit;
		fi # if [ "$1" == "find2fb" ] || [ "$1" == "find2tbl" ]; then

	if [ "$1" == "find2tbl" ] || [ "$1" == "find2tbl" ]; then
		j=0; k=0;
#		mp4s=`find ../mp4 -type f -name "*.mp4"`
# 		mp4s=`cat find_mp4_jtf.txt`
#		mp4s=`sqlite3 $db3 "select rowid,ext,pathfile,tn from $tbl where ext like "mp%"`
	
		printf "BUGS_210 db3=$db3 tbl=$tbl mp4s=$mp4s\n";
		j=0;

#	tbls="fb mp3 txt mp4 zm tl jpg gif pdf";
#	tbls="fb mp3 txt mp4 jpg pdf";
	j=0; k=0;
	for tbl in $tbls; do
		let j=j+1; k=0;

		psvback="../tl/json/tl_$tbl_$dttm.psv"
		psv="../tl/json/tl_$tbl.psv"
		jsonback="../tl/json/tl_$tbl_$dttm.json"
		json="../tl/json/tl_$tbl.json"

		if [ "$tbl" == "fb" ]; then items=`find ../fb -type f -name "1.jpg"`; fi
		if [ "$tbl" == "mp3" ]; then items=`find ../mp3 -type f -name "*.mp3"`; fi
		if [ "$tbl" == "mp4" ]; then items=`find ../mp4 -type f -name "*.mp4"`; fi
		if [ "$tbl" == "pdf" ]; then items=`find ../pdf -type f -name "*.pdf"`; fi
		if [ "$tbl" == "txt" ]; then items=`find ../txt -type f -name "*.txt"`; fi
		if [ "$tbl" == "jpg" ]; then items=`find ../imgs -type f -name "*.jpg"`; fi
		if [ "$tbl" == "gif" ]; then items=`find ../../kb -type f -name "*.gif"`; fi
		if [ "$tbl" == "tl" ]; then items=`find ../tl/json -type f -name "*.json"`; fi
		if [ "$tbl" == "zm" ]; then items=`find ../zm -type f -name "0-0-0.jpg"`; fi

		printf "BUGS_230 $j,$k tbl=$tbl item=$item ================\n"

#		printf "sqlite3 $db3 -header \"select * from $tbl\" > $psvback\n";
#		sqlite3 $db3 -header "select * from $tbl" > $psvback

		printf "sqlite3 $db3 \"delete from $tbl\"\n";


		if [ "$2" == "go" ]; then
			printf "sqlite3 $db3 -header \"select * from $tbl\" > $psvback\n";
			sqlite3 $db3 -header "select * from $tbl" > $psvback

			if [ -f $psvback ]; then
				printf "sqlite3 $db3 \"delete from from $tbl\"";
				sqlite3 $db3 "delete from from $tbl" 
				fi
			fi

		for item in $items; do
			let k=k+1;

			dttm=`date +"%Y%m%d_%H%M%S"`
			startdate=`date +"%Y,%m,%d"`
			starttime=`date +"%H:%M:%S"`
			enddate=$startdate;
			endtime=$starttime;
			pathfile=`echo $item | sed -e "s:../:/byrdbellvjk/:"`

			path=`dirname $pathfile`;
			base=`basename $pathfile`;
			file=`echo $base | awk -F"." '{ print $1 }'`;
			ext=`echo $base | awk -F"." '{ print $2 }'`;
#			printf "BUGS 150 pathfile=$pathfile path=$path base=$base file=$file ext=$ext\n";


			headline=$file;
			credit=$file;
			caption=$file;
			headline=$file;

			if [ "$tbl" == "fb" ]; then
				text="<a href=./ko_fb?fbid=$path target=_blank> <img title=$path src=/imgs/btn/koeye_fb.png height=20 border=0></a>"
				fi

			if [ "$tbl" == "pdf" ]; then
				text="<a href=/pdf/web/viewer.html?$pathfile  target=_blank> <img title=$path src=/imgs/btn/koeye_pdf.png height=20 border=0></a>"
				fi

			if [ "$tbl" == "jpg" ]; then
				text="<a href=$pathfile target=_blank> <img title=$path src=/imgs/btn/koeye_jpg.png height=20 border=0></a>"
				fi
			if [ "$tbl" == "mp3" ]; then
				text="<a href=$pathfile target=_blank> <img title=$path src=/imgs/btn/koeye_mp3.png height=20 border=0></a>"
				fi

			if [ "$tbl" == "mp4" ]; then
				text="<a href=$pathfile target=_blank> <img title=$path src=/imgs/btn/koeye_mp4.png height=20 border=0></a>"
				fi

			if [ "$tbl" == "txt" ]; then
				text="<a href=$pathfile target=_blank> <img title=$path src=/imgs/btn/koeye_txt.png height=20 border=0></a>"
				fi

			printf "$hostname $dttm $db3 ($j,$k) $tbl pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
			if [ "$usrcmd" != "g" ]; then
				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
				if [ "$usrcmd" == "q" ]; then exit; fi
				if [ "$usrcmd" == "s" ]; then continue; fi
				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
				fi
			printf "$hostname $dttm $db3 ($j,$k) $tbl bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n"







			let j=j+1

			flds="'pathfile','path','file','base','ext', 'startdate','starttime', 'enddate','endtime', 'headline','caption', 'credit', 'text'"

			vals="'$pathfile','$path','$file','$base','$ext', '$startdate','$starttime', '$enddate','$endtime', '$headline','$caption', '$credit', '$text'"

			printf "BUGS_220 $hostname $db3 $tbl j=$j item=$item pathfile=$pathfile\n";
			printf "sqlite3 $db3 \"insert into $tbl ( $flds ) values ( $vals );\"\n";
			if [ "$2" == "go" ]; then

				printf "sqlite3 $db3 \"insert into $tbl ( $flds ) values ( $vals );\"\n";
				sqlite3 $db3 "insert into $tbl ( $flds ) values ( $vals );"

				printf "sqlite3 $db3 \"select * from $tbl\" > $psv\n";
				sqlite3 $db3 "select * from $tbl" > $psv
				fi

			printf "sqlite3 $db3 \"select * from $tbl\" > $psv\n";
			sqlite3 $db3 "select * from $tbl" > $psv
			done
		done
		sqlite3 $db3 "select * from $tbl";
		exit;
		fi # if [ "$1" == "find2tbl" ] || [ "$1" == "find2tbl" ]; then

	if [ "$1" == "go_ocr" ] || [ "$1" == "ocr" ]; then
# pathfiles=`find kb/books .type f -name "zn_*.jpg"`
# pathfiles=`find kb/epson .type f -name "*.jpg"`
# pathfiles=`find kb/books .type f -name "*.jpg" | grep -v "/go"`
# pathfiles=`find kb/books/jmh/ -type f -name "*.JPG" | grep -v "tn"`
pathfiles=`find lb/books/alt/haslem_mariesmonkey -type f -name "*.jpg"`
		pathfiles_cnt=`echo $pathfiles | wc -l`
		printf "pathfiles_cnt=$pathfiles_cnt"
		printf "pathfiles=$pathfiles"
		j=0
		logfil="ocr.log"
		for pathfile in $pathfiles; do
			dttm=`date +"%Y%-m-%d %H:%M:%S"`
			let j=j+1
			path=`dirname $pathfile`
			base=`basename $pathfile`
			file=`echo $base | awk -F"." '{ print $1}'`
			ext=`echo $base | awk -F"." '{ print $2}'`
#			printf "j=$j file=$file path=$path pathfile=$pathfile\n" 
			path_ocr="$path/ocr"
			fil=$file
			fil=`echo $file | sed -e "s: ::"`
			printf "$j file=$file fil=$fil"
			outputbase="$path_ocr/ocr_$fil"
#			outputbase="$path_ocr/ocr_$file"
			
			cmd_tesseract="tesseract $pathfile $outputbase -l eng --psm 3"
			printf "$j $pathfile ====================================\n"
			printf "$j $outputbase ----------------------------------\n"
			printf "$j cmd_tesseract=$cmd_tesseract\n";
			printf "$j $outputbase ----------------------------------\n"
			path_ocr="$path/ocr"
			if [ ! -d $path_ocr ]; then
				printf "MSG_101 MKDIR j=$j mkdir $path_ocr\n"
				fi


			if [ "$usrcmd" != "g" ]; then
				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
				if [ "$usrcmd" == "q" ]; then exit; fi
				if [ "$usrcmd" == "s" ]; then continue; fi
				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
				fi

			printf "$dttm $j $file pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n"
			if [ ! -d $path_ocr ]; then
				printf "BUGS_102 j=$j mkdir $path_ocr"
				printf "BUGS_102 j=$j mkdir $path_ocr" >> $logfil
				mkdir $path_ocr
				fi
			printf "msg_101 $dttm $j $file ==========================================\n"
			printf "$cmd_tesseract\n"
			printf "$dttm $j $file ------------------------------------------\n"
			printf "$dttm $j $file bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n\n"
			printf "msg_102 $dttm $j $cmd_tesseract\n" >> $logfil
			$cmd_tesseract
			done



		exit
		fi # if [ "$1" == "go_ocr" ] || [ "$1" == "ocr" ]; then

	if [ "$1" == "go_db3s" ] || [ "$1" == "db3s" ]; then
to_db3file="tl.db3";
to_tbl="db3s"

db3s=`find . -type f -maxdepth 2 -name "*.db3"`
		j=0
#		for db3 in $db3s;do let j=j+1 printf "$j $db3\n"; done

		printf "BUGS_50 sqlite3 $to_db3file \"create table if not exists $to_tbl as select * from files0;\n"
		sqlite3 $to_db3file "create table if not exists $to_tbl as select * from files0"

		echo "BUGS_51 sqlite3 $to_db3file \"select * from $to_tbl;\""
		sqlite3 $to_db3file "select * from $to_tbl;"

		echo "BUGS_52 sqlite3 $to_db3file \"delete from $to_tbl;\""
		sqlite3 $to_db3file "delete from $to_tbl;"

#		echo "BUGS_53 sqlite3 $to_db3file \"drop table $to_tbl;\""
#		sqlite3 $to_db3file "drop table $to_tbl;"


		j=0; k=0;
		for db3 in $db3s;do
			if [ "$db3" == "" ]; then continue; fi

			pathfile=$db3;
			
#			printf "BUGS_70 j=$j k=$k db3=$db3\n"
			path=`dirname $pathfile` 
			base=`basename $pathfile`
			file=`echo $base | awk -F"." '{ print $1}'`
			ext=`echo $base | awk -F"." '{ print $2}'`
			size=`ls -lat $pathfile | awk '{ print $5 }'`
			dttm=`date +"%Y%-m-%d %H:%M:%S"`
			ctime=`date +"%Y%-m-%d %H:%M:%S"`
			assets="assets"
			t1=0

#			printf "BUGS_91 '$progid','$dttm','$status',\n"
#			printf "BUGS_92 '$size','$ctime',\n"
#			printf "BUGS_93 size=$size '$pathfile','$path',file='$file',ext='$ext',\n"
#			printf "BUGS_94 '$assets','$t1');\n"

			names=`sqlite3 $db3 "select name from sqlite_master where type=='table'"`
#			printf "BUGS_95 j=$j names=$names\n"
			k=0
			for name in $names; do
				tbl=$name;
				cnt=`sqlite3 $db3 "select count(*) from $tbl"`
				t1=$cnt
				asset=`sqlite3 $db3 "select sql from sqlite_master where name=='$tbl' and type=='table'" | tr -d '\n' | tr -d '\t' | sed -e "s:  : :g" `
				printf "BUGS_1990 k=$k db3=$db3 tbl=$tbl cnt=$cnt asset=$asset\n";

				printf "BUGS_1991 j=$j k=$k DB3=$db3 TBL=$tbl cnt=$cnt\n"
				printf "BUGS_1992 j=$j k=$k DB3=$db3 TBL=$tbl asset=$asset\n"

				sqlite3 $to_db3file "insert into $to_tbl ('pathfile','path','file','ext','assets','t1') values ('$pathfile','$path','$file','$ext','$assets','$t1');"


				let k=k+1	
				done

			let j=j+1
			done
		sqlite3 $to_db3file "select * from $to_tbl";
		sqlite3 $to_db3file "select count(*) from $to_tbl";
		exit
		fi # if [ "$1" == "go_db3s" ] || [ "$1" == "db3s" ]; then

# sqlite> .schema sqlite_master
# CREATE TABLE sqlite_master (type text, name text, tbl_name text, rootpage integer, sql text);

	if [ "$1" == "go_f2db3" ] || [ "$1" == "f2db3" ]; then
		usrcmd="prompt"
		db3file="fts/fts.db3"
		tbl="bks_v"
		rowid=21
		list=`sqlite3 $db3file "select rowid,pathfile from $tbl where rowid=$rowid"`
		j=0
		for line in $list; do
			let j=j+1
#			printf " j=$j line=$line\n"
			rowid=`echo $line | awk -F"|" '{ print $1 }'`
			pathfile=`echo $line | awk -F"|" '{ print $2 }'`

			printf "\n\n" 
			printf "=====================================\n"
			printf "BUGS_60 j=$j rowid=$rowid pathfile=$pathfile\n"


#			if [ "$usrcmd" != "" ]; then
#				read -e -p "q=quit s=skip g=go enter=continue:  " usrcmd
#				if [ "$usrcmd" == "q" ]; then exit; fi
#				if [ "$usrcmd" == "s" ]; then continue; fi
#				if [ "$usrcmd" == "q" ]; then usrcmd=""; fi
#				if [ "$usrcmd" == "" ]; then usrcmd="prompt"; fi
#				fi
for rowid in {4..400};do
#	rowid=21
	printf "BUGS_70 python ka1.py f2ftsdb3_content fts/fts.db3 bks_v $rowid\n"
	python ka1.py f2ftsdb3_content fts/fts.db3 bks_v $rowid
	done

# for j in (( j=3; j=j+1; j<400)); do
# 	printf "python ka1.py f2ftsdb3_content fts/fts.db3 bks_v $rowid"
#	python ka1.py f2ftsdb3_content fts/fts.db3 bks_v $rowid
#	done






#			printf "vi $pathfile"
#			vi $pathfile
#			printf "vi $pathfile"
			done
		exit;
		fi # if [ "$1" == "go_f2db3" ] || [ "$1" == "f2db3" ]; then

	if [ "$1" == "go_scp" ] || [ "$1" == "go_scp" ]; then
dir="../ht/fb/myco"
hostids="ko0 ko1 ko2 konet iperms";
# files="../ht/index.htm* ../ht/ko_coffeeshop.*"
files="../ht/index.htm*"
files="../ht/notice.html"
		for hostid in $hostids;do 
			if [ "$hostid" == "ko0" ]; then
				host="kozerus@ko0.us"
				hostdir="~/public_html/"
				fi
			if [ "$hostid" == "ko1" ]; then
				host="kotwous@ko2.us"
				hostdir="~/public_html/ko1/"
				fi
			if [ "$hostid" == "ko2" ]; then
				host="kotwous@ko2.us"
				hostdir="~/public_html/"
				fi
			if [ "$hostid" == "konet" ]; then
				host="kotwous@ko2.us"
				hostdir="~/public_html/konet"
				fi
			if [ "$hostid" == "iperms" ]; then
				host="kotwous@ko2.us"
				hostdir="~/public_html/iperms"
				fi

			for file in $files; do
#				echo "scp -r lb $host:~/public_html"
				printf "scp $file $host:$hostdir\n"
				if [ "$2" == "go" ]; then
#					scp -r $dir $host:$hostdir
					scp $file $host:$hostdir
					printf "scp $file $host:$hostdir\n"
					fi
				done
			done
		printf "BUGS_122 a1=$1 SCP\n"
		exit;
		fi # if [ "$1" == "go_scp" ] || [ "$1" == "go_scp" ]; then

	if [ "$1" == "go_f2db3" ] || [ "$1" == "f2db3" ]; then
#		db3file="tl.db3";
#		tbl="kb";
#		printf "BUGS_60 db3file=$db3file tbl=$tbl\n"
# files=`find lb/books -type f -name "*.txt" | head -10`
# files=`find lb/books -type f -name "*.jpg"` >> txt/books.txt
#files=`cat txt/books.txt`
#		j=0
#		for file in $files; do
#			printf "BUGS_123 j=$j file=$file"
#			content="content j=$j file=$file"
#			if [ -f $file ]; then
#				printf "BUGS_71 __FOUND j=$j file=$file\n"
#				printf "BUGS_72 __FOUND j=$j content=$content\n"
#				content=`cat $file`
#				content=`strings $file`
#			else
#				printf "BUGS_81 NOTFOUND j=$j file=$file\n"
#				printf "BUGS_82 NOTFOUND j=$j content=$content\n"
#				fi

#			bkid="lb/books/alt/mcduff"
#			avid=$bkid;
#			p=$j; ord=$p
#			dttm=`date +"%Y%m%d_%H%M%S"`
#			startdate=`date +"%Y-%m-%d"`
#			starttime=`date +"%H:%M:%S"`
#			enddate=`date +"%Y-%m-%d"`
#			endtime=`date +"%H:%M:%S"`
#			headline="headline $bkid $dttm $p"
#			text="text: $bkid $dttm $p"
#			media=$pathfile;
#			caption=$pathfile;
#			credit="/imgs/btn/gif/firebubbles.gif"
#
			
#			flds="'dttm','avid','ord', 'pathfile','path','file','ext', 'enddate','endtime', 'headline','text','media','caption','credit'"
#			vals="'$dttm','$avid','$ord', '$pathfile','$path','$file','$ext', '$enddate','$endtime', '$headline','$text','$media','$caption','$credit'"


#			sql_insert="insert or replace into $tbl ($flds) values ($vals);"
#			sqlite3 $db3file "$sql_insert"
#			done

#		printf "BUGS_124 a1=$1 f2ftsdb3\n"
#		printf "BUGS_90 files=$files\n\n"
		exit;
		fi # if [ "$1" == "go_f2db3" ] || [ "$1" == "f2db3" ]; then

	if [ "$1" == "go_fsftsdb3" ] || [ "$1" == "f2ftsdb3" ]; then
		db3file="tl_v.db3";
		tbl="kb_v";
		printf "BUGS_60 dbefile=$db3file tbl=$tbl\n"
# files=`find lb/books -type f -name "*.txt" | head -10`
files=`find lb/books -type f -name "*.txt"`
		j=0
		for file in $files; do
			printf "BUGS_123 j=$j file=$file"
			content="content j=$j file=$file"
			if [ -f $file ]; then
				printf "BUGS_71 __FOUND j=$j file=$file\n"
				printf "BUGS_72 __FOUND j=$j content=$content\n"
#				content=`cat $file`
				content=`strings $file`
			else
				printf "BUGS_81 NOTFOUND j=$j file=$file\n"
				printf "BUGS_82 NOTFOUND j=$j content=$content\n"
				fi

			flds="'pathfile','content','ext'"
			vals="'$file','$content','$ext'"
			sql_insert="insert or replace into $tbl ($flds) values ($vals);"
			sqlite3 $db3file "$sql_insert"
			done

#		printf "BUGS_124 a1=$1 f2ftsdb3\n"
		printf "BUGS_90 files=$files\n\n"
		exit;
		fi # if [ "$1" == "go_fsftsdb3" ] || [ "$1" == "f2ftsdb3" ]; then

	if [ "$1" == "go_testext" ] || [ "$1" == "testtext" ]; then
ids="konet iperms jtfdc ka go kt kids jtfdcr med law jtfinc kou";
 		i=0;j=0; k=0;
 		for id in $ids; do
			let i=i+1;
		
			for (( k=1; k<=12; k++ )); do
				dttm=`date +"%Y-%m-%d %H:%M:%S"`
 				txtfil="tl/txt/tl_$id""_m$k.txt";
 				printf "$dttm testtext i=$i j=$j k=$k txtfil=$txtfil\n";
				for (( l=1; l<=k; l++ )); do
					printf "$txtfil $dttm == $id == MONTH $l line_$l abcdefghijklmnopqrstuvwxyz\n" >> $txtfil;
					done
				printf "i=$i id=$id k=$k\n";
				done

			for (( k=1; k<=365; k++ )); do
 				txtfil="tl/txt/tl_$id""_d$k.txt"
 				printf "$dttm testtext i=$i j=$j k=$k txtfil=$txtfil\n";

				for(( l=1; l<k; l++ )); do
					dttm=`date +"%Y-%m-%d %H:%M:%S"`
					if [ $l == 1 ]; then
						printf "$txtfil $dttm == $id == DAY $l line_$l ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" >> $txtfil;
						continue;
						fi
					if [ $l == 2 ]; then
						printf "$txtfil $dttm == $id == DAY $l line_$l 0 1 2 3 4 5 6 7 8 9 0\n" >> $txtfil;
						continue;
						fi
					printf "$txtfil $dttm == $id == DAY $l line_$l line_$l abcdefghijklmnopqrstuvwxyz\n" >> $txtfil;
					done
				done
			done

		printf "BUGS_70 testtext i=$i j=$j k=$k\n";
		find tl/txt -type f -name "*.txt" | sed -e "s:^:/:" > lb/books/txts.txt
		cat lb/books/txts.txt | wc -l
 		exit;
 		fi # if [ "$1" == "go_testext" ] || [ "$1" == "testtext" ]; then
 
	if [ "$1" == "go_wc" ] || [ "$1" == "wc" ]; then
		ids="konet iperms jtfdc jtfdcr med law kids mars royal1 kt kou konabus ka jmh jkwii skwii byrdpucker"
		j=0; wc_tot=0;
		for id in $ids; do
			let j=j+1;
path_imgs="fb/$id/imgs";
path_pages="fb/$id/pages";
			wc_imgs=`find $path_imgs -type f -maxdepth 1 -name "*.jpg" | wc -l`;
			wc_pages=`find $path_pages -type f -maxdepth 1 -name "*.jpg" | wc -l`;
			let wc_tot=wc_tot+wc_imgs;
			let wc_tot=wc_tot+wc_pages;

			if [ "$2" == "go" ]; then
				find $path_imgs -type f -maxdepth 1 -name "*.jpg" >> lb/books/imgs.txt
				find $path_pages -type f -maxdepth 1 -name "*.jpg" >> lb/books/imgs.txt
				fi
			printf "BUGS_2250 j=$j wc_tot=$wc_tot id=$id wc_imgs=$wc_imgs wc_pages=$wc_pages<br>\n";
			done
		cat lb/books/imgs.txt | wc -l

		exit;
		fi # if [ "$1" == "go_wc" ] || [ "$1" == "wc" ]; then

	if [ "$1" == "go" ] || [ "$1" == "finds" ]; then
		rootdirs="/Volumes/ka1tbr1/i /Volumes/ka1tbr1/ht ."
		ids="iv snap jtfdc kb nasa ff"

		j=0; k=0;
		for rootdir in $rootdirs; do
			let j=j+1; k=0;
			for id in $ids; do
				let k=k+1;
				findcmd="find $rootdir -type d -name '$id' -exec ls -lat {} \;"
if [ "$rootdir" == "/Volumes/ka1tbr1/i" ]; then rootid="i1"; fi
if [ "$rootdir" == "/Volumes/ka1tbr1/ht" ]; then rootid="ht1"; fi
if [ "$rootdir" == "." ]; then rootid="ht"; fi
findfile="find_$rootid""_$id.txt"
#				echo "$progid $dttm $j $k findcmd=$findcmd"
				echo "$progid $dttm $j $k findfil=$findfile"
				if [ "$2" == "go" ]; then
					$findcmd > $findfile
					fi
				done
			done

		ko1i="ko1_in"; 
		ko2i="ko2_in"; 
#		ko1o="ko1_out";
#		ko2o="ko2_out";
#		ko1o=$(ko1 $ko1i);
#		ko2o=$(ko2 $ko2i);
#		koout="ko1o=$ko1o ko2o=$ko2o";
#		printf "$progid $dttm koout=$koout\n";
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "finds" ]; then

	if [ "$1" == "go" ] || [ "$1" == "random_int" ]; then
		min=1; max=100;
		if [ "$2" != "" ]; then max=$2; fi
		if [ "$3" != "" ]; then min=$3; fi
		rand=$(random_int $max $min);
		printf "$progid $dttm rand=$rand min=$min max=$max\n";
#		dd if=/dev/urandom count=4 bs=1 | od -t d
#		od -A n -t d -N 1 /dev/urandom | tr -d ' '
#		echo ${RANDOM:0:1} # random number between 1 and 9
#		echo ${RANDOM:0:2} # random number between 1 and 99
#		echo $(( $RANDOM % 113 + 1 ))
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "random_int" ]; then

	if [ "$1" == "go" ] || [ "$1" == "testdata" ]; then
txtfil="lb/books/gifs.txt"
# media=`cat $txtfil | awk -v j='$j' 'NR==j { prinlift "j="j" "$1 }'`
# media=`cat $txtfil | awk -v j='$j' 'NR==j { printif "j="j" "$1 }'`
# cat lb/books/gifs.txt | awk -v j='$j' 'NR==j { printf "j="j" "$1 }'
#		for j in 1 2 3 5 10 12 13 17 19 23 27 31; do
#			cmd_head="cat lb/books/gifs.txt | awk -v j='"
#		cmd_tail="' 'NR==j { print \$1 }'";
#		cmd="$cmd_head$j$cmd_tail";
#		line=`"cat $ifile | sed -n '$j""p'"`;

#		ifile="lb/books/gifs.txt";
#		line=`cat $ifile | head -$j | tail -1`
#	printf "j=$j line=$line ifile=$ifile\n";
#	done
#		printf "BUGS_100 cmd=$cmd";
#		printf "BUGS_100 media=$media";
#		exit;

printf "BUGS_2325 testdata";
ids="bcs gifs htms imgs mp3s mp4s pns pdfs tls txts yts zms"
ids="konet iperms jtfdc jtfdcr jtfinc ka kids kt go royal1 saic law med stlc"
		j=0; k=0;
		for id in $ids; do
			let j=j+1;  k=0;

#			echo "sqlite3 tl.db3 'create table if not exists $id as select * from files0'"
#			if [ "$2" == "go" ]; then
#				sqlite3 tl.db3 "create table if not exists $id as select * from files0"
#				fi

			txtfil="lb/books/$id.txt"
			txtfil="lb/books/gifs.txt";
			gifs="lb/books/gifs.txt"
			printf "$progid $dttm $j $k id=$id txtfil=$txtfil\n";
#			lines=`cat $txtfil | head -$j | tail -1`
			lines="line1";
			for line in $lines; do
				let k=k+1;
tlid="tl_$id";
startdate=`sqlite3 tl.db3 "select date('now','+$j day');"`
startdate=`echo $startdate | sed -e "s:-:,:g"`
enddate=$startdate;
# media=`cat $txtfil | awk -v j='$j' 'NR==j { print $1 }'`
gif=`cat $gifs | head -$j | tail -1`
media=$gif;
# media=`cat $txtfil | head -$j | tail -1`
printf "BUGS_180 media=$media\n";
headline="headline";
text="text";
pathfile=$media;
caption=$media;
credit='<a href=$gif target=_blank><img src=$gif height=100></a>';
pathfile=$media;
headline="$tlid startdate=$startdate $dttm";
headline='<h1>$tlid</h1><h2>startdate=$startdate</h2><h3>$dttm</h3>';
text='<hr color=goldenrod><a href=$gif target=_blank><img src=$gif height=100></a>$gif<hr color=goldenrod>';

				printf "$progid $dttm $j $k tlid=$tlid";
				printf "$progid $dttm $j $k startdate=$startdate\n";
				printf "$progid $dttm $j $k txtfil=$txtfil line=$line\n";
				printf "$progid $dttm $j $k gif=$gif\n";
				printf "$progid $dttm $j $k media=$media\n";
				printf "$progid $dttm $j $k headline=$headline\n";
				printf "$progid $dttm $j $k caption=$caption\n";
				printf "$progid $dttm $j $k credit=$credit\n";
				printf "=================================\n\n";
	tl_startdate=`echo $startdate | sed -e "s:-:,:g"`;
	tl_enddate=`echo $enddate | sed -e "s:-:,:g"`;

if [ "$2" == "go" ]; then
	sqlite3 tl.db3 "delete from tl where tlid like '$tlid'";
	flds="('tlid','startdate','enddate','headline','text','media','caption','credit','pathfile')";
	vals="('$tlid','$tl_startdate','$tl_enddate','$headline','$text','$media','$caption','$credit','$pathfile');";
	sqlite3 tl.db3 "insert or replace into tl $flds values $vals"
	printf "insert or update into tl $flds values $vals";


	sqlite3 tl.db3 "select tlid,startdate,media from tl where tlid='$tlid'"
	fi

				done
			done

		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "testdata" ]; then

	if [ "$1" == "go" ] || [ "$1" == "db3" ]; then
db3file="tl.db3";
tbls=`sqlite3 $db3file ".tables"`
# tbls='tl';

		j=0;
		for tbl in $tbls; do
			let j=j+1;
cnt=`sqlite3 $db3file "select count(*) from $tbl"`
sel=`sqlite3 $db3file "select tlid,startdate,media from $tbl limit 1"`
			echo "$progid $dttm j=$j tbl=$tbl cnt=$cnt"
			echo "$progid $dttm j=$j tbl=$tbl sel=$sel"
			done
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "db3" ]; then

	if [ "$1" == "go" ] || [ "$1" == "scan2pics" ]; then
# list=`find kb/scan/scan_20151123/books/kokt -type f -maxdepth 1 -name "*.*"`
list=`find kb/scan/scan_20151123/books/kt -type f -maxdepth 1 -name "*.*"`

		j=0;
#		tpath="bk/book/kokt/pics"
		tpath="bk/book/kt/pics"
		for item in $list; do
			let j=j+1;
			tpathfile=$tpath/$j.jpg
			echo "convert $item -resize 550x $tpathfile"
			if [ "$2" == "go" ]; then
				convert $item -resize 550x $tpathfile
				fi
			done
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "scan2pics" ]; then

	if [ "$1" == "go" ] || [ "$1" == "scp" ]; then
hosts="kozerus@ko0.us"
hosts="kozerus@ko0.us kotwous@ko2.us"
hosts="kotwous@ko2.us kozerus@ko0.us"

		for host in $hosts;do
#			echo "scp usps.html $host:~/public_html/"
#			echo "scp -r usps $host:~/public_html/"
#			echo "scp pdf/*usps*.pdf $host:~/public_html/pdf/"
#			echo "scp pdf/pdf/email_usps_postmaster_20211213*.pdf $host:~/public_html/pdf/"
#			echo "scp ko.php $host:~/public_html/"

#			echo "scp kb/aud/mp3/*.mp3 $host:~/public_html/kb/aud/mp3"
			echo "scp kb/vid/jkwii/*.* $host:~/public_html/kb/vid/jkwii/"
			if [ "$2" == "go" ]; then
				dttm=`date +"%Y%m%d_%H%M%S"`
				echo "$progid $dttm scp jkwii" >> ka1.log
				echo "scp kb/vid/jkwii/*.* $host:~/public_html/kb/vid/jkwii/"
				scp kb/vid/jkwii/*.* $host:~/public_html/kb/vid/jkwii/

#				echo "scp kb/aud/mp3/*.mp3 $host:~/public_html/kb/aud/mp3"
#				scp kb/aud/mp3/*.mp3 $host:~/public_html/kb/aud/mp3

#				echo "scp ko.php $host:~/public_html/"
#				scp ko.php $host:~/public_html/

#				echo "scp usps.html $host:~/public_html/"
#				scp usps.html $host:~/public_html/

#				echo "scp -r usps $host:~/public_html/"
#				scp -r usps $host:~/public_html/


#				echo "scp pdf/*usps*.pdf $host:~/public_html/pdf/"
#				scp pdf/*usps*.pdf $host:~/public_html/pdf/


#				echo "scp pdf/pdf/email_usps_postmaster_20211213*.pdf $host:~/public_html/pdf/"
#				scp pdf/pdf/email_usps_postmaster_20211213*.pdf $host:~/public_html/pdf/

				fi
			done
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "scp" ]; then

	if [ "$1" == "vi" ] || [ "$1" == "vi" ]; then
		if [ "$2" == "notes" ]; then
			yyyymm=`date +"%Y%m"`
			rootpath="/Volumes/ka1tbr2/pj"
			notesfile="$rootpath/notes_$yyyymm.txt"
			vi $notesfile
			printf "$progid $dttm notesfile=$notesfile"
			exit;
			fi

		printf "$progid.sh vi <$yyyymmdd>\n"
		rtpath="../ht/yt/txt"
		txtfil="$rtpath/ytlist_$yyyymmdd.txt"
		printf "txtfil=$txtfil\n"
		if [ -f $txtfil ]; then
			vi $txtfil
		else
			printf "$progid $dttm NOTFOUND txtfil=$txtfil\n"
			vi $txtfil
			fi
		exit;
		fi # if [ "$1" == "vi" ] || [ "$1" == "vi" ]; then

	if [ "$1" == "psv" ] || [ "$1" == "psv" ]; then
		printf "$progid.sh vi <$yyyymmdd>\n"
		rtpath="../ht/yt/txt"
		txtfil="$rtpath/ytlist_$yyyymmdd.txt"
		printf "txtfil=$txtfil\n"
		psvfil="$rtpath/ytlist_$yyyymmdd.psv";
		printf "psvfil=$psvfil\n"
#		yts=`cat $txtfil`
		OLDIFS=$IFS; IFS=$'\n'
# 		files=($(find $dir_ren -type f  -maxdepth 1  ))
		files=($(cat $txtfil  ))
		flen=${#files[@]}
		printf "$progid $dttm flen=$flen txtfil=$txtfil\n";

		printf "" > $psvfil

		IFS=$OLDIFS
		f=0;i=0;
		for (( f=0; f<${flen}; f++ )); do
			file="${files[$f]}"
			j=$f;
			skiphash=""; skipperc="";
			skiphash=`echo $file | grep "^#"`
			skipperc=`echo $file | grep "%" | sed -e s:%:_:g`
	
			if [ "$skipperc" != "" ]; then
				printf "$progid $dttm f=$f SKIP skiphash=>$skiphash<= skipperc=>$skipperc<=\n";
				continue;
				fi
	
			if [ "$skiphash" != "" ]; then 
				printf "$progid $dttm f=$f SKIP skiphash=>$skiphash<= skipperc=>$skipperc<=\nfile=$file\n";
				continue;
				fi
			fldcnt=`echo $file | awk -F"|" '{ print NF }'`
			f1=`echo $file | awk -F"|" '{ print $1 }'`
			f2=`echo $file | awk -F"|" '{ print $2 }'`
			f3=`echo $file | awk -F"|" '{ print $3 }'`
			f4=`echo $file | awk -F"|" '{ print $4 }'`
	

			id="id"; grp="grp"; url="url"; txt="";
			url=$f1;
			basename=`basename $url`

			printf "$progid $dttm f=$f fldcnt=$fldcnt file=$file basename=$basename\n";
			printf "$progid $dttm f1=$f1 f2=$f2 f3=$f3 f4=$f4\n";

#			$psvrec="$id|$grp|$dttm|$url|$txt|$basename";
			idcheck=`echo $file | grep "youtube.com"`;
			if [ "$idcheck" != "" ]; then
				id="yt"; txt=$f1; url=$f2; 
				printf "j=$j YOUTUBE\n";
				fi
			idcheck=`echo $file | grep "bitchute.com"`;
			if [ "$idcheck" != "" ]; then
				id="bc"; txt=$f1; url=$f2; 
				printf "j=$j BITCHUTE\n";
				fi
			idcheck=`echo $file | grep "rumble.com"`;
			if [ "$idcheck" != "" ]; then
				id="rm"; txt=$f1; url=$f2; 
				printf "j=$j RUMBLE\n";
				fi
			idcheck=`echo $file | grep "vimeo.com"`;
			if [ "$idcheck" != "" ]; then
				id="vm"; txt=$f1; url=$f2; 
				printf "j=$j VIMEO\n";
				fi

			idcheck=`echo $file | grep "dailymail"`;
			if [ "$idcheck" != "" ]; then
				id="dm"; txt=$f1; url=$f1; 
				printf "j=$j DAILYMAIL\n";
				fi
			idcheck=`echo $file | grep "jimstone"`;
			if [ "$idcheck" != "" ]; then
				id="js"; txt=$f1; url=$f1; 
				printf "j=$j JIMSTONE\n";
				fi
			idcheck=`echo $file | grep "gatewaypundit"`;
			if [ "$idcheck" != "" ]; then
				id="gp"; txt=$f1; url=$f1; 
				printf "j=$j GATEWAYPUNDENT\n";
				fi
			idcheck=`echo $file | grep "whatdoesitmean.com"`;
			if [ "$idcheck" != "" ]; then
				id="wm"; txt=$f1; url=$f1; 
				printf "j=$j WHATDOESITMEAN\n";
				fi
			idcheck=`echo $file | grep "zerohedge.com"`;
			if [ "$idcheck" != "" ]; then
				id="zh"; txt=$f1; url=$f1; 
				printf "j=$j ZEROHEDGE\n";
				fi


			psvrec="$id|$grp|$dttm|$url|$txt|$basename";
			printf "$psvrec\n" >> $psvfil
			done

		if [ -f $psvfil ]; then
#			vi $psvfil	
			wc -l $psvfil
			printf "$progid $dttm vi $psvfil\n";	
		else
			printf "$progid $dttm ERR_750 NOTFOUND psvfil=$psvfil\n";	
			fi
		exit;
		fi # if [ "$1" == "psv" ] || [ "$1" == "psv" ]; then

	if [ "$1" == "md" ] || [ "$1" == "mkdirs" ]; then
		rootpath="../i"
		rootpath="../ht/kb"
		printf "$progid.sh md <$yyyymmdd>\n"
		printf "ids=$ids\n";
 		i=0;j=0; k=0;
 		for id in $ids; do
			let i=i+1;
			dir=$id"/"$id"_"$yyyymmdd
			if [ -d $rootpath/$dir ]; then
				printf "$i FOUND $rootpath/$dir\n";
			else
				printf "mkdir $rootpath/$dir # $i\n";
				mkdir $rootpath/$dir # $i
				fi
			done
		exit;
		fi # if [ "$1" == "md" ] || [ "$1" == "mkdirs" ]; then

	if [ "$1" == "mvd" ] || [ "$1" == "mvdirs" ]; then
		rootpath="../i"
		suffixs="snap kb jtfdc nasa"
		j=0
		if [ "$2" != "" ]; then yyyymmdd=$2; fi
		printf "$progid $dttm  yyyymmdd=$yyyymmdd\n";
		printf "$progid $dttm  suffixs=$suffixs\n";
		for suffix in  $suffixs; do
			let j=j+1
			tdir=$rootpath/$suffix
			dirmask=$suffix"_????????"
			if [ "$2" != "" ]; then dirmask=$suffix"_$yyyymmdd"; fi
#			fdir=$rootpath/$suffix_$yyyymmdd
			fdirscnt=`find $rootpath -type d -name "$dirmask" -maxdepth 1 | wc -l | sed -e "s/ //g"`
			fdirs=`find $rootpath -type d -name "$dirmask" -maxdepth 1`
			printf "dirmask=$dirmask fdirscnt=$fdirscnt fdirs=$fdirs\n";
			
			if [ -d $tdir ]; then
				k=0
				for fdir in $fdirs; do
					let k=k+1
					printf "$k mv $fdir $tdir\n";
#					mv $fdir $tdir
					done
				
#				$progid $dttm mv $fdir $tdir
				fi
			printf "$progid $dttm $j suffix=$suffix\n";
			done

		exit;
		fi # if [ "$1" == "mvd" ] || [ "$1" == "mvdirs" ]; then

	if [ "$1" == "mv" ] || [ "$1" == "mvfils" ]; then
		rootpath="../i"
		suffixs="pdf jpg jpeg png webp mp4 mp3 gif avif"
		if [ "$2" != "" ]; then yyyymmdd=$2; fi


		printf "BUGS_680 yyyymmdd=$yyyymmdd\n";
		printf "$progid mv $rootpath/$yyyymmdd\n"
		printf "$progid suffixs $suffixs\n"

		if [ -d $rootpath/nasa/nasa_$yyyymmdd ]; then
			echo "mv $rootpath/NRB_*_.PNG $rootpath/nasa/nasa_$yyyymmdd"
			mv $rootpath/NRB_*_.PNG $rootpath/nasa/nasa_$yyyymmdd

			echo "mv $rootpath/CR0_*.PNG $rootpath/nasa/nasa_$yyyymmdd"
			mv $rootpath/CR0_*.PNG $rootpath/nasa/nasa_$yyyymmdd

			echo "mv $rootpath/FRB_*_.JPG $rootpath/nasa/nasa_$yyyymmdd"
			mv $rootpath/FRB_*_.JPG $rootpath/nasa/nasa_$yyyymmdd

			echo "mv $rootpath/NLB_*_.JPG $rootpath/nasa/nasa_$yyyymmdd"
			mv $rootpath/NLB_*_.JPG $rootpath/nasa/nasa_$yyyymmdd

			echo "mv $rootpath/NRB_*_.JPG $rootpath/nasa/nasa_$yyyymmdd"
			mv $rootpath/NRB_*_.JPG $rootpath/nasa/nasa_$yyyymmdd

			echo "mv $rootpath/CR0_*_.JPG $rootpath/nasa/nasa_$yyyymmdd"
			mv $rootpath/CR0_*_.JPG $rootpath/nasa/nasa_$yyyymmdd

			echo "mv $rootpath/*DXXX.jpg $rootpath/nasa/nasa_$yyyymmdd"
			mv $rootpath/*DXXX.jpg $rootpath/nasa/nasa_$yyyymmdd

			echo "mv $rootpath/D000M*.JPG $rootpath/nasa/nasa_$yyyymmdd"
			mv $rootpath/D000M*.JPG $rootpath/nasa/nasa_$yyyymmdd

			echo "mv $rootpath/Mars_Perseverance*J.png $rootpath/nasa/nasa_$yyyymmdd"
			mv $rootpath/Mars_Perseverance*J.png $rootpath/nasa/nasa_$yyyymmdd
			fi


#		if [ -d $rootpath/nasa_best ]; then
#			echo "mv $rootpath/*DXXX_*.jpg $rootpath/nasa_best"
#			mv $rootpath/*DXXX_*.jpg $rootpath/nasa_best
#
#			echo "mv $rootpath/Mars_Perseverance*.png $rootpath/nasa_best"
#			mv $rootpath/Mars_Perseverance*.png $rootpath/nasa_best
#
#			tail $rootpath/nasa_$yyyymmdd
#			ls $rootpath/nasa_$yyyymmdd | wc -l
#			fi

#		if [ -d $rootpath/jtfdc_$yyyymmdd ];  then
#			echo "mv $rootpath/jtfdc_*.mp4 $rootpath/jtfdc_$yyyymmdd"
#			mv $rootpath/jtfdc_*.mp4 $rootpath/jtfdc_$yyyymmdd
#			tail $rootpath/jtfdc_$yyyymmdd
#			ls $rootpath/jtfdc_$yyyymmdd | wc -l
#			fi

		if [ -d $rootpath/kb_$yyyymmdd ];  then
			for suffix in $suffixs; do
				let j=j+1
				echo "mv $rootpath/*.$suffix $rootpath/kb/kb_$yyyymmdd"
				mv $rootpath/*.$suffix $rootpath/kb/kb_$yyyymmdd
				done

			tail $rootpath/kb/kb_$yyyymmdd
			ls $rootpath/kb/kb_$yyyymmdd | wc -l
			fi

		if [ -d $rootpath/snap/snap_$yyyymmdd ];  then
			wc=`ls $rootpath/snap/snap_$yyyymmdd | wc -l`
			printf "snap_$yyyymmdd $wc\n"

			find "/Volumes/ka1tbr2/o/SnapNDrag Library.snapndraglibrary" -name "*.png" -exec cp {} $rootpath/snap/snap_$yyyymmdd \;
#			find "/Volumes/ka1tbr2/o/SnapNDrag Library.snapndraglibrary" -name "*.png" -exec cp {} $rootpath/snap/snap_$yyyymmdd \;
			wc=`ls $rootpath/snap_$yyyymmdd | wc -l`
			printf "snap_$yyyymmdd $wc\n"
			fi


		printf "BUGS_720 $progid.sh yyyymmdd=$yyyymmdd\n"
		exit;
		fi # if [ "$1" == "mv" ] || [ "$1" == "mvfils" ]; then

	if [ "$1" == "go" ] || [ "$1" == "new" ]; then
		rootpath="/Volumes/ka1tbr2/i"
		yyyymmdd=`date +"%Y%m%d"`
		if [ "$3" != "" ]; then yyyymmdd=$3; fi
		ids="kb_$yyyymmdd snap_$yyyymmdd jtfdc_$yyyymmdd nasa_$yyyymmdd"
		suffixs="pdf jpg jpeg png webbp mp4"
		echo "BUGS_911 NEW rootpath=$rootpath"
		echo "BUGS_912 NEW yyyymmdd=$yyyymmdd"
		echo "BUGS_913 NEW suffixs=$suffixs"
		echo "BUGS_914 NEW ids=$ids"

		if [ "$2" == "" ]; then exit; fi

		j=0;
		echo "$progid $dttm o1=$1 ids=$ids"
		if [ "$2" == "vi2" ]; then
			for id in $ids; do
				dttm=`date +"%Y%m%d_%H%M%S"`
				let j=j+1
				dir="../i/$id"
				if [ -d $dir ]; then
					echo "$progid $dttm $1 j=$j FOUND dir=$dir"
				else
					echo "$progid $dttm $1 mkdir $dir"
					mkdir $dir
					fi
				done
			fi

		if [ "$2" == "vi1" ]; then
#			echo "vi /Volumes/ka1tbr2/ht/yt/txt/ytlist_$yyyymmdd.txt"
#			vi /Volumes/ka1tbr2/ht/yt/txt/ytlist_$yyyymmdd.txt
			echo "vi ../ht/yt/txt/ytlist_$yyyymmdd.txt"
			vi ../ht/yt/txt/ytlist_$yyyymmdd.txt
			exit
			fi









		echo "BUGS_920 NEW END"
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "new" ]; then

	if [ "$1" == "go" ] || [ "$1" == "scp" ];  then
hosts="kozerus@ko0.us kotwous@ko2.us"
		for host in $hosts; do
			echo "pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq"

echo "scp index.htm* $host:~/public_html/"
scp index.htm* $host:~/public_html/

echo "scp index.htm* $host:~/public_html/fb/jtfdcr/jtfdcr_20211207_1515_usps_nondelivery3/"
scp index.htm* $host:~/public_html/fb/jtfdcr/jtfdcr_20211207_1515_usps_nondelivery3/
cp index.htm* fb/jtfdcr/jtfdcr_20211207_1515_usps_nondelivery3/

echo "scp index.htm* $host:~/public_html/fb/jtfdcr/jtfdcr_20211207_1815_accident/"
scp index.htm* $host:~/public_html/fb/jtfdcr/jtfdcr_20211207_1815_accident/
cp index.htm* fb/jtfdcr/jtfdcr_20211207_1815_accident/

echo "scp index.htm* $host:~/public_html/fb/jtfdcr/jtfdcr_20211211_powerup/"
scp index.htm* $host:~/public_html/fb/jtfdcr/jtfdcr_20211211_powerup/
cp index.htm* fb/jtfdcr/jtfdcr_20211211_powerup/



#			echo "scp -r fb/jtfcr/jtfdcr_20211207_1515_usps_nondelivery3 $host:~/public_html/fb/jtfdcr"
#			if [ "$2" == "go" ]; then
#				echo "scp -r fb/jtfcr/jtfdcr_20211207_1515_usps_nondelivery3 $host:~/public_html/fb/jtfdcr"
#scp -r fb/jtfcr/jtfdcr_20211207_1515_usps_nondelivery3 $host:~/public_html/fb/jtfdcr
#				fi
			continue;
			done
		exit;
		fi


#			echo "scp  pdf/jtfdcr_20211207_1815_accident.pdf $host:~/public_html/pdf"
#			echo "scp -r fb/jtfdcr/jtfdcr_20211207_1815_accident $host:~/public_html/fb/jtfdcr"

#			echo "============================="
#			echo "scp  fb/jtfdcr/jtfdcr_202111_powerup.pdf $host:~/public_html/pdf"
#			echo "scp -r fb/jtfdcr/jtfdcr_202111_powerup $host:~/public_html/fb/jtfdcr"
#
#			echo "============================="
#			echo "scp  fb/jtfdcr/jtfdcr_20211207_1515_usps_nondelivery3.pdf $host:~/public_html/pdf"
#			echo "scp -r fb/jtfdcr/jtfdcr_20211207_1515_usps_nondelivery3 $host:~/public_html/fb/jtfdcr"
#
#
#			if [ "$2" == "go" ]; then
#				echo "scp -r fb/jtfdcr/jtfdcr_20211207_1815_accident $host:~/public_html/fb/jtfdcr"
#				scp -r fb/jtfdcr/jtfdcr_20211207_1815_accident $host:~/public_html/fb/jtfdcr
#
#				echo "============================="
#				echo "scp -r fb/jtfdcr/jtfdcr_20211207_1515_usps_nondelivery3 $host:~/public_html/fb/jtfdcr"
#				scp -r fb/jtfdcr/jtfdcr_20211207_1515_usps_nondelivery3 $host:~/public_html/fb/jtfdcr
#
#				echo "============================="
#				echo "scp -r fb/jtfdcr/jtfdcr_202111_powerup $host:~/public_html/fb/jtfdcr"
#				scp -r fb/jtfdcr/jtfdcr_202111_powerup $host:~/public_html/fb/jtfdcr
#				echo "============================="
#				echo "scp  pdf/jtfdcr_20211207_1815_accident.pdf $host:~/public_html/pdf"
##				scp  pdf/jtfdcr_20211207_1815_accident.pdf $host:~/public_html/pdf
#				echo "============================="
#
#				echo "scp  pdf/jtfdcr_20211207_1515_usps_nondelivery3.pdf $host:~/public_html/pdf"
#				scp  pdf/jtfdcr_20211207_1815_accident.pdf $host:~/public_html/pdf
#				echo "host=$host"
#				fi
#			echo "bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd"
#			done
#		exit;
#		fi # if [ "$1" == "go" ] || [ "$1" == "scp" ];  then

	if [ "$1" == "go" ] || [ "$1" == "pdf2pages_append" ];  then
#		pdf="pdf/jtfdcr_20211207_1815_accident.pdf"
#		tdir="fb/jtfdcr/jtfdcr_20211207_1815_accident"

		pdf="pdf/jtfdcr_20211207_1515_usps_nondelivery3.pdf"
		tdir="fb/jtfdcr/jtfdcr_20211207_1515_usps_nondelivery3"

#		pdf="pdf/jtfdcr_202111_powerup.pdf"
#		tdir="fb/jtfdcr/jtfdcr_20211_powerup"

		tmpdir="tmp"
		if [ ! -d $tmpdir ]; then 
			echo "ERR_1 NOTFOUND tmpdir=$tmpdir"; 
			exit;
			fi	
		if [ ! -f $pdf ]; then 
			echo "ERR_2 NOTFOUND pdf=$pdf";
			exit;
			fi

		
		if [ "$2" == "go" ]; then
			echo "rm tmp/*.jpg"
			rm tmp/*.jpg
			echo "rm tmp/*.png"
			rm tmp/*.png
			fi

 
		echo "convert $pdf -resize 1100x -depth 600 $tmpdir/pdf_%01d.jpg"

		if [ "$2" == "go" ]; then
			echo "convert $pdf -resize 1100x -depth 600 $tmpdir/zn_%01d.jpg"
			convert $pdf -resize 1100x -depth 600 $tmpdir/pdf_%01d.jpg
			fi


imgs=`find tmp -type f -maxdepth 1 -name "pdf_*.jpg"`;
lastpage=`ls $path/*.jpg | wc -l`

		j=0; k=0;
		for img in $imgs; do
			echo "j=$j img=$img"
			dirname=`dirname $img`
			basename=`basename $img`
			base=`echo $basename | awk -F"." '{ print $1 }'`
			ext=`echo $basename | awk -F"." '{ print $2 }'`
			let k=j+lastpage
			k=$j;

			tn="$tmpdir/tn_$k.png"
			im="$tmpdir/$k.jpg"
			zn="$tmpdir/zn_$k.jpg"

			echo "convert $img -resize 200 $tn"
			echo "convert $img -resize 550x $im"
			echo "convert $img -resize 1100x $zn"
			if [ "$2" == "go" ]; then
				echo "$j=j k=$k convert $img -resize 200 $tn"
				convert $img -resize 200 $tn
				echo "$j=j k=$k convert $img -resize 550x $im"
				convert $img -resize 550x $im
				echo "j=$j k=$k convert $img -resize 1100x $zn"
				convert $img -resize 1100x $zn
				fi
			let j=j+1
			done

		if [ ! -d $tdir ]; then 
			echo "mkdir $tdir"
			if [ "$2" == "go" ]; then
				echo "mkdir $tdir"
				mkdir $tdir
				fi
			fi
		if [ ! -d $tdir/pages ]; then 
			echo "mkdir $tdir/pages"
			if [ "$2" == "go" ]; then
				echo "mkdir $tdir/pages"
				mkdir $tdir/pages
				fi
			fi
		if [ ! -d $tdir/pages/tn ]; then 
			echo "mkdir $tdir/pages/tn"
			if [ "$2" == "go" ]; then
				echo "mkdir $tdir/pages/tn"
				mkdir $tdir/pages/tn
				fi
			fi
		if [ ! -d $tdir/pages/zn ]; then 
			echo "mkdir $tdir/pages/zn"
			if [ "$2" == "go" ]; then
				echo "mkdir $tdir/pages/zn"
				mkdir $tdir/pages/zn
				fi
			fi
		echo "cp $tmpdir/*.jpg $tdir/pages/"
		echo "cp $tmpdir/zn_*.jpg $tdir/pages/zn/"
		echo "cp $tmpdir/tn_*.png $tdir/pages/tn/"
		if [ "$2" == "go" ] || [ "$2" == "go" ]; then
			echo "cp $tmpdir/zn_*.jpg $tdir/pages/zn/"
			cp $tmpdir/zn_*.jpg $tdir/pages/zn/

			echo "cp $tmpdir/tn_*.png $tdir/pages/tn/"
			cp $tmpdir/tn_*.png $tdir/pages/tn/

			echo "cp $tmpdir/?.jpg $tdir/pages/"
			cp $tmpdir/?.jpg $tdir/pages/
			cp $tmpdir/??.jpg $tdir/pages/
			fi

		ls -lat $tdir/pages
		ls -lat $tdir/pages/tn
		ls -lat $tdir/pages/zn

		exit; 
		fi # if [ "$1" == "go" ] || [ "$1" == "pdf2pages_append" ];  then

#	if [ "$1" == "go" ] || [ "$1" == "go" ]; then
#	dir="."; name="*.mp4"; lim=100;
# lines=`find $dir -type f -maxdepth 1 -name "$names" -exec ls {} \; head -$lim
#		echo "BUGS_100 $progid $dttm GO"
#		exit;
#		fi #	if [ "$1" == "go" ] || [ "$1" == "go" ]; then

	if [ "$1" == "go" ] || [ "$1" == "mp42gif" ] || [ "$1" == "mp4gifs" ]; then
# mp4s=`find ../i/jtfdc_20211128_police_johnson -type f -name "jtfdc_20211128_11*.mp4"`
# mp4s=`find ../i/jtfdc_20211128_police_johnson -type f -name "jtfdc_20211128_11*.mp4" | head -1`
# mp4s=`find kb/jtfdc/vid/jtfdc_20211128 -type f -name "jtfdc_20211128_11*.mp4"`
# mp4s=`find ../ht2/fb/usps/usps_20211207/mp4_orig -maxdepth 1 -type f -name "jtfdc*.mp4"`
# mp4s=`find ../i -maxdepth 1 -type f -name "jtfdc_2021*.mp4"`
# mp4s=`find ../i/jtfdc/jtfdc_20211218 -type f -name "jtfdc_20211218_1622_jtf29_maildelivered_pro_carrier_no_agenda.mp4"`
mp4s=`find ../i/ -maxdepth 1 -type f -name "jtfdc_20220606_*mailskip*.mp4"`

		tpath="./tmp"	
		if [ ! -d $tpath ]; then
			echo "ERR_101 NOTFOUND tpath=$tpath"
			exit;	
			fi


		echo "$mp4s"


		j=0;
		for mp4 in $mp4s;do
			let j=j+1
			if [ ! -f $mp4 ];  then
				echo "ERR_102 NOTFOUND mp4=$mp4"
				exit;	
				fi

			basename=`basename $mp4`
			base=`echo $basename | awk -F"." '{ print $1 }'`
			ext=`echo $basename | awk -F"." '{ print $2 }'`
			pngs="$tpath/$base%d.png"
			echo "j=$j ffmpeg -i $mp4 -f image2 -vf fps=1 $pngs"
			if [ "$2" == "go" ]; then
				ffmpeg -i $mp4 -f image2 -vf fps=1 $pngs
				fi

			pngs="$tpath/$base*.png"
			gif="$tpath/$base.gif"
			echo "convert -resize 300 -delay 15 loop 0 $pngs $gif"
			if [ "$2" == "go" ]; then
				convert -resize 300 -delay 15 loop 0 $pngs $gif
				fi

			done

		ls -lat $tpath/*.gif
#		ls -lat $tpath | more
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "mp42gif" ] || [ "$1" == "mp4gifs" ]; then

	if [ "$1" == "go" ] || [ "$1" == "imgs2pages_overlay" ]; then
#		imgs=`find ../ht2/kb/books/go/go_basics/imgs -name "zn*.png" | head -2`
#		j=1;
#		img_bg="../ht2/kb/books/go/go_basics/imgs/zn_0.png"
#		img="../ht2/kb/books/go/go_basics/imgs/zn_0$j.png"
#		zn="kb/books/go/go_basics/pages/zn/zn_0$j.jpg"
#		tn="kb/books/go/go_basics/pages/tn/tn_0$j.png"
#		im="kb/books/go/go_basics/pages/$0j.jpg"
#		
#		# echo "convert -resize 1000x -composite -gravity center $img $img_bg  $zn"
#		# convert -resize 1000x -composite -gravity center $img $img_bg  $zn
#		
#		
#		# echo "convert $img  -resize 1100x  $zn"
#		# convert $img  -resize 1100x  $zn
#		imgs=`find ../ht2/kb/books/go/go_basics/imgs -name "zn_*.png"`
#				j=0;
#				for img in $imgs; do
#					zn="kb/books/go/go_basics/pages/zn/zn_$j.jpg"
#					im="kb/books/go/go_basics/pages/$j.jpg"
#					tn="kb/books/go/go_basics/pages/tn/tn_$j.png"
#					echo "$j img=$img"
#		
#					echo "convert -resize 1000x -composite -gravity center $img $img_bg $zn"
#					convert -resize 1000x -composite -gravity center $img $img_bg  $zn
#		# convert image_1.jpg ( image_2.jpg -resize 100x100 ) -geometry +100+100 -composite  ( image_3.jpg -resize 200x200 ) -geometry +500+500 -composite output.jpg
#		
#		
# echo "convert $img_bg ( $img -resize 1000x ) -geometry +0+0 -composite  -geometry -gravity center $zn" 
# convert $img $img_bg -resize 1000x -composite  -geometry -gravity center $zn

			
#					echo "j=$j img=$img"
#					echo "j=$j zn=$zn"
#					echo "j=$j img_bg=$img_bg"
#		
#					echo "convert $img -resize 1100x $zn"
#					convert $img -resize 1100x $zn
#		
#					echo "convert $zn -resize 500x $im"
#					convert $zn -resize 500x $im
#		
#					echo "convert $zn -resize 200x $tn"
#					convert $zn -resize 200x $tn
#					echo "======================"
#					let j=j+1
#					done
#		
#					exit


#				echo "BUGS_101 imgs=$imgs"
#				echo "BUGS_102 img_bg=$img_bg"
#		
#				j=0;
#				for img in $imgs; do
#					let j=j+1
#					dirname=`dirname $img`
#					basename=`basename $img`
#					base=`echo $basename | awk -F"." '{ print $1}'`
#					echo "BUGS_000 img=$img"
#		
#		

#			tn="kb/books/go/go_basics/pages/tn/tn_$j.png"
#			zn="kb/books/go/go_basics/pages/zn/zn_$j.jpg"
#			im="kb/books/go/go_basics/pages/$j.jpg"
#
#			echo "BUGS_101 j=$j base=$base dirname=$dirname"
#			echo "BUGS_102 img=$img"
#			echo "BUGS_102 zn=$zn"
#			echo "BUGS_102 im=$im"
#			echo "BUGS_102 tn=$tn"
#			echo "convert  -resize 1000x -composite -gravity center $img_bg $img $zn"
#
#			if [ ! -d kb/books/go/go_basics/pages/zn  ]; then
#				zn="kb/books/go/go_basics/pages/zn/zn_a.jpg"
#				echo "ERR_101 NOTFOUND zn=$zn
#				exit;
#				fi
#			if [ ! -f $img ]; then 
#				echo "ERR_101 NOTFOUND img=$img
#				exit
#				fi
#			if [  -f $tn ]; then 
#				echo "MSG_101 FOUND tn=$tn
#				fi
#			if [ "$2" == "go" ]; then 
#				convert $img  -resize 1000x -composite -gravity center $img_bg $zn 
#				fi

#			echo "convert -resize 500x $zn $im"
#			if [ "$2" == "go" ]; then 
#				convert -resize 500x $zn $im 
#				fi
#			echo "convert -resize 200x $zn $tn"
#			if [ "$2" == "go" ]; then 
#				convert -resize 200x $zn $tn 
#				fi
#
#			done
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "imgs2pages_overlay" ]; then

	if [ "$1" == "go" ] || [ "$1" == "imgs2tns" ]; then
		hosts="kozerus@ko0.us kotwous@ko2.us"
		hosts="kotwous@ko2.us"
		hosts="kozerus@ko0.us"
		for host in $hosts; do
#			echo "scp go/ko_canvas.html $host:~/public_html/go"
#			echo "scp go/konva*.html $host:~/public_html/go"
#			echo "scp -r go/js $host:~/public_html/go/"
#			echo "scp -r go/pages $host:~/public_html/go/pages"

#			echo "scp ../safer/ko_startup.* $host:~/safer"
#			echo "scp index.htm* $host:~/public_html/"
#			echo "scp ko.php $host:~/public_html/"
#
			echo "scp index.htm* $host:~/public_html/"
			echo "scp ko.php $host:~/public_html/"
			echo "scp ko_form.html $host:~/public_html/"
			echo "scp ko_files.html $host:~/public_html/"
			if [ "$2" == "go" ]; then 
				scp index.htm* $host:~/public_html/
				scp ko.php $host:~/public_html/
				scp ko_form.html $host:~/public_html/
				scp ko_files.html $host:~/public_html/
#				scp go/ko_canvas.html $host:~/public_html/go
#				scp go/konva*.html $host:~/public_html/go

#				echo "scp -r go/js $host:~/public_html/go/"
#				scp -r go/js $host:~/public_html/go/
#				echo "scp -r go/pages $host:~/public_html/go/"

#				scp -r go/pages $host:~/public_html/go/pages
#				echo "scp -r go/js $host:~/public_html/go/"
#				scp -r go/js $host:~/public_html/go/

#				scp ../safer/ko_startup.* $host:~/safer
#				scp index.htm* $host:~/public_html/
#				scp ko.php $host:~/public_html/
				fi
			echo "======================================"
			done
		exit;


imgs=`find go/imgs -type f -maxdepth 2 -name "*.jpg"`
		tpath="go/pages";
		echo "BUGS_3200 IMGS2TNS imgs=$imgs"
		j=0;
		for img0 in $imgs; do
			let j=j+1
			dirname=`dirname $img0`;
			basename=`basename $img0`;
			base=`echo $basename | awk -F"." '{ print $1 }'`
			tn="$tpath/tn/tn_$j.png"
			zn="$tpath/zn/zn_$j.jpg"
			img="$tpath/$j.jpg"

			echo "j=$j convert $img0 -resize 200x $tn"
			echo "j=$j convert $img0 -resize 500x $img"
			echo "j=$j convert $img0 -resize 1100x $zn"

			if [ "$2" == "go" ]; then convert $img0 -resize 200x $tn; fi
			if [ "$2" == "go" ]; then convert $img0 -resize 550x $img; fi
			if [ "$2" == "go" ]; then convert $img0 -resize 1100x $zn; fi
			done
		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "imgs2tns" ]; then

	if [ "$1" == "go" ] || [ "$1" == "mp4gifs" ]; then
# mp4s=`find ../i/jtfdc_20211128_police_johnson -type f -name "jtfdc_20211128_11*.mp4"`
# mp4s=`find ../i/jtfdc_20211128_police_johnson -type f -name "jtfdc_20211128_11*.mp4" | head -1`
# mp4s=`find kb/jtfdc/vid/jtfdc_20211128 -type f -name "jtfdc_20211128_11*.mp4"`
mp4s=`find ../i/usps_20211207/mp4_orig -maxdepth 1 -type f -name "jtfdc*.mp4"
		echo "MP$GIFS"
		tpath="kb/jtfdc/vid/jtfdc_20211128"	
#		if [ ! -d $tpath ]; then
#			echo "ERR_101 NOTFOUND tpath=$tpath"
#			exit;	
#			if

		j=0;
		for mp4 in $mp4s;do
			let j=j+1
			if [ ! -f $mp4 ];  then
				echo "ERR_102 NOTFOUND mp4=$mp4"
				exit;	
				fi

			basename=`basename $mp4`
			base=`echo $basename | awk -F"." '{ print $1 }'`
			ext=`echo $basename | awk -F"." '{ print $2 }'`
			pngs="$tpath/$base%d.png"
			echo "j=$j ffmpeg -i $mp4 -f image2 -vf fps=1 $pngs"
			if [ "$2" == "go" ]; then
				ffmpeg -i $mp4 -f image2 -vf fps=1 $pngs
				fi

			pngs="$tpath/$base*.png"
			gif="$tpath/$base.gif"
			echo "convert -resize 300 -delay 15 loop 0 $pngs $gif"
			if [ "$2" == "go" ]; then
				convert -resize 300 -delay 15 loop 0 $pngs $gif
				fi

			done

		ls -lat $tpath/*.gif
#		ls -lat $tpath | more
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "mp4gifs" ]; then

	if [ "$1" == "go" ] || [ "$1" == "renumber" ]; then
		j=0;
		k=0;

# crop image target size 240×160 starting at x=100,y=50
# img_bg="imgs/bg/ko_colorado_mocha.jpg";
# img_fb="imgs/ko/ko.png";
# img_overlay="../ht2/kb/books/go/bo_basics/imgs/tmp";

#
# convert sleeves.png pattern.png \
# \( -clone 0 -auto-level \) \
# \( -clone 1 -clone 0 -alpha set -virtual-pixel transparent -compose displace \
# -set option:compose:args -5x-5 -composite \) \
# -delete 0,1 -compose multiply -composite sleeves_pattern.png

# convert sleeves.png pattern.png \
#	\( -size 440x440 gradient: -solarize 50% -level 0x50% \) \
#	\( -clone 2 -rotate 90 \) \
#	\( -clone 2 -clone 3 -compose multiply -composite -negate -scale 440x600! \) \
#	\( -clone 4 -negate \) \
#	\( -size 600x440 gradient: -rotate 90 -set colorspace RGB -threshold 50% \) \
#	\( -clone 4 -clone 5 -clone 6 -compose over -composite -scale 300% -gravity center -crop 440x600+0-30 +repage \) \
#	\( -clone 1 -clone 7 -alpha set -virtual-pixel transparent -compose displace \
#	-set option:compose:args -100x-100 -composite \) \
#	-delete 1-7 \
#	\( -clone 0 -auto-level \) \
#	\( -clone 1 -clone 0 -alpha set -virtual-pixel transparent -compose displace \
#	-set option:compose:args -5x-5 -composite \) \
#	-delete 0,1 -compose multiply -composite sleeves_pattern_displace_twice.png

#	convert -size 70x70 canvas:none -fill red -draw 'circle 35,35 10,30' red-circle.png
#	convert -size 70x70 canvas:none -draw 'circle 35,35 35,20' -negate \
#	-channel A -gaussian-blur 0x8 white-highlight.png
#	composite -compose atop -geometry -13-17 white-highlight.png red-circle.png red-ball.png 

#	mogrify  -format gif -path thumbs -thumbnail 100x100 *.jpg
#	convert input.jpg  -strip output.jpg
#	mogrify -strip  *.jpg

#	convert -size 100x100 xc:wheat  canvas_wheat.gif
#	convert canvas_khaki.gif -fill tomato -opaque khaki canvas_tomato.gif

#	convert pattern:leftshingle pattern:rightshingle +append \
#          -virtual-pixel tile  -blur 0x0.75 -resize 150% -shade 100x45 \
#          -fill Peru  -tint 100%   miff:- |\
#    convert  -size 100x100 tile:-   tile_slanted_bricks.jpg

#	convert font_A.gif font_P.gif font_P.gif font_E.gif font_N.gif \
#          font_D.gif font_E.gif font_D.gif +append  append_row.gif
#	
#	convert rose:  -background LawnGreen label:Rose \
#	-background white -gravity center -append \
#	append_center.jpg

#	convert font_{0,0,6,1,2}.gif +append  dragon_long.gif \
#          -background none   -append   append_multi.gif

#	convert \( font_1.gif font_2.gif font_3.gif +append \) \
#          \( font_4.gif font_5.gif font_6.gif +append \) \
#          \( font_7.gif font_8.gif font_9.gif +append \) \
#          \( -size 32x32 xc:none  font_0.gif +append \) \
#          -background none -append   append_array.gif

#	convert granite: rose: -gravity east -background none \
#          \( -clone 1 -chop 30x0 \) \( -clone 0,2 +append \) \
#          -delete 0,2 +swap -composite append_overlap.gif

#	convert -size 100x100 xc:skyblue comp_resize.gif
#	  composite -geometry 40x40+5+10  balloon.gif comp_resize.gif comp_resize.gif
#	  composite -geometry      +35+30 medical.gif comp_resize.gif comp_resize.gif
#	  composite -geometry 24x24+62+50 present.gif comp_resize.gif comp_resize.gif
#	  composite -geometry 16x16+10+55 shading.gif comp_resize.gif comp_resize.gif

#	convert -size 100x100 xc:skyblue \
#          balloon.gif  -geometry  +5+10  -composite \
#          medical.gif  -geometry +35+30  -composite \
#          present.gif  -geometry +62+50  -composite \
#          shading.gif  -geometry +10+55  -composite \
#          compose.gif

# convert balloon.gif \( +clone  -background navy  -shadow 80x3+5+5 \) +swap \
#          -background none   -flatten   flatten_shadow.png

#	convert rose: -repage +10+10 \
#          \( +clone -background black -shadow 60x3+5+5 \) \
#          \( granite: -crop 100x80+0+0 +repage \) \
#          -background none  -compose DstOver -layers merge layer_dstover.gif

# https://legacy.imagemagick.org/Usage/layers/#intro
#	convert -page +5+5    holocaust_tn.gif \
#          -page +80+50  spiral_stairs_tn.gif \
#          -page +40+105 chinese_chess_tn.gif \
#          +page \
#          -alpha Set -virtual-pixel transparent \
#          -channel A -blur 0x10  -level 50,100% +channel \
#          \( -size 200x200 tile:tile_fabric.gif -alpha Set \) -insert 0 \
#          -background None -flatten  overlap_canvas.jpg

#	 convert {balloon,castle,eye,eyeguy,ghost,hand_point,medical}.gif \
#          {news,noseguy,paint_brush,pencil,present,recycle}.gif \
#          {shading,skull,snowman,storm,terminal,tree}.gif \
#          \
#          -set page '+%[fx:80*cos((t/n)*2*pi)]+%[fx:80*sin((t/n)*2*pi)]' \
#          \
#          -background none -layers merge +repage image_circle.png

#	convert  rose: netscape: granite: \
#          \
#          +repage -set page '+%[fx:u[t-1]page.x+u[t-1].w]+0' \
#          \
#          -background none -layers merge +repage append_diy.png

#	convert map_venice.jpg    -page +142+242 push_pin.png \
#          -flatten  map_push_pin.jpg

#	convert \
#    \( holocaust_tn.gif -frame 10x10+3+3 \
#          -background none  -rotate 5 -repage +0+0 \) \
#    \
#    \( spiral_stairs_tn.gif -frame 10x10+3+3 \
#          -background none -rotate -15 -repage -90+60 \) \
#    \( -clone 0   -background black -shadow 70x3+4+7 \
#       -clone 1   -background black -compose DstATop -layers merge \
#       -trim \) \
#    \( -clone 2,0 -background none  -compose Over -layers merge \) \
#    -delete 0--2 \
#    \
#    \( chinese_chess_tn.gif -frame 10x10+3+3 \
#          -background none -rotate 20 -repage +60+90 \) \
#    \( -clone 0   -background black -shadow 70x3+4+7 \
#       -clone 1   -background black -compose DstATop -layers merge \
#       -trim \) \
#    \( -clone 2,0 -background none  -compose Over -layers merge \) \
#    -delete 0--2 \
#    \
#    \( +clone -background black -shadow 70x3+4+7 \) +swap \
#    -background none -compose Over -layers merge +repage \
#    layers_of_shadows.png
#
# convert xc:none xc:none \
#    \
#    \( holocaust_tn.gif -frame 10x10+3+3 \
#          -background none  -rotate 5 -repage +0+0 \) \
#    \( -clone 1   -background black -shadow 70x0+0+0 \
#       -clone 2   -background black -compose DstATop -layers merge \
#       -clone 0   -background none  -compose Over    -layers merge \) \
#    \( -clone 2,1 -background none  -compose Over    -layers merge \
#                  -background black -shadow 100x2+4+7 \) \
#    -delete 0-2 \
#    \
#    \( spiral_stairs_tn.gif -frame 10x10+3+3 \
#          -background none -rotate -15 -repage -90+60 \) \
#    \( -clone 1   -background black -shadow 70x0+0+0 \
#       -clone 2   -background black -compose DstATop -layers merge \
#       -clone 0   -background none  -compose Over    -layers merge \) \
#    \( -clone 2,1 -background none  -compose Over    -layers merge \
#                  -background black -shadow 100x2+4+7 \) \
#    -delete 0-2 \
#    \
#    \( chinese_chess_tn.gif -frame 10x10+3+3 \
#          -background none -rotate 20 -repage +60+90 \) \
#    \( -clone 1   -background black -shadow 70x0+0+0 \
#       -clone 2   -background black -compose DstATop -layers merge \
#       -clone 0   -background none  -compose Over    -layers merge \) \
#    \( -clone 2,1 -background none  -compose Over    -layers merge \
#                  -background black -shadow 100x2+4+7 \) \
#    -delete 0-2 \
#    \
#    \( -clone 1 -background black -shadow 70x0+0+0 \
#       -clone 0 -background none -compose Over -layers merge \) \
#    -delete 0-1 -trim +repage \
#    layers_of_deep_shadows.png
#
#	https://legacy.imagemagick.org/Usage/




# convert $img_bg $img_fg -gravity center -composite -format jpg -quality 90 $img_overlay.jpg
# dirs=`find ../ht2/kb/books/go -type d -maxdepth 1 | grep -v "go$" | grep -v "2013" grep -v "^pages$"`

# dirs=`find ../ht2/kb/books/go/go_basic/imgs -type f -maxdepth 1 -name "zn*.png" | grep -v "go$" | grep -v "2013" grep -v "^pages$"`
# dirs=`find ../ht2/kb/books/go -type d -maxdepth 1 -name "go_basics"`


dirs=`find ../ht2/kb/books/go/go_basics -type d -maxdepth 1 | grep -v "go$" | grep -v "2013" grep -v "^pages$"`
img_bg="imgs/bg/ko_colorado_white.jpg"
img_bg="imgs/bg/ko_colorado_mocha.jpg"

		echo "BUGS_101 dirs=$dirs"
		j=0; k=0; i=0;

		for dir in $dirs; do
			dirname=`dirname $dir`
			basedir=`echo $dir | awk -F"/" '{ print $6 }'`
			img_hw=`identify $img_bg | awk -F" " '{ print $3 }'`
			img_h=`echo $img_hw | awk -F"x" '{ print $1 }'`
			img_w=`echo $img_hw | awk -F"x" '{ print $2 }'`
			echo "BUGS_1927 img_bg=$img_bg img_h=$img_h img_w=$img_w"

			if [ $j == 0 ]; then 
				img0="kb/books/go/$basedir/pages/0.jpg"
				tn0="kb/books/go/$basedir/pages/tn/tn_0.png"
				zn0="kb/books/go/$basedir/pages/zn/zn_0.jpg"
				echo "BUGS_215 convert $img_bg -resize 550x $img0"; 

				if [ ! -f $img0 ]; then 
					echo "convert $img_bg -resize 550x $img0"
					convert $img_bg -resize 550x $img0
					fi
				if [ ! -f $tn0 ]; then 
					echo "convert $img_bg -resize 200x $tn0"
					convert $img_bg -resize 200x $tn0
					fi
				if [ ! -f $zn0 ]; then 
					echo "convert $img_bg -resize 1100x $zn0"
					convert $img_bg -resize 1100x $zn0
					fi
				convert $img_bg -resize 200x $tn0
				convert $img_bg -resize 1100x $zn0
#				if [ ! -f $img0 ]; then convert $img_bg -resize 550x $img0; fi
#				if [ ! -f $tn0 ]; then convert $img_bg -resize 200x $tn0; fi
#				if [ ! -f $zn0 ]; convert $img_bg -resize 1100x $zn0; fi
				echo "BUGS_240 j=$j open $img0"
				let j=j+1;
#				continue;
#				open $zn0
				fi

echo "BUGS_250 DIRS dirs=$dirs"
# imgs=`find ../ht2/kb/books/go/$basedir/pages/zn/zn*.*`
# imgs=`find ../ht2/kb/books/go/$basedir/imgs/zn*.* | head -1`
imgs=`find ../ht2/kb/books/go/$basedir/imgs/zn*.jpg`

# identify ./ht2/kb/books/go/go_basics/imgs/zn_img023.jpg 
# JPEG 3296x2550 3296x2550+0+0 8-bit sRGB 1.006MB 0.000u 0:00.000
			if [ "$basedir" == "go_basics" ]; then w1=1575; h1=2450; x1=10; y1=100; fi
			if [ "$basedir" == "go_basics" ]; then w2=1690; h2=2450; x2=1550; y2=100; fi

			if [ "$basedir" == "go_attack_defense" ]; then w1=1100; h1=1400; x1=10; y1=20; fi
			if [ "$basedir" == "go_attack_defense" ]; then w2=1100; h2=1400; x2=1500; y2=20; fi

			if [ "$basedir" == "go_equipment" ]; then w1=1100; h1=1400; x1=12; y1=22; fi
			if [ "$basedir" == "go_equipment" ]; then w2=1100; h2=1400; x2=1512; y2=22; fi

			if [ "$basedir" == "go_joseki" ]; then w1=1100; h1=1400; x1=13; y1=23; fi
			if [ "$basedir" == "go_joseki" ]; then w2=1100; h2=1400; x2=1513; y2=23; fi

			if [ "$basedir" == "go_middlegame" ]; then w1=1100; h1=1400; x1=14; y1=24; fi
			if [ "$basedir" == "go_middlegame" ]; then w2=1100; h2=1400; x2=1514; y2=24; fi

			if [ "$basedir" == "go_strategy" ]; then w1=1100; h1=1400; x1=15; y1=25; fi
			if [ "$basedir" == "go_strategy" ]; then w2=1100; h2=1400; x2=1515; y2=25; fi

			echo "BUGS_231 basedir=$basdir w1=$w1 h1=$h1 x1=$x1 y1=$y1"
			echo "BUGS_232 basedir=$basdir w2=$w2 h2=$h2 x2=$x2 y2=$y2"

			dir_pages="kb/books/go/$basedir/";
			dir_zn="kb/books/go/$basedir/pages/zn";
			dir_tn="kb/books/go/$basedir/pages/tn";
			if [ ! -d $dir_pages ]; then 
				echo "MKDIR_PAGES dir_pages=$dir_pages"
				if [ "$2" == "go" ]; then mkdir $dir_pages; fi
				fi
			if [ ! -d $dir_zn ]; then 
				echo "MKDIR_ZN dir_zn=$dir_zn"
				if [ "$2" == "go" ]; then mkdir $dir_zn; fi
				fi
			if [ ! -d $dir_tn ]; then 
				echo "MKDIR_TN dir_tn=$dir_tn"
				if [ "$2" == "go" ]; then mkdir $dir_tn; fi
				fi
			for img in $imgs; do
				basename=`basename img`
				base=`echo $basename | awk -F"." '{print $1}'`
				ext=`echo $basename | awk -F"." '{print $2}'`
				echo "j=$j k=$k i=$i basedir=$basedir base=$base ext=$ext"
				if [ "$basedir" == "go_strategy" ]; then 
					if [ "$basename" == "zn_IMG123.jpg" ]; then
						w1=1101; h1=1401; x1=15; y1=25;
						w2=1102; h2=1402; x2=1515; y2=25; 
						fi
					fi

				i1=0
				let i1=k
				let i2=i+1
#		 		convert -crop 240x160+100+50 img1.jpg img2.jpg
				zn1="kb/books/go/$basedir/pages/zn/zn_$i1.jpg";
				tn1="kb/books/go/$basedir/pages/tn/tn_$i1.png";
				img1="kb/books/go/$basedir/pages/$i1.mpg";
				echo "pqpqpqpqpqpqpqpqpqpqpqpqpqpq"
# 				echo "j=$j k=$k i=$i convert -crop $w1""x$h1+$x1+$y1 $img $zn1"
 				echo "j=$j k=$k i=$i convert -crop $w1""x$h1+$x1+$y1 -composite -gravity center $img_bg $img $zn1"
				let i=i+1
				img1="kb/books/go/$basedir/pages/$i1.jpg";
				zn1="kb/books/go/$basedir/pages/zn/zn_$i1.jpg";
				tn1="kb/books/go/$basedir/pages/tn/tn_$i1.png";
				img2="kb/books/go/$basedir/pages/$i2.jpg";
				zn2="kb/books/go/$basedir/pages/zn/zn_$i2.jpg";
				tn2="kb/books/go/$basedir/pages/tn/tn_$i2.png";

				geo_x=1; geo_y=1;

# https://legacy.imagemagick.org/Usage/annotating/#overlay
# 				echo "BUGS_271 j=$j k=$k i=$i convert -crop $w1""x$h1+$x1+$y1 -resize 1100x -composite -geometry $geo_x+$geo_y $img_bg $img $zn1"
 				echo "BUGS_271 j=$j k=$k i=$i convert -crop $w1""x$h1+$x1+$y1 -resize 1100x -composite -gravity center $img_bg $img $zn1"
 				echo "BUGS_272 j=$j k=$k i=$i convert -crop $w2""x$h2+$x2+$y2 -resize 1100x -composite -gravity center $img_bg $img $zn2"

#				echo "BUGS_4501 j=$j k=$k i1=$i1 convert $zn1 -resize 550x $img1"
#				echo "BUGS_4502 j=$j k=$k i2=$i2 convert $zn2 -resize 550x $img2"
#
#				echo "BUGS_4503 j=$j k=$k i1=$i1 convert $zn1 -resize 200x $tn1"
#				echo "BUGS_4504 j=$j k=$k i2=$i2 convert $zn2 -resize 200x $tn2"

				let i=i+1
				echo "bdbdbdbdbdbdbdbdbdbdbdbdbdbd"
				echo "q=quit s=skip g=go:  "
				if [ "$usrcmd" != "g" ]; then
					read usrcmd
					if [ "$usrcmd" == "q" ]; then exit; fi
					if [ "$usrcmd" == "s" ]; then continue; fi
					fi
				echo "MSG_100 CROP $i "
				if [ "$2" == "go" ]; then
 					echo "GO j=$j k=$k i=$i convert -crop $w2+$h2+$x2+$y2 $img $zn1"
 					echo "GO j=$j k=$k i=$i convert -crop $w2+$h2+$x2+$y2 -resize 1100x -composite -gravity center $img_bg $img $zn1"
					w1x=$w1"x"
					w2x=$w2"x"
# 					convert -crop  $w1x$h1+$x1+$y1 -resize 1100x $img $zn1
# 					convert -crop  $w1x$h1+$x1+$y1 -resize 1100x -composite -gravity center $img_bg $img $zn1
# 					echo "GO j=$j k=$k i=$i convert -crop $w2""x$h2+$x2+$y2 $img $img2"
# 					echo "convert -crop $w2""+$h2+$x2+$y2 -resize 1100x -composite -gravity center $img_bg $img $zn2"
# 					convert -crop $w2x$h2+$x2+$y2 -resize 1100x -composite -gravity center $img_bg $img $zn2


 					echo "GO j=$j k=$k i=$i convert -crop $w2""x$h2+$x2+$y2 $img $img2"
 					convert -resize 1100x -composite -gravity center $img_bg $img $zn1
 					convert -resize 1100x -composite -gravity center $img_bg $img $zn2


					echo "convert $zn1 -resize 550x $img1"
#					convert $zn1 -resize 550x $img1
					echo "convert $zn1 -resize 200x $tn1"
#					convert $zn1 -resize 200x $tn1

					echo "convert $zn2 -resize 550x $img2"
#					convert $zn2 -resize 550x $img2
					echo "convert $zn2 -resize 200x $tn2"
#					convert $zn2 -resize 200x $tn2
					if [ i < 2 ]; then
						open $img
						open $zn1
						open $zn2
						fi
					fi

				let k=k+1
				done
			echo "MSG_103 DONE_IMG j=$j k=$k i=$i basedir=$basedir"
			let j=j+1
			done
		echo "MSG_103 DONE_DIR j=$j k=$k i=$i basedir=$basedir"
		exit

# dirs=`find kb/books/go -type d -maxdepth 1 -name "*" | grep -v "2013"`
dirs=`find kb/books/go -type d -maxdepth 1 -name "go_basics"`
echo "BUGS_300 dirs=$dirs"
exit;
		j=0;
		for dir in $dirs; do
			if [ "$dir" == "" ]; then continue; fi
	
			basedir=`echo $dir | awk -F"/" '{ print $4}'`
			if [ "$basedir" == "" ]; then continue; fi

			echo "$progid $dttm DIR j=$j k=$k dir=$dir basedir=$basedir"
			
#			if [ ! -d ../ht2/kb/books/go/$basedir/pages ]; then
#				echo "mkdir ../ht2/kb/books/go/$basedir/pages"
#				if [ "$2" == "go" ]; then mkdir "../ht2/kb/books/go/$basedir/pages"; fi
#			else
#				echo "DIR_EXISTS PAGES $j ../ht2/kb/books/go/$basedir/pages"
#				ls -lat ../ht2/kb/books/go/$basedir/pages
##				continue
#				fi

#			 if [ ! -d ../ht/kb/books/go/$basedir/pages/zn ]; then 
#				echo "mv ../ht2/kb/books/go/$basedir/zn ../ht2/kb/books/go/$basedir/pages/"
#				if [ "$2" == "go" ]; then mv ../ht2/kb/books/go/$basedir/zn ../ht2/kb/books/go/$basedir/pages/; fi
#			else
#				echo "DIR_EXISTS PAGES/ZN $j ../ht2/kb/books/go/$basedir/pages"
#				ls -lat ../ht2/kb/books/go/$basedir/pages/zn
#				fi
#			continue

# imgs=`find $dir/pages/zn -type f -maxdepth 1 -name "tn_*.jpg"`
imgs=`find ../ht2/kb/books/go/$basedir/pages/zn -type f -maxdepth 1 -name "zn_*.jpg"`
echo "BUGS_200 j=$j basedir=$basedir"
echo "BUGS_201 imgs=$imgs"


			k=0;
			for img in $imgs; do
				basename=`basename $img`
				base=`basename $img | awk -F"." '{ print $1 }'`
				img1="kb/books/go/$basedir/pages/$k.jpg"
				tn="kb/books/go/$basedir/pages/tn/tn_$k.png"
				zn="kb/books/go/$basedir/pages/zn/zn_$k.jpg"
				imgtmp="kb/books/go/$basedir/pages/tmp_$k.jpg"

#				if [ ! -d kb/books/go/$basedir/pages/zn ]; then
#					echo "mkdir kb/books/go/$basedir/pages/zn"
#					if [ "$2" == "go" ]; then mkdir kb/books/go/$basedir/pages/zn; fi
#					fi


				if [ -f $img1 ]; then
					echo "$progid $dttm MSG_101 FOUND j=$j k=$k basedir=$basdeir img1=$img1";
					fi

##				echo "cp $img $zn"
##				if [ "$2" == "go" ]; then cp $img $zn; fi

				if [ ! -f $tn ]; then
					echo "convert $img -resize 200x $tn"
					if [ "$2" == "go" ]; then convert $img -resize 200x $tn; fi
					fi
				if [ ! -f $tn ]; then
					echo "convert $img -resize 550x $img1"
					if [ "$2" == "go" ]; then convert $img -resize 550x $img1; fi
					fi
				
				let k=k+1
				done

			let j=j+1
			done
		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "renumber" ]; then

	if [ "$1" == "go" ] || [ "$1" == "annotate" ]; then
		echo "convert pdf/gnome.pdf -resize 500x fb/gnome/pages/%01d.jpg"

pdfs="gnome.pdf go.pdf"
pdfs="new.pdf old.pdf"

		for pdf in $pdfs; do
			id=`echo $pdf | awk -"/" '{ $2 }'`
			if [! -f pdf/$pdf ]; then continue; fi
			convert pdf/$pdf -resize 500x fb/$id/pages/%01d.jpg
			convert pdf/$pdf -resize 200x fb/$id/pages/tn/tn_%01d.png
			convert pdf/$pdf -resize 1100x fb/$id/pages/zn/zn_%01d.jpg
			done


		convert pdf/gnome.pdf -resize 500x fb/gnome/pages/%01d.jpg
		convert pdf/gnome.pdf -resize 200x fb/gnome/pages/tn/tn_%01d.png
		convert pdf/gnome.pdf -resize 1100x fb/gnome/pages/zn/zn_%01d.jpg

		echo "convert pdf/go.pdf -resize 500x kb/books/go/go_equipment/pages/%01d.jpg"
		convert pdf/go.pdf -resize 500x kb/books/go/go_equipment/pages/%01d.jpg
		convert pdf/go.pdf -resize 200x kb/books/go/go_equipment/pages/tn/tn_%01d.png
		convert pdf/go.pdf -resize 1100x kb/books/go/go_equiopment/pages/zn/zn_%01d.jpg

		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "annotate" ]; then

	if [ "$1" == "go" ] || [ "$1" == "annotate" ]; then
		dttm=`date +"%Y%m%d_%H%M%S"`
list=`cat categories.psv`;

		j=0; k=0;
		img0="zc/imgs/peddlers/ko_colorado_mocha.jpg"
		if [ ! -f $img0 ]; then 
			echo "$progid $dttm ERR_101 NOTFIUND img0=$img0"; 
			exit; 
			fi
		csvfil_cat="../i/zc/csv/category_new.csv"
		csvfil_catdesc="../i/zc/csv/category_description_new.csv"

#		echo "cp ../i/categories.csv $csvfil_cat"
#		cp ../i/categories.csv $csvfil_cat

		echo "cat ../i/zc/csv/categories.csv | awk 'NR>1 { print $0 }' > $csvfil_cat"
		cat ../i/zc/csv/categories.csv | awk 'NR>1 { print $0 }' > $csvfil_cat
		echo "cat ../i/zc/csv/categories_description.csv | awk 'NR>1 { print $0 }' > $csvfil_catdesc"
		cat ../i/zc/csv/categories_description.csv | awk 'NR>1 { print $0 }' > $csvfil_catdesc
		jcat=64;

		if [ ! -f $img0 ]; then
			echo "BUGS_3760 NOTFOUND img0=$img0"
			exit
			fi

#		fontpath_cat="fonts/HERNGTON.TTF"
#		fontpath_subcat="/Volumes/ka1tbr2/ht/fonts/"
		batfil="annotate.bat"
		echo ":: $batfil $dttm" > $batfil
		echo ":: =========================" >> $batfil
		echo "" >> $batfil

		for line in $list; do
			if [ "$line" == "" ]; then continue; fi
			let j=j+1;
#			if [ j>1 ]; then break; fi
			let jcat=jcat+1;

			cat=`echo $line | awk -F"|" '{ print $1 }'`
			subcat=`echo $line | awk -F"|" '{ print $2 }'`
			text="$cat""_$subcat"

			img_cat="zc/imgs/categories/category_$cat.jpg"
			img_subcat="zc/imgs/categories/subcategory_$cat""_$subcat.jpg"
			tn_cat="zc/imgs/categories/tn/tn_category_$cat.png"
			tn_subcat="zc/imgs/categories/tn/tn_subcategory_$cat""_$subcat.png"
	
			echo "$j $line"
			if [ "$subcat" == "" ]; then
				echo "BUGS_111 CAT cat=$cat subcat=$subcat"
				echo "convert $img0 -gravity NorthWest -font fonts/HARNGTON.TTF -pointsize 70 -annotate +25+25 $cat $img_cat"
#				echo "convert $img0 -gravity NorthWest -font fonts/HARNGTON.TTF -pointsize 70 -strokewidth 2 -stroke brown -undercolor goldenrod -annotate +25+25 $cat $img_cat" >> annotate.bat
				echo "convert $img0 -gravity NorthWest -font fonts/HARNGTON.TTF -pointsize 70 -strokewidth 2 -stroke brown -annotate +25+25 $cat $img_cat" >> annotate.bat

				echo "convert $img_cat $tn_cat"
				echo "convert $img_cat $tn_cat" >> annotate.bat

cat_id=$jcat;
cat_img="/$img_cat";
parent_id="0";
let sort_order=jcat+2000;
dttm_added=`date +"%Y-%m-%d %H:%M:%S"`;
dttm_mod=$dttm_added;
cat_status="1";
echo "\"$cat_id\",\"$cat_img\",\"$parent_id\",\"$sort_order\",\"$dttm_added\",\"$dttm_mod\",\"$cat_stat\"" >> $csvfil_cat

lang_id="1"
cat_name="$cat"
cat_desc="desc_$cat"
echo "\"$cat_id\",\"$lang_id\",\"$cat_name\",\"$cat_desc\"" >> $csvfil_catdesc




				continue;
				fi

			echo "BUGS_102 SUBCAT cat=$cat subcat=$subcat"
#			echo "convert $img_cat -gravity NorthWest -font fonts/HARNGTON.TTF -pointsize 100 -strokewidth 2 -stroke brown -undercolor goldenrod -annotate +25+200 $subcat $img_subcat" >> $batfil
			echo "convert $img_cat -gravity NorthWest -font fonts/HARNGTON.TTF -pointsize 90 -strokewidth 2 -stroke brown -annotate +25+300 $subcat $img_subcat" >> $batfil


# echo "convert $img_cat -draw \"fill tomato  circle 250,30 310,30 fill limegreen  circle 55,75 15,80 font fonts/HARNGTON.TTF    font-size 72 decorate UnderLine fill goldenrod  stroke tan  stroke-width 2 translate 10,110 rotate -15 text 0,0 ' $subcat '\" $img_subcat " >> $batfil


			echo "convert $img_subcat -resize 200 $tn_subcat"
			echo "convert $img_subcat -resize 200 $tn_subcat" >> $batfil

let jcat=jcat+1;
cat_id=$jcat;
cat_img="/$img_subcat";
parent_id="0";
let sort_order=jcat+2000;
dttm_added=`date +"%Y-%m-%d %H:%M:%S"`;
dttm_mod=$dttm_added;
cat_status="1";
echo "\"$cat_id\",\"$cat_img\",\"$parent_id\",\"$sort_order\",\"$dttm_added\",\"$dttm_mod\",\"$cat_stat\"" >> $csvfil_cat

lang_id="1"
cat_name="$cat""_$subcat"
cat_desc="desc_$cat""_$subcat"
echo "\"$cat_id\",\"$lang_id\",\"$cat_name\",\"$cat_desc\"" >> $csvfil_catdesc


			done

#		if [ -f $img_cat ]; then 
#			open $img_cat; 
#			echo "$img_cat"
#			fi
#		if [ -f $img_subcat ]; then 
#			open $img_subcat; 
#			echo "$img_subcat"
#			fi

		echo "vi $csvfil_cat";
		echo "vi $csvfil_catdesc";
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "annotate" ]; then

	if [ "$1" == "go" ] || [ "$1" == "scp" ]; then
		hosts="kozerus@ko0.us kotwous@ko2.us";
		files="ko.php ko.db3";
		dirs="jq";
		for host in $hosts; do
			for dir in $dirs; do
				echo "scp -rp $dir $host:~/public_html/"
				scp -rp $dir $host:~/public_html/
				done

#			for file in $files; do
#				echo "scp $file $host:~/public_html/"
#				scp $file $host:~/public_html/
#				done
			done
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "scp" ]; then

	if [ "$1" == "go" ] || [ "$1" == "scp" ]; then
hosts="kozerus@ko0.us kotwous@ko2.us"
# hosts="kozerus@ko0.us"
# files="ko.php ko_selects.php ko_select.html ko_cheatsheets.html"
# files="index.htm* ko.php ko_selects.php ko_selects.html ko.db3 ko_templet.db3"
files="ko.php ko.db3"

j=0;k=0;
		for host in $hosts;do
			for file in $files; do
				dttm=`date +"%Y%m%d_%H%M%S"`
				echo "$progid $dttm $1 $2 scp $file $host:~/public_html/"
				scp $file $host:~/public_html/
				done

pdfs="ko.pdf kt.pdf konet.pdf jtfdc.pdf jtfinc.pdf jtfdcr.pdf iperms.pdf konet.pdf"
pdfs=""
pdfs="jkwii_about.pdf ko.pdf kt.pdf"
			for pdf in $pdfs; do
				dttm=`date +"%Y%m%d_%H%M%S"`
				echo "$progid $dttm $1i $2 scp pdf/$pdf $host:~/public_html/pdf"
				scp pdf/$pdf $host:~/public_html/pdf
				done

dirs="pn tl zm sl ko_center"
			for dir in $dirs; do
				dttm=`date +"%Y%m%d_%H%M%S"`
				echo "$progid $dttm $1 $2 scp -r $dir $host:~/public_html/"
				scp -r $dir $host:~/public_html/
				done
			done


		echo "$progid $dttm o1=$1 o2=$2"
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "scp" ]; then

	if [ "$1" == "go" ] || [ "$1" == "convert" ]; then
		echo "$progid $dttm BUGS_101 CONVERT 1=$1 2=$2 3=$3 4=$4"
		tpath="pages"
		pdffil_default="/pdf/ko.pdf"
		tpath_default="pages"

		pdffil=$pdffil_default;
		tpath=$tpath_default;
		if [ "$2" != "" ]; then pdffil=$2; fi
		if [ "$3" != "" ]; then tpath=$3; fi

		if [ ! -f $pdffil ]; then
			echo "$progid $dttm ERR_101 PDFFIL NOTFOUND pdffil=$pdffil"
			exit
			fi

# sqlite3 ka1.db3 .schema > ka1_schema.sql
# sqlite3 ka1_schema.db3 < ka1_schema.sql
# sqlite3 ka1_schema.db3 .tables


#		read -p "usr: " usr
#		read -sp "pw: " pw
#		echo "$progid $dttm  usr=$usr pw=$pw"
#		read -e -p "pathfile: " -i "fb/konet/sw" pathfile
#		echo "$progid $dttm pathfile=$pathfile"

		if [ ! -d $tpath ]; then
			echo "$progid $dttm ERR_102 TPATH NOTFOUND tpath=$tpath"
			echo " "
			read -e -p "create $tpath q=quit s=skip ENTER=continue: " usrcmd
			if [ "$usrcmd" == "q" ]; then 
				echo "$progid $dttm QUIT NO tpath=$tpath"
				exit; 
				fi
			fi

		if [ ! -d $tpath ] & [ "$usrcmd" == "" ]; then

dirs="$tpath $tpath/pages $tpath/pages/tn $tpath/pages/zn $tpath/imgs $tpath/pdf $tpath/mp3 $tpath/mp4"
			j=0;
			usrcmd=""
			for dir in $dirs; do
				let j=j+1
				if [ "$usrcmd" != "g" ] || [ "$usrcmd" != "S" ]; then
					echo "g=go s=skip q=quit"
					read -e -p "create $dir y=yes:" usrcmd
					if [ "$usrcmd" == "q" ]; then exit; fi
					if [ "$usrcmd" == "s" ]; then continue; fi
					fi
				if [ "$usrcmd" == "S" ]; then continue; fi
				if [ ! -d $dir ]; then
					echo "mkdir $dir # j=$j"
#					mkdir $dir
					fi
				done

files="index.htm* index_head.html index_tail.html ko_lists.html ko_lists_head.html ko_lists_tail.html books.sql marks.sql usbs.sql"
			fbid=`basename $tpath | awk -F"." '{ print $1 }'`
			j=0; usrcmd=""
			for file in $files; do
				let j=j+1;

				if [ "$usrcmd" != "g" ] || [ "$usrcmd" != "S"]; then
					read -e -p "copy $tpath/$file g=go s=skip q=quit: " usrcmd
					if [ "$usrcmd" == "q" ]; then exit; fi
					if [ "$usrcmd" == "s" ]; then continue; fi
					fi
				if [ "$usrcmd" == "S"]; then continue; fi

				if [ ! -f $tpath/$file ]; then
					echo "cp $file $tpath/"
#					cp $file $tpath/
					fi
				done

			if [ ! -f $tpath/$fbid.db3 ]; then
				echo "cp ka1_schema.db3 $tpath/$fbid.db3"
#				cp ka1_scheam.db3 $tpath/$fbid.db3
				fi

exts="py sh"
			j=0;
			for ext in $exts; do
				let j=j+1
				if [ ! -f $tpath/$fbid.$ext ]; then
					echo "cat ka1.$ext | sed -e s:ka1:$fbid > $tpath/$fbid.$ext"
#					cp ka1.$ext $tpath/$fbid.$ext | sed -e s:ka1:$fbid: > $tpath/$fbid.$ext
					fi
				done
#			fi
			
			echo "$progid $dttm MSG_109 FOUND tpath=$tpath"
			echo "convert $pdffil -resize 550x $tpath/pages/%01d.jpg"
			convert $pdffil -resize 550x $tpath/pages/%01d.jpg
			echo "convert $pdffil -resize 200x $tpath/pages/tn/tn_%01d.png"
			convert $pdffil -resize 200x $tpath/pages/tn/tn_%01d.png
			echo "convert $pdffil -resize 1100x $tpath/pages/zn/zn_%01d.jpg"
			convert $pdffil -resize 1100x $tpath/pages/zn/zn_%01d.jpg
		else
			tpath="."
			pdffil="pdf/ko.pdf"
			if [ ! -f $pdffil ]; then
				echo "$progid $dttm ERR_105 PDFFIL NOTFOUND pdffil=$pdffil"
				exit;
				fi
			if [ -d $tpath/pages ]; then
				echo "$progid $dttm MSG_106 TPATH/PAGES FOUND tpath/pages=$tpath/pages"


				echo "convert $pdffil -resize 550x $tpath/pages/%01d.jpg"
#				convert $pdffil -resize 550x $tpath/pages/%01d.jpg
				echo "convert $pdffil -resize 200x $tpath/pages/tn/tn_%01d.png"
#				convert $pdffil -resize 200x $tpath/pages/tn/tn_%01d.png
				echo "convert $pdffil -resize 1100x $tpath/pages/zn/zn_%01d.jpg"
#				convert $pdffil -resize 1100x $tpath/pages/zn/zn_%01d.jpg
			else
				echo "$progid $dttm ERR_106 TPATH/PAGES NOTFOUND tpath/pages=$tpath/pages"
				fi	
			echo "$progid $dttm MSG_107 END CONVERT tpath/pages=$tpath/pages"
			fi


		echo "$progid $dttm MSG_108 BEG SCP tpath=$tpath fbid=$fbid pdffil=$pdffil"
		if [ "$4" != "" ]; then 
			hosts="";
			if [ "$4" == "ko" ]; then
				hosts="kozerus@ko0.us kotwous@ko2.us"
				fi
			if [ "$4" == "ko0" ]; then
				hosts="kozerus@ko0.us"
				fi
			if [ "$4" == "ko1" ]; then
				hosts="kotwous@ko2.us"
				fi
			if [ "$4" == "ko2" ]; then
				hosts="kotwous@ko2.us"
				fi

			for host in $hosts;do
				if [ -d $tpath ]; then
					echo "scp $tpath/index.htm* $host:~/public_html/$tpath"
#					scp $tpath/index.htm* $host:~/public_html/$tpath/


					echo "scp -r $tpath/pages $host:~/public_html/$tpath/"
#					scp -r $tpath/pages $host:~/public_html/$tpath/

				else

					echo "scp -r pages $host:~/public_html/"
#					scp -r pages $host:~/public_html/
					fi
				done
			fi

		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "convert" ]; then


	if [ "$1" == "go" ] || [ "$1" == "psv2tbl" ]; then
		echo "$progid $dttm psv2tbl"
		db3file="ko.db3"
		tblname="books"
		books=""
		marks=""
		usbs=""
		j=0;
		types="books marks usbs"
		for type in $types; do
			grp=$type;
			if [ "$type" == "books" ]; then
				tblname="books"
				list=`cat books.psv`
				id_type="b_";
				fi
			if [ "$type" == "marks" ]; then
				tblname="marks"
				list=`cat marks.psv`
				id_type="m_";
				fi
			if [ "$type" == "usbs" ]; then
				tblname="usbs"
				list=`cat usbs.psv`
				id_type="u_";
				fi

		echo "sqlite3 $db3file \"delete from $tblname\""
		sqlite3 $db3file "delete from $tblname"
		for line in $list; do
			let j=j+1;

#			id=`echo $line|awk -F"|" '{ print $1}'`
			id="$id_type_$j";
			desc=`echo $line|awk -F"|" '{ print $2}'`
			amt=`echo $line|awk -F"|" '{ print $3}'`
			img=`echo $line|awk -F"|" '{ print $4}'`
			tn=`echo $line|awk -F"|" '{ print $5}'`
			credit=`echo $line|awk -F"|" '{ print $6}'`


#			echo "BUGS_102 j=$j id=$id desc=$desc amt=$amt img=$img credit=$credit"
			sql="insert or replace into $tblname "

			fbid="$id"
			credit=$amt;
			media=$img;
			headline="headline_$j";
			text="text_$j";
			assets="assets_$j";
			caption="caption_$j";

			sql=$sql"( "
			sql=$sql"'grp', "
			sql=$sql"'fbid', "
			sql=$sql"'credit'," 
			sql=$sql"'media', "
			sql=$sql"'tn', "
			sql=$sql"'desc'," 
			sql=$sql"'headline', "
			sql=$sql"'text', "
			sql=$sql"'assets'," 
			sql=$sql"'caption' "
			sql=$sql" ) values ( "
			sql=$sql"'$grp', "
			sql=$sql"'$fbid', "
			sql=$sql"'$credit', "
			sql=$sql"'$media', "
			sql=$sql"'$tn', "
			sql=$sql"'$desc', "
			sql=$sql"'$headline', "
			sql=$sql"'$text', "
			sql=$sql"'$assets', "
			sql=$sql"'$caption' "
			sql=$sql" );"

			echo "$progid $dttm BUGS_102 sql=$sql"


			echo "sqlite3 $db3file \"$sql\""
			sqlite3 $db3file "$sql"
			done
		done

		echo "sqlite3 $db3file \"select * from $tblname\""
		sqlite3 $db3file "select * from $tblname"
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "psv2tbl" ]; then

        if [ "$1" == "go" ] || [ "$1" == "refresh" ]; then
fbid_default="kt"
		fbid=$fbid_default;
		if [ "$2" != "" ]; then fbid=$2; fi
		echo "$progid $dttm REFRESH fbid=$fbid"
		fpath=fb/$fbid"

		echo "convert pdf/$fbid.pdf -resize 1100x $fpath/pages/zn/zn_%01d.jpg"
		convert pdf/$fbid.pdf -resize 1100x $fpath/pages/zn/zn_%01d.jpg
		echo "convert pdf/$fbid.pdf -resize 200x $fpath/pages/tn/tn_%01d.png"
		convert pdf/$fbid.pdf -resize 200x $fpath/pages/tn/tn_%01d.png
		echo "convert pdf/$fbid.pdf -resize 550x $fpath/pages/%01d.jpg"
		convert pdf/kt.pdf -resize 550x $fpath/pages/%01d.jpg
echo "BUGS_101 fbid=$fbid fpath=$fpath"
exit;


		if [ "$2" == "scp" ]; then
hosts="kozerus@ko0.us kotwous@ko2.us"
			scpflag=""
			if [ "$3" != "" ]; then
				scpflag="yes"
				fi
			for host in $hosts;do
				if [ "$scpflag" != "" ]; then
					echo "scp $fpath/index.htm* $host:~/public_html/$fpath"
#					scp $fpath/index.htm* $host:~/public_html/$fpath/


					echo "scp -r $fpath/pages $host:~/public_html/$fpath/"
#					scp -r $fpath/pages $host:~/public_html/$fpath/
					fi
				done

			fi


		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "refresh" ]; then

        if [ "$1" == "go" ] || [ "$1" == "pdf2fbnew" ]; then
fbid="ka"
#		if [ -d fb/$fbid ]; then
#			echo "BUGS_4220 pdf2fbnew EXISTS fb/$fbid"
#			exit;
#			fi

		if [ ! -d fb/$fbid ]; then
			echo "mkdir fb/$fbid"
			mkdir fb/$fbid
			fi

dirs="pages imgs mp3 mp4 pdf"
		for dir in $dirs; do
			if [ ! -d fb/$fbid/$dir ]; then
				echo "mkdir fb/$fbid/$dir"
				mkdir fb/$fbid/$dir
				fi
			done

		echo "mkdir fb/$fbid/pages/zn"
#		mkdir fb/$fbid/pages/zn
		echo "mkdir fb/$fbid/pages/tn"
#		mkdir fb/$fbid/pages/tn
		echo "mkdir fb/$fbid/imgs/zn"
#		mkdir fb/$fbid/imgs/zn
		echo "mkdir fb/$fbid/imgs/tn"
#		mkdir fb/$fbid/pages/tn

		echo "cp index.htm* fb/$fbid/"
#		cp index.htm* fb/$fbid/
#		cp index_head.html fb/$fbid/
#		cp index_tail.html fb/$fbid/

		echo "cp ko_lists.htm* fb/$fbid/"
#		cp ko_lists.htm* fb/$fbid/
#		cp ko_lists_head.html fb/$fbid/
#		cp ko_lists_tail.html fb/$fbid/

		echo "cp ka.db3 fb/$fbid/$fbid.db3"
#		cp ka.db3 fb/$fbid/$fbid.db3

		echo "cp books.sql fb/$fbid/"
#		cp books.sql fb/$fbid/
		echo "cp marks.sql fb/$fbid/"
#		cp marks.sql fb/$fbid/
		echo "cp usbs.sql fb/$fbid/"
#		cp usbs.sql fb/$fbid/

		echo "cat ka.py | sed -e s:ka1:$fbid: > fb/$fbid/$fbid.py"
#		cat ka.py | sed -e s:ka1:$fbid: > fb/$fbid/$fbid.py
		echo "cat ka.sh | sed -e s:ka1:$fbid: > fb/$fbid/$fbid.sh"
#		cat ka.sh | sed -e s:ka1:$fbid: > fb/$fbid/$fbid.sh



		echo "convert pdf/$fbid.pdf -resize 550x > fb/$fbid/pages/%01d.jpg"
##		convert pdf/$fbid.pdf -resize 550x > fb/$fbid/pages/%01d.jpg
		echo "convert pdf/$fbid.pdf -resize 1100x > fb/$fbid/pages/zn/zn_%01d.jpg"
#		convert pdf/$fbid.pdf -resize 1100x > fb/$fbid/pages/zn/zn_%01d.jpg
		echo "convert pdf/$fbid.pdf -resize 200x > fb/$fbid/pages/tn/tn_%01d.png"
#		convert pdf/$fbid.pdf -resize 200x > fb/$fbid/pages/tn/tn_%01d.png

# imgs=`find imgs -type f -name "*.jpg" | sed -e s:^:/:`
fpath="fb/$fbid/imgs"
imgs=`find $fpath -type f -name "*.jpg"`
imgs=""

	echo "BUGS_102 imgs=$imgs"
		j=0;
		for img in $imgs; do
			let j=j+1
#			img="$fpath/$fbid.jpg"
			fbid=`echo $img | awk -F"/" '{print $4}' | awk -F"." '{print $1}'`
#			echo "BUGS_103 j=$j img=$img"
			tn="$fpath/tn/tn_$fbid.png"
			zn="$fpath/zn/zn_$fbid.jpg"
			echo "convert $img -resize 1100x $zn"
#			convert $img -resize 1100x $zn
			echo "convert $img -resize 200x $tn"
#			convert $img -resize 200x $tn
			echo "convert $zn -resize 550x $img"
#			convert $zn -resize 550x $img
			done



		htmold_index="index_$dttm.html"
		htmnew_index="index_new.html"
		echo "" > $htmnew_index
		echo "cat index_head.html >> $htmnew_index"
		cat index_head.html >> $htmnew_index

		echo "jklists['pagelist_pages'] = \`" >> $htmnew_index
		
		find pages -name "*.jpg" >> $htmnew_index
#		find pages -name "*.jpg" >> $htmnew_index
#		find pages -type f -maxdepth 1 -name "*.jpg" >> $htmnew_index`
#		pages=`find pages/*.jpg -type f -maxdepth 1 -name "*.jpg" >> $htmnew_index`
#		echo $pages >> $htmnew_index
		echo "/imgs/btn/koeyeb.png.gif" >> $htmnew_index
		find imgs -name "*.jpg" | sed -e s:^:/: >> $htmnew_index

		echo "\`;" >> $htmnew_index

		echo "jklists['pagelist_imgs'] = \`" >> $htmnew_index
		echo "/imgs/btn/koeyew.png" >> $htmnew_index
		find imgs -name "*.jpg" | sed -e s:^:/: >> $htmnew_index
		echo "\`;" >> $htmnew_index

		echo "cat index_tail.html >> $htmnew_index"
		cat index_tail.html >> $htmnew_index

		index_save="index_$dttm.html"
		echo "cp index.html $index_save"
		cp index.html $index_save

#		echo "vi $htmnew_index"
#		vi $htmnew_index

fpath="fb/$fbid"
		finds="$fpath/finds.txt"
		echo "" > $finds
		echo "$fpath/imgs -name \"*.jpg\" | sed -e s:^:/: >> $finds"
		find $fpath/imgs -name "*.jpg" | sed -e s:^:/: >> $finds
		echo "find $fpath/pages -name \"*.jpg\" | sed -e s::: >> $finds"
		find $fpath/pages -name "*.jpg" | sed -e s:^:/: >> $finds

#		echo "BUGS_105 FINDS finds=$finds"
		echo "python $fbid.py go $finds lists"
		python $fbid.py go $finds lists

# db3="$fbid.db3";
db3="$fpath/$fbid.db3"
tbl="lists";
		echo "sqlite3 $db3 \".import $finds lists\""
#		sqlite3 $db3 \".import $finds $tbl\""

		echo "sqlite3 $db3 \"insert into books as select * from lists where pathfile like '%/imgs/books/$'\""
#		sqlite3 $db3 "insert into books as select * from lists where pathfile like '%/imgs/books/$'"

		echo "sqlite3 $db3 \"insert into marks as select * from lists where pathfile like '%/imgs/marks/$'\""
#		sqlite3 $db3 "insert into marks as select * from lists where pathfile like '%/imgs/marks/$'"

		echo "sqlite3 $db3 \"insert into usbs as select * from lists where pathfile like '%/imgs/usbs/$'\""
#		sqlite3 $db3 "insert into usbs as select * from lists where pathfile like '%/imgs/usbs/$'"

		echo "sqlite3 $db3 < books.sql > books.psv"
		sqlite3 $db3 < books.sql > books.psv
		echo "sqlite3 $db3 < marks.sql > marks.psv"
		sqlite3 $db3 < marks.sql > marks.psv
		echo "sqlite3 $db3 < usbs.sql > usbs.psv"
		sqlite3 $db3 < usbs.sql > usbs.psv

		htmnew_lists="ko_lists_new.html";
		echo "" > $htmnew_lists
		cat ko_lists_head.html >> $htmnew_lists
		echo "books = \`" >> $htmnew_lists
		find fb/bookmarkusb/imgs/books -name "*.jpg" | sed -e s:^:/: | grep -v "/tn/tn" | grep -v "/zn/zn" >> $htmnew_lists
		find fb/bookmarkusb/imgs/books -name "*.png" | sed -e s:^:/: | grep -v "/tn/tn" | grep -v "/zn/zn" >> $htmnew_lists
#		cat books.psv >> $htmnew_lists
		echo "\`;" >> $htmnew_lists
		echo "marks = \`" >> $htmnew_lists
		find fb/bookmarkusb/imgs/marks -name "*.jpg" | sed -e s:^:/: | grep -v "/tn/tn" | grep -v "/zn/zn" >> $htmnew_lists
		find fb/bookmarkusb/imgs/marks -name "*.png" | sed -e s:^:/: | grep -v "/tn/tn" | grep -v "/zn/zn" >> $htmnew_lists
#		cat marks.psv >> $htmnew_lists
		echo "\`;" >> $htmnew_lists
		echo "usbs = \`" >> $htmnew_lists
		find fb/bookmarkusb/imgs/usbs -name "*.jpg" | sed -e s:^:/: | grep -v "/tn/tn" | grep -v "/zn/zn" >> $htmnew_lists
		find fb/bookmarkusb/imgs/usbs -name "*.png" | sed -e s:^:/: | grep -v "/tn/tn" | grep -v "/zn/zn" >> $htmnew_lists
#		cat usbs.psv >> $htmnew_lists
		echo "\`;" >> $htmnew_lists

		cat ko_lists_tail.html >> $htmnew_lists

		htmbak_ko_lists="ko_lists_$dttm.html"
		echo "cp ko_lists.html $htmbak_ko_lists"
		cp ko_lists.html $htmbak_ko_lists

		echo "cp $htmnew_lists ko_lists.html"
		cp $htmnew_lists ko_lists.html


hosts="kozerus@ko0.us kotwous@ko2.us"
		for host in $hosts; do
			echo "scp -r fb/$fbid $host:~/public_html/fb/"
			scp -r fb/$fbid $host:~/public_html/fb/


			echo "scp pdf/$fbid.pdf $host:~/public_html/pdf"
			scp pdf/$fbid.pdf $host:~/public_html/pdf
			done

echo "BUGS_109 DONE fbid=$fbid"
		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "pdf2fbnew" ]; then

        if [ "$1" == "go" ] || [ "$1" == "scp" ]; then
hosts="kozerus@ko0.us kotwous@ko2.us"
		for host in $hosts;do
			echo "scp -r ko_jtf $host:~/public_html/"
			scp -r ko_jtf $host:~/public_html/
			done
		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "scp" ]; then

        if [ "$1" == "go" ] || [ "$1" == "downsize" ]; then
# ids=`find fb/pages/zn/zn_*.jpg | awk -F"/" '{ print $4 }' | sed -e s:.jpg::`
ids=`find fb/pages/zn/zn_*.jpg | awk -F"_" '{ print $2 }' | sed -e s:.jpg::`

echo "BUGS_101 ids=$ids"
                for id in $ids; do
                        let j=j+1
                        echo "j=$j id=$id"
                        echo "convert fb/pages/zn/zn_$id.jpg -resize 550x fb/pages/$id.jpg"
                       convert fb/pages/zn/zn_$id.jpg -resize 550x fb/pages/$id.jpg

                        echo "convert fb/pages/zn/zn_$id.jpg -resize 200x fb/pages/tn/tn_$id.png"
                       convert fb/pages/zn/zn_$id.jpg -resize 200x fb/pages/tn/tn_$id.png
                        done
                exit
                fi # if [ "$1" == "go" ] || [ "$1" == "downsize" ]; then

        if [ "$1" == "go" ] || [ "$1" == "htm2new" ]; then
		htmnew_index="index_new.html"
		echo "" > $htmnew_index
		echo "cat index_head.html >> $htmnew_index"
		cat index_head.html >> $htmnew_index

		echo "jklists['pagelist_pages'] = \`" >> $htmnew_index
		
		find pages -name "*.jpg" >> $htmnew_index
#		find pages -name "*.jpg" >> $htmnew_index
#		find pages -type f -maxdepth 1 -name "*.jpg" >> $htmnew_index`
#		pages=`find pages/*.jpg -type f -maxdepth 1 -name "*.jpg" >> $htmnew_index`
#		echo $pages >> $htmnew_index
		echo "/imgs/btn/koeyeb.png.gif" >> $htmnew_index
		find imgs -name "*.jpg" | sed -e s:^:/: >> $htmnew_index

		echo "\`;" >> $htmnew_index

		echo "jklists['pagelist_imgs'] = \`" >> $htmnew_index
		echo "/imgs/btn/koeyew.png" >> $htmnew_index
		find imgs -name "*.jpg" | sed -e s:^:/: >> $htmnew_index
		echo "\`;" >> $htmnew_index

		echo "cat index_tail.html >> $htmnew_index"
		cat index_tail.html >> $htmnew_index

#		echo "vi $htmnew_index"
#		vi $htmnew_index

		finds="find_files.txt"
		echo "" > $finds
		echo "find imgs -name \"*.jpg\" | sed -e s:^:/: >> $finds"
		find imgs -name "*.jpg" | sed -e s:^:/: >> $finds
		echo "find pages -name \"*.jpg\" | sed -e s::: >> $finds"
		find pages -name "*.jpg" | sed -e s::: >> $finds

		echo "python ka.py go $finds lists"
		python ka.py go $finds lists

db3="ka.db3";
tbl="lists";
		echo "sqlite3 $db3 \".import $finds lists\""
#		sqlite3 $db3 \".import $finds $tbl\""

		echo "sqlite3 $db3 \"insert into books as select * from lists where pathfile like '%/imgs/books/$'\""
#		sqlite3 $db3 "insert into books as select * from lists where pathfile like '%/imgs/books/$'"

		echo "sqlite3 $db3 \"insert into marks as select * from lists where pathfile like '%/imgs/marks/$'\""
#		sqlite3 $db3 "insert into marks as select * from lists where pathfile like '%/imgs/marks/$'"

		echo "sqlite3 $db3 \"insert into usbs as select * from lists where pathfile like '%/imgs/usbs/$'\""
#		sqlite3 $db3 "insert into usbs as select * from lists where pathfile like '%/imgs/usbs/$'"

		echo "sqlite3 $db3 < books.sql > books.psv"
		sqlite3 $db3 < books.sql > books.psv
		echo "sqlite3 $db3 < marks.sql > marks.psv"
		sqlite3 $db3 < marks.sql > marks.psv
		echo "sqlite3 $db3 < usbs.sql > usbs.psv"
		sqlite3 $db3 < usbs.sql > usbs.psv

		htmnew_lists="ko_lists_new.html";
		echo "" > $htmnew_lists
		cat ko_lists_head.html >> $htmnew_lists
		echo "books = \`" >> $htmnew_lists
		find fb/bookmarkusb/imgs/books -name "*.jpg" | sed -e s:^:/: | grep -v "/tn/tn" | grep -v "/zn/zn" >> $htmnew_lists
		find fb/bookmarkusb/imgs/books -name "*.png" | sed -e s:^:/: | grep -v "/tn/tn" | grep -v "/zn/zn" >> $htmnew_lists
#		cat books.psv >> $htmnew_lists
		echo "\`;" >> $htmnew_lists
		echo "marks = \`" >> $htmnew_lists
		find fb/bookmarkusb/imgs/marks -name "*.jpg" | sed -e s:^:/: | grep -v "/tn/tn" | grep -v "/zn/zn" >> $htmnew_lists
		find fb/bookmarkusb/imgs/marks -name "*.png" | sed -e s:^:/: | grep -v "/tn/tn" | grep -v "/zn/zn" >> $htmnew_lists
#		cat marks.psv >> $htmnew_lists
		echo "\`;" >> $htmnew_lists
		echo "usbs = \`" >> $htmnew_lists
		find fb/bookmarkusb/imgs/usbs -name "*.jpg" | sed -e s:^:/: | grep -v "/tn/tn" | grep -v "/zn/zn" >> $htmnew_lists
		find fb/bookmarkusb/imgs/usbs -name "*.png" | sed -e s:^:/: | grep -v "/tn/tn" | grep -v "/zn/zn" >> $htmnew_lists
#		cat usbs.psv >> $htmnew_lists
		echo "\`;" >> $htmnew_lists

		cat ko_lists_tail.html >> $htmnew_lists






		echo "vi $htmnew_lists +2760"
		vi $htmnew_lists +2760
		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "htm2new" ]; then

        if [ "$1" == "goo" ] || [ "$1" == "imgswap" ]; then
		fbdir="fb/mars"
		ids1="61 63"
		ids1="61 63 47 5 57 58 59 60 63 16 7 8 15 16 23 24 18 57 50"
		id2="4"
		j=0; 
		for id1 in $ids1; do
			let j=j+1
			dttm=`date +"%Y%m%d_%H%M%S"`
			img1="$fbdir/pages/$id1.jpg"
			tn1="$fbdir/pages/tn/tn_$id1.png"
			zn1="$fbdir/pages/zn/zn_$id1.jpg"
			img2="$fbdir/pages/$id2.jpg"
			tn2="$fbdir/pages/tn/tn_$id2.png"
			zn2="$fbdir/pages/zn/zn_$id2.jpg"
			zn2bak="$fbdir/pages/zn/zn_"$id2"_$dttm.jpg"

			echo " "
			echo "===================================="
			echo "$progid $dttm  $id1,$id2 img1=$img1 img2=$img2 zn2bak=$zn2bak"
echo "BUGS_101 jjjjjjjjjjjjjjjjjjjjjjjjjj"
			echo "cp $zn2 $zn2bak"
			cp $zn2 $zn2bak
			echo "cp $zn1 $zn2"
			cp $zn1 $zn2
echo "BUGS_102 kkkkkkkkkkkkkkkkkkkkk"

			echo "convert $zn2 -resize 550x $img2"
			convert $zn2 -resize 550x $img2
			echo "convert $zn2 -resize 200x $tn2"
			convert $zn2 -resize 200x $tn2

			echo "cp $zn2bak $zn1"
			cp $zn2bak $zn1
			echo "convert $zn1 -resize 550x $img1"
			convert $zn1 -resize 550x $img1
			echo "convert $zn1 -resize 200 $tn1"
#			convert $zn1 -resize 200 $tn1


			let id2=id2+1;
			done
		exit
		fi # if [ "$1" == "goo" ] || [ "$1" == "imgswap" ]; then

        if [ "$1" == "go" ] || [ "$1" == "jtf2hosts" ]; then
hosts="kozerus@ko0.us kotwous@ko2.us"
hosts=""
skips="28 29 30 31 32 38 39"
ids="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 33 34 35 36 37 40 41 42 43 44 45 46 47 48 49 50"
ids="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 33 34 35 36 37 40 41 42 43 44 45 46 47 48 49 50"
ids="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 33 34 35 36 37 40 41 42 43 44 45 46 47 48 49 50"
# rmids="45 46 47 48 49 50"
#		ids=$rmids

ids="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 33 34 35 36 37 38 39 40 41 42 43 44"
		j=0;
		for id in $ids; do
			let j=j+1
			jtfid="jtf$id"
			if [ "$jtf$id" == "" ]; then continue; fi
			echo "$j $id jtfid=$jtfid "
			fbdir="fb/jtfinc"

			if [ "$id" == "28" ]; then continue; fi
			if [ "$id" == "29" ]; then continue; fi
			if [ "$id" == "30" ]; then continue; fi
			if [ "$id" == "31" ]; then continue; fi
			if [ "$id" == "32" ]; then continue; fi
			if [ "$id" == "38" ]; then continue; fi
			if [ "$id" == "39" ]; then continue; fi
			echo "BUGS id=$id jtfid=$jtfid fbdir=$fbdir j=$j"	

##			echo "rm -r $fbdir/$jtfid"
##			#rm -r $fbdir/$jtfid
hosts="kotwous@ko2.us"
hosts="kozerus@ko0.us"
			fbid=$jtfid
			for host in $hosts; do
				dttm=`date +"%Y%m%d_%H%M%S"`
				echo "$progid $dttm j=$j scp -r $fbdir/$fbid $host:~/public_html/$fbdir/" >> $logfil
				echo "$progid $dttm j=$j scp -r $fbdir/$fbid $host:~/public_html/$fbdir/"
				scp -r $fbdir/$fbid $host:~/public_html/$fbdir/

#				echo "scp pdf/$fbid.pdf $host:~/public_html/pdf/"
#				scp pdf/$fbid.pdf $host:~/public_html/pdf/
				

				done
			done
		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "jtf2hosts" ]; then

        if [ "$1" == "go" ] || [ "$1" == "img2pad" ]; then
zpids="
1|https://www.zillow.com/homedetails/1-Jamestown-Farm-Dr-Florissant-MO-63034/2584775_zpid|ko.png|jtf36_2584775
2|https://www.zillow.com/homedetails/1-Jamestown-Farm-Dr-Florissant-MO-63034/2584775_zpid|ko.png|jtf36_2584775
3|https://www.zillow.com/homedetails/1-Jamestown-Farm-Dr-Florissant-MO-63034/2584775_zpid|ko.png|jtf36_2584775
4|https://www.zillow.com/homedetails/1-Jamestown-Farm-Dr-Florissant-MO-63034/2584775_zpid|ko.png|jtf36_2584775
5|https://www.zillow.com/homedetails/1-Jamestown-Farm-Dr-Florissant-MO-63034/2584775_zpid|ko.png|jtf36_2584775
6|https://www.zillow.com/homedetails/6-Jamestown-Farm-Dr-Florissant-MO-63034/2584780_zpid|ko.png|jtf06_2584780
7|https://www.zillow.com/homedetails/6-Jamestown-Farm-Dr-Florissant-MO-63034/2584780_zpid|ko.png|jtf06_2584780
8|https://www.zillow.com/homedetails/6-Jamestown-Farm-Dr-Florissant-MO-63034/2584780_zpid|ko.png|jtf06_2584780
9|https://www.zillow.com/homedetails/9-Jamestown-Farm-Dr-Florissant-MO-63034/2584743_zpid|ko.pngjtf09_2584743
10|https://www.zillow.com/homedetails/10-Jamestown-Farm-Dr-Florissant-MO-63034/2584767_zpid|/fb/zpid/imgs/zpid_2584767.jpg|jtf10_2584767
11|https://www.zillow.com/homedetails/11-Jamestown-Farm-Dr-Florissant-MO-63034/2584768_zpid|ko.png|jtf11_2584768
12|https://www.zillow.com/homedetails/12-Jamestown-Farm-Dr-Florissant-MO-63034/2584769_zpid|ko.png|jtf12_2584769
13|https://www.zillow.com/homedetails/13-Jamestown-Farm-Dr-Florissant-MO-63034/2584770_zpid|ko.png|jtf13_2584770
14|https://www.zillow.com/homedetails/14-Jamestown-Farm-Dr-Florissant-MO-63034/2584771_zpid|ko.png|jtf14_2584771
15|https://www.zillow.com/homedetails/15-Jamestown-Farm-Dr-Florissant-MO-63034/2584788_zpid|ko.png|jtf15_2584788
16|https://www.zillow.com/homedetails/16-Jamestown-Farm-Dr-Florissant-MO-63034/2584788_zpid|ko.png|jtf16_2584788
17|https://www.zillow.com/homedetails/17-Jamestown-Farm-Dr-Florissant-MO-63034/2584809_zpid|ko.png|jtf17_2584809
18|https://www.zillow.com/homedetails/18-Jamestown-Farm-Dr-Florissant-MO-63034/2584786_zpid|ko.png|jtf18_2584786
19|https://www.zillow.com/homedetails/19-Jamestown-Farm-Dr-Florissant-MO-63034/2584765_zpid|ko.png|jtf19_2584765
20|https://www.zillow.com/homedetails/20-Jamestown-Farm-Dr-Florissant-MO-63034/2584785_zpid|ko.png|jtf20_2584785
21|https://www.zillow.com/homedetails/21-Jamestown-Farm-Dr-Florissant-MO-63034/2584784_zpid|ko.png|jtf21_2584784
22|https://www.zillow.com/homedetails/22-Jamestown-Farm-Dr-Florissant-MO-63034/2584781_zpid|/fb/zpid/imgs/zpid_2584781.jpg|jtf22_2584781
23|https://www.zillow.com/homedetails/23-Jamestown-Farm-Dr-Florissant-MO-63034/2584782_zpid|ko.png|jtf23_2584782
24|https://www.zillow.com/homedetails/23-Jamestown-Farm-Dr-Florissant-MO-63034/2584782_zpid|ko.png|jtf23_2584782
25|https://www.zillow.com/homedetails/23-Jamestown-Farm-Dr-Florissant-MO-63034/2584782_zpid|ko.png|jtf23_2584782
26|https://www.zillow.com/homedetails/23-Jamestown-Farm-Dr-Florissant-MO-63034/2584782_zpid|ko.png|jtf23_2584782
27|https://www.zillow.com/homedetails/23-Jamestown-Farm-Dr-Florissant-MO-63034/2584782_zpid|ko.png|jtf23_2584782
28|https://www.zillow.com/homedetails/23-Jamestown-Farm-Dr-Florissant-MO-63034/2584782_zpid|ko.png|jtf23_2584782
29|https://www.zillow.com/homedetails/23-Jamestown-Farm-Dr-Florissant-MO-63034/2584782_zpid|ko.png|jtf23_2584782
30|https://www.zillow.com/homedetails/32-Jamestown-Farm-Dr-Florissant-MO-63034/2584316_zpid|/fb/zpid/imgs/zpid_2584316.jpg|jtf32_2584316 
31|https://www.zillow.com/homedetails/32-Jamestown-Farm-Dr-Florissant-MO-63034/2584316_zpid|/fb/zpid/imgs/zpid_2584316.jpg|jtf32_2584316 
32|https://www.zillow.com/homedetails/32-Jamestown-Farm-Dr-Florissant-MO-63034/2584316_zpid|/fb/zpid/imgs/zpid_2584316.jpg|jtf32_2584316 
33|https://www.zillow.com/homedetails/33-Jamestown-Farm-Dr-Florissant-MO-63034/2584317_zpid|ko.png|jtf33_2584317
34|https://www.zillow.com/homedetails/34-Jamestown-Farm-Dr-Florissant-MO-63034/2584323_zpid|ko.png|jtf34_2584323
35|https://www.zillow.com/homedetails/34-Jamestown-Farm-Dr-Florissant-MO-63034/2584323_zpid|ko.png|jtf34_2584323
36|https://www.zillow.com/homedetails/36-Jamestown-Farm-Dr-Florissant-MO-63034/2584325_zpid|ko.png|jtf36_2584325
37|https://www.zillow.com/homedetails/38-Jamestown-Farm-Dr-Florissant-MO-63034/2584806_zpid|/fb/zpid/imgs/zpid_2584806.jpg|jtf38_2584806
38|https://www.zillow.com/homedetails/38-Jamestown-Farm-Dr-Florissant-MO-63034/2584806_zpid|/fb/zpid/imgs/zpid_2584806.jpg|jtf38_2584806
39|https://www.zillow.com/homedetails/39-Jamestown-Farm-Dr-Florissant-MO-63034/2584808_zpid|/fb/zpid/imgs/zpid_2584808.jpg
40|https://www.zillow.com/homedetails/40-Jamestown-Farm-Dr-Florissant-MO-63034/2584810_zpid|ko.png|jtf40_2584810
41|https://www.zillow.com/homedetails/41-Jamestown-Farm-Dr-Florissant-MO-63034/2584789_zpid|ko.png|jtf41_2584789
42|https://www.zillow.com/homedetails/42-Jamestown-Farm-Dr-Florissant-MO-63034/2584790_zpid|ko.png|jtf42_2584790
43|https://www.zillow.com/homedetails/43-Jamestown-Farm-Dr-Florissant-MO-63034/2584791_zpid|ko.png|jtf43_2584791
44|https://www.zillow.com/homedetails/44-Jamestown-Farm-Dr-Florissant-MO-63034/2584794_zpid|ko.png|jtf36_2584794
45|https://www.zillow.com/homedetails/17570-Old-Jamestown-Rd-Florissant-MO-63034/2584793_zpid|ko.png|jtf36_2584793
46|https://www.zillow.com/homedetails/47-Jamestown-Farm-Dr-Florissant-MO-63034/2584776_zpid|ko.png|jtf36_2584776
47|https://www.zillow.com/homedetails/17620-Old-Jamestown-Rd-Florissant-MO-63034/2584707_zpid|ko.png|jtf36_2584707
48|https://www.zillow.com/homedetails/17630-Old-Jamestown-Rd-Florissant-MO-63034/2584706_zpid|ko.png|jtf36_2584706
49|https://www.zillow.com/homedetails/17630-Old-Jamestown-Rd-Florissant-MO-63034/2584706_zpid|ko.png|jtf36_2584706
50|https://www.zillow.com/homedetails/17630-Old-Jamestown-Rd-Florissant-MO-63034/2584706_zpid|ko.png|jtf36_2584706
";

		j=0; k=0;
		fimg="fb/zpid/imgs/zpid_0.jpg";
		for zpidline in $zpids; do
			if [ "$zpidline" == "" ]; then continue; fi
			let j=j+1
			zpid=`echo $zpidline | awk -F"|" '{ print $1 }'`
			url=`echo $zpidline | awk -F"|" '{ print $2 }'`
			tn=`echo $zpidline | awk -F"|" '{ print $3 }'`
			img=`echo $zpidline | awk -F"|" '{ print $4 }'`
#			echo "$progid $dttm j=$j zpid=$zpid url=$url tn=$tn img=$img"

			if [ "$zpid" == "28" ]; then echo "SKIP28"; continue; fi
			if [ "$zpid" == "29" ]; then echo "SKIP29"; continue; fi
			if [ "$zpid" == "30" ]; then echo "SKIP30"; continue; fi
			if [ "$zpid" == "31" ]; then echo "SKIP31"; continue; fi
			if [ "$zpid" == "32" ]; then echo "SKIP32"; continue; fi
			if [ "$zpid" == "38" ]; then echo "SKIP38"; continue; fi
			if [ "$zpid" == "39" ]; then echo "SKIP39"; continue; fi

#			timg="fb/zpid/imgs/zpid_"+id+".jpg";
			timg="fb/zpid/imgs/$img.jpg"
			if [ ! -f $timg ]; then
				echo "cp NOTFOUND $fimg $timg # $j $zpid"
				cp $fimg $timg
			else
				echo "FOUND $timg # $j $zpid"
				fi
			

			done
		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "img2pad" ]; then

        if [ "$1" == "scp" ] || [ "$1" == "scp" ]; then
hosts="kozerus@ko0.us kotwous@ko2.us"
		cp ko_lists_jtfinc.html fb/jtfdcr/ko_lists.html
		cp ko_lists_jtfinc.html fb/jtfdc/ko_lists.html
		cp ko_lists_jtfinc.html fb/jtfinc/ko_lists.html
		for host in $hosts; do
			echo "scp ko_lists_jtfinc.htm* $host:~/public_html/"
			scp ko_lists_jtfinc.htm* $host:~/public_html/

			echo "scp fb/jtfdc/ko_lists.htm* $host:~/public_html/fb/jtfdc/"
			scp fb/jtfdc/ko_lists.htm* $host:~/public_html/fb/jtfdc/

			echo "scp fb/jtfdcr/ko_lists.htm* $host:~/public_html/fb/jtfdcr/"
			scp fb/jtfdcr/ko_lists.htm* $host:~/public_html/fb/jtfdcr/
	
			echo "scp fb/jtfinc/ko_lists.htm* $host:~/public_html/fb/jtfinc/"
			scp fb/jtfinc/ko_lists.htm* $host:~/public_html/fb/jtfinc/
			done

		exit
		fi # if [ "$1" == "scp" ] || [ "$1" == "scp" ]; then

        if [ "$1" == "scp1" ] || [ "$1" == "scp1" ]; then
hosts="kozerus@ko0.us kotwous@ko2.us"
ids="28 29 30 31 32 38 39"
ids="28"
ids="29 30 31 32 38 39"
		for host in $hosts; do
			for id in $ids; do
				fbid="jtf$id"
				fbdir="fb/jtfinc"
				if [ "$id" == "28" ]; then fbdir="fb/jtfdc"; fi
				if [ "$id" == "29" ]; then fbdir="fb/jtfdc"; fi
				if [ "$id" == "30" ]; then fbdir="fb/jtfdc"; fi
				echo "scp -r $fbdir/$fbid $host:~/public_html/$fbdir"
#				scp -r $fbdir/$fbid $host:~/public_html/$fbdir
				done
			done
		exit
		fi # if [ "$1" == "scp1" ] || [ "$1" == "scp1" ]; then

        if [ "$1" == "go" ] || [ "$1" == "jtfid" ]; then
ids="28"
ids="29"
ids="28 29 30 31 32 38 39"
ids="1 2 3 4 5 6 7 8 9 10"
ids="1"
ids="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 33 34 35 36 37 40 41 42 43 44 45 46 47 48 49 50"

		for id in $ids; do
			jtfid="jtf$id"
			echo "$j $id jtfid=$jtfid "
			fbdir="fb/jtfinc"
			if [ $id == "28" ]; then fbdir="fb/jtfdc"; fi
			if [ $id == "29" ]; then fbdir="fb/jtfdc"; fi
			if [ $id == "30" ]; then fbdir="fb/jtfdc"; fi
			
			echo "mkdir $fbdir/$jtfid";
			mkdir $fbdir/$jtfid
			echo "mkdir $fbdir/$jtfid/imgs/"
			mkdir $fbdir/$jtfid/imgs/
			echo "mkdir $fbdir/$jtfid/pdf/"
			mkdir $fbdir/$jtfid/pdf/
			echo "mkdir $fbdir/$jtfid/cdr/"
			mkdir $fbdir/$jtfid/cdr/
			echo "mkdir $fbdir/$jtfid/pages/"
			mkdir $fbdir/$jtfid/pages/
			echo "mkdir $fbdir/$jtfid/pages/tn"
			mkdir $fbdir/$jtfid/pages/tn
			echo "mkdir $fbdir/$jtfid/pages/zn"
			mkdir $fbdir/$jtfid/pages/zn

			echo "cp index.htm* $fbdir/$jtfid/"
			cp index.htm* $fbdir/$jtfid/
			echo "cp ko_lists.htm* $fbdir/$jtfid/"
			cp ko_lists.htm* $fbdir/$jtfid/
			echo "cp ko_toggle.htm* $fbdir/$jtfid/"
			cp ko_toggle.htm* $fbdir/$jtfid/

			echo "cp cdr/$jtfid.pdf pdf/"
			cp cdr/$jtfid.pdf pdf/
			if [ -f pdf/$jtfid.pdf ]; then
				echo "convert pdf/$jtfid.pdf -resize 550x $fbdir/$jtfid/pages/%01d.jpg"
				convert pdf/$jtfid.pdf -resize 550x $fbdir/$jtfid/pages/%01d.jpg
				echo "convert pdf/$jtfid.pdf -resize 200x $fbdir/$jtfid/pages/tn/tn_%01d.png"
				convert pdf/$jtfid.pdf -resize 200x $fbdir/$jtfid/pages/tn/tn_%01d.png
				echo "convert pdf/$jtfid.pdf -resize 1100x $fbdir/$jtfid/pages/zn/zn_%01d.jpg"
				convert pdf/$jtfid.pdf -resize 1100x $fbdir/$jtfid/pages/zn/zn_%01d.jpg
			else
				echo "$progid $dttm NOTFOUND pdf/$jtfid.pdf"
				fi

			echo "cp pdf/$jtfid.pdf $fbdir/$jtfid/"
			cp pdf/$jtfid.pdf $fbdir/$jtfid/

hosts="kozerus@ko0.us kotwous@ko2.us"
hosts=""
			for host in $hosts; do
				echo "scp -r $fbdir/$fbid $host:~/public_html/$fbdir/"
#				scp -r $fbdir/$fbid $host:~/public_html/$fbdir/

				echo "scp pdf/$fbid.pdf $host:~/public_html/pdf/"
#				scp pdf/$fbid.pdf $host:~/public_html/pdf/
				

				done

			done
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "jtfid" ]; then

        if [ "$1" == "go" ] || [ "$1" == "scp" ]; then
hosts="kozerus@ko0.us kotwous@ko2.us"
		for host in $hosts; do
			echo "scp fb/index.htm* $host:~/public_html/fb/"
			scp fb/index.htm* $host:~/public_html/fb/
			echo "scp fb/fb.pdf $host:~/public_html/fb/"
			scp fb/fb.pdf $host:~/public_html/fb/
			echo "scp fb/pages/*.jpg $host:~/public_html/fb/pages/"
			scp fb/pages/*.jpg $host:~/public_html/fb/pages/
			echo "scp fb/pages/tn/tn_*.png $host:~/public_html/fb/pages/tn/"
			scp fb/pages/tn/tn_*.png $host:~/public_html/fb/pages/tn/
			echo "scp fb/pages/zn/zn_*.jpg $host:~/public_html/fb/pages/zn/"
			scp fb/pages/zn/zn_*.jpg $host:~/public_html/fb/pages/zn/
			done
		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "scp" ]; then

        if [ "$1" == "go" ] || [ "$1" == "imgs2pages" ]; then
findpath="../i"
findname="fb*.jpg"
imgs=`find $findpath -maxdepth 1 -name "$findname" -exec basename {} \;`
		j=0; k=0;
		for img in $imgs; do
			let j=j+1
			timg="fb/pages/$j.jpg"
			tn="fb/pages/tn/tn_$j.png"
			zn="fb/pages/zn/zn_$j.jpg"
			echo "cp $findpath/$img $timg"
			cp $findpath/$img $timg
			echo "convert $timg -resize 200x $tn"
			convert $timg -resize 200x $tn
			echo "convert $timg -resize 1100x $zn"
			convert $timg -resize 1100x $zn
			done
		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "imgs2pages" ]; then

        if [ "$1" == "go" ] || [ "$1" == "fbs" ]; then
		findname="1.jpg";
		findpath="fb";
		echo "$progid $dttm findpath=$findpath findname=$findname"
# fbs=`find $findpath -maxdepth 3 -name "$findname" -exec ls {} \;  | grep "pages/" | sed -e s:^:/:`;
fbs=`find $findpath -maxdepth 3 -name "$findname" -exec ls {} \;  | grep "pages/"`;

# | grep "pages" | grep -v "imgs" | grep -v "shoebox" \;`
out=""; k=0;
skips="6 9 10 11 12 20 25 27 28 32 33 34 46 46 56 57 58 71 85 101 102 103 113 127"
		for fb in $fbs; do
			if [ "$j" == "10" ]; then continue; fi
			if [ "$j" == "11" ]; then continue; fi
			if [ "$j" == "12" ]; then continue; fi
			if [ "$j" == "20" ]; then continue; fi
			if [ "$j" == "25" ]; then continue; fi
			if [ "$j" == "28" ]; then continue; fi
			if [ "$j" == "32" ]; then continue; fi
			if [ "$j" == "34" ]; then continue; fi
			if [ "$j" == "46" ]; then continue; fi
			if [ "$j" == "56" ]; then continue; fi
			if [ "$j" == "58" ]; then continue; fi
			if [ "$j" == "71" ]; then continue; fi
			if [ "$j" == "85" ]; then continue; fi
			if [ "$j" == "101" ]; then continue; fi
			if [ "$j" == "102" ]; then continue; fi
			if [ "$j" == "103" ]; then continue; fi
			if [ "$j" == "113" ]; then continue; fi
			if [ "$j" == "127" ]; then continue; fi
			let j=j+1; 
			timg="fb/pages/$j.jpg"
			tn="fb/pages/tn/tn_$j.png"
			zn="fb/pages/zn/zn_$j.jpg"
			echo "$progid $dttm fbs j=$j fb=$fb"
			echo "$progid $dttm fbs j=$j fb=$fb"

			echo "cp $fb $timg"
#			cp $fb $timg

			echo "convert $timg -resize 200x $tn"
#			convert $timg -resize 200x $tn

			echo "convert $timg -resize 1100 $zn"
#			convert $timg -resize 1100 $zn
			done

		echo "$progid $dttm fbs out=$out"
		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "fbs" ]; then

        if [ "$1" == "goo" ] || [ "$1" == "reorder" ]; then
		imgpath="../../../i"
		imgnames="mars*.jpg"
#		imgnames="mars01.jpg"
imgs=`find $imgpath -maxdepth 1 -name "$imgnames" -exec basename {} \;`
		j=0; k=0;
		fbeg=1; fend=48; tbeg=65;
		j=$fbeg; k=$tbeg;
		echo "$progid $dttm reorder imgpath=$imgpath imgnames=$imgnames fbeg=$fbeg fend=$fend tbeg=$tbeg ";
		for img in $imgs; do
			fimg="pages/$j.jpg";
			timg="pages/$k.jpg";
			tn="pages/tn/tn_$j.png";
			zn="pages/zn/zn_$j.jpg";
			saveimg="pages/$k""_$dttm.jpg";
			newimg="$imgpath/$img"
			if [ -f $timg ]; then
				echo "cp $fimg $saveimg"
				cp $fimg $saveimg
				fi
			echo "cp $fimg $timg"
			cp $fimg $timg

			echo "cp $imgpath/$img $fimg"
			cp $imgpath/$img $fimg
			echo "convert $fimg -resize 200x $tn"
			convert $fimg -resize 200x $tn
			echo "convert $fimg -resize 1100 $zn"
			convert $fimg -resize 1100 $zn

			let j=j+1;
			let k=k+1;
			done
		exit;
		fi # if [ "$1" == "goo" ] || [ "$1" == "reorder" ]; then

	if [ "$1" = "go" ] || [ "$1" == "divs" ]; then
		echo "$progid $dttm divs"
divs=`cat indexmin.html | awk '/<div id=/ && length($0) < 1000   { print NR" "$0 }' ` 
divs=`cat divss.txt`
#		echo "$progid $dttm divs=$divs"
		j=0
		echo "" > divs.txt
		for div in $divs; do
			let j=j+1
#			div=`echo "$divtext" | awk -F"=" '{ print $2 }' | sed -e s/\"//g | sed -e s/>//`
#			div=`echo $divtext | sed -e s/\"//g | sed -e s/>// | awk -F"=" '{ print $2 }'`
#			echo "BUGS_4970 j=$j divtext=$divtext"
			echo "<div id=$div >" >> divs.txt
			echo "	<h1>$div</h1>" >> divs.txt
			echo "	</div>" >> divs.txt
			done

		vi divs.txt
		exit
		fi # if [ "$1" = "go" ] || [ "$1" == "divs" ]; then

	if [ "$1" = "go" ] || [ "$1" == "lists" ]; then
		echo "$progid $dttm lists"
lists=`cat indexmin.html | awk '/^jklists\[/ && length($0) < 1000   { print NR" "$0 }' | awk -F"'" '{ print $2 }' `
		echo "$progid $dttm lists=$lists"
		j=0
		echo "" > lists.txt
		for list in $lists; do
			let j=j+1
			echo "jklists['"$list"'] = \`" >> lists.txt
			echo "ko.png" >> lists.txt
			echo $list"_1" >> lists.txt
			echo $list"_2" >> lists.txt
			echo $list"_3" >> lists.txt
			echo "ok.png" >> lists.txt
			echo "\`;" >> lists.txt
			echo "" >> lists.txt

			done

		vi lists.txt
		exit
		fi # if [ "$1" = "go" ] || [ "$1" == "lists" ]; then

	if [ "$1" = "goo" ] || [ "$1" == "pagespad" ]; then
		echo "$progid $dttm pagespad $2"
		exit;
		j=0; k=0; padlim=64;
		for id in $ids; do
			let j=j+1;
			tpath="fb/$id"
			findpath=$tpath"/pages"
			findfile=$tpath"/find_"$id"_pages.txt"
			pagefile0="./fb/$id/pages/0.jpg"
			tnpath="./fb/$id/pages/tn/"
			znpath="./fb/$id/pages/zn/"
			if [ ! -d $tnpath ]; then mkdir $tnpath; fi
			if [ ! -d $znpath ]; then mkdir $znpath; fi
			for j in {1..64}; do
				pagefile="./fb/$id/pages/$j.jpg"
				tnfile="./fb/$id/pages/tn/tn_$j.png"
				znfile="./fb/$id/pages/zn/zn_$j.jpg"
				echo "BUGS_32 pagefile=$pagefile";
				if [ ! -f $pagefile ]; then
					if [ ! -f $pagefile0 ]; then 
						echo "BUGS_39 NOTFOUND pagelist0=$pagefile0"
						exit;
						fi
					echo "BUGS_33 NOTFOUND cp $pagefile0 $pagefile"
					cp $pagefile0 $pagefile
#				else
#					echo "BUGS_34 FOUND $pagefile"
					fi

				if [ ! -f $tnfile ]; then
					echo "$progid $dttm convert $pagefile -resize 200 $tnfile"
					convert $pagefile -resize 200 $tnfile
					fi
				if [ ! -f $znfile ]; then
					echo "$progid $dttm BUGS_52 convert $pagefile -resize 1100 $znfile"
					convert $pagefile -resize 1100 $znfile
					fi
				done
			echo "BUGS_60 pagespad id=$id findpath=$findpath findfile=$findfile"
			done
		exit;
		fi # if [ "$1" = "goo" ] || [ "$1" == "pagespad" ]; then

	if [ "$1" = "go" ] || [ "$1" == "tn" ]; then
		echo "$progid $dttm tn $2"
		j=0; k=0;


ids="konet iperms jtfdc jtfdcr jtfinc law med kids kou"
ids="bookusb"
	
	echo "BUGS_70 ids=$ids"
	for id in $ids; do
		echo "BUGS_71 id=$id"
		fpath="fb/"$id"/imgs"


		imgs=`find $fpath -name "*.jpg"`
		echo "BUGS_72 imgs=$imgs"

#		echo "q|enter"
#		read usrcmd
#		echo "BUGS_80 usrcmd=$usrcmd"
#		if [ "$usrcmd" == "q" ]; then exit; fi
#		if [ "$usrcmd" == "" ]; then continue; fi

# imgs=`find $fpath -name "*.jpg"`
# imgs=`ls fb/konet/imgs`


#		echo "BUGS_70 TN imgs=$imgs"
		tnpath="$fpath/tn"
		if [ ! -d $tnpath ]; then
			echo "BUGS_71 MKDIR_TN mkdir $tnpath "
			mkdir $tnpath
			fi
		znpath="$fpath/zn"
		if [ ! -d $znpath ]; then
			echo "BUGS_72 MKDIR_ZN mkdir $znpath "
			mkdir $znpath
			fi

		for img in $imgs; do
			let j=j+1;
			path=`dirname $img`
			basename=`basename $img`
			filename=`echo $basename | awk -F"." '{ print $1}'`;
			ext=`echo $basename | awk -F"." '{ print $2}'`;
			tnfile="$tnpath/tn_$filename.png"
			znfile="$znpath/zn_$filename.jpg"
			echo "BUGS_91 j=$j img=$img path=$path filename=$filename ext=$ext"
			echo "BUGS_92 tnfile=$tnfile znfile=$znfile"

			if [ ! -f $tnfile ]; then
				echo "convert $img -resize 200 $tnfile"
				convert $img -resize 200 $tnfile
				fi
			if [ ! -f $znfile ]; then
				echo "convert $img -resize 1100 $znfile"
				convert $img -resize 1100 $znfile
				fi
			echo "BUGS_81 tnfile=$tnfile znfile=$znfile"
			done

		done
		exit;
		fi # if [ "$1" = "go" ] || [ "$1" == "tn" ]; then

	if [ "$1" = "goo" ] || [ "$1" == "find" ]; then
		echo "$progid $dttm go $2"
		j=0; k=0;
		for id in $ids; do
			let j=j+1;
			tpath="fb/$id"
			findpath=$tpath"/pages"
			findfile=$tpath"/find_"$id"_pages.txt"
			echo "BUGS_90 findpath=$findpath findfile=$findfile"
			find $findpath -name "*.jpg" -exec ls -lat {} \;  > $tpath"/find_"$id"_pages.txt"


			findpath=$tpath"/imgs"
			findfile=$tpath"/find_"$id"_imgs.txt"
			echo "BUGS_31 findpath=$findpath findfile=$findfile"
			find $findpath -name "*.jpg" -exec ls -lat {} \; > $tpath"/find_"$id"_imgs.txt"

			findpath=$tpath"/pdf"
			findfile=$tpath"/find_"$id"_pdf.txt"
			echo "BUGS_32 findpath=$findpath findfile=$findfile"
			find $findpath -name "*.pdf" -exec ls -lat {} \; > $tpath"/find_"$id"_pdf.txt"

			findpath=$tpath"/mp3"
			findfile=$tpath"/find_"$id"_mp3.txt"
			echo "BUGS_33 findpath=$findpath findfile=$findfile"
			find $findpath -name "*.mp3" -exec ls -lat {} \; > $tpath"/find_"$id"_mp3.txt"

			findpath=$tpath"/mp4"
			findfile=$tpath"/find_"$id"_mp4.txt"
			echo "BUGS_34 findpath=$findpath findfile=$findfile"
			find $findpath -name "*.mp4" -exec ls -lat {} > $tpath"/find_"$id"_mp4.txt"

			cat $tpath"/find_"$id"_pages.txt" > $tpath"/find_"$id".txt"
			cat $tpath"/find_"$id"_imgs.txt" >> $tpath"/find_"$id".txt"
			cat $tpath"/find_"$id"_pdf.txt" >> $tpath"/find_"$id".txt"
			cat $tpath"/find_"$id"_mp3.txt" >> $tpath"/find_"$id".txt"
			cat $tpath"/find_"$id"_mp4.txt" >> $tpath"/find_"$id".txt"

			wc -l $tpath"/find_"$id"_"*".txt"
#			head $tpath"/find_"$id"_"*".txt"

			ka_pyfile="./ka1.py"
			echo "python ./fb/$id/$id.py go "$tpath"/find_"$id".txt"
			pyfile="./fb/$id/$id.py"
			wlfile=$tpath"/find_"$id".txt"


#			cat $ka_pyfile | sed -e s/$konet/$id/g > $pyfile
			cp $ka_pyfile $pyfile
			python $pyfile go $wlfile $id



			db3="./fb/$id/$id.db3"
			tbl=$id
			find_psv=$tpath"/find_"$id".psv"
			find_json=$tpath"/find_"$id".json"
			find_sql=$tpath"/find_"$id".sql"
			psv=$tpath"/"$id".psv"
			json=$tpath"/"$id".json"
			sql=$tpath"/"$id".sql"
			mv $find_psv $psv
			mv $find_sql $sql
			mv $find_json $json

			sqlite3 $db3 "create table if not exists $tbl as select * from files"
			sqlite3 $db3 "delete from $tbl"
			sqlite3 $db3 ".import $psv $id"
			sqlite3 $db3 -header "select * from $tbl limit 5"

			done





		exit;
		fi # if [ "$1" = "goo" ] || [ "$1" == "find" ]; then

	if [ "$1" = "build" ] || [ "$1" == "build" ]; then
		echo "$progid $dttm ./$progid build id"
		echo "$prigid $dttm ids=$ids"
		exit;
		for id in $ids;do
#			echo "$progid $dttm id=$id"
#			echo "cp fb/$id/index.html fb/$id/index_$dttm.html"
#			cp fb/$id/index.html fb/$id/index_$dttm.html
#			echo "cp fb/$id/index.html fb/$id/index_$id.html"
#			cp fb/$id/index.html fb/$id/index_$id.html
#			echo "cp fb/$id/index.html fb/$id/$id.html"
#			cp fb/$id/index.html fb/$id/$id.html
			echo "cp fb/$id/index.html fb/$id/fb_$id.html"
			cp fb/$id/index.html fb/$id/fb_$id.html
			done
		exit;
		fi # if [ "$1" = "build" ] || [ "$1" == "build" ]; then

	if [ "$1" = "go1" ] || [ "$1" == "g1" ]; then



		echo "go do what?"
		exit;
btns="ko.png ok.png kb.png kw.png ki.png kob.png kow.png kib.png kiw.png koeye.png koeyew.png koeyeb.png kop1.png kop2.png kop3.png kop4.png kop12.png kop23.png kop34.png kop14.png btn.png btn_n.png btn_s.png btn_e.png btn_w.png dragon.png koeye_handhither.gif koeye_handhi.gif ";
		echo "$progid $dttm go: btns=$btns"
		echo "" > b64btn.txt
		for btn in $btns;do
			echo "btn=$btn"
			echo "// "$btn 					>> b64btn.txt
			echo $btn' = url("data:/img/png;base64,'	>> b64btn.txt
			base64 imgs/btn/$btn 				>> b64btn.txt
			echo '");' 					>> b64btn.txt
			done




		exit;
		fi # if [ "$1" = "go1" ] || [ "$1" == "g1" ]; then

	if [ "$1" = "scp" ] || [ "$1" == "scp" ]; then
		files="index.htm* ko_coffeeshop.*"
		printf "$progid $dttm scp files=$files\n";
		for file in $files; do
			printf "scp kozerus@ko0.us:~/public_html/ $file\n";
			printf "scp kotwous@ko2.us:~/public_html/ $file\n";
			printf "scp kotwous@ko2.us:~/public_html/ko1/ $file\n";
			printf "scp kotwous@ko2.us:~/public_html/konet/ $file\n";
			printf "scp kotwous@ko2.us:~/public_html/iperms/ $file\n";
			done


		exit;
		fi # if [ "$1" = "scp" ] || [ "$1" == "scp" ]; then

	if [ "$1" = "todo" ] || [ "$1" == "todo" ]; then
		host=`uname -a`;
		if [ "$2" != "" ]; then host=$2; fi
		printf "$progid $dttm todo: host=$host\n";

		exit;
		fi # if [ "$1" = "todo" ] || [ "$1" == "todo" ]; then

	if [ "$1" = "ssh" ] || [ "$1" == "ssh" ]; then
hosts="kozerus@ko0.us kotwous@ko2.us";
hosts="kozerus@ko0.us";
subhosts="ko1 konet iperms";
		printf "$progid $dttm ssh files=$files\n";
		for host in $hosts; do
			printf "ssh $host pj/ko.sh uapi email list\n";
			ssh $host pj/ko.sh uapi email list

			printf "ssh $host pj/ko.sh sql3 sel\n";
			ssh $host pj/ko.sh sql3 sel
			done


		exit;
		fi # if [ "$1" = "ssh" ] || [ "$1" == "ssh" ]; then

	if [ "$1" == "sql3" ] || [ "$1" == "db3" ]; then
db3fil="../public_html/ko.db3";
tbl="ko_coffeeshop";
psv="../public_html/ko_coffeeshop.psv";
		printf "$progid $dttm sql3 db3fil=$db3fil tbl=$tbl psv=$psv\n";
		if [ "$2" == "sel" ] || [ "$2" == "sel" ]; then
			sql="select * from $tbl";
			printf "$progid $dttm sql3 SEL sql=$sql\n";
			fi
		if [ "$2" == "up" ] || [ "$2" == "update" ]; then
			tblbak="$tbl""_$dttm";
			printf "$progid $dttm sql3 UPATE db3fil=$db3fil tbl=$tbl psv=$psv\n";
			printf "sqlite3 $db3fil 'alter $table copy from $tblbak'\n";
			printf "sqlite3 $db3fil 'delete from $tbl'\n";
			printf "sqlite3 $db3fil '.import $psv $tbl'\n";
			fi
		exit;
		fi # if [ "$1" == "sql3" ] || [ "$1" == "db3" ]; then

	if [ "$1" == "uapi" ] || [ "$1" == "uapi" ]; then
# files="index.htm ko_coffeeshop"
host="ko2.us";
emails="konet iperms ko0 ko1 ko2 ko kassil ka jkwii skwii jtfdc jtfdcr jtfinc kids koed"
ids="konet iperms ko0 ko1 ko2 ko kassil ka jkwii skwii jtfdc jtfdcr jtfinc kids koed"
smedias="fab gab li pl ss tw ts bc rm vm yt bcn shp sqr str buy";

ids="test1 test2 test3"
smedias="ss tw shp str buy"
domain="ko1.us";

		printf "$progid $dttm uapi host=$host domain=$domain\n";
		printf "$progid $dttm uapi ids=$ids\n";
		printf "$progid $dttm uapi smedias=$smedias\n";
		if [ "$2" == "email" ] || [ "$2" == "email" ]; then
			printf "$progid $dttm uapi EMAIL ids=$ids\n";
			if [ "$3" == "l" ] || [ "$3" == "list" ]; then
				printf "$progid $dttm uapi email list\n";
				printf "uapi Email list_pops\n";
				if [ "$4" == "go" ] || [ "$4" == "g" ]; then
					uapi Email list_pops
					fi
				fi




			if [ "$3" == "del" ] || [ "$3" == "delete" ]; then
				printf "$progid $dttm uapi email delete\n";
				username="kotwous";
				j=0;k=0;
				for smedia in $smedias; do
					let j=j+1; k=0;
					for id in $ids; do
						let k=k+1
						user="$id"_"$smedia";
						caps=`echo $smedia | tr 'a-z' 'A-Z'`
						pass="\$$caps=$email""01;"
						email="$user@$domain"
						printf "uapi Email add_pop $email $pass\n";
						printf "$j,$k uapi Email delete_pop email=$user domain=$domain\n";
						if [ "$4" == "go" ] || [ "$4" == "g" ]; then
							uapi Email delete_pop email=$user password=$pass domain=$domain
							fi
						done
					done
				fi
#			fi

			if [ "$3" == "cr" ] || [ "$3" == "create" ]; then
				printf "$progid $dttm uapi email create\n";
				username="kotwous";
				j=0;k=0;
				for smedia in $smedias; do
					let j=j+1; k=0;
					for id in $ids; do
						let k=k+1
						user="$id"_"$smedia";
						caps=`echo $smedia | tr 'a-z' 'A-Z'`
						pass="\$$caps=$id""01;"
						email="$user@$domain"
						printf "uapi Email add_pop $email $pass\n";
	#					printf "uapi --user=username Email add_pop email=user password=replace_me quota=0 domain=example.com skip_update_db=1\n";
	# 					printf "uapi --user=$username Email add_pop email=$user password=$replace_me quota=0 domain=$domain skip_update_db=1\n";
						printf "$j,$k uapi Email add_pop email=$user password=$pass quota=0 domain=$domain skip_update_db=1 send_welcome_email=1\n";
						if [ "$4" == "go" ] || [ "$4" == "g" ]; then
							uapi Email add_pop email=$user password=$pass quotoa=100 domain=$domain skip_update_db=1 send_welcome_email=1
							fi
						done
					done
				fi
			fi

#				printf "$j uapi=$uapi pw=$pw\n";
#				printf "uapi 
#				done
#			done
		exit;
		fi # if [ "$1" == "uapi" ] || [ "$1" == "uapi" ]; then

	if [ "$1" = "sql3" ] || [ "$1" == "sql3" ]; then
files="index.htm* ko_coffeeshop.*"
		printf "$progid $dttm sql3 files=$files\n";
		for file in $files; do
			printf "ssh kozerus@ko0.us ~/public_html/pj/ko.sh todo\n";
			printf "ssh kotwous@ko2.us ~/public_html/pj/ko.sh todo\n";
			printf "ssh kotwous@ko2.us ~/public_html/pj/ko.sh todo ko1\n";
			printf "ssh kotwous@ko2.us ~/public_html/pj/ko.sh todo konet\n";
			printf "ssh kotwous@ko2.us ~/public_html/pj/ko.sh todo iperms\n";
			printf "ssh kotwous@ko2.us ~/public_html/pj/ko.sh todo ka1\n";
			done


		exit;
		fi # if [ "$1" = "sql3" ] || [ "$1" == "sql3" ]; then

	if [ "$1" == "go" ] || [ "$1" == "pdf2pub" ]; then
		fpath="fb";
		fnames="*";
		hosts="kozerus@ko0.us kotwous@ko2.us"
		fbids=`find $fpath -maxdepth 1 -type d -name "$fnames" | awk -F"/" '{print $2}'`
		j=0;k=0;

		if [ "$2" != "" ]; then fbids=$2; fi

		for fbid in $fbids; do
			if [ "$fbid" == "zn" ]; then continue; fi
			if [ "$fbid" == "templets" ]; then continue; fi
			if [ "$fbid" == "zpid" ]; then continue; fi
			if [ "$fbid" == "zpid" ]; then continue; fi
			let j=j+1;
			echo "convert pdf/$fbid.pdf -resize 550x -depth 600 fb/$fbid/pages/%01d.jpg"
#			convert pdf/$fbid.pdf -resize 550x -depth 600 fb/$fbid/pages/%01d.jpg

			echo "convert pdf/$fbid.pdf -resize 1100x -depth 600 fb/$fbid/pages/zn/zn_%01d.jpg"
#			convert pdf/$fbid.pdf -resize 1100x -depth 600 fb/$fb/pages/zn/zn_%01d.jpg

			echo "convert pdf/$fbid.pdf -resize 200x -depth 600 fb/$fbid/pages/tn/tn_%01d.png"
#			convert pdf/$fbid.pdf -resize 200x -depth 600 fb/$fb/pages/tn/tn_%01d.png

			for host in $hosts;do
				echo "scp -r fb/$fbid/pages $host:~/public_html/fb/$fbid/"
#				scp -r fb/$fbid/pages $host:~/public_html/fb/$fbid/
				done


			done

		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "pdf2pub" ]; then

	if [ "$1" == "go" ] || [ "$1" == "pdf2jpg" ]; then
		echo "convert pdf/konet1.pdf -density 600 -resize 550x pdf/pages/%01d.jpg"
#		convert pdf/konet1.pdf -density 600 -resize 550x pdf/pages/%01d.jpg


		echo "convert pdf/konet1.pdf -density 600 -resize 1100x pdf/pages/zn/zn_%01d.jpg"
#		convert pdf/konet1.pdf -density 600 -resize 1100x pdf/pages/zn/zn_%01d.jpg

		echo "convert pdf/konet1.pdf -density 600 -resize 200x pdf/pages/tn/tn_%01d.png"
		convert pdf/konet1.pdf -density 600 -resize 200x pdf/pages/tn/tn_%01d.png
g

		ls -lat pdf/pages
		ls -lat pdf/pages/zn
		ls -lat pdf/pages/tn
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "pdf2jpg" ]; then

	if [ "$1" == "go" ] || [ "$1" == "shoeboxes" ]; then
ids=`find fb -type d -maxdepth 2 -name "shoebox"`
		echo "$progid $dttm ids=$ids"
		j=0; k=0;
		echo "BUGS_5475"
		for id in $ids; do
			echo "BUGS_101a j=$j id=$id"
			let j=j+1
			id=`echo $id | awk -F"/" '{ print $2}'`
			echo "$progid $dttm $j id=$id"
			if [ "$id" == "shoebox" ]; then continue; fi
			if [ ! -d fb/shoebox/$id ]; then
				echo "mkdir fb/shoebox/$id"
				mkdir fb/shoebox/$id
				fi
#			echo "cp fb/$id/shoebox/*.* fb/shoebox/$id/"
#			cp fb/$id/shoebox/*.* fb/shoebox/$id/

			ls -lat fb/shoebox/$id/*.* | wc -l
			echo "rm fb/$id/shoebox/*.*"
			done



		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "shoeboxes" ]; then

	if [ "$1" == "goo" ] || [ "$1" == "scp3" ]; then
hosts="kozerus@ko0.us kotwous@ko2.us"
		for host in $hosts; do
			echo "scp fb/usps/pages/*.jpg $host:~/public_html/fb/usps/pages/"
			scp fb/usps/pages/*.jpg $host:~/public_html/fb/usps/pages/
			scp fb/usps/pages/zn/zn_*.jpg $host:~/public_html/fb/usps/pages/zn/
			scp fb/usps/pages/tn/tn_*.png $host:~/public_html/fb/usps/pages/tn/
			echo "scp fb/usps/usps.pdf $host:~/public_html/fb/usps/"
			scp fb/usps/usps.pdf $host:~/public_html/fb/usps/
			scp pdf/usps.pdf $host:~/public_html/pdf/
			done

		exit
		fi # if [ "$1" == "goo" ] || [ "$1" == "scp3" ]; then

	if [ "$1" == "go" ] || [ "$1" == "imgs2pages" ]; then
pages=`find ../i -name "usps??.jpg"`
		echo "pages=$pages"
		j=0; k=0;
		for page in $pages; do
			let j=j+1;
			newimg="$page"
			zn="fb/usps/pages/zn/zn_$j.jpg"
			tn="fb/usps/pages/tn/tn_$j.png"
			img="fb/usps/pages/$j.jpg"
#			echo "convert $newimg -resize 550 $img"
#			convert $newimg -resize 550 $img
			echo "convert $newimg -resize 1100x $zn"
			convert $newimg -resize 1100x $zn
#			echo "convert $newimg -resize 200x $tn"
#			convert $newimg -resize 200x $tn


			done



		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "imgs2pages" ]; then

	if [ "$1" == "go" ] || [ "$1" == "go" ]; then
		convert ../i/usps_1.jpg -resize 1100x fb/usps/pages/zn/zn_1.jpg
		convert ../i/usps_1.jpg -resize 550 fb/usps/pages/1.jpg
		convert ../i/usps_1.jpg -resize 200x fb/usps/pages/tn/tn_1.png

		cp ../i/usps.pdf pdf/usps.pdf
		cp ../i/usps.pdf fb/usps/usps.pdf


hosts="kozerus@ko0.us kotwous@ko2.us"
		for host in $hosts; do
			scp fb/usps/pages/1.jpg $host:~/public_html/fb/usps/pages
			scp fb/usps/pages/zn/zn_1.jpg $host:~/public_html/fb/usps/pages/zn
			scp fb/usps/pages/tn/tn_1.png $host:~/public_html/fb/usps/pages/tn

			scp fb/usps/usps.pdf $host:~/public_html/fb/usps
			scp pdf/usps.pdf $host:~/public_html/pdf/
			done
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "go" ]; then

	if [ "$1" == "go" ] || [ "$1" == "fbpdfs2pdf" ]; then
fbs=`find fb -maxdepth 1 -type d -name "*"`
		j=0; k=0; 
		skiplist=""
		for fb in $fbs; do
			fb=`echo $fb | awk -F"/" '{print $2}'`

#			if [ "$fb" != "usps" ]; then
#				echo "$progid $dttm SKIP fb=$fb"
#				continue
#				fi

			let j=j+1
			echo "$progid $dttm j=$j fb=$fb"
			if [ ! -f fb/$fb/$fb.pdf ]; then
				echo "$progid $dttm NOTFOUND fb/$fb/$fb.pdf" >> $logfil
				skiplist=skiplist"\n$j $k fb/$fb/$fb.pdf"
				continue
			else
				ls -lat fb/$fb/$fb.pdf
				if [ ! -f pdf/$fb.pdf ]; then
					echo "cp fb/$fb/$fb.pdf pdf/" >> $logfil
					cp fb/$fb/$fb.pdf pdf/
					ls -lat pdf/$fb.pdf
				else
					echo "$progid $dttm FOUND pdf/$fb.pdf" >> $logfil
					fi
				fi
			let k=k+1

			done

		ls -lat pdf/*.pdf
		echo "$progid $dttm skiplist=$skiplist"

hosts="kozerus@ko0.us kotwous@ko2.us"
		for host in $hosts; do
			dttm=`date +"%Y%m%d_%H%M%S"`
			echo "$progid $dttm scp pdf/*.pdf $host:~/public_html/pdf" >> $logfil
			scp pdf/*.pdf $host:~/public_html/pdf/
			done



		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "fbpdfs2pdf" ]; then

	if [ "$1" == "go" ] || [ "$1" == "upd" ]; then
		hosts="kozerus@ko0.us kotwous@ko2.us"
		for host in $hosts; do

			echo "scp index.htm* $host:~/public_html/"
			scp index.htm* $host:~/public_html/

			echo "scp fb/mars/index.htm* $host:~/public_html/fb/mars/"
			scp fb/mars/index.htm* $host:~/public_html/fb/mars/

			echo "scp kb/aud/index.htm* $host:~/public_html/kb/aud/"
			scp kb/aud/index.htm* $host:~/public_html/kb/aud/

			echo "scp kb/vid/index.htm* $host:~/public_html/kb/vid/"
			scp kb/vid/index.htm* $host:~/public_html/kb/vid/

			echo "scp pdf/index.htm* $host:~/public_html/pdf/"
			scp pdf/index.htm* $host:~/public_html/pdf/

			echo "scp fb/index.htm* $host:~/public_html/fb"
			scp fb/index.htm* $host:~/public_html/fb


			done
		exit
		fi # if [ "$1" == "go" ] || [ "$1" == "upd" ]; then

	if [ "$1" == "go" ] || [ "$1" == "scp" ]; then
		hosts="kozerus@ko0.us kotwous@ko2.us"
		for host in $hosts; do
			echo "$progid $dttm  DISABLED scp pdf/*_big.pdf $host:~/public_html/pdf/"
#			echo "scp pdf/*_big.pdf $host:~/public_html/pdf/"
#			scp pdf/*_big.pdf $host:~/public_html/pdf/
			done
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "scp" ]; then

	if [ "$1" == "go1" ] || [ "$1" == "pdfs2big" ]; then
		findpath="pdf";
		findname="*.pdf";
		pdfs=`find $findpath -maxdepth 1 -name "$findname" -exec basename {} \;`
#	 	echo "$progid $dttm pdfs=$pdfs"

		j=0; k=0;
		for pdf in $pdfs; do
			let j=j+1;
			filename=`basename  $pdf | awk -F"." '{ print $1}'`
			echo "BUGS_5660 j=$j pdf=$pdf filename=$filename"
			fpdf=$findpath/$pdf
			tpdf=$findpath/$filename"_big.pdf"
			echo "$progid $dttm j=$j pdf=$pdf"
#			echo "cp $fpdf $tpdf"
#			cp $fpdf $tpdf
		done
		ls -lat pdf/*.pdf
		exit;
		fi # if [ "$1" == "go1" ] || [ "$1" == "pdfs2big" ]; then


	echo "$progid $dttm ./$progid.sh go"
	echo "$progid $dttm ./$progid.sh find <id>"
	echo "$progid $dttm ./$progid.sh build <id>"
	echo "$progid $dttm ./$progid.sh imgs2tn <id>"
	echo "$progid $dttm ./$progid.sh imgs2zn <id>"
	echo "$progid $dttm ./$progid.sh pagespad <id>"
	echo "$progid $dttm ./$progid.sh tn <id>"
	echo "$progid $dttm ./$progid.sh lists"
	echo "$progid $dttm ./$progid.sh divs"
	echo "$progid $dttm ./$progid fbs	# index fb to pages/"
	echo "$progid $dttm ./$progid imgs2pages"
	echo "$progid $dttm ./$progid jtfid"

	echo " "
	echo "pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq"
	echo "$progid $dttm"
	echo "./$progid fbpdfs2pdf"
	echo "./$progid upd"
	echo "./$progid pdfs2big"
	echo "./$progid shoeboxes"
	echo "./$progid pdf2pub	#"
        echo "./$progid jtf2hosts"
        echo "./$progid imgswap"
        echo "./$progid htm2new"
        echo "./$progid downsize"
        echo "./$progid jtf2hosts"
        echo "./$progid refresh <fbid> <scp_id> # fbid_default=$fbid_default"
	echo "bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd"

	echo "./$progid convert ko.pdf .	# refresh ./pages"
	echo "./$progid convert ko.pdf . ko	# refresh ./pages scp ko0 ko2"
	echo "./$progid convert ko.pdf . ko0	# refresh ./pages scp ko0"
	echo "./$progid convert ko.pdf . ko2	# refresh ./pages scp ko2"
	echo " "
	echo "./$progid convert <pdffil> <tpath> ko	# refresh ./pages scp ko0 ko2"
	echo "./$progid convert <pdffil> <tpath> ko0	# refresh ./pages scp ko0"
	echo "./$progid convert <pdffil> <tpath> ko2	# refresh ./pages scp ko2"

	echo "./$progid convert ko ko	# convert ./pages scp ko0 ko2"

	if [ "$1" == "go" ] || [ "$1" == "done" ]; then
		echo "$progid $dttm DONE"
		exit;
		fi # if [ "$1" == "go" ] || [ "$1" == "done" ]; then

printf "pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq\n";
printf "$progid $dttm\n ";
printf "================================\n";
printf "hosts=$hosts\n";
printf "dirs=$dirs\n";
printf "files=$files\n";
printf "pdfs=$pdfs\n";
printf "ids=$ids\n";
printf "================================\n";
printf "./$progid.sh todo\n";
printf "./$progid.sh done\n";
printf "./$progid.sh psv2tbl\n";
printf "./$proid.sh convert <pdf> <path>\n";
# printf "./$proid.sh new\n";
# printf "./$proid.sh new vi\n";
# printf "./$proid.sh new mv\n";
# printf "./$proid.sh new vi <yyyymmdd>\n";
# printf "./$proid.sh new mv <yyyymmdd>\n";
# printf "./$progid.sh go\n";

printf "./$progid.sh vi <yyyymmdd>\n";
printf "./$progid.sh vi notes\n";
printf "./$progid.sh vi notes <yyyymmdd>\n";
printf "./$progid.sh md <yyyymmdd> # mkdirs\n";
printf "./$progid.sh mv <yyyymmdd> # mvfils dirs\n";
printf "./$progid.sh mvd <yyyymmdd> # mvdirs \n";
printf "./$progid.sh scp # scp \n";
printf "./$progid.sh ssh # ssh \n";
printf "./$progid.sh uapi email <list|create> # \n";
printf "./$progid.sh sql3 <sel|create> #  \n";
printf "./$progid.sh find2tbl <go> # find and insert to $tbl \n";
printf "./$progid.sh find2fb <go> # find and insert to $tbl \n";
printf "./$progid.sh ssk <go> #  \n";
printf "./$progid.sh bugs <go> #  \n";
printf "./$progid.sh dirs2fb <go> #  from_fb=$from_fb to_fb=$to_fb to_pdf=$to_pdf \n";
printf "./$progid.sh txt2txt <go> #  \n";
printf "./$progid.sh db3s2psv	# db3s=$db3s psvdir=$psvdir\n";
printf "./$progid.sh items2sl	# sl_items_html=$sl_items_html\n";
printf "./$progid.sh items2leds	# leds_items_html=leds_items_html\n";
printf "./$progid.sh dirs2html	# fdir=$fdir htmlfile=$htmlfile ht_htmlfile=$ht_htmlfile ht=$ht\n";
printf "./$progid.sh json2db3   #  jsonfile=$jsonfile db3fil=db3fil tbl=$tbl \n";
printf "./$progid.sh mvs <go>   #  mv dirs jtfdc nasa kb snap\n";
printf "./$progid.sh wz <go> #  \n";
printf "./$progid.sh koarrays <go> #  \n";
printf "\n";
printf "./$progid.sh finds <id> <go> #  \n";
printf "./$progid.sh selects <id> <go> #  \n";
printf "./$progid.sh todos <id> <go> #  \n";
printf "./$progid.sh todo <id> <go> #  \n";
printf "./$progid.sh tododb <id> <go> #  \n";
printf "./$progid.sh todofs <id> <go> #  \n";
printf "./$progid.sh todotx <id> <go> #  \n";
printf "./$progid.sh awks <id> <go> #  \n";
printf "./$progid.sh fors <id> <go> #  \n";
printf "./$progid.sh kolists <id> <go> #  \n";
printf "./$progid.sh bs4 <id> <go> #  \n";
printf "./$progid.sh b64 <id> <go> #  \n";
printf "./$progid.sh kolists0 <go> #  \n";
printf "./$progid.sh b64s0 <go> #  \n";
printf "./$progid.sh csv2jsn <csvfil> <jsnfil> #  \n";
printf "./$progid.sh jsn2csv <jsnfil> <csvfil> #  \n";
printf "./$progid.sh apps <id> <file> #  \n";
printf "./$progid.sh items <go> #  \n";
printf "./$progid.sh items2db <go> #  \n";
printf "./$progid.sh dls <go> # downloads \n";
printf "./$progid.sh dlsmvs <go> # downloads mv \n";
printf "./$progid.sh dlsrm <go> # downloads rm \n";
printf "./$progid.sh db3s <go> #  \n";
printf "./$progid.sh go <go> #  \n";
printf "\n";
printf "./$progid.sh sql <tbls|cr|drop|del|imp|exp|sel|ins> <go> #  \n";
printf "./$progid.sh scp <ka|k2|ka1|ka2|ko0|ko2|ko> #  \n";
printf "./$progid psv \n";
printf "./byrdbellvjk/ko.sh\n";
printf "./$progid.sh $hostname $dttm $db3 $tbl # \n";
printf "./$progid.sh $hostname $dttm $db3 tbls=$tbls # \n";

printf "bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd\n";
# sqlite3 memory "select datetime('now','localtime');"
# prlctl -version
