#!/bin/sh ###################################################################### # tirindex - Generate tir directory index. # Created 2006-8-13 David Meyer. # 2007-05-09 Version 0.2 ###################################################################### # Identification ##################################################### PROGRAM='tirindex' VERSION=0.2 COPYRIGHT='Copyright (C) 2007 David Meyer' DESCRIPTION='Generate tir directory index.' USAGE="Usage: $0 [-rVh] [DIRECTORY]" CONTACT='David Meyer ' # Initialize environment ############################################# unset IFS PATH= BASENAME=/usr/bin/basename CAT=/bin/cat ECHO=/bin/echo SED=/bin/sed : ${TIRROOT:=/mnt/card/Meyer21C} # Arguments ########################################################## while getopts rVh option do case $option in r ) ROOT=1 ;; V ) $ECHO "$PROGRAM $VERSION" $ECHO $COPYRIGHT exit 0 ;; h ) $CAT << ENDHELP $USAGE $DESCRIPTION DIRECTORY defaults to current directory. Options: -r Target directory is site root -V Display version number -h Display this help message Report bugs to $CONTACT. ENDHELP exit 0 ;; * ) $ECHO $USAGE >&2 exit 1 ;; esac done shift $(( $OPTIND-1 )) HERE=${1:-.} # Functions ########################################################## cat_filter_root_path() { if [ $HERE -ef $TIRROOT ] then $SED -e 's:\.\./:./:' $1 else $CAT $1 fi } inherit_fn() { fn=${2:?"Insufficient arguments: inherit_fn $@"} if [ -f $fn ] then eval $1=$fn elif [ -f $TIRROOT/$fn ] then eval $1=$TIRROOT/$fn else eval $1=${3:-/dev/null} fi } # Main driver ######################################################## cd $HERE test -f .title && title=`$CAT .title` test -f $TIRROOT/.title && site=`$CAT $TIRROOT/.title` if [ x"${title:=`$BASENAME $HERE`}" = x"." ] then title="Site under construction" fi $ECHO "

$title

" if [ -f .image ] then $ECHO '
' $ECHO "" $ECHO '
' fi if [ -f .description ] then $ECHO '
' $CAT .description $ECHO '
' fi objects='' exits='' for name in * do if [ -f $name ] then case $name in index.html | *~ ) : ;; *.html ) objects="$objects$name " ;; * ) test ! -f ${name%.*}.html && objects="$objects$name " ;; esac elif [ -d $name ] then exits="$exits$name " fi done if [ "$objects" ] then $ECHO '
You see here:
' fi # Subdirectories of root (topic nexus)... if [ "$exits" ] then $ECHO '
Obvious ways out:
' fi # Inter-topic connections... if [ -f .exits ] then $ECHO '
Obvious ways out:
' fi if [ -f .copyright ] then $ECHO '' fi if [ -f .license ] then $ECHO '
' cat_filter_root_path .license $ECHO '
' fi exit