X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/6e04c69fadd2c8534aa28ca7d115e7bbedbf1608..085bca07c0b505f095a50666a3752e5fcb69bc70:/etc/sendfiles?ds=sidebyside diff --git a/etc/sendfiles b/etc/sendfiles index b3f49716..8fe6a9d2 100755 --- a/etc/sendfiles +++ b/etc/sendfiles @@ -1,4 +1,4 @@ -#!/bin/sh +#! /bin/sh # # Sends multiple files and/or directories in a MIME message. # Requires tar and any specified compression program. @@ -12,9 +12,8 @@ usage='Usage: sendfiles [switches] -to recipient -subject subject '"\ or sendfiles [switches] recipient subject file1 [file2 ...] switches are: - -compress [bzip2 | compress | gzip | lzma | none | zip] + -compress [bzip2 | compress | gzip | lzma | none] -from - -[delay] (expressed in seconds) -version -help Can use PERSON environment variable instead of -from switch.' @@ -32,20 +31,26 @@ finddir() { esac } +help() { + printf '%s\n' "$usage" + #### Print the nmh intro text. + ${nmhbindir}/mhparam -help | sed -n -e '/^$/,$p' + exit +} + die() { - printf '%s\n' "$usage"; exit ${1:-1} + printf '%s\n' "$usage" + exit 1 } bindir=`finddir $0` nmhbindir=`cd "$bindir" && pwd` -nmhlibdir=`$nmhbindir/mhparam libdir` +nmhlibexecdir=`$nmhbindir/mhparam libexecdir` #### Process switches. compress= ## compress method compressarg=0 ## whether currently handling -compress -delay= ## delay value -delayarg=0 ## whether currently handling -delay from= ## From: contents fromarg=0 ## whether currently handling -from subject= ## Subject: contents @@ -55,26 +60,20 @@ toarg=0 ## whether currently handling -to for arg in "$@"; do case $arg in -c|-co|-com|-comp|-compr|-compre|-compres|-compress) compressarg=1 ;; - -d|-de|-del|-dela|-delay) delayarg=1 ;; - -[0-9]|-[0-9][0-9]|-[0-9][0-9][0-9]|-[0-9][0-9][0-9][0-9]) - delay=`printf '%s\n' "$arg" | sed -e 's%-%%'` ;; -f|-fr|-fro|-from) fromarg=1 ;; #### Support -gzip for backward compatibility. -gzip) compress=gzip ;; - -h|-he|-hel|-help) die 0 ;; + -h|-he|-hel|-help) help ;; #### Support -none for backward compatibility. -none) compress=none ;; -s|-su|-sub|-subj|-subje|-subjec|-subject) subjectarg=1 ;; -t|-to) toarg=1 ;; -v|-ve|-ver|-vers|-versi|-versio|-version) - "$nmhlibdir/viamail" -version | sed 's/viamail/sendfiles/'; exit ;; + "$nmhlibexecdir/viamail" -version | sed 's/viamail/sendfiles/'; exit ;; -*) die ;; *) if [ $compressarg -eq 1 ]; then compress="$arg" compressarg=0 - elif [ $delayarg -eq 1 ]; then - delay="$arg" - delayarg=0 elif [ $fromarg -eq 1 ]; then from="$arg" fromarg=0 @@ -119,8 +118,6 @@ fi checkforargs() { if [ $compressarg -eq 1 ]; then printf 'sendfiles: missing argument to -compress\n' >&2; exit 1 - elif [ $delayarg -eq 1 ]; then - printf 'sendfiles: missing argument to -delay\n' >&2; exit 1 elif [ $fromarg -eq 1 ]; then printf 'sendfiles: missing argument to -from\n' >&2; exit 1 elif [ $subjectarg -eq 1 ]; then @@ -136,7 +133,7 @@ checkforargs if [ x"$from" = x ]; then if [ x"$PERSON" = x ]; then - from=`"$nmhlibdir/ap" -format '%(localmbox)' 0` + from=`"$nmhlibexecdir/ap" -format '%(localmbox)' 0` else from="$PERSON" fi @@ -145,7 +142,7 @@ fi #### Determine compression method and descriptive info. if [ x"$compress" = x ]; then - for compressor in gzip bzip2 lzma zip compress none; do + for compressor in gzip bzip2 lzma compress none; do if [ x"`finddir $compressor`" = x ]; then :; else compress="$compressor" break @@ -161,8 +158,6 @@ case $compress in conversion='; x-conversions=gzip' ;; lzma) compress='lzma -c'; uncompress='lzma -cd' conversion='; x-conversions=lzma' ;; - zip) compress='zip -q'; uncompress='unzip -p' - conversion='; x-conversions=zip' ;; none) compress=cat uncompress=cat; conversion= ;; *) printf 'sendfiles: unknown compression method "%s"\n' \ "$compress" >&2 @@ -172,7 +167,7 @@ esac #### Send using viamail. tar cvf - "$@" | $compress | \ - "$nmhlibdir/viamail" -to "$to" -subject "$subject" \ + "$nmhlibexecdir/viamail" -to "$to" -subject "$subject" \ -from "$from" -parameters "type=tar$conversion" \ -comment "extract with $uncompress | tar xvpf -" \ - -delay "$delay" -verbose + -verbose