]> git.proxmox.com Git - pmg-api.git/blob - debian/postinst
config: add spam option for extract_text
[pmg-api.git] / debian / postinst
1 #!/bin/sh
2
3 set -e
4
5 ucf_register_templates() {
6 for template in /etc/pmg/templates/*; do
7 [ -e "$template" ] || continue;
8 template_base=$(basename "${template}")
9 if echo "${template_base}" | grep -q '\.ucf-'; then
10 continue
11 fi
12 if [ -e "/var/lib/pmg/templates/${template_base}" ]; then
13 ucf "/var/lib/pmg/templates/${template_base}" "${template}"
14 ucfr pmg-api "${template}"
15 else
16 echo "template '${template}' not shipped by pmg-api."
17 fi
18 done
19 }
20
21 migrate_apt_auth_conf() {
22 output=""
23 removed=""
24 match=0
25
26 while read -r l; do
27 if echo "$l" | grep -q "^machine enterprise.proxmox.com/debian/pmg"; then
28 match=1
29 elif echo "$l" | grep -q "machine"; then
30 match=0
31 fi
32
33 if test "$match" = "1"; then
34 removed="$removed\n$l"
35 else
36 output="$output\n$l"
37 fi
38 done < /etc/apt/auth.conf
39
40 if test -n "$removed"; then
41 if test ! -e /etc/apt/auth.conf.d/pmg.conf; then
42 echo "Migrating APT auth config for enterprise.proxmox.com to /etc/apt/auth.conf.d/pmg.conf .."
43 echo "$removed" > /etc/apt/auth.conf.d/pmg.conf
44 else
45 echo "Removing stale APT auth config from /etc/apt/auth.conf"
46 fi
47 echo "$output" > /etc/apt/auth.conf
48 fi
49 }
50
51 case "$1" in
52 triggered)
53
54 test -e /proxmox_install_mode && exit 0;
55
56 # Note: reload-or-try-restart fails if service is not active
57 for service in pmgdaemon pmgproxy pmg-smtp-filter pmgpolicy pmgtunnel pmgmirror; do
58 if systemctl --quiet is-active $service.service ; then
59 deb-systemd-invoke reload-or-try-restart $service.service >/dev/null || true
60 fi
61 done
62
63 exit 0
64 ;;
65
66 configure)
67 # FIXME: remove in PMG 8.0
68 if test ! -e /proxmox_install_mode && test -n "$2" && dpkg --compare-versions "$2" 'lt' '7.0-2~'; then
69 # PMG 5 ISOs had a bug and did not generated a unique machine-id. below is a list of
70 # all machine-ids from all ISOs (released, tests & internal) possibly affected
71 if grep -q \
72 -e e378bde63ac54872a85af23a8e4dac73 \
73 -e 932b668d1fad4709b4976d54152d223c \
74 -e 931a8410cd034202a26b0e19d56e157a \
75 -e 9a1f3c5284e1423c9b0e0ee5819db6c9 \
76 -e 5472a49c6436426fbebd7881f7b7f13b \
77 /etc/machine-id
78 then
79 echo "found static machine-id bug from Proxmox Mail Gateway ISO installer <= 5.4, regenerating machine-id"
80 systemd-id128 new | tee /etc/machine-id.new /var/lib/dbus/machine-id.new
81 # atomically replace
82 mv /etc/machine-id.new /etc/machine-id
83 mv /var/lib/dbus/machine-id.new /var/lib/dbus/machine-id
84 echo "new machine-id generated, a reboot is recommended"
85 else
86 echo "machine-id check OK"
87 fi
88 fi
89
90 if test ! -e /proxmox_install_mode ; then
91
92 pmgconfig init
93 pmgdb init
94
95 ucf_register_templates
96 pmgconfig sync --restart
97
98 if [ -z "$2" ]; then
99 if systemctl --quiet is-active pmgpolicy.service ; then
100 deb-systemd-invoke reload-or-try-restart postgresql.service >/dev/null || true
101 fi
102 deb-systemd-invoke restart postfix.service >/dev/null || true
103 fi
104
105 pmgdb update >/dev/null 2>&1 &
106
107 update-mime-database /usr/share/mime
108
109 else
110 # rewrite banner
111 pmgbanner || true
112 fi
113
114 if test ! -e /proxmox_install_mode && test -n "$2" && dpkg --compare-versions "$2" 'lt' '7.1-7~'; then
115 if test -e /etc/apt/auth.conf ; then
116 migrate_apt_auth_conf
117 fi
118 fi
119 ;;
120
121 abort-upgrade)
122 ucf_register_templates
123 ;;
124
125 abort-remove|abort-deconfigure)
126 ;;
127
128 *)
129 echo "postinst called with unknown argument \`$1'" >&2
130 exit 1
131 ;;
132 esac
133
134 # dh_installdeb will replace this with shell code automatically
135 # generated by other debhelper scripts.
136
137 #DEBHELPER#
138
139 if test ! -e /proxmox_install_mode ; then
140 for service in pmgdaemon pmgproxy; do
141 if [ -n "$2" ]; then
142 # Note: reload-or-try-restart fails if service is not active
143 if systemctl --quiet is-active $service.service ; then
144 deb-systemd-invoke reload-or-try-restart $service.service >/dev/null || true
145 fi
146 else
147 deb-systemd-invoke start $service.service > /dev/null || true
148 fi
149 done
150 fi
151
152 exit 0