: ########################################################################## # Title : tarmail - send files/directories as tar-archive via e-mail # Author : Heiner Steven # Date : 2000-07-13 # Requires : gunzip gzip sendfile tar # Category : Mail # SCCS-Id. : @(#) tarmail 2.5 07/12/03 ########################################################################## # Description # # See also # cpiomail ########################################################################## PN=`basename "$0"` # program name VER='2.5' # Change the usage message below if you change anything of this: : ${COMPRESS:=gzip} : ${UNCOMPRESS:=gzip -d} : ${COMPRESS_SUFFIX:=.gz} : ${TMPDIR:=/tmp} TarFlags= # Default tar options Silent=false # "true" or "false" usage () { echo >&2 "$PN - send files/directories as tar archive via e-mail, $VER usage: $PN e-mail-address {file|directory} [...] The program searches all given files and directories (including subdirectories), creates a compressed \"tar\" archive, and sends it to the specified e-mail address." exit 1 } error () { echo >&2 "$PN: $*"; } fatal () { error "$@"; exit 1; } while [ $# -gt 0 ] do case "$1" in -v) TarFlags=${TarFlags}v;; -s) Silent=true;; --) shift; break;; -h) usage;; -*) usage;; *) break;; # First file name esac shift done [ $# -lt 2 ] && usage User="$1"; shift # Set restrictive access permissions for newly created temporary files umask 0077 for entry do filename=$entry.tar archive=$filename$COMPRESS_SUFFIX file=`basename "$archive"` [ -r "$entry" ] || { error "cannot read $entry - ignored"; continue; } for new in "$archive" "$TMPDIR/$file" "" do [ -s "$new" ] && continue # do not overwrite existing file (> "$new") 2>/dev/null || continue break done if [ X"$new" = X"" ] then error "cannot create new archive: $archive. File either exists already, or directory not writeable (tried $TMPDIR, too) - file ignored" continue fi [ X"$archive" != X"$new" ] && archive=$new $Silent || echo >&2 "$archive" trap 'rm -f "$archive"' 0 trap "exit 2" 1 2 3 15 tar c${TarFlags}f - "$entry" | $COMPRESS > "$archive" || { error "cannot create and compress archive file: $archive"; continue; } sendfile -s "$file" -f "$User" "$archive" <<-EOT This is an "tar" archive of "$entry", compressed using "$COMPRESS". To extract the original files, save it to a file (e.g. "$file"), and unpack it using the following command: $UNCOMPRESS < "$file" | tar xf - Contents of $archive: `$UNCOMPRESS < "$archive" 2>&1 | tar tvf - 2>&1` EOT [ $? -eq 0 ] || error "could not send file: $archive" rm -f "$archive" trap 0 1 2 3 15 done