#!/bin/sh -e #----------------------------------------------------------------------------- # $Sendmail: sendmailconfig,v 8.14.4 2010-10-16 19:38:59 cowboy Exp $ # # Interactively configure Sendmail for Debian # # Copyright (c) 1998-2010 Richard Nelson. All Rights Reserved. # # Robert Leslie , # Rick Nelson # #----------------------------------------------------------------------------- set -e; PATH='/usr/sbin:/usr/bin:/sbin:/bin'; SENDMAIL_MC="/etc/mail/sendmail.mc"; SUBMIT_MC="/etc/mail/submit.mc"; # Path to other sendmail helpers if [ -x ./update_sendmail ]; then sm_path='.'; elif [ -x $(dirname $0)/update_sendmail ]; then sm_path=$(dirname $0); else sm_path=/usr/share/sendmail; fi; # Bring in sendmail.conf for the network definitions if [ ! -f /etc/mail/sendmail.conf ]; then if [ -x $sm_path/update_conf ]; then $sm_path/update_conf; fi; fi; if [ -f /etc/mail/sendmail.conf ]; then . /etc/mail/sendmail.conf; fi; set +e; reload="yes"; umask 022; #------------------------------------------------------------------------------ while [ $# -gt 0 ]; do case "$1" in --no-reload) reload=""; shift; ;; *) echo "Usage: $0 [--no-reload]" >&2; exit 1; ;; esac; done; #------------------------------------------------------------------------------ descrip() { echo ''; echo "$1"; echo "$1" | sed -e 's/./-/g'; cat -; echo ''; }; yesno() { local N='N' Y='Y'; local q="$1" def=$(eval "echo -n \$$2"); while :; do echo -n "$q? [$def] "; read REPLY; REPLY=$(echo -n "$REPLY" | sed -e "s/^\ *//" -e "s/^\t*//"); test -n "$REPLY" || REPLY="$def"; case "$REPLY" in [Yy]*) echo yes > /dev/null; eval "$2=\"Y\""; return 0; ;; [Nn]*) echo no > /dev/null; eval "$2=\"N\""; return 1; ;; esac; done; }; input() { local q="$1" def=$(eval "echo -n \$$2"); echo -n "$q? [$def] "; read REPLY REPLY=$(echo "$REPLY" | sed -e 's/^[ ]*//' -e 's/[ ]*$//' | cat); test -n "$REPLY" || REPLY="$def"; if [ "NONE" = "$3" ]; then case "$REPLY" in [Nn][Oo][Nn][Ee]*) REPLY=''; ;; esac; fi; eval "$2=\"$REPLY\""; }; testconfig() { CONFIG=$(grep -Ee "^[[:space:]]*$1" $SENDMAIL_MC 2>/dev/null); }; makecf() { if [ -x $sm_path/update_sendmail ]; then echo "Updating sendmail environment ..."; $sm_path/update_sendmail || true; fi; if [ "$reload" ] && \ yesno \ "Reload the running sendmail now with the new configuration" Y then echo "Reloading sendmail ..."; /etc/init.d/sendmail reload >/dev/null; fi; } #------------------------------------------------------------------------------ if [ -f $SENDMAIL_MC ]; then if yesno "Configure sendmail with the existing /etc/mail/sendmail.conf" Y then if ! $sm_path/update_conf; then echo "Correct /etc/mail/sendmail.conf before continuing."; exit 1; fi; else echo "Edit /etc/mail/sendmail.conf and reissue $0."; exit 0; fi; if yesno "Configure sendmail with the existing $SENDMAIL_MC" Y then makecf; exit 0; fi; fi; ############################################################################### exec 3>$SENDMAIL_MC.new; trap "rm -f $SENDMAIL_MC.new" 0; ############################################################################### descrip "Sendmail Configuration" <<-EOT By answering the following questions, you can configure sendmail for your system. Default values are determined either by your existing configuration or from common usage. EOT echo -n "Press [ENTER] "; read REPLY; cat /usr/share/sendmail/cf/debian/sendmail.mc >&3; cp -a /usr/share/sendmail/cf/debian/submit.mc \ $SUBMIT_MC.new; echo "LOCAL_CONFIG" >&3; ############################################################################### descrip "Mail Name" </dev/null || hostname --fqdn); input "Mail name" mailname; echo "$mailname" >/etc/mailname; ############################################################################### descrip "Null Client" <&3; echo "LOCAL_USER(root)dnl" >&3; echo "MASQUERADE_AS(\`$mailname')dnl" >&3; echo "FEATURE(\`allmasquerade')dnl" >&3; echo "FEATURE(\`masquerade_envelope')dnl" >&3; echo "FEATURE(\`nullclient', $nullclient)dnl" >&3; fi; if [ -z "$nullclient" ]; then ############################################################################### descrip "Smart Host" <&3; echo "MASQUERADE_AS(\`$mailname')dnl" >&3; fi; #if [ -n "$nullclient" ] && [ ! -z "$smarthost" ]; then # echo "undefine(\`ALIAS_FILE')dnl" >&3 # echo "define(\`confFORWARD_PATH', \`')dnl" >&3 # echo "define(\`MAIL_HUB', \`$smarthost')dnl" >&3 # echo "MASQUERADE_AS(\`$smarthost')dnl" >&3 # echo "FEATURE(\`allmasquerade')dnl" >&3 # echo "FEATURE(\`masquerade_envelope')dnl" >&3 # fi ############################################################################### descrip "Address Canonification" <&3; ############################################################################### #descrip "SMTP Mailer" <&3; ############################################################################### descrip "All Masquerade" <&3; ############################################################################### descrip "Dont masquerade mail to local users" <&3; ############################################################################### descrip "Always Add Domain" <&3; ############################################################################### descrip "Mail Acceptance" <&3; ############################################################################### descrip "Alternate Names" </dev/null | tr -s '\n \t' ' ' | sed -e 's/^ *//' -e 's/ *$//'); input "Alternate names" altnames NONE; if [ -n "$altnames" ]; then echo "$altnames" | tr -s ' \t' '\n' >$cw_file; else echo "localhost" >$cw_file; fi; chown root:smmsp $cw_file; chmod 0644 $cw_file; echo "FEATURE(\`use_cw_file')dnl" >&3; ############################################################################### descrip "Trusted Users" </dev/null | tr -s '\n \t' ' ' | sed -e 's/^ *//' -e 's/ *$//'); input "Trusted users" trusted NONE; if [ -n "$trusted" ]; then echo "$trusted" | tr -s ' \t' '\n' >$ct_file; chown root:smmsp $ct_file; chmod 0644 $ct_file; else cat /dev/null >$ct_file; fi; echo "FEATURE(\`use_ct_file')dnl" >&3; echo "FEATURE(\`use_ct_file')dnl" >> $SUBMIT_MC.new; ############################################################################### descrip "Redirect Feature" <.REDIRECT, causing sendmail to return mail to the sender with an error but indicating the recipient's new address. EOT redirect="N"; ! testconfig "FEATURE\(\`?redirect" || redirect="Y"; ! yesno "Enable redirect option" redirect || \ echo "FEATURE(\`redirect')dnl" >&3; ############################################################################### descrip "UUCP Addresses" <&3; ############################################################################### descrip "Sticky Host" <&3; ############################################################################### descrip "DNS" <&3; ############################################################################### if [ Y = "$dns" ]; then ############################################################################### descrip "Best MX is Local" <&3; ############################################################################### fi; # finished DNS configuration ############################################################################### descrip "Mailertable" <&3; ############################################################################### descrip "Sendmail Restricted Shell" <&3; ############################################################################### #descrip "Mailer Name" <&3; ############################################################################### #descrip "Me Too" <&3; ############################################################################### descrip "Message Timeouts" <&3; test "5d" = "$qr" || echo "define(\`confTO_QUEUERETURN', \`$qr')dnl" >&3; ############################################################################### # Support dialup configuration cat <<-EOT >&3 dnl # dnl # Dialup/LAN connection overrides dnl # include(\`/etc/mail/m4/dialup.m4')dnl include(\`/etc/mail/m4/provider.m4')dnl dnl # EOT ############################################################################### echo "MAILER_DEFINITIONS" >&3 echo "MAILER(local)dnl" >&3 test "N" = "$smtp" || echo "MAILER(smtp)dnl" >&3; ############################################################################### if [ -e /etc/ifmail/config ] && \ [ -e /usr/share/sendmail/cf/mailer/ifmail.m4 ]; then echo "MAILER(ifmail)dnl" >&3; fi; ############################################################################### fi; # finished non-"null client" configuration ############################################################################### echo "" >&3; echo "LOCAL_CONFIG" >&3; #if [ -z $nullclient ]; then # echo "MASQUERADE_AS($mailname)dnl" >&3 # fi if [ -f $SENDMAIL_MC ]; then sed -n -e '/^## Custom/,$p' $SENDMAIL_MC >&3; else echo "## Custom configurations below (will be preserved)" >&3; fi; descrip "Configuration Complete" <&-; if [ -f $SENDMAIL_MC ];then echo "Saving old $SENDMAIL_MC as $SENDMAIL_MC.old ..."; mv -f $SENDMAIL_MC $SENDMAIL_MC.old; fi; chown root:smmsp $SENDMAIL_MC.new; chmod 0644 $SENDMAIL_MC.new; mv -f $SENDMAIL_MC.new $SENDMAIL_MC; if [ ! -f /usr/share/sendmail/cf/feature/msp.m4 ]; then chown root:smmsp $SUBMIT_MC.new; chmod 0644 $SUBMIT_MC.new; mv -f $SUBMIT_MC.new $SUBMIT_MC; fi; trap - 0; makecf; exit 0;