set -e
+ucf_register_templates() {
+ for template in /etc/pmg/templates/*; do
+ [ -e "$template" ] || continue;
+ template_base=$(basename "${template}")
+ if echo "${template_base}" | grep -q '\.ucf-'; then
+ continue
+ fi
+ if [ -e "/var/lib/pmg/templates/${template_base}" ]; then
+ ucf "/var/lib/pmg/templates/${template_base}" "${template}"
+ ucfr pmg-api "${template}"
+ else
+ echo "template '${template}' not shipped by pmg-api."
+ fi
+ done
+}
+
+migrate_apt_auth_conf() {
+ output=""
+ removed=""
+ match=0
+
+ while read -r l; do
+ if echo "$l" | grep -q "^machine enterprise.proxmox.com/debian/pmg"; then
+ match=1
+ elif echo "$l" | grep -q "machine"; then
+ match=0
+ fi
+
+ if test "$match" = "1"; then
+ removed="$removed\n$l"
+ else
+ output="$output\n$l"
+ fi
+ done < /etc/apt/auth.conf
+
+ if test -n "$removed"; then
+ if test ! -e /etc/apt/auth.conf.d/pmg.conf; then
+ echo "Migrating APT auth config for enterprise.proxmox.com to /etc/apt/auth.conf.d/pmg.conf .."
+ echo "$removed" > /etc/apt/auth.conf.d/pmg.conf
+ else
+ echo "Removing stale APT auth config from /etc/apt/auth.conf"
+ fi
+ echo "$output" > /etc/apt/auth.conf
+ fi
+}
case "$1" in
triggered)
- test -e /proxmox_install_mode && exit 0;
+ test -e /proxmox_install_mode && exit 0;
- # Note: reload-or-try-restart fails if service is not active
- systemctl --quiet is-active pmgdaemon.service && deb-systemd-invoke reload-or-try-restart pmgdaemon.service
- systemctl --quiet is-active pmgproxy.service && deb-systemd-invoke reload-or-try-restart pmgproxy.service
- systemctl --quiet is-active pmg-smtp-filter.service && deb-systemd-invoke reload-or-try-restart pmg-smtp-filter.service
- systemctl --quiet is-active pmgpolicy.service && deb-systemd-invoke reload-or-try-restart pmgpolicy.service
+ # Note: reload-or-try-restart fails if service is not active
+ for service in pmgdaemon pmgproxy pmg-smtp-filter pmgpolicy pmgtunnel pmgmirror; do
+ if systemctl --quiet is-active $service.service ; then
+ deb-systemd-invoke reload-or-try-restart $service.service >/dev/null || true
+ fi
+ done
- exit 0
+ exit 0
;;
configure)
- test -e /proxmox_install_mode || pmgdb init
- test -e /proxmox_install_mode || pmgdb update >/dev/null 2>&1 &
-
+ if test ! -e /proxmox_install_mode ; then
+
+ pmgconf="/etc/pmg/pmg.conf"
+ if test -n "$2" && dpkg --compare-versions "$2" 'lt' '8.0.2'; then
+ # on upgrade add pre 8.0 default values for advfilter, use_awl and use_bayes
+ # TODO: remove with 9.0
+ if test ! -e $pmgconf ; then
+ # if the config does not exist at all, fill with previous default configs
+ printf "section: admin\n\tadvfilter 1\n" > $pmgconf
+ printf "\nsection: spam\n\tuse_bayes 1\n\tuse_awl 1\n" >> $pmgconf
+ else
+ if ! grep -qP '\s+advfilter' $pmgconf ; then
+ echo "hard-code old default for 'advfilter'"
+ if ! grep -q '^section: admin$' $pmgconf ; then
+ printf "\nsection: admin" >> $pmgconf
+ fi
+ sed -i '/^section: admin$/a\\tadvfilter 1' $pmgconf
+ fi
+
+ if ! grep -q '^section: spam$' $pmgconf ; then
+ printf "\nsection: spam" >> $pmgconf
+ fi
+ if ! grep -qP '^\s+use_bayes\s' $pmgconf ; then
+ echo "hard-code old default for 'use_bayes'"
+ sed -i '/^section: spam$/a\\tuse_bayes 1' $pmgconf
+ fi
+ if ! grep -qP '^\s+use_awl\s' $pmgconf ; then
+ echo "hard-code old default for 'use_awl'"
+ sed -i '/^section: spam$/a\\tuse_awl 1' $pmgconf
+ fi
+ fi
+ fi
+
+ pmgconfig init || true
+ pmgdb init || true
+
+ ucf_register_templates
+ pmgconfig sync --restart || true
+
+ if [ -z "$2" ]; then
+ if systemctl --quiet is-active pmgpolicy.service ; then
+ deb-systemd-invoke reload-or-try-restart postgresql.service >/dev/null || true
+ fi
+ deb-systemd-invoke restart postfix.service >/dev/null || true
+ fi
+
+ pmgdb update >/dev/null 2>&1 &
+
+ update-mime-database /usr/share/mime
+
+ else
+ # rewrite banner
+ pmgbanner || true
+ fi
+
+ if test ! -e /proxmox_install_mode && test -n "$2" && dpkg --compare-versions "$2" 'lt' '7.1-7~'; then
+ if test -e /etc/apt/auth.conf ; then
+ migrate_apt_auth_conf
+ fi
+ fi
+ ;;
+
+ abort-upgrade)
+ ucf_register_templates
;;
- abort-upgrade|abort-remove|abort-deconfigure)
+ abort-remove|abort-deconfigure)
;;
*)
#DEBHELPER#
+if test ! -e /proxmox_install_mode ; then
+ for service in pmgdaemon pmgproxy; do
+ if [ -n "$2" ]; then
+ # Note: reload-or-try-restart fails if service is not active
+ if systemctl --quiet is-active $service.service ; then
+ deb-systemd-invoke reload-or-try-restart $service.service >/dev/null || true
+ fi
+ else
+ deb-systemd-invoke start $service.service > /dev/null || true
+ fi
+ done
+fi
+
exit 0