#!/bin/sh	" > ~/Documents//Software/unixscripts//webmovie/webmovie.sh
#v webmovie v. 1.0 by duus        (Dec 28, 2007)
#v   location: http://thedu.us/scripts/THISSIR/webmovie
#h webmovie script by duus
_SCRIPT_NAME=webmovie            
_SCRIPT_LOCATION=~/bin           
# --------------------------   help and version commands, std. #   
if [ "$1" = "version" -o "$1" = "v" ]                
	then   
	grep "^#v" $_SCRIPT_LOCATION/${_SCRIPT_NAME} | more                              
	exit 1;
elif [ "$1" = "help" -o "$1" = "h" ]
	then
	grep "^#h" $_SCRIPT_LOCATION/${_SCRIPT_NAME} | more
	exit 1;
fi #---------------------------------------------------------#
# begin webmovie   (Dec 28, 2007)
# --------------------------
#h webmovie SOURCEFOLDER OUTFOLDER SECS
#h  takes the txt files in SOURCEFOLDER and makes then into a webpage movie in alpha order
#h  webpagemovie advances every SECS seconds
#h  the format of the textfiles is: it is assumed that the first line is the title.
# webmovie new DESTFOLDER 
#  creates a blank _generic.webmovie in DESTFOLDER (_generic.webmovie will be skipped)
#
#  setting (debug on)
_verbose=1
#
while [ "$1" != "" ]
	do
	__command=""
	echo " curr command: $1"
#h	
if [ "$arg" = "LET" -o "$arg" = "WORD" ]
 		then
#h   <LET>WORD :  COMMAND  HELPLINE
			__command="COMMAND"
			if [ ${_verbose} -eq 1 ] then echo "TAG"
		fi
	
if [ "$arg" = "a" -o "$arg" = "activate" ]
 	then
#h   <a>activate :  activate  activate a sync
	__command="activate"
	if [ ${_verbose} -eq 1 ] then echo "activating a sync now..."
fi

#shcm\t rocks!


################################################# information commands
		
#h 
#h _isync cli information_		
		if [ "$arg" = "i" -o "$arg" = "install" ]
			then
#h    <(i)nstall> displays install information
			grep "^#i" $_SCRIPT_LOCATION/${_SCRIPT_NAME} | more
			__command="no_command"
		fi		

		if [ "$arg" = "v" -o "$arg" = "version" ]
			then
#h    <(v)ersion> displays version information
			grep "^#v" $_SCRIPT_LOCATION/${_SCRIPT_NAME} | more
			__command="no_command"
		fi
		if [ "$arg" = "h" -o "$arg" = "help" ]
			then
#h    <(h)elp> displays this help file
			grep "^#h" $_SCRIPT_LOCATION/${_SCRIPT_NAME} | more
			__command="no_command"
		fi
		if [ "$arg" = "src" -o "$arg" = "source" -o "$arg" = "code" ]
			then
#h    <src> displays the source code
			more $_SCRIPT_LOCATION/${_SCRIPT_NAME}
			__command="no_command"
		fi
		

#h
#h _Other_
		if [ "$__command" = "" ]
			then
#h    an unrecognized argument will be passed to isync as a command
#h       (please see the Script Editor iSync Dictionary for more commands)
			__command="$arg"
		fi
		
	#
	# run command
	#

	#
	#
	####### shift
	shift
done



if [ "$1" = "nohelp" ]
	then
	_nohelp=1
	shift
	else
	_nohelp=0
fi
if [ "$1" = "noversion" ]
	then
	_noversion=1
	shift
	else
	_noversion=0
fi
if [ "$1" = "skip" ]
	then
	_skip=1
	shift
	else
	_skip=0
fi
_thismovie=$1
_thisphrase=$2
_webmoviefolder=.
_maindir=${_webmoviefolder}
#
########################################## make a page for tmp
# 0. get phrase

if [ "${_thisphrase}" = "" ]
	then
	if [ -e ${_maindir}/${_thismovie}phrase.txt ]
		then
		_thisphrase=`cat ${_maindir}/${_thismovie}phrase.txt`
		else
		echo "please input catchphrase."
		read -e _thisphrase
	fi
fi
# update phrase file
echo -n "${_thisphrase}" > ${_maindir}/${_thismovie}phrase.txt

