Text File

#!/bin/sh # # @(#) mkmenus 1.17 95/05/23 01:10:26 # # mkmenus - Construct a set of "gn" menus for a directory tree. # # Edit at tabstops=4. # # Chip Rosenthal # Unicom Systems Development # <chip@chinacat.unicom.com> # http://www.unicom.com/ #

USAGE="usage: $0 [-rc] [-d start_dir] [-f footer_name] [-m menu_name] [-x exclude_file]"

# # Site-specific definitions. # GN_ROOT=/pub/web # root of the web tree GN_LIB=/local/libexec/gn # where gn support files reside GN_MIMETYPES=/gn_mime.types # map of document content-types MKCACHE=/mkcache # path to "mkcache" command DFLT_XCLUDE=' *~' # default exclusion list to "eval"

# # Initialize. # Progname=`basename $0` menu_name="menu" # name of file to produce footer_name="menu.footer" # file to append as menu footer recurse=false # TRUE to recurse thru subdirs mkcache=false # TRUE to run "mkcache" when done xclude="" # list of glob patterns to exclude startdir= # where we are relative to GN_ROOT current_footer= # current footer file

# # Crack the command line. # set X `getopt "cd:f:m:rx:" $*` if [ $? -ne 0 ] ; then echo "" >&2 exit 1 fi shift while : ; do case "$1" in -c) mkcache=true ; shift ;; -d) startdir="$2" ; shift 2 ;; -f) footer_name="$2" ; shift 2 ;; -m) menu_name="$2" ; shift 2 ;; -r) recurse=true ; shift ;; -x) xclude=" $2" ; shift 2 ;; --) shift ; break ;; *) echo "" >&2 ; exit 1 ;; esac done if [ $# -ne 0 ] ; then echo "" >&2 exit 1 fi

# # Add in the standard things to the exclusion list. # eval xclude=\"\ \"

# # Build up a shell "case" command that we can "eval" to analyze the # selection specifed by "". This should "type" to the Gopher type # (or "SKIP" if the item should be excluded) and "content" to the MIME # Content-type for the item. # examine_item=" case \"\\" in `for x in ; do echo \") type=SKIP content= ;;\" ; done` `awk ' BEGIN {n = 0} /^#/ {next} NF == 3 {x[$2] = sprintf(\"*.%s) type=%s content=%s ;;\", $2, $1, $3)} END {for (ext in x) print x[ext]} ' ` *) type=0 content= ;; esac "

# # Figure out where we are relative to . This will *not* work # if there are any symlinks between us and , in which case # you'll need to use "-d" to specify the starting directory. # if [ "X" = "X" ] ; then startdir=`pwd` rootdir=`cd ; pwd` if [ "" = "" ] ; then startdir="." else startdir=`expr "" : "${rootdir}/\\(.*\\)"` fi fi

# # Build a banner to stuff at the top of the menu files. # u=${LOGNAME-${USER-"?unknown?"}} h=`( hostname || uuname -l || uname -n || echo "?oopsvax?" ) 2>/dev/null` banner="\ # Created by @ on `date` # with the \"$0\" command. "

mkmenu() { currdir=$1 echo ": building / ..." 1>&2

echo ""

# # See if there is a footer file in this directory. # We want to load it in now in case we recurse into subdirectories. # test -f "" && current_footer=//

# # Process all the entries in this directory. # for item in * ; do

# # Calculate the path to this item from GN_ROOT. # if [ "" = "." ] ; then p= else p=/ fi

# # Examine this item. # eval "" test "" = "SKIP" && continue if [ -d "" ] ; then type=1 content= title="Directory " && ( cd && mkmenu > ) else case "" in *.html) title=`sed -n -e '/<[Tt][Ii][Tt][Ll][Ee]>/{ s![ ][ ]*! !g s!.*<[Tt][Ii][Tt][Ll][Ee]> *!! s! *</[Tt][Ii][Tt][Ll][Ee]>.*!! p q }' ` ;; *) title= ;; esac fi

# # Emit the menu entry for item. # if [ "X" != "X" ] ; then echo "Hname=</A>" else echo "Name=" fi echo "Path=/" test "X" != "X" && echo "ContentType=" echo ""

done

# # See if there is a footer that should be added to the menu. # test -f "" && cat

}

mkmenu >

if ; then if ; then -m -r else -m fi fi