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

# tl.sh	20220124_0500	
# ka.sh	20220119_1930	db3
# ka.sh	20220119_1145	db3
# ka.sh	20220118_1830	db3
# ka.sh	20211009_1900

#	tl_b64s = `ls b*.txt`
progid="tl"
dttm=`date +"%Y%m%d_%H%M%S"`
logfil="$progid.log"
logfil_dttm="$progid""_$dttm.log"

ids="iperms";
ids="jtfdc jtfdcr jtfinc"
ids="konet";
ids="konet jtfdc jtfdcr jtfinc iperms";
ids="bookusb"

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_100 1=$1 2=$2 3=$3 4=$4"
#	echo "$progid $dttm books=$books"
	if [ "$1" == "vi" ] || [ "$1" == "vi" ];  then
		vi $progid.sh; 
		exit; 
		fi


	if [ "$1" == "go" ] || [ "$1" == "scp" ]; then
hosts="kotwous@ko2.us kozerus@ko0.us"
		for host in $hosts;do 
			dttm=`date +"%Y%m%d_%H%M%S"`
			echo " "
			echo "$progid $dttm host=$host $logfil_dttm ============================"
			echo "$progid $dttm host=$host $logfil_dttm ============================" >> $logfil_dttm
			echo "scp -r txt $host:~/public_html/"
			echo "scp index_tl.htm* $host:~/public_html"
			echo "scp tl.* $host:~/public_html"
			echo "scp tl.* $host:~/public_html/tl"
			echo "scp -r tl/txt $host:~/public_html/tl/"
#			echo "scp index.htm* $host:~/public_html"
			if [ "$2" == "go" ]; then

				dttm=`date +"%Y%m%d_%H%M%S"`
				echo "$progid $dttm scp index_tl.htm* $host:~/public_html/" >> $logfil_dttm
				scp index_tl.htm* $host:~/public_html/

				dttm=`date +"%Y%m%d_%H%M%S"`
				echo "$progid $dttm scp -r txt $host:~/public_html/" >> $logfil_dttm
				scp -r txt $host:~/public_html/

				dttm=`date +"%Y%m%d_%H%M%S"`
				echo "$progid $dttm scp tl.* $host:~/public_html" >> $logfil_dttm
				scp tl.* $host:~/public_html

				dttm=`date +"%Y%m%d_%H%M%S"`
				echo "$progid $dttm scp tl.* $host:~/public_html/tl" >> $logfil_dttm
				scp tl.* $host:~/public_html/tl




				dttm=`date +"%Y%m%d_%H%M%S"`
				echo "$progid $dttm scp -r tl/txt $host:~/public_html/tl/" >> $logfil_dttm
				scp -r tl/txt $host:~/public_html/tl/

#				dttm=`date +"%Y%m%d_%H%M%S"`
#				echo "$progid $dttm scp index.htm* $host:~/public_html" >> $logfil_dttm
#				scp index.htm* $host:~/public_html
				fi
			done

		exit;
		fi


	if [ "$1" == "go" ] || [ "$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
 
# printf "BUGS_105 head wc EXIT\n"; exit;

	if [ "$1" == "go" ] || [ "$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_100 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

printf "BUGS_130 head finds\n";

	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" == "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" == "testdata" ]; then
txtfil="lb/books/gifs.txt"
# media=`cat $txtfil | awk -v j='$j' 'NR==j { print "j="j" "$1 }'`
# media=`cat $txtfil | awk -v j='$j' 'NR==j { print "j="j" "$1 }'`
# cat lb/books/gifs.txt | awk -v j='$j' 'NR==j { print "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_100 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

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


	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" == "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" == "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" == "new" ]; then
		yyyymmdd=`date +"%Y%m%d"`
ids="kb_$yyyymmdd snap_$yyyymmdd jtfdc_$yyyymmdd"
echo "BUGS_910 NEW "

		j=0;
		echo "$progid $dttm o1=$1 ids=$ids"
		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 "mkdir $dir"
				mkdir $dir
				fi
			done

		if [ "$2" == "vi" ] || [ "$2" != "" ]; then
			echo "vi yt/txt/ytlist_$yyyymmdd.txt"
			vi yt/txt/ytlist_$yyyymmdd.txt
			fi
		echo "BUGS_920 NEW END"
		exit;
		fi

	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" == "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" == "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" == "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"`

		tpath="./tmp"	
#		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" == "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" == "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_100 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" == "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" == "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_220 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_281 j=$j k=$k i1=$i1 convert $zn1 -resize 550x $img1"
#				echo "BUGS_282 j=$j k=$k i2=$i2 convert $zn2 -resize 550x $img2"
#
#				echo "BUGS_291 j=$j k=$k i1=$i1 convert $zn1 -resize 200x $tn1"
#				echo "BUGS_292 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" == "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
		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_100 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" == "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
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
echo "BUGS_900 NEW BEG"

echo "BUGS_930 NEXT "
exit;


	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




db3file="ko.db3"
tblname="books"
books=""
marks=""
usbs=""

	if [ "$1" == "go" ] || [ "$1" == "psv2tbl" ]; then
		echo "$progid $dttm psv2tbl"
		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" == "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" == "pdf2fbnew" ]; then
fbid="ka"

#		if [ -d fb/$fbid ]; then
#			echo "BUGS_100 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" == "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" == "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" == "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" == "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" == "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" == "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" == "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" == "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" == "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" == "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" == "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" == "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" == "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" = "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_100 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" == "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" = "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" = "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" = "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" = "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" = "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" = "pub" ] || [ "$1" == "publish" ]; then


		exit;
		fi
# jk.sh 	20211016_1900

progid="jk"
dttm=`date +"%Y%m%d_%H%M%S"`
progfile="$progid.sh"
logfil="$progid.log"

	echo "$progid $dttm "
	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" == "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" == "shoeboxes" ]; then
ids=`find fb -type d -maxdepth 2 -name "shoebox"`
		echo "$progid $dttm ids=$ids"
		j=0; k=0;
		echo "BUGS_100"
		for id in $ids; do
			echo "BUGS_101 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" == "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" == "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" == "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" == "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" == "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" == "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" == "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_100 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


	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


echo "pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq"
echo "$progid $dttm "
echo "================================"
echo "hosts=$hosts"
echo "dirs=$dirs"
echo "files=$files"
echo "pdfs=$pdfs"
echo "ids=$ids"
echo "================================"
echo "./$progid.sh todo"
echo "./$progid.sh done"
echo "./$progid.sh psv2tbl"
echo "./$proid.sh convert <pdf> <path>"
echo "./$proid.sh new"
echo "./$progid.sh go"
echo "bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd"
