1 |
#!/bin/bash |
#!/bin/bash |
2 |
# $Id: mkinfodir,v 1.7 2005-06-01 15:48:42 niro Exp $ |
|
3 |
# Generate the top-level Info node, given a directory of Info files |
# Generate the top-level Info node, given a directory of Info files |
4 |
# and (optionally) a skeleton file. The output will be suitable for a |
# and (optionally) a skeleton file. The output will be suitable for a |
5 |
# top-level dir file. The skeleton file contains info topic names in the |
# top-level dir file. The skeleton file contains info topic names in the |
21 |
# modified 7 April 1995 by Joe Harrington <jh@tecate.gsfc.nasa.gov> to |
# modified 7 April 1995 by Joe Harrington <jh@tecate.gsfc.nasa.gov> to |
22 |
# take special flags |
# take special flags |
23 |
|
|
24 |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mkinfodir,v 1.7 2005-06-01 15:48:42 niro Exp $ |
# $Id$ |
25 |
|
|
26 |
INFODIR=$1 |
INFODIR="$1" |
27 |
if [ $# = 2 ] ; then |
if [[ $# = 2 ]] |
28 |
SKELETON=$2 |
then |
29 |
|
SKELETON="$2" |
30 |
else |
else |
31 |
SKELETON=/dev/null |
SKELETON="/dev/null" |
32 |
fi |
fi |
33 |
|
|
34 |
skip= |
skip= |
35 |
|
|
36 |
if [ $# -gt 2 ] ; then |
if [[ $# -gt 2 ]] |
37 |
echo usage: $0 info-directory [ skeleton-file ] 1>&2 |
then |
38 |
exit 1 |
echo "usage: $0 info-directory [ skeleton-file ]" 1>&2 |
39 |
elif [ -z "${INFODIR}" ] ; then |
exit 1 |
40 |
INFODIR="%%DEFAULT_INFO_DIR%%" |
elif [[ -z ${INFODIR} ]] |
41 |
else |
then |
42 |
true |
INFODIR="%%DEFAULT_INFO_DIR%%" |
43 |
|
else |
44 |
|
true |
45 |
fi |
fi |
46 |
|
|
47 |
if [ ! -d ${INFODIR} ] ; then |
if [[ ! -d ${INFODIR} ]] |
48 |
echo "$0: first argument must specify a directory" |
then |
49 |
exit 1 |
echo "$0: first argument must specify a directory" |
50 |
|
exit 1 |
51 |
|
fi |
52 |
|
|
53 |
|
# sanity checks |
54 |
|
for cmd in sed awk zcat ls grep egrep wc expr fgrep sort tr cut |
55 |
|
do |
56 |
|
if [[ -z $(type -P ${cmd}) ]] |
57 |
|
then |
58 |
|
echo "Command ${cmd} not found, not running $0" |
59 |
|
exit 1 |
60 |
|
fi |
61 |
|
done |
62 |
|
|
63 |
|
if [[ -x $(type -P date) ]] |
64 |
|
then |
65 |
|
_DATE="$(date)" |
66 |
|
else |
67 |
|
_DATE="unknown date" |
68 |
|
fi |
69 |
|
if [[ -x $(type -P whoami) ]] |
70 |
|
then |
71 |
|
_WHOAMI="$(whoami)" |
72 |
|
else |
73 |
|
if [[ -n ${USER} ]] |
74 |
|
then |
75 |
|
_WHOAMI="${USER}" |
76 |
|
else |
77 |
|
_WHOAMI="unknown user" |
78 |
|
fi |
79 |
|
fi |
80 |
|
if [[ -x $(type -P hostname) ]] |
81 |
|
then |
82 |
|
_HOSTNAME="$(hostname)" |
83 |
|
else |
84 |
|
if [[ -n ${HOSTNAME} ]] |
85 |
|
then |
86 |
|
_HOSTNAME="${HOSTNAME}" |
87 |
|
else |
88 |
|
_HOSTNAME="unknown hostname" |
89 |
|
fi |
90 |
|
fi |
91 |
|
if [[ -x $(type -P pwd) ]] |
92 |
|
then |
93 |
|
_PWD="$(cd ${INFODIR}; pwd)" |
94 |
|
else |
95 |
|
if [[ -n ${PWD} ]] |
96 |
|
then |
97 |
|
_PWD="$(cd ${INFODIR}; echo $PWD)" |
98 |
|
else |
99 |
|
_PWD="unknown directory" |
100 |
|
fi |
101 |
fi |
fi |
102 |
|
|
103 |
### output the dir header |
### output the dir header |
104 |
echo "-*- Text -*-" |
echo "-*- Text -*-" |
105 |
echo "This file was generated automatically by $0." |
echo "This file was generated automatically by $0." |
106 |
echo "This version was generated on `date`" |
echo "This version was generated on ${_DATE}" |
107 |
echo "by `whoami`@`hostname` for `(cd ${INFODIR}; pwd)`" |
echo "by ${_WHOAMI}@${_HOSTNAME} for ${_PWD}" |
108 |
|
|
109 |
cat << moobler |
cat << moobler |
110 |
\$Id: mkinfodir,v 1.7 2005-06-01 15:48:42 niro Exp $ |
|
111 |
This is the file .../info/dir, which contains the topmost node of the |
This is the file .../info/dir, which contains the topmost node of the |
112 |
Info hierarchy. The first time you invoke Info you start off |
Info hierarchy. The first time you invoke Info you start off |
113 |
looking at that node, which is (dir)Top. |
looking at that node, which is (dir)Top. |
114 |
|
|
115 |
File: dir Node: Top This is the top of the INFO tree |
File: dir Node: Top This is the top of the INFO tree |
116 |
|
|
117 |
This (the Directory node) gives a menu of major topics. |
This (the Directory node) gives a menu of major topics. |
135 |
### then generate entries for those in the same way, putting the info for |
### then generate entries for those in the same way, putting the info for |
136 |
### those at the end.... |
### those at the end.... |
137 |
|
|
138 |
infofiles=`(cd ${INFODIR}; /bin/ls | grep -v '\-[0-9]*\.gz$' | grep -v '\-[0-9]*$' | egrep -v '^dir$|^dir\.info$|^dir\.orig$')` |
infofiles=$(cd ${INFODIR}; /bin/ls | grep -v '\-[0-9]*\.gz$' | grep -v '\-[0-9]*$' | egrep -v '^dir$|^dir\.info$|^dir\.orig$') |
139 |
|
|
140 |
# echoing gets clobbered by backquotes; we do it the hard way... |
# echoing gets clobbered by backquotes; we do it the hard way... |
141 |
lines=`wc $SKELETON | awk '{print $1}'` |
lines=$(wc ${SKELETON} | awk '{print $1}') |
142 |
line=1 |
line=1 |
143 |
while [ $lines -ge $line ] ; do |
while [ ${lines} -ge ${line} ] |
144 |
# Read one line from the file. This is so that we can echo lines with |
do |
145 |
# whitespace and quoted characters in them. |
# Read one line from the file. This is so that we can echo lines with |
146 |
fileline=`awk NR==$line $SKELETON` |
# whitespace and quoted characters in them. |
147 |
|
fileline=$(awk NR==${line} ${SKELETON}) |
148 |
# flag fancy features |
|
149 |
if [ ! -z "$echoline" ] ; then # echo line |
# flag fancy features |
150 |
echo "$fileline" |
if [[ ! -z ${echoline} ]] |
151 |
fileline= |
then |
152 |
echoline= |
# echo line |
153 |
elif [ "${fileline}" = "--" ] ; then # should we echo the next line? |
echo "${fileline}" |
154 |
echoline=1 |
fileline= |
155 |
elif [ "${fileline}" = "%%" ] ; then # eliminate remaining files from dir? |
echoline= |
156 |
skip=1 |
elif [ "${fileline}" = "--" ] |
157 |
elif [ "${fileline}" = "!!" ] ; then # quit now |
then |
158 |
exit 0 |
# should we echo the next line? |
159 |
fi |
echoline=1 |
160 |
|
elif [ "${fileline}" = "%%" ] |
161 |
# handle files if they exist |
then |
162 |
for file in $fileline"" ; do # expand wildcards ("" handles blank lines) |
# eliminate remaining files from dir? |
163 |
|
skip=1 |
164 |
fname= |
elif [ "${fileline}" = "!!" ] |
165 |
|
then |
166 |
if [ -z "$echoline" -a ! -z "$file" ] ; then |
# quit now |
167 |
|
exit 0 |
168 |
# Find the file to operate upon. Check both possible names. |
fi |
169 |
infoname=`echo $file | sed 's/\.gz$//'` |
|
170 |
infoname=`echo $infoname | sed 's/\.info$//'` |
# handle files if they exist |
171 |
noext= |
for file in ${fileline}"" |
172 |
ext= |
do |
173 |
if [ -f ${INFODIR}/$infoname ] ; then |
# expand wildcards ("" handles blank lines) |
174 |
noext=$infoname |
fname= |
175 |
fi |
if [[ -z ${echoline} ]] && [[ -n ${file} ]] |
176 |
if [ -f ${INFODIR}/${infoname}.info ] ; then |
then |
177 |
ext=${infoname}.info |
# Find the file to operate upon. Check both possible names. |
178 |
fi |
infoname=$(echo ${file} | sed 's/\.gz$//') |
179 |
if [ -f ${INFODIR}/${infoname}.info.gz ] ; then |
infoname=$(echo ${infoname} | sed 's/\.info$//') |
180 |
ext=${infoname}.info.gz |
noext= |
181 |
fi |
ext= |
182 |
# If it exists with both names take what was said in the file. |
if [ -f ${INFODIR}/${infoname} ] |
183 |
if [ ! -z "$ext" -a ! -z "$noext" ]; then |
then |
184 |
fname=$file |
noext="${infoname}" |
185 |
warn="### Warning: $ext and $noext both exist! Using ${file}. ###" |
fi |
186 |
elif [ ! \( -z "$ext" -a -z "$noext" \) ]; then |
if [ -f ${INFODIR}/${infoname}.info ] |
187 |
# just take the name if it exists only once |
then |
188 |
fname=${noext}${ext} |
ext="${infoname}.info" |
189 |
fi |
fi |
190 |
|
if [ -f ${INFODIR}/${infoname}.info.gz ] |
191 |
# if we found something and aren't skipping, do the entry |
then |
192 |
if [ ! -z "$fname" ] ; then |
ext="${infoname}.info.gz" |
193 |
if [ -z "$skip" ] ; then |
fi |
194 |
|
# If it exists with both names take what was said in the file. |
195 |
if [ ! -z "$warn" ] ; then # issue any warning |
if [[ -n ${ext} ]] && [[ -n ${noext} ]] |
196 |
echo $warn |
then |
197 |
warn= |
fname="${file}" |
198 |
fi |
warn="### Warning: $ext and $noext both exist! Using ${file}. ###" |
199 |
if [ "${fname##*.}" = "gz" ] ; then |
elif [ ! \( -z "$ext" -a -z "$noext" \) ] |
200 |
entry=`zcat ${INFODIR}/${fname} | sed -e '1,/START-INFO-DIR-ENTRY/d' \ |
then |
201 |
-e '/END-INFO-DIR-ENTRY/,$d' ` |
# just take the name if it exists only once |
202 |
else |
fname=${noext}${ext} |
203 |
entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \ |
fi |
204 |
-e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$fname` |
# if we found something and aren't skipping, do the entry |
205 |
fi |
if [[ -n ${fname} ]] |
206 |
if [ ! -z "${entry}" ] ; then |
then |
207 |
echo "${entry}" |
if [[ -z ${skip} ]] |
208 |
else |
then |
209 |
echo "* ${infoname}: (${infoname})." |
if [ -n ${warn} ]] |
210 |
fi |
then |
211 |
fi |
# issue any warning |
212 |
|
echo "${warn}" |
213 |
# remove the name from the directory listing |
warn= |
214 |
infofiles=`echo "" ${infofiles} "" | sed -e "s/ ${fname} / /" -e "s/ / /g"` |
fi |
215 |
|
if [[ ${fname##*.} = gz ]] |
216 |
fi |
then |
217 |
|
entry=$(zcat ${INFODIR}/${fname} | sed -e '1,/START-INFO-DIR-ENTRY/d' -e '/END-INFO-DIR-ENTRY/,$d') |
218 |
fi |
else |
219 |
|
entry=$(sed -e '1,/START-INFO-DIR-ENTRY/d' -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/${fname}) |
220 |
done |
fi |
221 |
|
if [[ -n ${entry} ]] |
222 |
line=`expr $line + 1` |
then |
223 |
|
echo "${entry}" |
224 |
|
else |
225 |
|
echo "* ${infoname}: (${infoname})." |
226 |
|
fi |
227 |
|
fi |
228 |
|
# remove the name from the directory listing |
229 |
|
infofiles=$(echo "" ${infofiles} "" | sed -e "s/ ${fname} / /" -e "s/ / /g") |
230 |
|
fi |
231 |
|
fi |
232 |
|
done |
233 |
|
line=$(expr $line + 1) |
234 |
done |
done |
235 |
|
|
236 |
if [ -z "${infofiles}" ] ; then |
if [[ -z ${infofiles} ]] |
237 |
exit 0 |
then |
238 |
elif [ $lines -gt 0 ]; then |
exit 0 |
239 |
echo |
elif [[ ${lines} -gt 0 ]] |
240 |
|
then |
241 |
|
echo |
242 |
fi |
fi |
243 |
|
|
244 |
# Sort remaining files by INFO-DIR-SECTION. |
# Sort remaining files by INFO-DIR-SECTION. |
245 |
prevsect= |
prevsect= |
246 |
filesectdata=`(cd ${INFODIR}; fgrep INFO-DIR-SECTION /dev/null ${infofiles} | \ |
filesectdata=$(cd ${INFODIR}; fgrep INFO-DIR-SECTION /dev/null ${infofiles} | fgrep -v 'INFO-DIR-SECTION Miscellaneous' | sort -t: -k2 -k1 | tr ' ' '_') |
247 |
fgrep -v 'INFO-DIR-SECTION Miscellaneous' | \ |
for sectdata in ${filesectdata} |
248 |
sort -t: -k2 -k1 | tr ' ' '_')` |
do |
249 |
for sectdata in ${filesectdata}; do |
file=$(echo ${sectdata} | cut -d: -f1) |
250 |
file=`echo ${sectdata} | cut -d: -f1` |
section=$(sed -n -e 's/^INFO-DIR-SECTION //p' ${INFODIR}/${file}) |
251 |
section=`sed -n -e 's/^INFO-DIR-SECTION //p' ${INFODIR}/${file}` |
infofiles=$(echo "" ${infofiles} "" | sed -e "s/ ${file} / /" -e "s/ / /g") |
252 |
infofiles=`echo "" ${infofiles} "" | sed -e "s/ ${file} / /" -e "s/ / /g"` |
if [[ ${prevsect} != ${section} ]] |
253 |
|
then |
254 |
if [ "${prevsect}" != "${section}" ] ; then |
if [[ -n ${prevsect} ]] |
255 |
if [ ! -z "${prevsect}" ] ; then |
then |
256 |
echo "" |
echo "" |
257 |
fi |
fi |
258 |
echo "${section}" |
echo "${section}" |
259 |
prevsect="${section}" |
prevsect="${section}" |
260 |
fi |
fi |
261 |
infoname=`echo $file | sed 's/\.gz$//'` |
infoname=$(echo ${file} | sed 's/\.gz$//') |
262 |
infoname=`echo $infoname | sed 's/\.info$//'` |
infoname=$(echo ${infoname} | sed 's/\.info$//') |
263 |
if [ "${file##*.}" = "gz" ] ; then |
if [[ ${file##*.} = gz ]] |
264 |
entry=`zcat ${INFODIR}/$file | sed -e '1,/START-INFO-DIR-ENTRY/d' \ |
then |
265 |
-e '/END-INFO-DIR-ENTRY/,$d' ` |
entry=$(zcat ${INFODIR}/${file} | sed -e '1,/START-INFO-DIR-ENTRY/d' -e '/END-INFO-DIR-ENTRY/,$d') |
266 |
else |
else |
267 |
entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \ |
entry=$(sed -e '1,/START-INFO-DIR-ENTRY/d' -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/${file}) |
268 |
-e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$file` |
fi |
269 |
fi |
if [[ -n ${entry} ]] |
270 |
if [ ! -z "${entry}" ] ; then |
then |
271 |
echo "${entry}" |
echo "${entry}" |
272 |
elif [ ! -d "${INFODIR}/${file}" ] ; then |
elif [[ ! -d ${INFODIR}/${file} ]] |
273 |
echo "* ${infoname}: (${infoname})." |
then |
274 |
fi |
echo "* ${infoname}: (${infoname})." |
275 |
|
fi |
276 |
done |
done |
277 |
|
|
278 |
# Process miscellaneous files. |
# Process miscellaneous files. |
279 |
for file in ${infofiles}; do |
for file in ${infofiles} |
280 |
if [ ! -z "${prevsect}" ] ; then |
do |
281 |
echo "" |
if [[ -n ${prevsect} ]] |
282 |
echo "Miscellaneous" |
then |
283 |
prevsect="" |
echo "" |
284 |
fi |
echo "Miscellaneous" |
285 |
|
prevsect="" |
286 |
infoname=`echo $file | sed 's/\.gz$//'` |
fi |
287 |
infoname=`echo $infoname | sed 's/\.info$//'` |
|
288 |
if [ "${file##*.}" = "gz" ] ; then |
infoname=$(echo ${file} | sed 's/\.gz$//') |
289 |
entry=`zcat ${INFODIR}/${file} | sed -e '1,/START-INFO-DIR-ENTRY/d' \ |
infoname=$(echo ${infoname} | sed 's/\.info$//') |
290 |
-e '/END-INFO-DIR-ENTRY/,$d'` |
if [[ ${file##*.} = gz ]] |
291 |
else |
then |
292 |
entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \ |
entry=$(zcat ${INFODIR}/${file} | sed -e '1,/START-INFO-DIR-ENTRY/d' -e '/END-INFO-DIR-ENTRY/,$d') |
293 |
-e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$file` |
else |
294 |
fi |
entry=$(sed -e '1,/START-INFO-DIR-ENTRY/d' -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/${file}) |
295 |
|
fi |
296 |
|
|
297 |
if [ ! -z "${entry}" ] ; then |
if [[ -n ${entry} ]] |
298 |
echo "${entry}" |
then |
299 |
elif [ ! -d "${INFODIR}/${file}" ] ; then |
echo "${entry}" |
300 |
echo "* ${infoname}: (${infoname})." |
elif [[ ! -d ${INFODIR}/${file} ]] |
301 |
fi |
then |
302 |
|
echo "* ${infoname}: (${infoname})." |
303 |
|
fi |
304 |
done |
done |
|
|
|