#!/bin/bash # sd2h - ScriptDirToHtml # Makes an sdindex.html (which gets written over if it already exists!) # with links for a directory of scripts. # It is GNU software, and based on DirToHtml. Please send us any # customizations you have made so they can be incorporated in # future releases. # Have fun, Tomas IV., brunclik@mail.com, http://tom4.hyperlink.cz (DirToHtml) # Rob Reid, http://www.drao.nrc.ca/~rreid/ (added script comment extraction) ## Version info if [ "-v" = "${1}" -o "--version" = "${1}" ] then cat <["]] OR: sd2h -h OR: sd2h -v sd2h - ScriptDirToHtml (this instance invoked as ${0}) Script to generate html indices of current directory. index.html: Sorted by last modification time. atoz.html: Alphabetically sorted. -h, --help Show this help screen -v, --version Version info ! exit fi nargs=$# scriptdir=$(basename $(pwd)) rm -f sdindex.html atoz.html ${scriptdir}.tar.gz owd=$PWD mkdir $scriptdir cd $scriptdir for (( i = 1; i <= nargs ; i++ )) ; do f=${!i} ln -s $owd/$f $(basename $f) done if [ -f ../COPYING ]; then ln -s $owd/COPYING COPYING fi cd - tar chfz ${scriptdir}.tar.gz $scriptdir rm -rf $scriptdir makepage(){ ## Set default values of variables sortord=$1 shift fmask=$(ls -1 $@) page=atoz.html if [ "$sortord" = "time" ]; then page=sdindex.html fmask=`ls -1t $fmask` fi echo Files: $fmask # HTML header echo \ > $page echo \ >> $page echo \$scriptdir scripts\ >> $page echo \ >> $page echo \ >> $page echo \ >> $page #echo \List of Files\ >> $page echo \\$scriptdir scripts\\ >> $page echo '

' >> $page echo 'These scripts are available under the GNU General Public License.' >> $page echo \ >> $page echo '

' >> $page echo "Note that there is no warranty! Although I have put some effort into making" >> $page echo "them generally useful, they were mainly written to help with a task at hand." >> $page echo "So they may not yet work for all cases, and you may have some fixing to do." >> $page echo "Please send me any fixes or enhancements." >> $page echo \ >> $page echo \ >> $page echo \\ >> $page echo "The whole shebang ($(ls -sh ${scriptdir}.tar.gz|sed 's/ .*//'))" >> $page echo \ >> $page echo \ >> $page echo \\ >> $page if [ "$sortord" = "time" ]; then echo \Sort alphabetically.\>> $page else echo \Sort by last modification time.\>> $page fi echo \\ >> $page echo \ >> $page echo \ >> $page #echo \ >> $page echo \ >> $page # Link the files for i in $fmask ; do if [[ $i == $page ]] ; then # No point listing the page continue; # itself. fi # echo \\${i}\\ >> $page # echo \\\${i}\\\ \ \;\ \;\ \;\ \; "Last modified " `ls -o $i | awk '{printf "%s %s %s, %s bytes\n", $5, $6, $7, $4}'` \ >> $page echo \ >> $page echo \\\ >> $page echo \${i}\ >> $page echo \\\ >> $page blmod=$(ls -o --full-time $i | sed 's/ */ /g' | cut -d ' ' -f 4-9) echo \
>> $page echo Last modified ${blmod#* } >> $page echo \ >> $page echo \ >> $page echo ${blmod%% *} bytes >> $page echo \ >> $page echo \ >> $page echo \ >> $page echo \ >> $page bangcheck=`egrep '^#!' $i | cut -c 1-2` # Unfortunately this does not seem to work properly inside a loop. # shopt -s extglob fext=${i#${i%.*}} # Grab the extension. if [[ ${fext#.s} == "html" || ${fext%l} == ".htm" ]] ; then grep \ $i | sed 's%%%g' >> $page echo \ >> $page elif [[ $bangcheck == "#!" || $fext == ".py" ]] ; then # Allows proportional fonts, but wrecks things that depend on # monospace alignment. # echo \ >> $page # extractcomment < $i | sed 's/^$/

/;s/$/
/' >> $page # echo \ >> $page # Preserves monospaced arrangement. echo \ >> $page extractcomment < $i >> $page echo \ >> $page else file $i | sed "s/${i}: //" >> $page echo \ >> $page fi echo \ >> $page echo \ >> $page echo \ >> $page # Go back to regular filename expansion so $fmask will work as expected. # shopt -u extglob done # Close the HTML. echo \ >> $page echo \ >> $page echo \ >> $page echo \ >> $page echo Page generated by \s2dh\, based on >> $page echo \DirToHtml\, GNU generator of html directory listings. >> $page echo \ >> $page echo \ >> $page echo \ >> $page } makepage "time" $@ makepage "alpha" $@