# 1. make folder in webscripts
#
if [ ${_skip} -eq 0 ]
	then
	cd ${_webscripts}
	if [ ! -e ${_thismovie} ]
		then
		mkdir ${_thismovie}
	fi
	cd ${_thismovie}
	if [ ! -e index.html ]
		then
		echo "<html><head><title>404 Not Found</title></head><body><h1>404 File Not Found</h1><a href=\"..\">back</a></body>" > index.html
	fi
	if [ ! -e ${_thismovie} ]
		then
		mkdir ${_thismovie}
	fi
	cd ${_thismovie}
	#
	# 2. put script in that folder
	#
	cp ${_maindir}/${_thismovie}.sh .
	perl -i -pe 's#~#~#g' ${_thismovie}.sh
	perl -i -pe 's#duus#duus#g' ${_thismovie}.sh
	#
	# 3. make a cover page for that folder
	echo "...making page ${_maindir}/${_thismovie}/index.html"
	echo "  ${_thismovie}: ${_thisphrase}"
	echo "<html><head><title>${_thismovie} - a duusscript</title></head><body><tt><h1>${_thismovie}: ${_thisphrase}</h1><p>" > index.html
	if [ ${_noversion} -eq 0 ]
		then
		echo "<b>version information:</b><p>"  >> index.html
		${_maindir}/${_thismovie}.sh version | perl -i -pe 's#~#~#g' | perl -i -pe 's#duus#duus#g'  |  perl -i -pe 's/</&lt;/g' |  perl -i -pe 's/>/&gt;/g'| perl -i -pe 's/#v/<br>/g' >> index.html
	fi
	if [ ${_nohelp} -eq 0 ]
		then
		echo "<p><b>help information:</b><p>" >> index.html
		${_maindir}/${_thismovie}.sh help | perl -i -pe 's#~#~#g' | perl -i -pe 's#duus#duus#g'  |  perl -i -pe 's/</&lt;/g' |  perl -i -pe 's/>/&gt;/g'  | perl -i -pe 's/#h/<br>/g' >> index.html
	fi
	echo "<p><a href=\"${_thismovie}.sh\">(download script)</a><p>" >> index.html
	echo "<p> to install: <ol><li>copy script into a folder on your path.<li>type chmod +x ${_thismovie}.sh to make it executable" >> index.html
	echo "</ol><p><hr>">>index.html
	echo "<i> a <a href=\"http://thedu.us/scripts/\">duusscript</a>... This page updated: `date`, ">>index.html
	echo "when duus was feeling `getmood`.</i>" >> index.html
	echo "</body></html>" >> index.html
	echo "${_thisphrase}" > phrase.txt
fi
# 4. make new scripts page
##################### make new scripts page
_olddir=`pwd`
echo "...remaking ${_webscripts}/${_scripts_webpage}"
cd ${_webscripts}
echo "<html><head><title>duusscripts</title></head><body><tt>" > ${_webscripts}/${_scripts_webpage}
echo "<blockquote><blockquote><blockquote>&nbsp;<p>&nbsp;<p>&nbsp;<p>" >> ${_webscripts}/${_scripts_webpage}
echo "<h2>duusscripts</h2>" >> ${_webscripts}/${_scripts_webpage}
echo "<ol>" >> ${_webscripts}/${_scripts_webpage}
for dir in `ls -p | grep "/"`
        do
        _adir=`echo $dir | perl -i -pe 's#/##g' | perl -i -pe 's/\n//g'`
        #echo $_adir
        echo "   <li><b>${_adir}<b><ul>" >> ${_webscripts}/${_scripts_webpage}
		cd ${_adir}
		for _scriptpage in `ls -p | grep "/"`
			do
			_ascriptpage=`echo $_scriptpage | perl -i -pe 's#/##g' | perl -i -pe 's/\n//g'`
			#echo ${_ascriptpage}
			cd ${_ascriptpage}
			echo "   <li><i><a href=\"${_adir}/${_ascriptpage}\">${_ascriptpage} info page</a></i>  (<a href=\"${_adir}/${_ascriptpage}/${_ascriptpage}.sh\">download script</a>)<br>" >> ${_webscripts}/${_scripts_webpage}
			if [ -e phrase.txt ]
				then
				cat phrase.txt >> ${_webscripts}/${_scripts_webpage}
			fi
			cd ..
		done
		cd ..
		echo "</ul>" >> ${_webscripts}/${_scripts_webpage}
done
echo "</ol><p>&nbsp;<p>&nbsp;<p>updated: `date`, when duus was feeling">> ${_webscripts}/${_scripts_webpage}
echo " `getmood`.</tt></blockquote></blockquote></blockquote></body>" >> ${_webscripts}/${_scripts_webpage}
#cat ${_scripts_webpage}
cd ${_olddir}
##################################################
#
# --------------------------
# <verbatim>           :               end webmovie
#                      . 
#            ...---.,o8:i__,8Pd8   
#         _//      `"' :  d8'",8d8   
#       ,/''  vVv      . dP   b8P.8|
#      ./;|  d^_^b     .     ,P O||]
#       |||  duus@thedu.us\     |||| 
#       |||  duus.thedu.us/      || 
#       ||\            .        /_' 
#        ;+,           :       |\8
#          '.`>+.     _./'_/2/b/_
#           '-oh\._.._j:;'`P;8/,
#              `'->:o:.:src/='
#                      :    
#                      :    http://thedu.us/scripts/THISSIR/webmovie 
# </verbatim>          .    (Dec 28, 2007)
# -------------------------- 


