#!/p/bin/zsh # # This script will make a INDEX file from a subtree of files # # Hannu.Aronsson@cs.hut.fi, Tero.Kivinen@hut.fi # # Put your information into files which names are filename.ind # (maybe .ind later) for easy moving along the original files. # The description will be fed through fmt # # set +a setopt shwordsplit ###################################################################### # Directory options # DIR=/pub/unix/386ix FTP=ftp.funet.fi MANAGER=kate@nic.funet.fi ARCHIVE="386 Unix archive" ###################################################################### # HTML page footer # HTMLPOSTDATA="
Kate Alhola <kate@nic.funet.fi>" ###################################################################### # Other configuration variables etc # DEBUG=: # DEBUG="echo [DEBUG]:" INDEXF=INDEX POSTFIX=.ind HTMLFILE=index.html HTMLPREFIX=html NEWFILES=NEW-FILES INDEXHDR=00Readme SHORTIND=SHORT$INDEXF TMPFILE=/tmp/news.$$ ###################################################################### # Programs etc # PUBLIC="chmod u=rw,og=r" PRIVATE="chmod u=rw,g=r,o=" AWK=gawk ###################################################################### # Start of code # cd $DIR echo "$0: Working in `pwd`" rm -f $INDEXF $SHORTIND $NEWFILES rm -f $HTMLFILE $INDEXF.HTMLPREFIX $SHORTIND.$HTMLPREFIX $NEWFILES.$HTMLPREFIX ###################################################################### # File headers #################### INDEX #################### echo " ***** $FTP $DIR $INDEXF file ***** " >$INDEXF cat $INDEXHDR >> $INDEXF #################### SHORTINDEX #################### echo " ***** $FTP $DIR $SHORTIND file ***** This is the short index for the $DIR archives at $FTP. Please see the file INDEX in the abovementioned archive for detailed descriptions for the files. " > $SHORTIND #################### NEW-FILES #################### echo " ***** $FTP $DIR $OUTPUT file ***** This is a list of the $DIR archive files, ordered by date and newest first. From this list, you can quickly check what is new and what has changed since your last check here. Please see the file $INDEXF in the same directory for full detailed descriptions. Any complaints and/or requests about the $DIR archive at $FTP can be sent to $MANAGER. This file is up to date as of `date`. " >$NEWFILES #################### index.html #################### echo "Home page of $ARCHIVE on $FTP

Home page of $ARCHIVE on $FTP

`cat $INDEXHDR.$HTMLPREFIX`


