#!/bin/bash # # vim: ts=4 sw=4 et # # generate_index_html # # Generates index.html files with a link to each file in the directory, and # recursively for its sub-directories. # # Note: This script recursively calls itself, so if invoked without # an absolute path name, it had better be in its own path! # CURRENT_RELEASE=11.01 BETA_RELEASE=11.07 # We need bash's extended globbing for the case patterns # matching the release numbers. shopt -s extglob INDEX=index.html.$HOST.$$ LOCKDIR=generate_index_html.lock handled_files= # Lock the directory (this script may be invoked by test_mercury # on multiple machines at once). timeout=20 retries=0 until mkdir $LOCKDIR; do case $retries in $timeout) echo "** $0: creating lock directory `pwd`/$LOCKDIR failed" 1>&2 echo "** $0: remove it manually if it is stale" 1>&2 exit 1 ;; esac sleep 5 retries=`expr $retries + 1` done trap 'rm -rf $INDEX $LOCKDIR; exit 1' 1 2 3 13 15 # These are the standard locations for Apache's icons. # img_txt="" img_dir="" img_bak="" echo "" \ > $INDEX echo "" >> $INDEX echo "" >> $INDEX echo "The Mercury Project: Directory Listing" >> $INDEX echo "" >> $INDEX echo "" >> $INDEX echo "

Directory listing

" >> $INDEX echo "
" >> $INDEX #-----------------------------------------------------------------------------# # link_to_file prefix filename description. # # Generate a line with the prefix followed by a link to the given file. # Record that the file has been handled. link_to_file () { prefix="$1" this_file="$2" this_file_descr="$3" q='"' if test -d "$this_file" then echo "$prefix $this_file_descr" >> $INDEX else this_file_size=`ls -Ll "$this_file" | awk '{ print $5; }'` this_file_sizekb=`expr "$this_file_size" / 1024` echo "$prefix $this_file_descr ($this_file_sizekb kilobytes)" >> $INDEX fi handled_files="$this_file $handled_files" } #-----------------------------------------------------------------------------# skip_file () { stable_file="$1" unstable_file="$2" if [ -f "$stable_file" ]; then handled_files="$unstable_file $handled_files" fi } #-----------------------------------------------------------------------------# # link_to_file filename description # # Generate a link to a file if it exists. # This should be called within a `