#! /bin/tcsh -f ###################################################################### # This script prepares a list of files in the website's zip archive. # # Two .html files are involved: one with a list of the # latest $theCount (typically 25) files and one with a list of all the files. # # jtb 050601 # Previous versions of this script generated the file lists from html # templates. This version edits previously existing html files, inserting # the updated info into the file. This eliminates the need for template # files. I also eliminated the proliferating 'sed' scripts, and let 'ed' # do the editing instead. # ###################################################################### # Abort if the env variables aren't set set me=${0} if (! ${?HTML_DIR}) then echo ${me}: HTML_DIR environment variable not set\! exit else if (! ${?ZIP_DIR}) then echo ${me}: ZIP_DIR environment variable not set\! exit endif set theCount = 25 # number of files to include in the short file list set theBulkFile = $ZIP_DIR/bulk/bulk.zip # the "bulk download" file set shortFilesList = $HTML_DIR/tech/download/newfiles.html set allFilesList = $HTML_DIR/tech/download/allfiles.html # some tmp files set tmpFile_0 = ~/tmp/${me:t}.tmp0 set tmpFile_1 = ~/tmp/${me:t}.tmp1 set tmpFile_2 = ~/tmp/${me:t}.tmp2 set tmpFile_3 = ~/tmp/${me:t}.tmp3 # Use 'ed' to cosmeticize and HTML-ize the file list generated by 'unzip -l'. # I used to have 'sed' do this, but the pipeline of sed scripts just got too # darned ugly and unwieldy. 'ed' is much easier to work with. # # Among the less obvious edits: # # 1. unzip -l dates are not Y2K compatible (1999=99, 2000=100, 2001=101, etc.). # The fix: # 1,$s/\([0-9]* [0-9][0-9]-[0-9][0-9]-\)1/\120/ # 2. Convert the date to a sortable YYYY.MM.DD form: # 1,$s/\([0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9][0-9][0-9]\)/\3.\1.\2/ # 3. Put a clickable ... around each file: # 1,$s/\(.*:.. \)\([^ ]*[^\/]\)$/\1\2<\/a>/ # 4. Delete zero-size files (i.e., directories) that sometimes creep into # the zip file list: # 1,$g/ 0/d # 5. Delete the root-level index.html file (because it will always appear # near the top of the sorted file list and it's, well, just plain boring): # /a href="..\/index.html">index.html/d echo -n "${me:t}: Building a workable file list: " unzip -l $theBulkFile > $tmpFile_0 #ed master >& /dev/null << END_INPUT echo -n "editing... " ed -s $tmpFile_0 << END_INPUT /Archive:/d /Length.*Date.*Time/d 1,\$s/.*----.*// 1,\$s/\([0-9]* [0-9][0-9]-[0-9][0-9]-\)1/\120/ 1,\$s/\([0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9][0-9][0-9]\)/\3.\1.\2/ 1,\$s/\(.*:.. \)\([^ ]*[^\/]\)\$/\1\2<\/a>/ /a href="..\/..\/index.html">index.html/d 1,\$g/ 0/d 1,\$g/^\$/d \$ w $tmpFile_3 \$d 1,\$w $tmpFile_1 Q END_INPUT echo -n "sorting... " sort +1 -r -o $tmpFile_2 $tmpFile_1 echo "done." # Get some useful stats from the file lists set nFiles = `wc -l $tmpFile_1` ; set nFiles = $nFiles[1] set nBytes = `cat $tmpFile_3` ; set nBytes = $nBytes[1] # Insert the new sorted file list into $allFilesList echo -n "${me:t}: Building list of all files... " ed -s $allFilesList << END_INPUT /
/+1,/<\/pre>/-1 d
/
/a
  Size      Date     Time    File
 ------  ----------  ----    ----
.
.r $tmpFile_2
a

Total:
      $nFiles files
      $nBytes bytes
.
w
Q
END_INPUT
echo "done."


# Insert the short file list into $shortFilesList 
echo -n "${me:t}: Building list of the first $theCount files... "
ed -s $shortFilesList << END_INPUT
/
/+1,/<\/pre>/-1 d
/
/a
  Size      Date     Time    File
 ------  ----------  ----    ----
.
.r ! head -$theCount $tmpFile_2
w
Q
END_INPUT
echo "done."


stamp_rev-date $shortFilesList $allFilesList

/bin/rm -f $tmpFile_0 $tmpFile_1 $tmpFile_2 $tmpFile_3

echo "${me}: done."