Info files

  • Index of $ARCHIVE
  • Short index of $ARCHIVE
  • New files list
  • Directories / Files

    " > $HTMLFILE #################### INDEX.html #################### echo "Contents of $ARCHIVE at $FTP

    Contents of $ARCHIVE at $FTP

    " > $INDEXF.$HTMLPREFIX #################### SHORTINDEX.html #################### echo "Contents of $ARCHIVE on $FTP

    Contents of $ARCHIVE on $FTP

    " > $SHORTIND.$HTMLPREFIX #################### NEW-FILES.html #################### echo " $FTP $DIR $OUTPUT file

    $FTP $DIR $OUTPUT file

    This is a list of the $DIR archive files, ordered by date and newest first. From this list, you can quickly check what is new and what has changed since your last check here.

    Please see the file $INDEXF in the same directory for full detailed descriptions. Any complaints and/or requests about the $DIR archive at $FTP can be sent to $MANAGER.

    This file is up to date as of `date`.

    " >$NEWFILES.$HTMLPREFIX ######################################## # End of file headers ####################################################################### # Make files public # $PUBLIC $INDEXF $SHORTIND $NEWFILES $PUBLIC $HTMLFILE $PUBLIC $INDEXF.$HTMLPREFIX $SHORTIND.$HTMLPREFIX $NEWFILES.$HTMLPREFIX ###################################################################### # Create per directory index.html file headers echo -n "Making index.html headers..." >&2 find . -type d -perm -04 -print | egrep -v "(^\./incoming)|(^\./old)|(^\.$)" | sed 's_^\./__g' | while read name do $DEBUG $name rm -f $name/$HTMLFILE echo "Contents of directory $name

    Contents of directory $name

    " > $name/$HTMLFILE if [[ -f $name.ind ]] then cat $name.ind >> $name/$HTMLFILE echo "

    " >> $name/$HTMLFILE fi echo "

    " >> $name/$HTMLFILE $PUBLIC $name/$HTMLFILE echo -n ".">&2 done echo "done">&2 ###################################################################### # Create contents of INDEX{,.html}, SHORTINDEX{,.html} and # per directory index.html # echo -n "Making INDEX and index.html data..." >&2 typeset -R 8 sizebytes prevdirn="." lvl=0; find . -perm -04 -ls | egrep -v "($POSTFIX\$)|( \./todo)|( \./incoming)|( \./old)|( \./$INDEXF)\ |( \./$SHORTIND)|( \./$NEWFILES)|( \./hidden)|(/\.FTP_LS_DATA)|(\.html)" | sort +10 | sed '/ \.$/d;s- \./- -' | while read inode blocks perm linkcount owner group size month day time name symp sym do dirn=`dirname $name` base=`basename $name` if [[ $dirn != $prevdirn ]] then newlvl=`echo $dirn | tr '/' ' ' | wc -l` $DEBUG "New dirlevel $dirn($newlvl) $prevdirn($lvl)" if [[ $newlvl -gt $lvl ]] then while [[ $newlvl -gt $lvl ]] do lvl=$[ lvl + 1 ] echo "" >>$INDEXF.$HTMLPREFIX echo "" >>$SHORTIND.$HTMLPREFIX $DEBUG "Up " done else if [[ $newlvl -lt $lvl ]] then while [[ $newlvl -lt $lvl ]] do lvl=$[ lvl - 1 ] echo "" >>$INDEXF.$HTMLPREFIX echo "" >>$SHORTIND.$HTMLPREFIX $DEBUG "Down " done fi if [[ $dirn = "." ]] then while [[ $lvl -gt 0 ]] do lvl=$[ lvl - 1 ] echo "" >>$INDEXF.$HTMLPREFIX echo "
    " >>$SHORTIND.$HTMLPREFIX $DEBUG "Down " done fi fi prevdirn=$dirn fi $DEBUG $name $dirn REALLY="" INFOFILE="$name$POSTFIX" case "X$perm" in Xd*) type="d" size="--dir--" sizebytes="--dir--" sizekb="--dir--" echo -n ".">&2 LINKTYPE="http" $DEBUG Directory ;; Xl*) type="l" REALLY="-- really archived at $sym " size="--link--" sizebytes="--link--" sizekb="--link--" LINKTYPE="ftp" $DEBUG Symlink ;; *) type="f" sizebytes=$size sizekb="$[ (size + 512) / 1024 ] KB" if [[ $sizekb = "0 KB" ]] then sizekb="$size bytes" fi LINKTYPE="ftp" ;; esac case "X$perm" in ???????-??) echo "$0: Not public file: $name, skipping">&2 ;; *) left="$sizebytes $name" right="[$month $day $time]" info="$left $right" echo "$info">>$INDEXF echo "$info">>$SHORTIND href="" hesz=" ($sizekb)" case $type in d) echo "
  • $href$base$hesz ">>$INDEXF.$HTMLPREFIX echo "
  • $href$base$hesz

    " >>$dirn/$HTMLFILE echo "

  • $href$base$hesz" >>$SHORTIND.$HTMLPREFIX ;; f) htmlinfo="
  • $href$base$hesz $right

    " echo "$htmlinfo">>$INDEXF.$HTMLPREFIX echo "$htmlinfo">>$dirn/$HTMLFILE echo "

  • $href$base$hesz $right" >>$SHORTIND.$HTMLPREFIX echo "
  • $href$name$hesz $right">>$TMPFILE.$HTMLPREFIX echo "$left $right">> $TMPFILE ;; l) htmlinfo="
  • $href$base$hesz $right

    " echo "$htmlinfo">>$INDEXF.$HTMLPREFIX echo "$htmlinfo">>$dirn/$HTMLFILE echo "

  • $href$base$hesz $right" >>$SHORTIND.$HTMLPREFIX ;; esac if [[ -r $INFOFILE ]] then $PRIVATE $INFOFILE 2>/dev/null cat $INFOFILE | sed 's_\(.*\)_URL(\2) = \1_g; s/^/ /'| fmt | \ sed '/^$/d' >>$INDEXF echo "" >>$INDEXF cat $INFOFILE >>$INDEXF.$HTMLPREFIX echo "

    " >>$INDEXF.$HTMLPREFIX cat $INFOFILE >>$dirn/$HTMLFILE echo "

    " >>$dirn/$HTMLFILE fi $DEBUG $size $name, $month.$day.$time esac done echo "don">&2 ###################################################################### # End of create contents of INDEX{,.html}, SHORTINDEX{,.html} and # per directory index.html ###################################################################### # Creating NEW-FILES and NEW-FILES.html # echo -n "Making $NEWFILES file from $TMPFILE..." >&2 for i in "" ".$HTMLPREFIX" do (date cat $TMPFILE$i )| $AWK 'BEGIN { montable["Jan"] = 1 montable["Feb"] = 2 montable["Mar"] = 3 montable["Apr"] = 4 montable["May"] = 5 montable["Jun"] = 6 montable["Jul"] = 7 montable["Aug"] = 8 montable["Sep"] = 9 montable["Oct"] = 10 montable["Nov"] = 11 montable["Dec"] = 12 getline thisyear = $(NF)+0 # last field of `date` thismons = $2 thismon=montable[thismons] } NR>1 { mons=$(NF-2); day=$(NF-1); gsub(/\[/,"",mons); mon=montable[mons]; if (length($(NF)) == 5) { year=substr($(NF),1,4)+0; # 19xx] } else { year=thisyear; # hh:mm] if (mon > thismon) year--; } printf "%04d%02d%02d %s\n", year, mon, day, $0 }' | # Here we have YYYYMMDD sort -nr | $AWK -v www=$i 'BEGIN { oldmon = 0; oldyear = 0 } { year=substr($1,1,4)+0 mon= substr($1,5,2)+0 if (mon != oldmon || year != oldyear) { oldmon=mon; oldyear=year if (www != "") printf "


  • Files from %d/%d

    \n", mon, year; else printf "\n------ files from %d/%d ------\n\n", mon, year } print substr($0, 10) }' >>$NEWFILES$i done echo "done">&2 ###################################################################### # End of creating NEW-FILES and NEW-FILES.html ###################################################################### # Add footers to index files # #################### INDEX #################### echo " ------ end of $INDEXF ------ " >> $INDEXF #################### SHORTINDEX #################### echo " ------ end of $SHORTIND ------ " >> $SHORTIND #################### NEW-FILES #################### echo " ------ end of $NEWFILES ------ " >>$NEWFILES #################### index.html #################### echo $HTMLPOSTDATA >> $HTMLFILE #################### INDEX.html #################### echo $HTMLPOSTDATA >> $INDEXF.$HTMLPREFIX #################### SHORTINDEX.html #################### echo $HTMLPOSTDATA >> $SHORTIND.$HTMLPREFIX #################### NEW-FILES.html #################### echo "


    End of $NEWFILES

    " >>$NEWFILES.$HTMLPREFIX echo $HTMLPOSTDATA >> $NEWFILES.$HTMLPREFIX ###################################################################### # Create per directory index.html file footers echo -n "Making index.html footers..." >&2 find . -type d -perm -04 -print | egrep -v "(^\./incoming)|(^\./old)|(^\.$)" | sed 's_^\./__g' | while read name do $DEBUG $name echo $HTMLPOSTDATA >> $name/$HTMLFILE echo -n ".">&2 done echo "done">&2 ###################################################################### # Cleanup rm /tmp/news.$$ /tmp/news.$$.html ###################################################################### # Show them to user # ls -l $INDEXF $SHORTIND $NEWFILES >&2 ls -l $INDEXF.$HTMLPREFIX $SHORTIND.$HTMLPREFIX $NEWFILES.$HTMLPREFIX >&2 ls -l $HTMLFILE ###################################################################### # EOF ######################################################################