#!/bin/bash # script to move a web directory tree in the file system # and then patch up all references in the URL space. usage() { echo "usage: `basename $0` destDir" echo echo " Recursively moves the entire tree at the cwd to " echo " the destination directory given. Then updates " echo " HTML files reflect new location. " echo echo "Bugs: Too numerous to mention, primarily in the design" echo " of the interface and functionality." } webRoot="www.cs.washington.edu/" fsRoot="/cygdrive/d/cse490c/03au/" # When invoked by the user, we should have exactly one argument. # When we invoke ourselves, we have 4 (-x file fromURLpattern toURLpattern) if [ $1 = "-x" ] && [ $# = 4 ]; then if [ ! `sed "s,$3,$4," $2 >.webmovetemp` ]; then echo "Patched $2" mv .webmovetemp $2 fi exit 0 elif [ ! $# = 1 ]; then echo "Error: $*" usage exit 1 fi cwd=`pwd` destDir="$1" if [ -e $destDir ]; then echo "Destination direction $destDir already exists." exit 2 fi # we want full path names for everything. The destination # directory might be something like "../../newdir". # So, create it, cd to it, and pwd it. if [ `mkdir "$destDir"` ]; then echo "Couldn't create destination diretory $destDir" exit 3 fi cd $destDir destDir=`pwd` # get full path name # now get out of our own way... cd $fsRoot # and copy rm -r $destDir # remove dir so cp works as expected cp -r "$cwd" "$destDir" # now patch any links shopt -s extglob # turn on extglob option of shell echo "fromURL = $fromURL" fromURL=`echo "$cwd" | sed "s,$fsRoot,$webRoot,"` toURL=`echo "$destDir" | sed "s,$fsRoot,$webRoot,"` echo "toURL = $toURL" find . \( -name "*.html" -o -name "*.htm" \) -exec "$cwd/$0" -x \{\} "$fromURL" "$toURL" \; exit 0