#!/bin/csh -f # # Upload new web-page files to my Comcast.net bdchivers account. # Brent Chivers 2004/Jan/24 # # Find any new files and upload them to my space on the ISP's # web server IF the files are also mentioned in my *.html files. # If the top-level index.html file has been modified, modify it # to set the for the web site instead of the local file. # # FTP access depends on my ~/.netrc file. # # Major shortcoming: If I link old files (jpg, mp3, txt, etc) # into the local webpage area and use them, this script will # not notice them to upload them to the ISP's server. # # Look for new subdirectories; create them on web server. BDC 2004/Jan/26 # (Will probably get an error trying to create "." the # first time. Is it worth adding code to avoid this?) # Show the time/date of the last previous run. # # Looking for new files in *.html -- chop off path. BDC 2004/Jan/26 # When looking for a new index.html file, filter out # any index.html files from subdirectories. # # Elminate new files without "." in the name -- BDC 2004/Jan/29 # files without extensions -- probably plain-text # files used to generate html pages with tables. # (Link plain-name files we DO want to include BDC 2004/Feb/02 # (like makefile) to "name.txt" so this script # will still include them. Link scripts like "do.stuff" to # "do.stuff.txt" so browsers will know how to display them.) # # Addressing the major shortcoming above: keep a list BDC 2004/Feb/08 # of files that were here before and compare it with # what's here now. This finds files that have been linked/copied # in with old timestamps. (I consider old timestamps valuable.) # # If there are files to upload, link the new list to BDC 2004/Feb/08 # newfiles.txt (and add newfiles.txt to the list). # # Have not been able to filter the '^220-' responses BDC 2004/Feb/08 # from the FTP dialog. # # Yesterday I started using Tumult HyperEdit for editing BDC 2004/Apr/03 # HTML files. It has a problem writing out files that # are hard-linked to multiple names, and I typically do this with # the index.html pages in each subdirectory. With insistence # (using "save as" instead of "save"), HyperEdit will write # the modified file, but it breaks the link. Find and restore # these broken links. # (Probably would have been easier to just use symbolic links....) # # Changed the BASE HREF from BDC 2004/Apr/03 # from http://home.comcast.net/~bdchivers/ # to http://bdchivers.home.comcast.net/ # I prefer the latter -- shorter, cleaner, easier to # type, and easier to remember and hand out to others. # Comcast's documentation states that the first form is required. # I've been thinking they were wrong, and I finally tested it today. # # Call FTP with "-V" to reduce the amount of output to BDC 2004/Apr/09 # to the screen. Things I'd like to see have been # scrolling out of sight, and the FTP connect dialog has had # no surprises for a long time. Turn progress and verbose # on after the FTP connection is established in a new file, # .ftp_init. # # Modified to support a 2nd web site -- the Ad Hoc BDC 2004/Apr/23 # Singers pages are moving to www.SitesbySteve.com/adhoc. # The AdHoc index.html page will need its own BASE HREF with # mods when uploaded, and the FTP server is different. # (The account name and password are in ~/.netrc.) # Don't cd to $home/webpages/bdchivers -- # # ls|cut to show previous update date can't use BDC 2004/Nov/04 # fixed-char columns because the byte-count size # of .newfiles will affect the output of ls. Remove duplicate spaces # and count fields instead. (Tedious, but should be reliable.) # # Progress messages assumed uploades were to Comcast. BDC 2006/Mar/23 # Now they say upload to $ftp_site instead. # # Move definition of $ftp_site to BEFORE it's first use. BDC 2006/May/01 # # Ad Hoc Singers now has its own domain adhocsingers.org BDC 2006/Dec/09 # hosted by GoDaddy.com. Renamed the old directory # (hosted at sitesbysteve.com) adhoc-sbs. # Updated the $ftp_site and index.web sed editing. # # Changed the BASE HREF from BDC 2009/Sep/06 # from http://bdchivers.home.comcast.net/ # back to http://home.comcast.net/~bdchivers/ # webcheck reports "301 Moved Permanently" errors on the shorter form. # # Created index.web for bchivers (like bdchivers). BDC 2009/Oct/20 # # Home directory is now in /home instead of /Users. BDC 2011/Jan/06 # (Moved from MacOSX/Darwin to Linux.) # Base HREF editing must be modified to match. # Darwin's -V option for ftp to supress messages # is not valid on Linux. # # Comcast homepage URLs now look like BDC 2012/May/03 # http://bdchivers.home.comcast.net/~bdchivers/ # (This change also fixed webcheck for going recursive again.) ##! /bin/csh -fb # for setuid/setgid scripts (tsk) # set verbose # see commands before variable substitution # set echo # see commands after variable substitution unset histchars # get other users' history characters out of the way unalias * # get other users' .cshrc stuff out of the way ## set nonomatch # don't require wildcard matches # $0:t construction doesn't work! set cmd_name = $0 set cmd_name = $cmd_name:t # the name of this command # cd $home/webpages/bdchivers # where the web-page files are kept if ( -f .newfiles ) then # timestamp file found from previous run echo -n "$cmd_name last run " # ls -l .newfiles | cut -c35-46 # date/time from old timestamp file ls -l .newfiles | sed 's/ */ /g' | cut -d' ' -f6-8 else # script has not been run before echo "There is no timestamp file from a previous run of $cmd_name." endif if ( -f .newdirs ) then mv .newdirs .subdirs # save previous list of subdirectories endif find . -type d -print | sed 's-^./--' | sort > .newdirs foreach dir (`cat .newdirs`) # check for broken index.html hard links set index = "$dir/index.html" # figure out the index file name if (-e "$index") then # there is an index.html file set link = "$dir.html" # figure out matching link name if (-e "$link") then # there is a matching link set index_inode = `ls -i "$index"` # get inode for files set link_inode = `ls -i "$link"` # (hard links will have the same inode) if ($index_inode[1] == $link_inode[1]) then echo "$index and $link are hard links" else # figure out which file is newer set newer = `find $dir -name index.html -newer $link` if ("$newer" == "$index") then # $index is newer echo "Replacing $link with a link from $index." /bin/rm "$link" /bin/ln "$index" "$link" else # $link is newer echo "Replacing $index with a link from $link." /bin/rm "$index" /bin/ln "$link" "$index" endif endif else echo "index file $index does not have a matching link $link." endif else echo "sub-directory $dir does not have an index file $index." endif end if ( -f .subdirs ) then # there's a prev list of subdirectories; find new subdirs set newdirs = `diff .subdirs .newdirs | grep '^>' | cut -f2 -d' '` else # no old list of subdirs; treat all subdirectories as new set newdirs = `cat .newdirs` endif if ( -f .newfiles ) then # find new files set newfiles = `find . -type f -newer .newfiles -print | sed 's-^./--' | fgrep '.' | grep -v '^index.html$'` set newindex = `find . -name index.html -newer .newfiles -print | grep '^\./index.html$' | sed 's-^./--'` else # no timestamp, find everything set newfiles = `find . -type f -print | sed 's-^./--' | fgrep '.'` set newindex = index.html endif if ( -f .oldfiles ) then # find newly-linked old files find . -type f -o -type l | cut -c3- | grep '\.' > .allfiles set addedfiles = `diff .oldfiles .allfiles | grep '^> ' | cut -c3-` if ( $#addedfiles ) then # add $addedfiles to $newfiles, drop duplicates set newfiles = `echo $newfiles $addedfiles | fmt -1 | sort -u` endif mv .allfiles .oldfiles # save new list for next time else # leave a list ready for next time set addedfiles = "" # assume no old files were linked in find . -type f | cut -c3- | grep '\.' > .oldfiles endif set htmlfiles = `find . -type f -name \*.html -print | sed 's-^./--'` set usedfiles = "" # new files that are used by a web page foreach file ( $newfiles ) # grep -q $file $htmlfiles grep -q $file:t $htmlfiles if ($status == 0) then # file is mentioned on a page set usedfiles = ($usedfiles $file) endif end cat /dev/null > .newfiles # start new command list foreach dir ( $newdirs ) # make mkdir commands echo "mkdir $dir" >> .newfiles end foreach file ( $usedfiles ) # make put commands if ( "$file" == "$cmd_name" ) continue # we don't need to upload comand AND command.txt; we've been getting both echo "put $file $file" >> .newfiles end if ( $#newindex ) then # top-level index file has been updated # cat $newindex | sed -e 's/ index.web # cat $newindex | sed -e 's---' > index.web switch ( $cwd:t ) case adhoc: cat $newindex | sed -e 's---' > index.web breaksw case adhoc-sbs: cat $newindex | sed -e 's---' > index.web breaksw case bchivers: cat $newindex | sed -e 's---' > index.web breaksw case bdchivers: default: cat $newindex | sed -e 's---' > index.web breaksw endsw touch -r index.html index.web # set timestamp to match echo "put index.web index.html" >> .newfiles endif switch ( $cwd:t ) case adhoc: set ftp_site = adhocsingers.org breaksw case adhoc-sbs: set ftp_site = www.SitesbySteve.com breaksw case bchivers: set ftp_site = upload.comcast.net breaksw case bdchivers: default: set ftp_site = upload.comcast.net breaksw endsw if ( -z .newfiles ) then # nothing to upload echo "No new/updated files to upload to ${ftp_site}." else # there are files to upload echo "put newfiles.txt newfiles.txt" >> .newfiles /bin/rm newfiles.txt ln .newfiles newfiles.txt echo "Files to upload to ${ftp_site}:" ls -l `grep '^put ' .newfiles | cut -f2` | sed 's/^/ /' echo "bye" >> .newfiles cat .ftp_init .newfiles | ftp $ftp_site # ftp $ftp_site < .newfiles | grep -v "^220-" endif