#!/usr/bin/env bash
#
# mail-wrapper -- Report results of a command by email
-# Copyright (c)2017 Alexander Barton (alex@barton.de)
+# Copyright (c)2017,2018 Alexander Barton (alex@barton.de)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
echo " $NAME {parameters} [<command> [<arg> [<…>]]]"
echo
echo " -C Use the \"C\" locale, no localized (error) messages."
+ echo " --dontfail|-n Don't return the error code of the command called."
echo " --errors|-e Generate email on errors only."
echo " --from|-f Email address of the sender of the email."
echo " --stderr-is-warning|-W Exit code indicates error; stderr is only warning."
# Some defaults (can be adjusted by command line parameters).
unset do_errors_only
+unset dont_fail
unset stderr_is_warning
unset subject
from="${LOGNAME:-root} <${LOGNAME:-root}@$host>"
"--debug"|"-D")
export DEBUG=1
;;
+ "--dontfail"|"-n")
+ dont_fail=1
+ ;;
"--errors"|"-e")
do_errors_only=1
;;
) | mail -n -a "From: $from" -s "$subject" "$to" \
|| ax_abort -l "Failed to send email to \"$to\"!"
-exit $exit_code
+[[ -n "$dont_fail" ]] && exit 0 || exit $exit_code