pmg-api/debian/postinst
Thomas Lamprecht 737c6f66ec d/postinst: handle static machine-id from ISO 5.0 <= x <= 6.0
Ported over from commit 8797cc74cd94583130ab4c2f541d1a75b518cfa6
of pve-manager, but with the list of machine-id extracted from PMG
ISOs.

The full map:

PMG 5.0-5  -> "e378bde63ac54872a85af23a8e4dac73"
PMG 5.1-1  -> "932b668d1fad4709b4976d54152d223c"
PMG 5.1-2  -> "931a8410cd034202a26b0e19d56e157a"
PMG 5.2-1  -> "9a1f3c5284e1423c9b0e0ee5819db6c9"
PMG 6.0-1  -> "5472a49c6436426fbebd7881f7b7f13b"

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-06-29 10:42:10 +02:00

118 lines
3.0 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
}
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)
# FIXME: remove in PMG 8.0
if test ! -e /proxmox_install_mode && test -n "$2" && dpkg --compare-versions "$2" 'lt' '7.0-2~'; then
# PMG 5 ISOs had a bug and did not generated a unique machine-id. below is a list of
# all machine-ids from all ISOs (released, tests & internal) possibly affected
if grep -q \
-e e378bde63ac54872a85af23a8e4dac73 \
-e 932b668d1fad4709b4976d54152d223c \
-e 931a8410cd034202a26b0e19d56e157a \
-e 9a1f3c5284e1423c9b0e0ee5819db6c9 \
-e 5472a49c6436426fbebd7881f7b7f13b \
/etc/machine-id
then
echo "found static machine-id bug from Proxmox Mail Gateway ISO installer <= 5.4, regenerating machine-id"
systemd-id128 new | tee /etc/machine-id.new /var/lib/dbus/machine-id.new
# atomically replace
mv /etc/machine-id.new /etc/machine-id
mv /var/lib/dbus/machine-id.new /var/lib/dbus/machine-id
echo "new machine-id generated, a reboot is recommended"
else
echo "machine-id check OK"
fi
fi
if test ! -e /proxmox_install_mode ; then
pmgconfig init
pmgdb init
ucf_register_templates
pmgconfig sync --restart
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
;;
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