1 1.1 christos #!@BASH@ 2 1.1 christos # Id: install-info-html,v 1.3 2004/04/11 17:56:47 karl Exp 3 1.1 christos 4 1.1 christos name=install-info-html 5 1.1 christos version=1.0 6 1.1 christos 7 1.1 christos all= 8 1.1 christos index_dir=. 9 1.1 christos 10 1.1 christos # 11 1.1 christos # debugging 12 1.1 christos # 13 1.1 christos debug_echo=: 14 1.1 christos 15 1.1 christos 16 1.1 christos # 17 1.1 christos # print usage 18 1.1 christos # 19 1.1 christos function help () 20 1.1 christos { 21 1.1 christos cat << EOF 22 1.1 christos $name $version 23 1.1 christos Install HTML info document. 24 1.1 christos 25 1.1 christos Usage: $name [OPTION]... [DOCUMENT-DIR]... 26 1.1 christos 27 1.1 christos Options: 28 1.1 christos -a,--all assume all subdirectories of index to be DOCUMENT-DIRs 29 1.1 christos -d,--dir=DIR set index directory to DIR (default=.) 30 1.1 christos -D,--debug print debugging info 31 1.1 christos -h,--help this help text 32 1.1 christos -v,--version show version 33 1.1 christos EOF 34 1.1 christos } 35 1.1 christos 36 1.1 christos 37 1.1 christos function cleanup () 38 1.1 christos { 39 1.1 christos $debug_echo "cleaning ($?)..." 40 1.1 christos } 41 1.1 christos 42 1.1 christos trap cleanup 0 9 15 43 1.1 christos 44 1.1 christos # 45 1.1 christos # Find command line options and switches 46 1.1 christos # 47 1.1 christos 48 1.1 christos # "x:" x takes argument 49 1.1 christos # 50 1.1 christos options="adhvW:" 51 1.1 christos # 52 1.1 christos # ugh, "\-" is a hack to support long options 53 1.1 christos # must be in double quotes for bash-2.0 54 1.1 christos 55 1.1 christos while getopts "\-:$options" O 56 1.1 christos do 57 1.1 christos $debug_echo "O: \`$O'" 58 1.1 christos $debug_echo "arg: \`$OPTARG'" 59 1.1 christos case $O in 60 1.1 christos a) 61 1.1 christos all=yes 62 1.1 christos ;; 63 1.1 christos D) 64 1.1 christos [ "$debug_echo" = "echo" ] && set -x 65 1.1 christos debug_echo=echo 66 1.1 christos ;; 67 1.1 christos h) 68 1.1 christos help; 69 1.1 christos exit 0 70 1.1 christos ;; 71 1.1 christos v) 72 1.1 christos echo $name $version 73 1.1 christos exit 0 74 1.1 christos ;; 75 1.1 christos d) 76 1.1 christos index_dir=$OPTARG 77 1.1 christos ;; 78 1.1 christos # a long option! 79 1.1 christos -) 80 1.1 christos case "$OPTARG" in 81 1.1 christos a*|-a*) 82 1.1 christos all=yes 83 1.1 christos ;; 84 1.1 christos de*|-de*) 85 1.1 christos [ "$debug_echo" = "echo" ] && set -x 86 1.1 christos debug_echo=echo 87 1.1 christos ;; 88 1.1 christos h*|-h*) 89 1.1 christos help; 90 1.1 christos exit 0 91 1.1 christos ;; 92 1.1 christos di*|-di*) 93 1.1 christos index_dir="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`" 94 1.1 christos ;; 95 1.1 christos version|-version) 96 1.1 christos echo $name $version 97 1.1 christos exit 0 98 1.1 christos ;; 99 1.1 christos *|-*) 100 1.1 christos echo "$0: invalid option -- \"$OPTARG\"" 101 1.1 christos help; 102 1.1 christos exit -1 103 1.1 christos ;; 104 1.1 christos esac 105 1.1 christos esac 106 1.1 christos done 107 1.1 christos shift `expr $OPTIND - 1` 108 1.1 christos 109 1.1 christos # 110 1.1 christos # Input file name 111 1.1 christos # 112 1.1 christos if [ -z "$all" ] && [ -z "$1" ]; then 113 1.1 christos help 114 1.1 christos echo "$name: No HTML documents given" 115 1.1 christos exit 2 116 1.1 christos fi 117 1.1 christos 118 1.1 christos if [ -n "$all" ] && [ -n "$1" ]; then 119 1.1 christos echo "$name: --all specified, ignoring DIRECTORY-DIRs" 120 1.1 christos fi 121 1.1 christos 122 1.1 christos if [ -n "$all" ]; then 123 1.1 christos document_dirs=`/bin/ls -d1 $index_dir` 124 1.1 christos else 125 1.1 christos document_dirs=$* 126 1.1 christos fi 127 1.1 christos 128 1.1 christos index_file=$index_dir/index.html 129 1.1 christos rm -f $index_file 130 1.1 christos echo -n "$name: Writing index: $index_file..." 131 1.1 christos 132 1.1 christos # head 133 1.1 christos cat >> $index_file <<EOF 134 1.1 christos <html> 135 1.1 christos <head><title>Info documentation index</title></head> 136 1.1 christos <body> 137 1.1 christos <h1>Info documentation index</h1> 138 1.1 christos This is the directory file \`index.html' a.k.a. \`DIR', which contains the 139 1.1 christos topmost node of the HTML Info hierarchy. 140 1.1 christos <p> 141 1.1 christos This is all very much Work in Progress (WiP). 142 1.1 christos <p> 143 1.1 christos <ul> 144 1.1 christos EOF 145 1.1 christos 146 1.1 christos #list 147 1.1 christos for i in $document_dirs; do 148 1.1 christos echo "<li> <a href=\"$i/$i.html\">$i</a></li>" 149 1.1 christos done >> $index_file 150 1.1 christos 151 1.1 christos # foot 152 1.1 christos cat >> $index_file <<EOF 153 1.1 christos </ul> 154 1.1 christos </body> 155 1.1 christos </html> 156 1.1 christos EOF 157 1.1 christos echo 158