diff options
author | Erich Eckner <git@eckner.net> | 2016-04-19 09:18:08 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2016-04-19 09:29:39 +0200 |
commit | 4ce14217822ee0927b007753198250e494191b52 (patch) | |
tree | 503462de3d5c68745941ebba8b39e981de7069ea | |
parent | 7eebdef03cc9eee7aec5ded3fe1e45eb1234d2a1 (diff) | |
download | sendmailadvanced-1.0.4.tar.xz |
mehr Optionen, Hooks umstrukturiertv1.0.4
-rwxr-xr-x | sendmailadvanced | 61 | ||||
-rwxr-xr-x | sendmailadvanced.conf | 32 |
2 files changed, 60 insertions, 33 deletions
diff --git a/sendmailadvanced b/sendmailadvanced index 12a327c..3c3122d 100755 --- a/sendmailadvanced +++ b/sendmailadvanced @@ -1,14 +1,25 @@ #!/bin/bash verwendung() { - >&2 echo 'sendmailadvanced [-h|--hook param-for-hooks] [-i|--inline file] [-e|--encrypt] [-s|--stamp] [-t] [--no-hooks]' + >&2 echo 'sendmailadvanced [(-h|--hook) hook] [(-i|--inline) file | -t|--no-inline] [-e|--[no-]encrypt] [-s|--[no-]stamp]' + >&2 echo ' -h|--hook: activate hook' + >&2 echo ' -i|--inline: enhance email file in situ' + >&2 echo ' "--inline -" has the same effect as "-t"' + >&2 echo ' conflicts with -t|--no-inline' + >&2 echo ' -t|--no-inline: enhance email from stdin to stdout' + >&2 echo ' conflicts with -i|--inline' + >&2 echo ' -e|--[no-]encrypt: do (not) encrypt' + >&2 echo ' -s|--[no-]stamp: do (not) stamp' exit 1 } datei="" -encrypt=false -stamp=false -applyHooks=true +encrypt=true +stamp=true + +dForced=false +eForced=false +sForced=false if [ -x /etc/sendmailadvanced.conf ] then @@ -22,8 +33,10 @@ else done fi +gpg --list-keys "${gpg_recipient}" &> /dev/null || encrypt=false +which hashcash &> /dev/null || stamp=false -eval set -- "$(getopt -o eh:i:st --long encrypt,hook:,inline:,no-hooks,stamp -n "$(basename "$0")" -- "$@")" +eval set -- "$(getopt -o eh:i:st --long encrypt,no-encrypt,hook:,inline:,no-inline,stamp,no-stamp -n "$(basename "$0")" -- "$@" || echo verwendung)" while true do @@ -33,22 +46,36 @@ do hooks[${#hooks[@]}]="$1" ;; -i|--inline) - echo "inline erkannt" + ${dForced} && verwendung shift datei="$1" + [ "${datei}" == "-" ] && datei="" + dForced=true + ;; + -t|--no-inline) + ${dForced} && verwendung + datei="" + dForced=true ;; -e|--encrypt) + ${eForced} && verwendung encrypt=true + eForced=true + ;; + --no-encrypt) + ${eForced} && verwendung + encrypt=false + eForced=true ;; -s|--stamp) + ${sForced} && verwendung stamp=true + sForced=true ;; - --no-hooks) - applyHooks=false - ;; - -t) - encrypt=true - stamp=true + --no-stamp) + ${sForced} && verwendung + stamp=false + sForced=true ;; --) shift @@ -121,9 +148,15 @@ fi echo "${zeile}" ( - ${applyHooks} && body_header_hook "${hooks[@]}" + for hookParam in "${hooks[@]}" + do + body_header_hook "${hookParam}" + done cat - ${applyHooks} && body_footer_hook "${hooks[@]}" + for hookParam in "${hooks[@]}" + do + body_footer_hook "${hookParam}" + done ) | \ ( ${encrypt} && gpg -e -a -s -r ${gpg_recipient} || cat diff --git a/sendmailadvanced.conf b/sendmailadvanced.conf index 7b37bfc..cf7932d 100755 --- a/sendmailadvanced.conf +++ b/sendmailadvanced.conf @@ -11,28 +11,22 @@ hashcash_bits=22 # things to put into head of (body of) email body_header_hook() { - true + [ "$(whoami)" == "root" ] && [ "$1" == "last-backups" ] && return 0 + echo "Unkonwn header-hook: '$1'" } # things to put into foot of email body_footer_hook() { - while [ $# -gt 0 ] - do - if [ "$1" == "-t" ] - then - true - elif [ "$(whoami)" == "root" ] && [ "$1" == "-wb" ] - then - echo "----------------------- Last Backups Begin -------------------------" - echo - lastBackups - echo - echo "------------------------ Last Backups End --------------------------" - echo - else - echo "Unknown option: '$1'" - fi - shift - done + if [ "$(whoami)" == "root" ] && [ "$1" == "last-backups" ] + then + echo "----------------------- Last Backups Begin -------------------------" + echo + lastBackups + echo + echo "------------------------ Last Backups End --------------------------" + echo + else + echo "Unknown footer-hook: '$1'" + fi } |