#!/bin/bash #Copyright 2001-2004, William Stearns #GPL'd. HtmlFileListVer="0.8.3" True=0 False=1 InList () { #Params: List, object to check if [ -n "`echo ' '$1' ' | grep ' '$2' '`" ]; then return $True else return $False fi } Usage () { echo 'Usage:' >&2 echo $0 '[--fullpage] [--coalesce dirname] [--help] >filelist.html' >&2 echo >&2 echo '--fullpage creates an entire page from to (without' >&2 echo 'this, it just creates the page body.)' >&2 echo '--coalesce dirname only shows a single entry for that directory' >&2 echo 'and all subdirectories and files. Without this, all subdirs/files' >&2 echo 'are individually shown. Can be specified multiple times.' >&2 } if type -path mktemp >/dev/null 2>/dev/null ; then TmpFile=`mktemp -q /tmp/htmlfilelist.XXXXXX` if [ $? -ne 0 ]; then echo "$0: Can't create temp file ${TmpFile}." >&2 exit 1 fi else TmpFile="/tmp/htmlfilelist.$$.$RANDOM" touch $TmpFile if [ $? -ne 0 ]; then echo "$0: Can't create temp file ${TmpFile}." >&2 exit 1 fi fi touch --date="61 days ago" $TmpFile while [ -n "$1" ]; do case "$1" in [Ff][Uu][Ll][Ll][Pp][Aa][Gg][Ee]|--[Ff][Uu][Ll][Ll][Pp][Aa][Gg][Ee]) FullPage='yes' ;; --[Cc][Oo][Aa][Ll][Ee][Ss][Cc][Ee]) if [ -z "$2" ]; then echo "Missing --coalesce parameter, exiting" exit 1 fi Coalesce="$Coalesce $2" shift ;; --[Hh][Ee][Ll][Pp]) Usage exit 1 ;; *) echo "Unknown option $1, exiting" Usage exit 1 ;; esac shift done if [ "$FullPage" = 'yes' ]; then cat < `pwd | sed -e 's@.*/@@'` file listing EOHEADER fi if [ -f htmlfilelist-header.html ]; then cat htmlfilelist-header.html echo \ fi echo \ echo \\ \\\ \\\ Up one level\\\ \\\\\\ \\\ \\\ \ RawList="`find | sed -e 's@\./@@' | grep -v '^\.$' | sort`" #echo "$RawList" for OneCoalesce in $Coalesce ; do #echo ==== $OneCoalesce RawList=`echo "$RawList" | sed -e "s@\($OneCoalesce\).*@\1@" -e 's@/$@@' | uniq` done #echo "$RawList" #FIXME doesn't handle files with spaces correctly; -e 's/^/"/' -e 's/$/"/' gives too many quotes to ls and -e 's/ /\\ /g' fails. for OneObj in $RawList ; do ObjName=`echo "$OneObj" | sed -e 's@.*/@@'` if echo "$OneObj" | grep -q '/' ; then ObjPath=`echo "$OneObj" | sed -e 's@\(.*\)/.*@\1@'` else ObjPath="." fi #echo X${ObjPath}X${ObjName}X >&2 if [ $OneObj -nt $TmpFile ]; then #NewImage='' NewImage='' else NewImage='' fi if [ -d $OneObj ]; then if InList "$Coalesce" "$ObjName" ; then echo \\ $NewImage\ \\\ \$OneObj\\\\ \\\\\\ \ `ls -ald "$OneObj" | awk '{print $6,$7}'`\\ \ `ls -ald "$OneObj" | awk '{print $8}'`\\ \ OneCoalesced='yes' else echo \\ $NewImage\ \\\ $OneObj\\\ \\\\\\ \ `ls -ald "$OneObj" | awk '{print $6,$7}'`\\ \ `ls -ald "$OneObj" | awk '{print $8}'`\\ \ fi #FIXME - do a case on *filelist.html, index. elif [ "$ObjName" = "htmlfilelist-header.html" ]; then : elif [ "$ObjName" = "htmlfilelist-footer.html" ]; then : elif [ "$ObjName" = "filelist.html" ]; then #Leave off size, date and timestamp for the currently-being-modified filelist.html echo \\ \\\ \\\ $OneObj\\\ \\\ \\\ \\\ \ elif [ "$ObjName" = "index.html" ] && [ $OneObj -ef $ObjPath/filelist.html ]; then #Same as above (only used if the exact same inode as filelist.html). echo \\ \\\ \\\ $OneObj\\\ \\\ \\\ \\\ \ else case "$ObjName" in #|*.thumb.ico|*.thumb.ICO not right now *.thumb.jpg|*.thumb.JPG|*.thumb.gif|*.thumb.GIF|*.thumb.xbm|*.thumb.XBM|*.thumb.png|*.thumb.PNG|*.thumb.pbm|*.thumb.PBM) : ;; #These should be caught by the image height test below, no need to special case anymore. #toc.gif|prev.gif|next.gif|first0.gif|first1.gif|index.gif|last0.gif|last1.gif|next0.gif|next1.gif|prev0.gif|prev1.gif|text.gif) # #Normal file, don't thumbnail these # echo \\ # \\\ $OneObj\\\ # \ `ls -ald "$OneObj" | awk '{print $5}'`\\ # \ `ls -ald "$OneObj" | awk '{print $6,$7}'`\\ # \ `ls -ald "$OneObj" | awk '{print $8}'`\\ # \ # ;; #|*.ico|*.ICO not right now *.jpg|*.JPG|*.gif|*.GIF|*.xbm|*.XBM|*.png|*.PNG|*.pbm|*.PBM) Images="$Images $ObjPath/$ObjName" echo \\ $NewImage\ \\\ $OneObj\\\ \ `ls -ald "$OneObj" | awk '{print $5}'`\\ \ `ls -ald "$OneObj" | awk '{print $6,$7}'`\\ \ `ls -ald "$OneObj" | awk '{print $8}'`\\ \ ;; *) #Normal file echo \\ $NewImage\ \\\ $OneObj\\\ \ `ls -ald "$OneObj" | awk '{print $5}'`\\ \ `ls -ald "$OneObj" | awk '{print $6,$7}'`\\ \ `ls -ald "$OneObj" | awk '{print $8}'`\\ \ ;; esac fi done echo \ if [ "$OneCoalesced" = 'yes' ]; then echo \Boldfaced directories have been collapsed into one listing. Click on them to see their contents.\ fi if [ -n "$Images" ]; then #[wstearns@sparrow icons]$ identify mason_logo-50.gif | less #mason_logo-50.gif GIF 178x56+0+0 PseudoClass 256c 8-bit 4291b 0.0u 0:01 #Born-to-Frag.jpg JPEG 180x240 DirectClass 8-bit 9333b 0.0u 0:01 #Tux_visor.png[1] PNG 90x113 DirectClass 8-bit 13690b 0.0u 0:01 #filing.cabinet.xbm[2] XBM 32x32 PseudoClass 2c 8-bit 914b 0.0u 0:01 #ruler.gif[3] GIF 586x18+0+0 PseudoClass 4c 8-bit 943b 0.0u 0:01 #width x height echo \ for OneImage in $Images ; do #-e 's/.*ICO //' not right now ImageHeight=`identify $OneImage | \ sed -e 's/.*GIF //' -e 's/.*JPEG //' -e 's/.*XBM //' -e 's/.*PNG //' -e 's/.*PNM //' \ -e 's/=>.*//' -e s'/ .*//' -e 's/.*x//' -e 's/\+.*//' | tail -1` Thumbnail=`echo $OneImage | sed -e 's/\(\.[gijpxGIJPX][[bcinpBCINP][fgmoFGMO]\)$/.thumb\1/'` case $ImageHeight in [0-9]|[0-9][0-9]|100) rm -f $Thumbnail ImageWidth=`identify $OneImage | \ sed -e 's/.*GIF //' -e 's/.*JPEG //' -e 's/.*XBM //' -e 's/.*PNG //' -e 's/.*PNM //' \ -e 's/=>.*//' -e s'/ .*//' -e 's/x.*//' | tail -1` #Debugging checks #case "$ImageWidth" in #[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) : ;; #*) echo Invalid Width $ImageWidth for $OneImage >&2 ;; #esac #case "$ImageHeight" in #[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) : ;; #*) echo Invalid Height $ImageWidth for $OneImage >&2 ;; #esac echo \\\ ;; *) if [ ! -f "$Thumbnail" ]; then convert -geometry 100x100 $OneImage $Thumbnail fi ImageHeight=`identify $Thumbnail | \ sed -e 's/.*GIF //' -e 's/.*JPEG //' -e 's/.*XBM //' -e 's/.*PNG //' -e 's/.*PNM //' \ -e 's/=>.*//' -e s'/ .*//' -e 's/.*x//' -e 's/\+.*//' | tail -1` ImageWidth=`identify $Thumbnail | \ sed -e 's/.*GIF //' -e 's/.*JPEG //' -e 's/.*XBM //' -e 's/.*PNG //' -e 's/.*PNM //' \ -e 's/=>.*//' -e s'/ .*//' -e 's/x.*//' | tail -1` #case "$ImageWidth" in #[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) : ;; #*) echo Invalid Width $ImageWidth for $OneImage >&2 ;; #esac #case "$ImageHeight" in #[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) : ;; #*) echo Invalid Height $ImageWidth for $OneImage >&2 ;; #esac echo \\\ ;; esac done fi for OneFile in README* ; do if [ -f $OneFile ] && [ -s $OneFile ]; then echo \ echo \$OneFile\ case $OneFile in *.html|*.htm|*.HTML|*.HTM) cat $OneFile | grep -v '' | grep -v '' | \ grep -v '' | grep -v '' | \ grep -v '' | grep -v '' | \ grep -v '' | grep -v '' ;; *) echo \ cat $OneFile | sed -e 's/<\([^@]*@[^>]*\)>/\<\1\><\/a>/g' echo \ ;; esac fi done ViewedRpms='' #Sort newest (even in any subdirectory) up top. # | grep -v '^sam/' | grep -v '^pof/' would handle the hyperlink pointing into sam instead of samlib. for OneRpm in `ls -A1 --sort=time *.rpm */*.rpm */*/*.rpm */*/*/*.rpm */*/*/*/*.rpm */*/*/*/*/*.rpm */*/*/*/*/*/*.rpm */*/*/*/*/*/*/*.rpm 2>/dev/null | grep -v '\.src\.rpm' | grep -v '^neweststable/'` ; do RpmName=`rpm --queryformat '%{NAME}' -qp $OneRpm` if ! InList "$ViewedRpms" "$RpmName" ; then ObjName=`echo "$OneRpm" | sed -e 's@.*/@@'` echo \ if echo "$OneRpm" | grep -q '/' ; then ObjPath=`echo "$OneRpm" | sed -e 's@\(.*\)/.*@\1@'` echo \\$ObjPath\/\$ObjName\\ else echo \\$ObjName\\ fi echo \ rpm -qpi "$OneRpm" | sed -e 's@<@\<@g' -e 's@>@\>@g' -e 's/\<\([a-zA-Z0-9\-_\.]*@[a-zA-Z0-9\-_\.]*\)\>/\<\1<\/a>\>/g' -e 's@^\(URL\W*:\W*\)\([^\W]*\)@\1\2@' echo \ ViewedRpms="$ViewedRpms $RpmName" fi done if [ -f htmlfilelist-footer.html ]; then echo \ cat htmlfilelist-footer.html fi if [ "$FullPage" = 'yes' ]; then cat < Generated `date` by htmlfilelist version $HtmlFileListVer EOFOOTER fi rm -f $TmpFile