diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2022-05-13 15:12:41 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2022-05-13 15:52:55 +0200 |
commit | a85c1858548b8686d8dcba44b1f4f9ff82e1d234 (patch) | |
tree | 1bb8c6c1883ac87871826d1fe04d143e305bb741 | |
parent | d6601831b7e50041c829b05155dcd4537021a9c4 (diff) | |
download | alpine-conf-a85c1858548b8686d8dcba44b1f4f9ff82e1d234.zip |
setup-mta: add usage help text
-rw-r--r-- | setup-mta.in | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/setup-mta.in b/setup-mta.in index c75431a..eaea499 100644 --- a/setup-mta.in +++ b/setup-mta.in @@ -1,10 +1,25 @@ #!/bin/sh PREFIX=@PREFIX@ -. "$PREFIX/lib/libalpine.sh" +: ${LIBDIR=$PREFIX/lib} +. "$LIBDIR/libalpine.sh" conf="$ROOT/etc/ssmtp/ssmtp.conf" +usage() { + cat <<-EOF + usage: setup-mta [-h] [SMTPSERVER] + + Setup SMTP server for outgoing email + + options: + -h Show this help + + If SMTPSERVER is not prompted user will be prompted + EOF + exit $1 +} + cfgval() { awk -F= "/^$1/ {print \$2}" $conf 2>/dev/null } @@ -12,12 +27,23 @@ cfgval() { setcfg() { local key=$1 local value=$2 - sed -i "s/^\\(\\#\\)*$key=.*/$key=$value/" "$conf" - if ! grep "^$key=" "$conf" >/dev/null ; then + mkdir -p "${conf%/*}" + sed -i "s/^\\(\\#\\)*$key=.*/$key=$value/" "$conf" 2>/dev/null + if ! grep -q "^$key=" "$conf" 2>/dev/null; then echo "$key=$value" >> "$conf" fi } +while getopts "h" opt; do + case $opt in + h) usage 0;; + '?') usage "1" >&2;; + esac +done +shift $(( $OPTIND - 1 )) + +mailhub="$1" + if [ -f "$conf" ] ; then mailhub=$(cfgval mailhub) fi @@ -32,7 +58,7 @@ fi res= -while [ "$res" != "221" ]; do +while [ $# -eq 0 ] && [ "$res" != "221" ]; do ask "Outgoing mail server? (e.g 'smtp.isp.com')" "$mailhub" mailhub="$resp" if ! ask_yesno "Test connection? (y/n)" y; then @@ -42,7 +68,7 @@ while [ "$res" != "221" ]; do [ "x$res" = "x221" ] && echo "Connection to $mailhub is ok." done -apk add ssmtp +$MOCK apk add ssmtp setcfg mailhub $mailhub setcfg FromLineOverride YES |