Current File : /var/lib/dpkg/info/msmtp.postinst
#!/bin/sh

set -e

if [ -e /usr/share/debconf/confmodule ]; then
    . /usr/share/debconf/confmodule
fi

# Automatically added by dh_apparmor/2.13.6-10
if [ "$1" = "configure" ]; then
    APP_PROFILE="/etc/apparmor.d/usr.bin.msmtp"
    if [ -f "$APP_PROFILE" ]; then
        # Add the local/ include
        LOCAL_APP_PROFILE="/etc/apparmor.d/local/usr.bin.msmtp"

        test -e "$LOCAL_APP_PROFILE" || {
            mkdir -p `dirname "$LOCAL_APP_PROFILE"`
            install --mode 644 /dev/null "$LOCAL_APP_PROFILE"
        }

        # Reload the profile, including any abstraction updates
        if aa-enabled --quiet 2>/dev/null; then
            apparmor_parser -r -T -W "$APP_PROFILE" || true
        fi
    fi
fi
# End automatically added section


write_config () {
    # preserve local permissions/ownership
    if [ -f /etc/msmtprc ]; then
        touch /etc/msmtprc.new
        chmod --reference=/etc/msmtprc /etc/msmtprc.new
        chown --reference=/etc/msmtprc /etc/msmtprc.new
    fi

    exec 1> /etc/msmtprc.new
    echo "account default"

    db_get msmtp/host
    if [ -n "$RET" ]; then
        echo "host $RET"
    fi

    db_get msmtp/port
    if [ "$RET" != "25" ]; then
        echo "port $RET"
    fi

    db_get msmtp/auto_from
    if [ "$RET" = "true" ]; then
        db_get msmtp/maildomain
        RET="${RET:-$(hostname --fqdn || true)}"
        if [ -n "$RET" ]; then
            echo "auto_from on"
            echo "maildomain $RET"
        fi
    fi

    db_get msmtp/tls
    if [ "$RET" = "true" ]; then
        echo "tls on"
    fi
}

case $1 in
    configure)
        if ! getent passwd msmtp >/dev/null; then
            adduser --quiet --system --group --no-create-home --home /var/lib/msmtp msmtp
        fi

        if ! dpkg-statoverride --list /usr/bin/msmtp >/dev/null; then
            chgrp msmtp /usr/bin/msmtp
            chmod 2755 /usr/bin/msmtp
        fi

        db_get msmtp/sysconfig
        if [ "$RET" = "true" ]; then
            write_config
            if [ -f /etc/msmtprc ]; then
                ucf --debconf-ok /etc/msmtprc.new /etc/msmtprc
                rm -f /etc/msmtprc.new
            else
                mv /etc/msmtprc.new /etc/msmtprc
            fi
        fi
        ;;
    *)
        exit 0
        ;;
esac