finished the heirloom shell workaround
[miscscripts.git] / readme2html
blob208aa3d4a5667703076fc856d5144b02a337c271
1 #!/bin/sh
3 script=`basename $0`
5 # Flags or not, if anyone else were to run this script, they'd want to change
6 # at least the first couple of these defaults and at least the header/prolog.
7 maintainer="slakmagik"
8 output=$HOME/Projects/website/readmes.html
9 date=`date "+%F %H:%M"`
11 usage() {
12 cat << EOF
13 $script: usage:
14 $script [-c location_of_sbopkg.conf] [-m MAINTAINER] [-o OUTPUT]
16 OUTPUT will be overwritten (if it exists) as $script generates an HTML
17 page composed of the READMEs of the SBo packages MAINTAINER maintains.
18 EOF
21 mp() {
22 find $lib -name '*.info' \
23 -exec grep -il '^MAINTAINER="'"$maintainer"'"' {} + |
24 sed "s:$lib/::;s:/[^/]*$::" | sort
27 while getopts :c:hm:o: opt; do
28 case $opt in
29 c) conf="$OPTARG" ;;
30 m) maintainer="$OPTARG" ;;
31 o) output="$OPTARG" ;;
32 h) usage; exit ;;
33 *) usage; exit 1;;
34 esac
35 done
36 shift `expr $OPTIND - 1`
38 if [ $# -ne 0 ]; then
39 usage
40 exit 1
43 # In order to allow the location of the sbopkg config file to be given as an
44 # argument, these assignments need to come after option processing. And, since
45 # lib and base_url depend on the conf file, they need to come after the final
46 # conf assignment and (attempted) eval of select lines. (If you did have a
47 # local repo and didn't use sbopkg, you'd need to do it differently.)
48 conf=${conf:-/etc/sbopkg/sbopkg.conf}
49 if [ -r $conf ]; then
50 eval `egrep '^REPO_(ROOT|NAME|BRANCH)=' $conf`
51 if [ -z "$REPO_ROOT" -o -z "$REPO_NAME" -o -z "$REPO_BRANCH" ]; then
52 echo "$script: $conf not valid." >&2
53 exit 1
55 else
56 cat << EOF >&2
57 $script: $conf not readable.
58 EOF
59 exit 1
61 lib=$REPO_ROOT/$REPO_NAME/$REPO_BRANCH
62 base_url=http://slackbuilds.org/repository/$REPO_BRANCH
64 touch $output 2>/dev/null
65 # if we can't create it, or if it previously existed but is unwriteable, stop
66 if [ $? -ne 0 ] || [ ! -w $output ]; then
67 echo "$script: couldn't write to $output" >&2
68 exit 1
71 pkgs="`mp`"
72 if [ -z "$pkgs" ]; then
73 echo "$script: maintainer \"$maintainer\" not found." >&2
74 rm $output
75 exit 1
78 # header/prolog
79 cat << EOF > $output
80 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
81 "http://www.w3.org/TR/html4/strict.dtd">
82 <link rel="stylesheet" type="text/css" href="current.css">
83 <title>$maintainer's SBo packages</title>
85 <pre>
86 This page is composed of the README files of the packages I maintain.
87 (The contents are mostly copied from the program documentation rather
88 than written by me.)
89 </pre>
91 EOF
93 # body
94 for f in $pkgs; do
96 echo "<h1 id=\"`basename $f`\"><a href=\"$base_url/$f/\">$f</a></h1>"
97 echo "<pre>"
98 cat $lib/$f/README | sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
99 echo "</pre>"
100 echo
101 ) >> $output
102 done
104 # footer
105 cat << EOF >> $output
106 <div id="footer">
107 <hr>
108 <a href="index.html">Home</a>
109 <hr>
110 Page created: 2010-04-28 23:30<br>
111 Last updated: $date
112 </div>