diff options
Diffstat (limited to 'debian/sendmail.postinst.in')
-rw-r--r-- | debian/sendmail.postinst.in | 356 |
1 files changed, 356 insertions, 0 deletions
diff --git a/debian/sendmail.postinst.in b/debian/sendmail.postinst.in new file mode 100644 index 0000000..d2cd445 --- /dev/null +++ b/debian/sendmail.postinst.in @@ -0,0 +1,356 @@ +#!/bin/sh -e +# +# Debian post installation script +# +# Install of already installed package: +# 1) old-prerm upgrade new-version +# *) new-prerm failed-upgrade old-version +# *) old-postinst abort-upgrade new-version +# +# If a `conflicting' package is being removed at the same time: +# 1) forall packages depending on conflicting package and --auto-deconfigure +# deconfigured's-prerm deconfigure \ +# in-favour package-being-installed version \ +# removing conflicting-package version +# *) deconfigured's-postinst abort-deconfigure \ +# in-favour package-being-installed-but-failed version \ +# removing conflicting-package version +# 2) To prepare for removal of the conflicting package +# conflictor's-prerm remove \ +# in-favour package new-version +# *) conflictor's-postinst abort-remove \ +# in-favour package new-version +# +# Configuration of package: +# postinst configure most-recently-configured-version +# +set -e; + +PACKAGE=`echo "$(basename $0)" | sed -e 's/\.postinst$//'`; + +# do we have debconf? +if [ -f /usr/share/debconf/confmodule ]; then + DEBCONF=true; + #. /usr/share/debconf/confmodule; + #db_stop; # For testing +else + DEBCONF=''; + fi; + +case "$1" in + configure) + # continue below + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + exit 0; + ;; + + *) + echo "$PACKAGE postinst called with unknown argument \`$1'" >&2; + exit 1; + ;; + esac; + +#-------------------------------------------------------------------- +# Continuation of "$1" = "configure" + +if [ "$2" = "" ]; then + echo " "; + echo "A new sendmail user, welcome!"; + fi; + +# Note: can't use debhelper here because the actions aren't contiguous +#xxxHELPER# + +# This would be done via debhelper, but the start of sendmail must be delayed + +if [ '@DEBIAN_DH@' != '4.1' ]; then +# Automatically added by dh_installdocs +if [ "$1" = "configure" ]; then + if [ -d /usr/doc -a ! -e /usr/doc/sendmail -a -d /usr/share/doc/sendmail ]; then + ln -sf ../share/doc/sendmail /usr/doc/sendmail + fi +fi +# End automatically added section +fi; +# Automatically added by dh_installinit +if [ -x "@sysconfdir@/init.d/sendmail" ]; then + update-rc.d sendmail defaults >/dev/null + #/etc/init.d/sendmail start +fi +# End automatically added section +# Automatically added by dh_installmenu +#if test -x /usr/bin/update-menus ; then update-menus ; fi +# End automatically added section + +#----------------------------------------------------------- +# Tell users about new and interesting things... +if [ -x @datadir@/sendmail/update_notices ]; then + @datadir@/sendmail/update_notices $2; + fi; + + +#----------------------------------------------------------- +if test ! -z "$version" && \ + (dpkg --compare-versions "$version" lt 8.12.6-5); then + if [ -x /usr/sbin/deluser ]; then + deluser --quiet smmsp || true; + else + userdel smmsp || true; + fi; + if [ -x /usr/sbin/delgroup ]; then + delgroup --quiet smmsp || true; + else + groupdel smmsp || true; + fi; + fi; +# Create group/user smmsp iff needed +touch @sysconfdir@/mail/smmsp; +if ! chown root:smmsp @sysconfdir@/mail/smmsp 2>/dev/null; then + addgroup --system --quiet smmsp; + fi; +if ! chown smmsp:smmsp @sysconfdir@/mail/smmsp 2>/dev/null; then + adduser --system --ingroup smmsp --home "/var/lib/sendmail" \ + --disabled-password \ + --quiet --gecos 'Mail Submission Program' smmsp; + fi; +rm @sysconfdir@/mail/smmsp; + +#----------------------------------------------------------- +# With a dynamic uid/gid, have to set appropriate ownership herein +if command -v suidregister >/dev/null 2>&1 && test -s /etc/suid.conf; then + suidregister -s sendmail @sbindir@/sendmail root smmsp 02755; + suidregister -s sendmail @libexecdir@/mailstats root smmsp 02755; +elif [ -x @sbindir@/sendmail ]; then + chown root:smmsp @sbindir@/sendmail; + chmod 02755 @sbindir@/sendmail; + chown root:smmsp @libexecdir@/mailstats; + chmod 02755 @libexecdir@/mailstats; + fi; +chown root:smmsp @sysconfdir@/mail/sasl; +chown root:smmsp @sysconfdir@/mail/tls; + +#----------------------------------------------------------- +# Make sure inetd.conf has sendmail in it (but disabled) +if [ -x /usr/sbin/update-inetd ]; then + update-inetd --group MAIL --remove smtp; + update-inetd --group MAIL --remove smtps; + update-inetd --group MAIL --remove 587; + update-inetd --group MAIL --add \ + "smtp \tstream\ttcp\tnowait\troot\t@sbindir@/sendmail sendmail -Am -bs"; + update-inetd --group MAIL --add \ + "587 \tstream\ttcp\tnowait\troot\t@sbindir@/sendmail sendmail -Am -bs"; + update-inetd --group MAIL --add \ + "smtps\tstream\ttcp\tnowait\troot\t@sbindir@/sendmail sendmail -Am -bs"; + update-inetd --group MAIL --disable smtp,smtps,587; + fi; + +#----------------------------------------------------------- +# Save the current configuration files in safe place... +if [ -x @sysconfdir@/cron.daily/sendmail ]; then + echo "Saving current /etc/mail/sendmail.mc,cf to /var/backups"; + @sysconfdir@/cron.daily/sendmail || true; + fi; + +#----------------------------------------------------------- +#stop(): stop sendmail +stop () { + # Account for varying PIDfile locations of older sendmail packages + if [ -f /var/run/sendmail/msp/sendmail.pid ]; then + start-stop-daemon --stop --oknodo --quiet \ + --pidfile /var/run/sendmail/msp/sendmail.pid > /dev/null; + start-stop-daemon --stop --oknodo --quiet \ + -pidfile /var/run/sendmail/mta/sendmail.pid > /dev/null; + elif [ -f /var/run/sendmail/sendmail.pid ]; then + start-stop-daemon --stop --oknodo --quiet \ + --pidfile /var/run/sendmail/sendmail.pid > /dev/null; + elif [ -f /var/run/sendmail.pid ]; then + start-stop-daemon --stop --oknodo --quiet \ + --pidfile /var/run/sendmail.pid > /dev/null; + fi; + if [ -x @sysconfdir@/init.d/sendmail ]; then + if [ -x /usr/sbin/invoke-rc.d ]; then + /usr/sbin/invoke-rc.d --quiet --force sendmail stop; + else + @sysconfdir@/init.d/sendmail stop; + fi; + fi; + }; + +start_ask=0; + +#----------------------------------------------------------- +#start(): start sendmail +start () { + local enter; + if [ $start_ask -eq 1 ]; then + echo " "; + echo -n "Start sendmail now? (Y/n) "; + read yn; + yn=$(echo -n "$yn" | sed -e "s/^\ *//" -e "s/^\t*//"); + test -n "$yn" || yn="Y"; + case "$yn" in + [Yy]*) + if [ -x /usr/sbin/invoke-rc.d ]; then + /usr/sbin/invoke-rc.d sendmail start; + else + @sysconfdir@/init.d/sendmail start; + fi; + ;; + [Nn]*) + echo " "; + echo "Not started; to start later," \ + "type: @sysconfdir@/init.d/sendmail start"; + echo -n "Press [ENTER] "; + read enter; + ;; + esac; + fi; + }; + +#----------------------------------------------------------- +# configure(): save sendmail.cf, call sendmailconfig +configure () { + local enter; + echo -n "Configure now ? (y/N) "; + read yn; + yn=$(echo -n "$yn" | sed -e "s/^\ *//" -e "s/^\t*//"); + test -n "$yn" || yn="N"; + case "$yn" in + [Yy]*) + if [ -f @sysconfdir@/mail/sendmail.cf ]; then + echo "Saving old /etc/mail/sendmail.cf" \ + "as /etc/mail/sendmail.cf.old ..."; + mv -f @sysconfdir@/mail/sendmail.cf \ + @sysconfdir@/mail/sendmail.cf.old; + chown root:root @sysconfdir@/mail/sendmail.cf.old; + chmod 0644 @sysconfdir@/mail/sendmail.cf.old; + fi; + @sbindir@/sendmailconfig --no-reload; + start; + ;; + + [Nn]*) + echo -e "\nTo configure sendmail later, type" \ + "sendmailconfig"; + echo "After configuring sendmail, you can" \ + "start it via @sysconfdir@/init.d/sendmail start"; + echo -n "Press [ENTER] "; + read enter; + ;; + esac; + }; + +#----------------------------------------------------------- +# Create /etc/mail/sendmail.mc if it doesn't exist +if [ ! -f @sysconfdir@/mail/sendmail.mc ]; then + cat <<-EOT + + You are doing a new install, or have erased /etc/mail/sendmail.mc. + If you've accidentaly erased /etc/mail/sendmail.mc, check /var/backups. + + Sendmail will not start until it is configured. + Do you wish to configure sendmail now, or wait until later? + + EOT + start_ask=1; + start_txt=""; + configure; + exit 0; + fi; + +#----------------------------------------------------------- +# See if we can do this automagically... +cat <<-EOT + +It is a good idea to regenerate the sendmail configuration +file with each new spin of the sendmail package. + +But, if you hand edit sendmail.cf instead of making changes through +sendmail.mc, then you want to say no, save your old sendmail.cf, run +sendmailconfig, then migrate your changes into the new version. + +EOT +echo -n "Automagically regenerate the sendmail.cf configuration file? (Y/n) "; +read yn; +yn=$(echo -n "$yn" | sed -e "s/^\ *//" -e "s/^\t*//"); +test -n "$yn" || yn="Y"; +case "$yn" in + [Yy]*) + if [ -f @sysconfdir@/mail/sendmail.cf ]; then + echo "Saving old /etc/mail/sendmail.cf" \ + "as /etc/mail/sendmail.cf.old ..."; + cp -f @sysconfdir@/mail/sendmail.cf \ + @sysconfdir@/mail/sendmail.cf.old; + chown root:root @sysconfdir@/mail/sendmail.cf.old; + chmod 0644 @sysconfdir@/mail/sendmail.cf.old; + fi; + if [ -x @datadir@/sendmail/update_sendmail ]; then + stop; + echo "Updating sendmail environment ..."; + @datadir@/sendmail/update_sendmail || true; + fi; + ;; + + [Nn]*) + cat <<-EOT + + Your files (sendmail.mc,cf, etc) have *not* been altered. + + *** Warning *** Warning *** Warning *** Warning *** Warning *** Warning *** + + There have been changes in + * Paths of some databases and executables + * FEATUREs, DOMAIN, includes + * Internal Database storage + + These changes were *NOT* made for you ... And will not be + until you run sendmailconfig! + + Until you update /etc/mail/sendmail.cf via sendmailconfig, + you should expect to have problems running sendmail! + + "Well, a pet peeve of mine is people who directly edit the + .cf file instead of using the m4 configuration files. + Don't do it! [laughs] I treat the .cf file as a binary + file - you should too." + -- Eric Allman 1999/10/18 + + *** Warning *** Warning *** Warning *** Warning *** Warning *** Warning *** + + EOT + echo "Do you wish to run sendmailconfig now, or later"; + start_ask=0; + stop; + configure; + case "$yn" in + [Yy]*) + cat <<-EOT + + Do you wish to start sendmail with the new sendmail.cf, + or do you wish to delay until you can merge any changes + from your older sendmail.cf.old? + EOT + start_ask=1; + start; + ;; + esac; + exit 0; + esac; + +#----------------------------------------------------------- +# If we're still here, we're going the automagic path... +# Now, liberal application of smoke and mirrors +if [ -f @sysconfdir@/mail/sendmail.mc ]; then + start_ask=1; + start; + fi; + +exit 0; + +#----------------------------------------------------------- +# +# List herein (for reference) what debhelper would've done: +#DEBHELPER# +exit 0; |