#!/bin/sh - # # Shell script for FreeBSD (requires fetch, lynx or mget). # # It downloads the current directory of HTML docs for NetPBM # and converts them to text files suitable as "cat" pages. # They're stored in the current directory. Therefore, # please run this script in a separate directory that's not # writable for anybody else. Also, there's no reason to run # this script as root. # # As an admin, jst move the files to /usr/local/man/cat1. # # As a normal user, create a directory man/cat1 in your # home directory and move the files there (you might have # to add $HOME/man to your MANPATH environment variable # so the man command finds them). # # Copyright (C) 2006-2007 by Oliver Fromme, Munich, Germany # All rights reserved. Contact: olli@fromme.com # Standard 2-clause BSD license and disclaimer applies. # set -Cefu unset LC_CTYPE LC_ALL LANG COMPRESS=true HEAD="NetPBM Manual" BASE_URL="http://netpbm.sourceforge.net/doc" FETCH="fetch -q -o -" # FETCH="lynx -source" # FETCH="mget" rm -f tmp.html Tagline() { CENTER="$1" TAG="$2" SPACE=$(( (79 - ${#CENTER}) / 2 )) printf '%-*s%s%*s\n' $SPACE "$TAG" "$CENTER" $SPACE "$TAG" } $FETCH "$BASE_URL"/directory.html \ | tr '<\n' '\n ' \ | sed -n 's/^[]*[Aa][ ][ ]*[Hh][Rr][Ee][Ff]=["'\'']*//p' \ | sed 's/["'\''> ].*$//' \ | sort -u \ | while read PAGE; do case "$PAGE" in '#'*) continue ;; esac NAME="${PAGE%.html}" if [ -f "$NAME".1 -o -f "$NAME".1.gz ]; then echo "File ${NAME}.1[.gz] already exists, skipping!" >&2 continue fi UPNAME=$(echo "$NAME" | tr '[a-z]' '[A-Z]') if ! $FETCH "$BASE_URL/$PAGE" > tmp.html ; then echo "Cannot fetch $PAGE, skipping!" >&2 rm -f tmp.html continue fi DATE=$( egrep '(Updated|Created):' tmp.html \ | head -1 \ | sed 's/^.*[UC][pr][de]ated:[ ]*//;s/<.*$//' ) ( Tagline "$HEAD" "${UPNAME}(1)" if grep -q '[Hh][Rr][Ee][Ff].*Table Of Contents' tmp.html; then STOP="Table Of Contents" else STOP="<[Bb][Rr]>" fi sed '/<[Hh][Rr]>/,$d' tmp.html \ | sed '/<[Hh]1>/,/'"$STOP"'/d' \ | lynx -dump -nolist -force_html -with_backspaces /dev/stdin echo "" Tagline "$DATE" "NetPBM" ) \ | unexpand -a \ | cat -s > "$NAME".1 if $COMPRESS; then gzip -9 "$NAME".1 ls -l "$NAME".1.gz else ls -l "$NAME".1 fi rm tmp.html done #--