| 1 | #!/bin/sh |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | # summary of how this script can be called: |
| 6 | # * <postinst> `configure' <most-recently-configured-version> |
| 7 | # * <old-postinst> `abort-upgrade' <new version> |
| 8 | # * <conflictor's-postinst> `abort-remove' `in-favour' <package> |
| 9 | # <new-version> |
| 10 | # * <postinst> `abort-remove' |
| 11 | # * <deconfigured's-postinst> `abort-deconfigure' `in-favour' |
| 12 | # <failed-install-package> <version> `removing' |
| 13 | # <conflicting-package> <version> |
| 14 | # for details, see http://www.debian.org/doc/debian-policy/ or |
| 15 | # the debian-policy package |
| 16 | |
| 17 | . /usr/share/debconf/confmodule |
| 18 | |
| 19 | CONFIG_FILE=/etc/email-reminder.conf |
| 20 | |
| 21 | case "$1" in |
| 22 | configure) |
| 23 | # Ensure the email-reminder user exists before we try to use it |
| 24 | if ! getent passwd email-reminder > /dev/null; then |
| 25 | systemd-sysusers /usr/lib/sysusers.d/email-reminder.conf |
| 26 | fi |
| 27 | |
| 28 | # The config file can include the SMTP password so hide it |
| 29 | touch "$CONFIG_FILE" |
| 30 | chmod 640 "$CONFIG_FILE" |
| 31 | chown email-reminder:root "$CONFIG_FILE" |
| 32 | |
| 33 | # Update the config file with debconf settings |
| 34 | DEBCONF_START="### BEGIN DEBCONF SECTION - DO NOT EDIT ###" |
| 35 | DEBCONF_END="### END DEBCONF SECTION ###" |
| 36 | USER_SECTION="### Add your custom settings below this line ###" |
| 37 | |
| 38 | # Save user customizations (everything after USER_SECTION marker) |
| 39 | USER_CUSTOMS="" |
| 40 | if [ -f "$CONFIG_FILE" ] && grep -q "^${USER_SECTION}" "$CONFIG_FILE" 2>/dev/null; then |
| 41 | USER_CUSTOMS=$(sed -n "/^${USER_SECTION}/,\$p" "$CONFIG_FILE" | tail -n +2) |
| 42 | fi |
| 43 | |
| 44 | # Rebuild the config file from scratch |
| 45 | cat > "$CONFIG_FILE" <<EOF |
| 46 | ${DEBCONF_START} |
| 47 | # WARNING: This section is automatically generated from debconf settings. |
| 48 | # DO NOT edit this section directly or your changes will be lost. |
| 49 | # To change these values, run: dpkg-reconfigure email-reminder |
| 50 | EOF |
| 51 | |
| 52 | db_get email-reminder/send_reminders |
| 53 | echo "send_reminders = ${RET}" >> "$CONFIG_FILE" |
| 54 | db_get email-reminder/smtp_server |
| 55 | echo "smtp_server = ${RET}" >> "$CONFIG_FILE" |
| 56 | db_get email-reminder/smtp_username |
| 57 | echo "smtp_username = ${RET}" >> "$CONFIG_FILE" |
| 58 | db_get email-reminder/smtp_password |
| 59 | echo "smtp_password = ${RET}" >> "$CONFIG_FILE" |
| 60 | db_reset email-reminder/smtp_password |
| 61 | db_get email-reminder/smtp_ssl |
| 62 | echo "smtp_ssl = ${RET}" >> "$CONFIG_FILE" |
| 63 | db_get email-reminder/mail_from |
| 64 | echo "mail_from = ${RET}" >> "$CONFIG_FILE" |
| 65 | |
| 66 | cat >> "$CONFIG_FILE" <<EOF |
| 67 | ${DEBCONF_END} |
| 68 | |
| 69 | ${USER_SECTION} |
| 70 | EOF |
| 71 | |
| 72 | # Append user customizations if any were saved |
| 73 | if [ -n "$USER_CUSTOMS" ]; then |
| 74 | echo "$USER_CUSTOMS" >> "$CONFIG_FILE" |
| 75 | fi |
| 76 | |
| 77 | # Create the spool directory for that user |
| 78 | mkdir -p /var/spool/email-reminder |
| 79 | chown email-reminder:root /var/spool/email-reminder/ |
| 80 | chmod 770 /var/spool/email-reminder/ |
| 81 | ;; |
| 82 | |
| 83 | abort-upgrade|abort-remove|abort-deconfigure) |
| 84 | ;; |
| 85 | |
| 86 | *) |
| 87 | echo "postinst called with unknown argument \`$1'" >&2 |
| 88 | exit 1 |
| 89 | ;; |
| 90 | esac |
| 91 | |
| 92 | # dh_installdeb will replace this with shell code automatically |
| 93 | # generated by other debhelper scripts. |
| 94 | |
| 95 | #DEBHELPER# |
| 96 | |
| 97 | exit 0 |