script to dynamically generate the hints list
olivier.peres at laposte.net
Sat Sep 13 02:22:37 PDT 2003
Here it is. I tried to conform to the specs, with the addition of error
messages (to stderr, not to the html file) in case information to be extracted
is missing. It seems to work on my system, tell me if it crashes on yours...
Note: I cut my lines to 80 characters so it should work, but if copy-pasting
the script is a problem for you I can resend it as an attachment or upload it to
-- beginning of file: genlist.sh --
# Script to automatically generate a list of LFS hints
# by Olivier Pérès (Olivier Peres if your terminal cannot print accents)
# email: olivier dot peres at laposte dot net
# Last updated September 13th, 2003
# License: GPL.
# Usage: copy it to the directory that contains the hints/ subdirectory and
# run it. If you want to run it from somewhere else, the easiest way is to
# edit the cd command, below.
# * hint file names must not contain colons, spaces, or any control characters.
# That wasn't in the specs...
# * I noticed information is missing from a few hints supposedly in the new
# format, so I added messages on stderr to report missing fields. I think
# that makes sense since they are mandatory, so their absence is a bug in
# the hint file. If you don't want them, comment out the echo line in the
# check_and_report function.
# the simplest way to handle paths properly is to work in the hints/ directory.
if [ -d hints ]
echo "Error - no hints/ subdirectory" >> /dev/stderr
# the file to which to write
# echoes its argument to OUTPUTFILE
echo $1 >> $OUTPUTFILE
# replaces '<' and '>' with the corresponding entities so that they
# can appear in documents (useful for the authors' email addresses).
echo `echo $1 | sed -e 's/>/\>/' -e 's/</\</'`
# reports an error message if a field is empty
# (but continues processing as it is not a fatal error)
if [ -z "$1" ]
echo "hint "`basename $2 .txt`": missing "$3 >> /dev/stderr
# DATEDHINTS = list of all the files that contain a DATE
# in reverse chronological order.
DATEDHINTS=`grep -H "DATE:" files/* | sort -fbi -r -k3 -t: | cut -f1 -d:`
# UNDATEDHINTS = list of all the files that do *not* contain a DATE.
UNDATEDHINTS=`grep -LH "DATE:" files/*`
# initialise output file
echo "" > $OUTPUTFILE # create it if it didn't exist and empty it.
output "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"
output "<TITLE>Linux From Scratch Hints list</TITLE>"
# write hints
for HINT in $DATEDHINTS $UNDATEDHINTS
DATE=`echo \`grep -h "DATE:" $HINT | cut -f2 -d:\``
SYNOPSIS=`echo \`grep -h "SYNOPSIS:" $HINT | cut -f2 -d:\``
AUTHORS=`echo \`grep "AUTHOR:" $HINT | \
cut -f2 -d: | sed 's/$/,/'\` | sed 's/,$//'`
LICENSE=`echo \`grep -h "LICENSE:" $HINT | cut -f2 -d:\``
check_and_report "$DATE" $HINT "date"
check_and_report "$SYNOPSIS" $HINT "synopsis"
check_and_report "$AUTHORS" $HINT "authors"
check_and_report "$LICENSE" $HINT "license"
# if the synopsis is missing we have to do something about it
# (otherwise there will be no usable link to it in the web page!)
if [ -z "$SYNOPSIS" ]
SYNOPSIS=`basename $HINT .txt`
output "<LI><H4><A HREF=\"$HINT\">$SYNOPSIS</A></H4>"
output "<DD>`htmlclean "$AUTHORS"`</DD>"
output "<DT>Date Last Updated:</DT>"
# finalise output file
-- end of file --
More information about the website