#!/bin/ksh if [ ! -f .htmp.tar ] then touch .htmp.tar else rm .htmp.tar touch .htmp.tar fi if [ $# -eq 0 ] then echo "har: Improper usage" echo "Usage: har [-n file] new_file directory 1 | file 1 [directory 2 | file 2 ...]" # if -n is used and there are only three arguments elif [ $1 = "-n" -a $# -lt 4 ] then echo "har: Improper usage" echo "Usage: har [-n file] new_file directory 1 | file 1 [directory 2 | file 2 ...]" elif [ $1 != "-n" -a $# -lt 2 ] then echo "har: Improper usage" echo "Usage: har [-n file] new_file directory 1 | file 1 [directory 2 | file 2 ...]" else if [ $1 = "-n" ] then # test to see if bundle requested already exists as a file if [ ! -f $2 ] then echo "har: "$2" does not exist. Exiting" rm .htmp.tar exit 1 elif [ -f $3 ] then echo "har: "$3" already exists. Cannot make a file with this name" echo "Exiting" rm .htmp.tar exit 1 elif [ -d $3 ] then echo $3" is a directory, not a file; cannot make" echo "Exiting" rm .htmp.tar exit 1 else # loop through list of dirs i=1 # by not naming list, loops through command-line args for current do if [ $i -lt 4 ] then i=$(($i+1)) else if [ ! -d $current -a ! -f $current ] then echo $current" is not a directory or a file" echo "Exiting and removing "$3 rm .htmp.tar exit 1 elif [ -d $current ] then find $current -type f -newer $2 -exec tar rvf .htmp.tar {} \; i=$(($i+1)) else # current is a file if [ $current -nt $2 ] then tar rvf .htmp.tar $current fi fi fi done echo "#!/bin/ksh" > $3 echo "uudecode << HAR_DELIM" >> $3 uuencode -m .htmp.tar .htmp.tar >> $3 rm .htmp.tar echo "HAR_DELIM" >> $3 # use p option to restore files to original permissions echo "tar xvfp .htmp.tar" >> $3 echo "rm .htmp.tar" >> $3 chmod +x $3 fi elif [ $1 != "-n" ] then if [ -f $1 ] then echo "har: "$3" already exists. Cannot make a file with this name" echo "Exiting" rm .htmp.tar exit 1 elif [ -d $1 ] then echo $1" is a directory, not a file; cannot make" echo "Exiting" rm .htmp.tar exit 1 else # loop through list of dirs i=1 for current do if [ $i -lt 2 ] then i=$(($i+1)) else if [ ! -d $current -a ! -f $current ] then echo $current" is not a directory or a file" echo "Exiting and removing "$1 rm .htmp.tar exit 1 elif [ -d $current ] then find $current -type f -exec tar rvf .htmp.tar {} \; i=$(($i+1)) else # current is a file tar rvf .htmp.tar $current fi fi done echo "#!/bin/ksh" > $1 echo "uudecode << HAR_DELIM" >> $1 uuencode -m .htmp.tar .htmp.tar >> $1 rm .htmp.tar echo "HAR_DELIM" >> $1 # use p option to restore files to original permissions echo "tar xvfp .htmp.tar" >> $1 echo "rm .htmp.tar" >> $1 chmod +x $1 fi fi fi exit 0