head 1.6; access; symbols; locks ids:1.6; strict; comment @# @; 1.6 date 2007.10.01.19.34.52; author ids; state Exp; branches; next 1.5; 1.5 date 2000.10.21.19.55.12; author ids; state Exp; branches; next 1.4; 1.4 date 99.04.22.21.23.12; author ids; state Exp; branches; next 1.3; 1.3 date 98.10.22.11.34.01; author ids; state Exp; branches; next 1.2; 1.2 date 98.07.31.14.37.26; author ids; state Exp; branches; next 1.1; 1.1 date 98.07.19.20.32.10; author ids; state Exp; branches; next ; desc @@ 1.6 log @"-html" -> "--html" as flag syntax. @ text @#!/bin/sh - # # find_RCS_dirs_and_files_for_web: # finds all the RCS directories, and files therein, which would be shown # in the "directory listing" web pages for my home directory # and its various sub-directories, were it not for the fact # that the current DoC server setup is to suppress # RCS directories and files from such listings. # # usage: find_RCS_dirs_and_files_for_web [--html] # # Writes to the standard output. # # The RCS directories and files are given as relative pathnames from the # "gateway directory". Since they're not necessarily all actually # reachable from the gateway directory # (some being in public_html/ itself), # we have to traverse the directory structure from "..". # But (Gordon Bennett!!), to avoid going down the forbidden gateway # name "realdotdot" and getting an infinite recursion in the traversal, # we have to parse the forbidden gateway name away. # Hence the rather complicated traversal arrangements. So now you know! # # Output format *without* --html flag is like this (per directory): # RCS-dir-as-relative-pathname-from-gateway-directory [NEWLINE] # [TAB] file-therein-as-ditto [NEWLINE] # [TAB] file-therein-as-ditto [NEWLINE] # [TAB] (etc, for each file therein) [NEWLINE] # # Output format *with* --html flag is like this (per directory, and with # the pathnames massaged at least passably into "URL syntax"): #
  • # [RCS-dir-as-relative-pathname-from-gateway-directory] # [NEWLINE] # [TAB] [NEWLINE] #
  • [NEWLINE] # # It's best to run this as someone else, e.g. a test account, # so that only RCS directories and files whose presence is # actually visible on the web are reported. # The environment variable $USER is used to determine who we're scanning # for RCS directories and files of. # progname=`basename $0` gateway_dir="/homes/$USER/public_html/dotdot" forbidden_gateway_name="realdotdot" # # argument checking # html_flag="$*" if [ "x$html_flag" != "x" -a "x$html_flag" != "x--html" ]; then echo "usage: $progname [--html]" >&2 exit 1 fi # # do we have a gateway directory in the expected location? # cd "$gateway_dir" # # Amazingly, on our Linux and FreeBSD machines, the Bourne shell # "cd" command doesn't cause exit on failure - it just barges on! # Naturally, all hell can break loose in a shell script which is # in a different directory from where it thinks it is. # So, to avoid such chaos, we check explicitly for failure here. # if [ $? -ne 0 ]; then echo "$progname: no gateway dir '$gateway_dir', exiting" >&2 exit 1 fi # # OK, now do a recursive listing, and extract things that look like # RCS directories. (yeah, not an ideal method, I know!) # # The "ls -ARFL $potential_dirs_to_traverse" below *will* catch "../RCS" # (if it exists) and report it as "../RCS:" in its output, # just as we want it to. One might worry that "../RCS" might be the only # item in $potential_dirs_to_traverse, causing ls to behave differently # (ls doesn't report the name of a directory when the directory is # the only argument); # but in fact that can't happen, since the gateway directory itself # will be an item in $potential_dirs_to_traverse as well. # (And a good thing too, since the traversal of the gateway directory # is likely to provide the great bulk of the output!) # potential_dirs_to_traverse=`ls -A .. | sed -e '/^'$forbidden_gateway_name'$/d' -e 's|^|../|'` gateway_dir_basename=`basename $gateway_dir` RCS_dirs=`ls -ARFL $potential_dirs_to_traverse | egrep '^RCS:$|^.*/RCS:$' | sed -e 's|:$|/|' -e 's|^../'$gateway_dir_basename'/||'` # # Now produce appropriate output from this list of RCS directories. # if [ "x$html_flag" = "x" ]; then #plain output for RCS_dir in $RCS_dirs ; do files_therein=`ls -A $RCS_dir` echo "$RCS_dir" for file_therein in $files_therein ; do echo " $RCS_dir$file_therein" done #for file_therein done #for RCS_dir elif [ "x$html_flag" = "x--html" ]; then #fancy html output for RCS_dir in $RCS_dirs ; do files_therein=`ls -A $RCS_dir` RCS_dir_as_URL=`echo $RCS_dir | sed -e 's/%/%25/g' -e 's/+/%2B/g' -e 's/ /%20/g' -e 's/"/%22/g'` echo "
  • $RCS_dir_as_URL" echo " " echo "
  • " done #for RCS_dir else #something's gone awfully wrong! echo "$progname: fatal error with flow of control, exiting" >&2 exit 1 fi @ 1.5 log @we now deal with the business of hyperlinking explicitly to, not just RCS directories, but the files therein too: the current DoC server setup now suppresses RCS files too from "directory listing" web pages. Plus: * massaging of pathnames at least passably into "URL syntax" is now done only if the "-html" flag has been given * layout and comment improvements. @ text @d10 1 a10 1 # usage: find_RCS_dirs_and_files_for_web [-html] d24 1 a24 1 # Output format *without* -html flag is like this (per directory): d30 1 a30 1 # Output format *with* -html flag is like this (per directory, and with d59 2 a60 2 if [ "x$html_flag" != "x" -a "x$html_flag" != "x-html" ]; then echo "usage: $progname [-html]" >&2 d113 1 a113 1 elif [ "x$html_flag" = "x-html" ]; then #fancy html output @ 1.4 log @bloody hell! we need to change things like if [ "$" = "" ]; then to: if [ "x$" = "x" ]; then (or analogous changes which achieve the same protective goal) now that our current Linux version of "test", alias "[", has become too clever by half and allows (quote from manual page) "the special expression `-l STRING', which evaluates to the length of STRING". (If $ in the unprotected example above happens to be "-l", the next argument ("=" above) is taken to be a string whose length is to be measured, and the parsing gets totally screwed up.) [Note: in some files being dealt with in this checking-in, this revision message is essentially the same as in one or more previous revision(s). That's simply because I missed a few cases first time(s) round!] @ text @d3 2 a4 2 # find_RCS_dirs_for_web: # finds all the RCS directories which would be shown d8 1 a8 1 # RCS directories from such listings. d10 1 a10 1 # usage: find_RCS_dirs_for_web [-html] d14 1 a14 1 # The directories are given as relative pathnames from the d24 20 a43 7 # Output format *without* -html flag is one entry per line, like this: # relative-pathname-from-gateway-directory [NEWLINE]. # # Output format *with* -html flag is one entry per line, like this: #
  • # [relative-pathname-from-gateway-directory] #
  • [NEWLINE]. d46 2 a47 1 # so that only RCS directories actually visible on the web are reported. d49 1 a49 1 # for RCS directories of. a82 1 # We also massage them into a form suitable for giving as URLs. d97 1 a97 1 RCS_dirs=`ls -ARFL $potential_dirs_to_traverse | egrep '^RCS:$|^.*/RCS:$' | sed -e 's|:$|/|' -e 's|^../'$gateway_dir_basename'/||' -e 's/%/%25/g' -e 's/+/%2B/g' -e 's/ /%20/g' -e 's/"/%22/g'` d103 1 d105 2 d108 3 d112 1 d114 1 d116 11 a126 1 echo "
  • $RCS_dir
  • " d128 1 d130 1 d133 1 @ 1.3 log @whoops! the search process wasn't truly comprehensive when run purely from the gateway directory. I've now beefed it up. Here's the comment explaining the new regime. > # The directories are given as relative pathnames from the > # "gateway directory". Since they're not necessarily all actually > # reachable from the gateway directory > # (some being in public_html/ itself), > # we have to traverse the directory structure from "..". > # But (Gordon Bennett!!), to avoid going down the forbidden gateway > # name "realdotdot" and getting an infinite recursion in the traversal, > # we have to parse the forbidden gateway name away. > # Hence the rather complicated traversal arrangements. So now you know! @ text @d45 1 a45 1 if [ "$html_flag" != "" -a "$html_flag" != "-html" ]; then d89 1 a89 1 if [ "$html_flag" = "" ]; then #plain output d93 1 a93 1 elif [ "$html_flag" = "-html" ]; then #fancy html output @ 1.2 log @added comment explaining explicit exit status check on cd: # # Amazingly, on our Linux and FreeBSD machines, the Bourne shell # "cd" command doesn't cause exit on failure - it just barges on! # Naturally, all hell can break loose in a shell script which is # in a different directory from where it thinks it is. # So, to avoid such chaos, we check explicitly for failure here. # @ text @d14 10 d38 2 a52 1 gateway_dir="/homes/$USER/public_html/dotdot" d71 14 a84 1 RCS_dirs=`ls -aRFL | egrep '^RCS:$|^.*/RCS:$' | sed -e 's|:$|/|' -e 's/%/%25/g' -e 's/+/%2B/g' -e 's/ /%20/g' -e 's/"/%22/g'` @ 1.1 log @Initial revision @ text @d43 7 @