#!/bin/tcsh -f # Make a local backup of all the the .htaccess files on the remote server #set debugHTML set me=$0:t # the name of this program goto Start ############################## Usage: cat << END_INPUT usage: ${me} password Locates all the .htaccess files on the remote server and copies them into a single file on the local server. END_INPUT goto Abort ############################## Start: if ($#argv == 0) then echo "Password required." goto Usage endif if ($# != 1) then echo "Too many arguments." goto Usage endif set password = "$1" # Abort if the required env variables aren't set if (! ${?HTML_DIR}) then echo ${me}: HTML_DIR environment variable not set\! exit endif # set a bunch of tmp variables set tmpDir = ~/tmp/$me set resultsDir = $tmpDir/results set resultsDir_for_sed = `echo "$resultsDir" | sed -e "s/\//\\\//g"` set ftpCommandList = $tmpDir/${me}.ftpCommandList set tmp1 = $tmpDir/${me}.tmp1 set tmp2 = $tmpDir/${me}.tmp2 set theResult = $HTML_DIR/tech/htaccess.html set localRoot = "ati" if (! ${?debugHTML}) then /bin/rm -fr $tmpDir mkdir $tmpDir $resultsDir endif echo "${me}: fetching .htaccess files." echo -n " Pass 1: prep..." # Note: The ftp server hangs after three consecutive failed "get" commands, # which means we can't just do "get" in every directory in hopes of # catching all the .htaccess files. # This is probably some sort of security feature. # So we have to locate the files in a more roundabout way that doesn't # give any errors. # This script assumes that the directory hierarchy on the remote server is a # mirror of the local files. # Let's build a list of dirs on the local website that might # contain .htaccess files. We'll use "find" to do this. # But before that, let's record one file that "find" will miss: echo "." > $ftpCommandList cd $HTML_DIR find . -path './cgi' -prune -o -type d \! -name .\* -print >> $ftpCommandList # Create a list of ftp "dir" commands ed -s $ftpCommandList > /dev/null << END_INPUT %s/^/dir / %s/\$/\/.htaccess %w $tmp1 Q END_INPUT # Create a list of local file names into which the results of the remote # "dir" commands will go. sed -e "s/./$localRoot/" -e "s/\//./g" -e 's/$/.htaccess/' -e "s/^/$resultsDir_for_sed\//" $ftpCommandList > $tmp2 # Now paste the two lists together into a list of ftp commands of the form: # dir [remote path to a .htaccess file] [local filename] paste $tmp1 $tmp2 > $ftpCommandList # Execute the ftp commands # -i = non-interactive # -V = non-verbose echo -n "done. Searching for .htaccess files (takes a minute or two)..." if (! ${?debugHTML}) then ftp -iV ftp://accesstoinsight.org:${password}@ftp-dom.earthlink.net < $ftpCommandList endif if ($status) then echo "${me}: Abort\!" echo "${me}: ftp command (1) failed. Aborting. See tmp files to debug." goto Abort endif cd $resultsDir set theList=`find . -type f \! -size 0 -print` set nFiles = $#theList if ($nFiles == 0) then echo; echo " No .htaccess files found on remote server." goto Cleanup else echo "done." endif # OK. So now the directory $resultsDir is filled with files # containing the results of ftp's "dir" commands. A zero-size file # means that the corresponding remote directory contained no .htaccess file. echo " Pass 2: prep ($nFiles files):" # Now that we know the paths to the .hgtaccess files, we can construct another # ftp command list to actually retrieve them from the server echo "" > $ftpCommandList foreach localFile ($theList) set remoteFile = `echo $localFile | sed -e "s/${localRoot}.//" -e "s/\./\//g" -e "s/\/\//.\//" -e 's/htaccess$/.htaccess/'` echo " $remoteFile" echo "get $remoteFile $localFile" >> $ftpCommandList end # We're done with the zero-length files. Tidiness dictates that we delete them. find . -type f -size 0 -exec /bin/rm {} \; echo -n " fetching..." # Execute the ftp commands # -i = non-interactive # -V = non-verbose if (! ${?debugHTML}) then ftp -iV ftp://accesstoinsight.org:${password}@ftp-dom.earthlink.net < $ftpCommandList endif if ($status) then echo "${me}: Abort\!" echo "${me}: ftp command (2) failed. Aborting. See tmp files to debug." goto Abort endif echo "done." # Now the files in $resultsDir contain copies of the remote .htaccess files # Backup the old results file if (-e $theResult) then mv $theResult ${theResult}.old endif set theDate=`date "+$DATE_FORMAT_ATI_REV_DATE"` ############################ # Write the header cat << END_INPUT > $theResult Remote Server .htaccess Directives Help | Home » Technical Notes

Remote Server .htaccess Directives

$theDate


END_INPUT ############################ # Insert each .htaccess file into $theResult foreach localFile ($theList) set remoteFile = `echo $localFile | sed -e "s/${localRoot}.//" -e "s/\./\//g" -e "s/\/\//.\//" -e 's/htaccess$/.htaccess/'` set remoteFile = `echo $localFile | sed -e "s/${localRoot}.//" -e "s/\./\//g" -e "s/\/\//.\//" -e 's/htaccess$/.htaccess/'` cat << END_INPUT >> $theResult

$remoteFile

END_INPUT
	cat $localFile  >> $theResult
	cat << END_INPUT >> $theResult

END_INPUT end ############################ # write the footer cat << END_INPUT >> $theResult Revised: Undated
http://www.accesstoinsight.org/tech/$theResult:t
END_INPUT ############################ echo "${me}: $nFiles .htaccess files were successfully merged to ${theResult}." Cleanup: cd if (! ${?debugHTML}) then /bin/rm -fr $tmpDir endif exit Abort: exit