pmg-api/debian/postinst
Thomas Lamprecht b3558c4521 d/postinst: version-guard migration to new pending pmg-score location
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2025-02-25 20:02:08 +01:00

175 lines
5.7 KiB
Bash

#!/bin/sh
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;
# 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
;;
configure)
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
if test -n "$2" && dpkg --compare-versions "$2" 'lt' '8.2.0'; then
old_score_location=/var/cache/pmg-scores.cf
new_score_location=/etc/mail/spamassassin/pmg-scores.cf.new
if test -e "$old_score_location"; then
if ! test -e "$new_score_location"; then
echo "moving $old_score_location to $new_score_location"
mv "$old_score_location" "$new_score_location"
else
echo "both $old_score_location and $new_score_location exist - please review manually"
fi
fi
fi
;;
abort-upgrade)
ucf_register_templates
;;
abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#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