use gzip by default if available. Fix sendmail To: envelope

This commit is contained in:
2022-04-25 14:52:00 +02:00
parent 159e70d654
commit f623bfe80c

View File

@@ -55,7 +55,8 @@
# This option disables this redirection. It is useful (together with # This option disables this redirection. It is useful (together with
# bash's -x option) when some errors are difficult to track. # bash's -x option) when some errors are difficult to track.
# -Z # -Z
# activate email attachment compression (with gzip). # By default, if gzip utility is available, the log attachment is
# compressed. This option will prevent any compression.
# #
# GENERAL # GENERAL
# You should avoid modifying variables in this script. # You should avoid modifying variables in this script.
@@ -136,7 +137,7 @@ NUMID="" # (-u) use numeric IDs
#VERBOSE=0 # TODO: (-v) logs level (0/1) #VERBOSE=0 # TODO: (-v) logs level (0/1)
DEBUG=n # (-D) debug: no I/O redirect (y/n) DEBUG=n # (-D) debug: no I/O redirect (y/n)
MAILTO=${MAILTO:-""} # (-n) mail recipient. -n sets it to "" MAILTO=${MAILTO:-""} # (-n) mail recipient. -n sets it to ""
ZIPMAIL="cat" # (-Z) zip mail attachment ZIPMAIL="gzip" # (-Z) zip mail attachment
# options not available on command line, but settable in config file. # options not available on command line, but settable in config file.
NYEARS=3 # keep # years (int) NYEARS=3 # keep # years (int)
@@ -187,7 +188,7 @@ do
z) COMPRESS=-y;; # rsync compression. Depends on net/CPU perfs z) COMPRESS=-y;; # rsync compression. Depends on net/CPU perfs
u) NUMID="--numeric-ids";; u) NUMID="--numeric-ids";;
D) DEBUG=y;; D) DEBUG=y;;
Z) ZIPMAIL="gzip";; Z) ZIPMAIL="cat";;
*) usage;; *) usage;;
esac esac
done done
@@ -305,6 +306,8 @@ exit_handler() {
MIMESTR="FEDCBA_0987654321" MIMESTR="FEDCBA_0987654321"
# email header # email header
printf "To: %s\n" "$MAILTO"
#printf "From: %s" "$MAILTO"
printf "Subject: %s\n" "${SUBJECT}" printf "Subject: %s\n" "${SUBJECT}"
printf "MIME-Version: 1.0\n" printf "MIME-Version: 1.0\n"
printf 'Content-Type: multipart/mixed; boundary="%s"\n' "$MIMESTR" printf 'Content-Type: multipart/mixed; boundary="%s"\n' "$MIMESTR"
@@ -340,7 +343,7 @@ exit_handler() {
$ZIPMAIL | base64 $ZIPMAIL | base64
fi fi
printf "\n--%s--\n" "$MIMESTR" printf "\n--%s--\n" "$MIMESTR"
} | sendmail -i -- "${MAILTO}" } | sendmail -it
else else
grep -vE "^\*+\ Mark$" grep -vE "^\*+\ Mark$"
fi fi
@@ -395,14 +398,21 @@ for cmd in rsync gzip base64 sendmail; do
if type -p "$cmd" > /dev/null; then if type -p "$cmd" > /dev/null; then
log "ok" log "ok"
else else
if [[ "$cmd" = "gzip" ]]; then
log "NOK (ignored, disabling compression)"
ZIPMAIL="cat"
continue
fi
log "NOK" log "NOK"
cmdavail+=("$cmd") cmdavail+=("$cmd")
fi fi
done done
if (( ${#cmdavail[@]} )); then if (( ${#cmdavail[@]} )); then
log -s "Fatal. Please install the following programs: ${cmdavail[*]}." log -s "Fatal. Please install the following programs: ${cmdavail[*]}."
error_handler $LINENO 1 error_handler $LINENO 1
fi fi
unset cmdavail
log -s "Mark" # to separate email body log -s "Mark" # to separate email body