#!/bin/bash # archivedir--Creates a compressed archive of the specified directory. setglobal maxarchivedir = '10' # Size, in blocks, of 'big' directory setglobal compress = 'gzip' # Change to your favorite compress app. setglobal progname = $[basename $0] # Nicer output format for error messages if test $Argc -eq 0 { # No args? That's a problem. echo "Usage: $progname directory" > !2 ;exit 1 } if test ! -d $1 { echo "$(progname): can't find directory $1 to archive." > !2; exit 1 } if test $[basename $1] != $1 -o $1 = "." { echo "$(progname): you must specify a subdirectory" > !2 exit 1 } if test ! -w . { echo "$(progname): cannot write archive file to current directory." > !2 exit 1 } # Is the resultant archive going to be dangerously big? Let's check... setglobal dirsize = $[du -s $1 | awk '{print $1}] if test $dirsize -gt $maxarchivedir { echo -n "Warning: directory $1 is $dirsize blocks. Proceed? [n] " read answer setglobal answer = $[echo $answer | tr '[:upper:]' '[:lower:]' | cut -c1] if test $answer != "y" { echo "$(progname): archive of directory $1 canceled." > !2 exit 0 } } setglobal archivename = ""$1.tgz"" if tar cf - $1 | $compress > $archivename { echo "Directory $1 archived as $archivename" } else { echo "Warning: tar encountered errors archiving $1" } exit 0