diff options
Diffstat (limited to 'debian/sendmail.postinst')
-rw-r--r-- | debian/sendmail.postinst | 427 |
1 files changed, 291 insertions, 136 deletions
diff --git a/debian/sendmail.postinst b/debian/sendmail.postinst index 14d7efc..1e4aa11 100644 --- a/debian/sendmail.postinst +++ b/debian/sendmail.postinst @@ -1,176 +1,331 @@ #!/bin/sh -e -# -# Debian package postinst -# Version 1.2 -# -# Robert Leslie <rob@mars.org> -# Note: can't use debhelper here because the actions aren't contiguous +set -e case "$1" in configure) # continue below - ;; + ;; abort-upgrade|abort-remove|abort-deconfigure) exit 0 - ;; + ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 0 - ;; -esac + ;; + esac -#if [ "$2" == "" ]; then echo "first time"; fi +#-------------------------------------------------------------------- +# Continuation of "$1" = "configure" -if [ -e /etc/suid.conf -a -x /usr/sbin/suidregister ]; then - suidregister -s sendmail /usr/sbin/sendmail root root 4755 -else - chown root.root /usr/sbin/sendmail - chmod 4755 /usr/sbin/sendmail -fi +#if [ "$2" = "" ]; then echo "first time"; fi -if [ ! -d /etc/mail ] -then - mkdir /etc/mail - chown 0.0 /etc/mail - chmod 755 /etc/mail -fi +# Note: can't use debhelper here because the actions aren't contiguous +#xxxHELPER# -if [ ! -d /var/spool/mqueue ] -then - mkdir /var/spool/mqueue - chown 0.0 /var/spool/mqueue - chmod 700 /var/spool/mqueue -fi +# This would be done via debhelper, but the start of sendmail must be delayed -if [ ! -f /var/log/sendmail.st ] -then - touch /var/log/sendmail.st - chown 0.0 /var/log/sendmail.st - chmod 644 /var/log/sendmail.st +# 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 +# Automatically added by dh_installinit update-rc.d sendmail defaults >/dev/null -update-inetd --disable smtp +#/etc/init.d/sendmail start +# End automatically added section +# Automatically added by dh_installmenu +#if test -x /usr/bin/update-menus ; then update-menus ; fi +# End automatically added section +# Automatically added by dh_suidregister +if command -v suidregister >/dev/null 2>&1 && [ -e /etc/suid.conf ]; then + suidregister -s sendmail /usr/sbin/sendmail root mail 04755 +elif [ -e /usr/sbin/sendmail ]; then + chown root.mail /usr/sbin/sendmail + chmod 04755 /usr/sbin/sendmail + fi +if command -v suidregister >/dev/null 2>&1 && [ -e /etc/suid.conf ]; then + suidregister -s sendmail /usr/lib/sm.bin/mail.local root mail 04755 +elif [ -e /usr/lib/sm.bin/mail.local ]; then + chown root.mail /usr/lib/sm.bin/mail.local + chmod 04755 /usr/lib/sm.bin/mail.local + fi +# End automatically added section -# Move old configuration files to their new home +/etc/init.d/sendmail stop +update-inetd --disable smtp -if [ -f /etc/sendmail.cf -a \ - ! -L /etc/sendmail.cf -a \ - ! -f /etc/mail/sendmail.cf ] -then - echo "This version of the Debian sendmail package keeps its configuration" - echo "files under /etc/mail. You already have some sendmail configuration" - echo -n "files in /etc; would you like to move them to /etc/mail? [Y] " - read yn - test -n "$yn" || yn="Y" +#----------------------------------------------------------- +# Create any needed directories, and move any prior data to +# its new home - case "$yn" in - [Yy]*) - echo "Moving /etc/sendmail.* to /etc/mail ..." - mv -f /etc/sendmail.* /etc/mail/. +if [ ! -d /etc/mail ]; then + mkdir /etc/mail + chown root.mail /etc/mail + chmod 02770 /etc/mail + fi - test ! -f /etc/mail/sendmail.cf || \ - mv -f /etc/mail/sendmail.cf /etc/mail/sendmail.cf.old - ;; +if [ ! -f /etc/mail/aliases -a ! -f /etc/aliases ]; then + if [ -f /usr/doc/sendmail/examples/db-examples/aliases ]; then + cp /usr/doc/sendmail/examples/db-examples/aliases /etc/aliases + fi + fi - *) - echo "Okay, leaving them where they are; they won't be used." - ;; - esac -fi +if [ ! -d /var/spool/mail ]; then + mkdir /var/spool/mail + chown root.mail /var/spool/mail + chmod 03775 /var/spool/mail + fi -# Make sure /etc/sendmail.cf points to /etc/mail/sendmail.cf +if [ ! -d /var/spool/mqueue ]; then + mkdir /var/spool/mqueue + chown root.mail /var/spool/mqueue + chmod 0750 /var/spool/mqueue + fi -if [ -e /etc/sendmail.cf ] -then - if [ -L /etc/sendmail.cf ] - then - rm -f /etc/sendmail.cf - else - echo "Saving old /etc/sendmail.cf as /etc/sendmail.cf.old ..." - mv -f /etc/sendmail.cf /etc/sendmail.cf.old +if [ ! -d /var/lib/sendmail ]; then + mkdir /var/lib/sendmail + chown root.mail /var/lib/sendmail + chmod 02750 /var/lib/sendmail fi -fi -#ln -sf mail/sendmail.cf /etc/sendmail.cf -#----------------------------------------------------------- -if test "$1" = configure && dpkg --compare-versions "$2" lt 8.9.1-13; then - echo " " - echo "*** IMPORTANT ***" - echo " " - echo "The format of sendmails databases has changed (now using libdb2)." - echo "You *MUST* update your databases (newaliases, users, etc.)" - echo "before allowing sendmail to restart." - echo " " - echo "Press <Enter> to continue" - read yn +if [ -d /var/state/sendmail/host_status ]; then + echo "Moving host_status to /var/lib/sendmail/host_status" + mv /var/state/sendmail/host_status /var/lib/sendmail/host_status +elif [ -d /var/sendmail ]; then + echo "Moving /var/sendmail to /var/lib/sendmail" + mv -f /var/sendmail/* /var/lib/sendmail/ || true + rm -rf /var/sendmail + fi +if [ ! -d /var/lib/sendmail/host_status ]; then + mkdir /var/lib/sendmail/host_status + fi +if [ -d /var/lib/sendmail/host_status ]; then + chown root.mail /var/lib/sendmail/host_status + chmod 02750 /var/lib/sendmail/host_status + fi + +if [ -f /var/log/sendmail.st ]; then + echo "Moving /var/log/sendmail.st to /var/lib/sendmail/sendmail.st" + mv /var/log/sendmail.st /var/lib/sendmail/sendmail.st + fi +if [ -f /var/lib/sendmail/sendmail.st ]; then + chown root.mail /var/lib/sendmail/sendmail.st + chmod 0660 /var/lib/sendmail/sendmail.st fi - + #----------------------------------------------------------- -# Check existing /etc/mail/sendmail.cf - -if [ -f /etc/mail/sendmail.cf ]; then - if test "$1" = configure && dpkg --compare-versions "$2" lt 8.9.2; then - echo " " - echo "*** IMPORTANT ***" - echo " " - echo "This version of sendmail moves more configuration files from" - echo "/etc/... to /etc/mail/... ie: domaintable,genericstable, etc." - echo " " - echo "If you you use any of these, you *MUST*:" - echo " 1)" - echo " A) Move them by hand from /etc/... to /etc/mail/..." - echo " B) Move any script to create databases from the text" - echo " or" - echo " 2) Update your sendmail.mc to explicitly name the file" - echo " FEATURE(genericstable, \`hash -o /etc/mail/genericstable.db')dnl" - echo " " - echo "Press <Enter> to continue" - read yn - fi - if (sed -n -e "/^DZ/s/^DZ//p" /etc/mail/sendmail.cf \ - | grep "8.9.3" > /dev/null); then - echo "Existing /etc/mail/sendmail.cf found, and it appears it may be" - echo -n "compatible with this version of sendmail. Use it? [Y] " - read yn - test -n "$yn" || yn="Y" - else - echo "Existing /etc/mail/sendmail.cf found, but it was made for" - echo -n "an older version of sendmail. Use it anyway? [N] " +# Move sendmail.{mc,cf} from /etc/ to /etc/mail +if [ ! -f /etc/mail/sendmail.mc ]; then + if [ -f /etc/sendmail.mc ]; then + # Move from /etc/sendmail.* to /etc/mail/sendmail.* + echo "Moving /etc/sendmail.* to /etc/mail" + mv /etc/sendmail.mc /etc/mail/sendmail.mc + chown root.mail /etc/mail/sendmail.mc + chmod 0664 /etc/mail/sendmail.mc + mv /etc/sendmail.mc /etc/mail/sendmail.cf + fi; + fi; + +start_ask=0 +#----------------------------------------------------------- +#start(): start sendmail +start () { + 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]*) + /etc/init.d/sendmail start + ;; + [Nn]*) + echo " " + echo "Not started; to start later," \ + "type: /etc/init.d/sendmail start" + echo -n "Press [ENTER] " + read yn + ;; + esac + fi; + } + +#----------------------------------------------------------- +# configure(): save sendmail.cf, call sendmailconfig +configure () { + echo -n "Configure now ? (y/N) " read yn + yn=$(echo -n "$yn" | sed -e "s/^\ *//" -e "s/^\t*//") test -n "$yn" || yn="N" - fi + case "$yn" in + [Yy]*) + if [ -f /etc/mail/sendmail.cf ]; then + echo "Saving old /etc/mail/sendmail.cf" \ + "as /etc/mail/sendmail.cf.old ..." + mv -f /etc/mail/sendmail.cf \ + /etc/mail/sendmail.cf.old + chown root.mail /etc/mail/sendmail.cf.old + chmod 0644 /etc/mail/sendmail.cf.old + fi; + sendmailconfig --no-reload + start + ;; + [Nn]*) + echo -e "\nTo configure sendmail later, type" \ + "sendmailconfig" + echo "After configuring sendmail, you can" \ + "start it via /etc/init.d/sendmail start" + echo -n "Press [ENTER] " + read yn + ;; + esac + } + + +#----------------------------------------------------------- +# Create /etc/mail/sendmail.mc if it doesn't exist +if [ ! -f /etc/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; + +#----------------------------------------------------------- +# Next, save the current files in safe place... +echo "Saving current /etc/mail/sendmail.{mc,cf} to /var/backups" +/etc/cron.daily/sendmail + +#----------------------------------------------------------- +# Perform some updated to an existing sendmail.mc to make +# sure it is compatible with the current executables. +changed=0 +if (grep -q "^[[:space:]]*FEATURE(mailertable, \`text /etc/mail/mailertable')dnl" /etc/mail/sendmail.mc); then + echo "Correcting FEATURE(mailertable) in /etc/mail/sendmail.mc" + sed "s?FEATURE(mailertable, \`text /etc/mail/mailertable')dnl?FEATURE(mailertable)dnl?g" \ + /etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new + changed=1 + chown root.mail /etc/mail/sendmail.mc.new + chmod 0664 /etc/mail/sendmail.mc.new + mv /etc/mail/sendmail.mc.new /etc/mail/sendmail.mc + fi; +if (grep -q "^[[:space:]]*FEATURE(smrsh, \`/usr/sbin/smrsh')dnl" /etc/mail/sendmail.mc); then + echo "Correcting FEATURE(smrsh) in /etc/mail/sendmail.mc" + sed "s?FEATURE(smrsh, \`/usr/sbin/smrsh')dnl?FEATURE(smrsh, \`/usr/lib/sm.bin/smrsh')dnl?g" \ + /etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new + changed=1 + chown root.mail /etc/mail/sendmail.mc.new + chmod 0664 /etc/mail/sendmail.mc.new + mv /etc/mail/sendmail.mc.new /etc/mail/sendmail.mc + fi; - case "$yn" in - [Yy]*) - ;; - - *) - echo "Saving old /etc/mail/sendmail.cf" \ - "as /etc/mail/sendmail.cf.old ..." - mv -f /etc/mail/sendmail.cf /etc/mail/sendmail.cf.old - ;; - esac -fi -test -f /etc/mail/sendmail.cf || sendmailconfig --no-reload +#----------------------------------------------------------- +# See if we can do this automagically... +cat <<-EOT -# Start server +It's usually a good idea to regenerate the sendmail.cf configuration +file with each new spin of the sendmail package. -echo -n "Start sendmail now? [Y] " +But, if you hand edited it 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 - [Nn]*) - echo "Not started; to start later, do: /etc/init.d/sendmail start" - echo -n "Press [ENTER] " - read line - ;; + [Yy]*) + ;; + [Nn]*) + cat <<-EOT - *) - /etc/init.d/sendmail start - ;; -esac + OK, your sendmail.cf has *not* been altered. + EOT + if [ $changed -eq 1 ]; then + cat <<-EOT + + *** Warning *** + There have been changes in the paths + of some databases and executables referenced + in /etc/mail/sendmail.mc. These changes + were made for you (see the "Correcting" messages + above), but they have *not* been + reflected in /etc/mail/sendmail.cf! + + Until you update /etc/mail/sendmail.cf as + outlined above, 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 + + EOT + fi; + echo "Do you wish to run sendmailconfig now, or later" + start_ask=0 + 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 /etc/mail/sendmail.mc ]; then + if [ -f /etc/mail/sendmail.cf ]; then + echo "Saving old /etc/mail/sendmail.cf" \ + "as /etc/mail/sendmail.cf.old ..." + cp -f /etc/mail/sendmail.cf \ + /etc/mail/sendmail.cf.old + chown root.mail /etc/mail/sendmail.cf.old + chmod 0644 /etc/mail/sendmail.cf.old + fi; + /usr/share/sendmail/updatedb || true + start_ask=1 + start + fi; + +exit 0 + +#----------------------------------------------------------- +#if test "$1" = configure && dpkg --compare-versions "$2" lt 8.9.3-4; then +#if (sed -n -e "/^DZ/s/^DZ//p" /etc/mail/sendmail.cf \ +#| grep "8.9.3" > /dev/null); then +#echo "Existing /etc/mail/sendmail.cf found, and it appears it may be" +#echo -n "compatible with this version of sendmail. Use it? [Y] " +# +# List herein (for reference) what debhelper would've done: +#xDEBHELPER# +exit 0 |