#!/bin/bash # Configure sSMTP. # Intended primarily for use with a frequently varying # host address and name, typically a PPP link. # Usage: ssmtp-ppp-config [ option ... ] # -v Be verbose # -p Use current PPP host name (default) # -d Use default local host name from # \"\$PROJ_ETC/localHost\" (\"$PROJ_ETC/localHost\") # -h localHost Specify the local host name # -m mailHost Specify mail delivery host name # -fy | -foy | -floy Allow From: override from message header # -fn | -fon | -flon Forbid From: override from message header # -h | -help | --help Display this usage summary usageSummary="Usage: ssmtp-ppp-config [ option ... ] # -v Be verbose # -p Use current PPP host name (default) # -d Use default local host name from # \"\$PROJ_ETC/localHost\" (\"$PROJ_ETC/localHost\") # -h localHost Specify the local host name # -m mailHost Specify mail delivery host name # -fy | -foy | -floy Allow From: override from message header # -fn | -fon | -flon Forbid From: override from message header # -h | -help | --help Display this usage summary " showUsage() { echo -n "ssmtp-ppp-config: " echo "$usageSummary" } localHost= mailHost= fromOverride="FromLineOverride=YES" flo= operateQuietly=1 quitEarly= # Process arguments while [ $# -gt 0 ]; do arg="$1" shift case "$arg" in -v) operateQuietly= ;; -p) localHost= ;; -d) checkenv PROJ_ETC || exit 1 if [ ! -s "$PROJ_ETC/localhost" ]; then localHost="$(cat "$PROJ_ETC/localHost")" else echo "ssmtp-ppp-config: Error: \"$RPOJ_ETC/localhost\" does not exist or is empty." >&2 quitEarly=1 fi ;; -m) mailHost="$1" shift ;; -h) localHost="$1" shift ;; -fy | -foy | -floy) flo=1 fromOverride="FromLineOverride=YES" ;; -fn | -fon | -flon) flo=0 fromOverride="FromLineOverride=NO" ;; -h | -help | --help) showUsage quitEarly=0 ;; esac done # If not specified, use the local PPP host name as the local host name if [ -z "$localHost" ]; then localHost="${2:-$(pppDNS)}" if [ -z "$localHost" ]; then echo "ssmtp-ppp-config: Cannot ascertain local host name" quitEarly=1 fi fi # If not specified, use the default mail hub name if [ -z "$mailHost" ]; then checkenv PROJ_ETC || exit 1 if [ -s "$PROJ_ETC/mailhost" ]; then . "$PROJ_ETC/mailhost" else echo "No outgoing mail host information available" >&2 quitEarly=1 fi fi if [ "$quitEarly" ]; then exit $quitEarly fi if [ ! "$operateQuietly" ]; then echo "Using mail delivery host \"$mailHost\" and local host name \"$localHost\"" [ "$flo" ] && echo "From-line override allowed" || echo "From-line override forbidden" fi # # Generate the ssmtp configuration file # cat >|"/etc/ssmtp/ssmtp.conf" <<-EOCONFIG # # /etc/ssmtp.conf -- a config file for sSMTP sendmail. # # The person who gets all mail for userids < 10 root=postmaster # The place where the mail goes. The actual machine name is required # no MX records are consulted. Commonly mailhosts are named mail.domain.com # The example will fit if you are in domain.com and you mailhub is so named. mailhub=$mailHost # Where will the mail seem to come from? #rewriteDomain=$mailname # The full hostname hostname=$localHost # Set this to never rewrite the "From:" line (unless not given) and to # use that address in the "from line" of the envelope. $fromOverride EOCONFIG