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