]> git.proxmox.com Git - pmg-api.git/blob - debian/postinst
utils: check if file changed before reusing its hash
[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
68 if test ! -e /proxmox_install_mode ; then
69
70 pmgconf="/etc/pmg/pmg.conf"
71 if test -n "$2" && dpkg --compare-versions "$2" 'lt' '8.0.2'; then
72 # on upgrade add pre 8.0 default values for advfilter, use_awl and use_bayes
73 # TODO: remove with 9.0
74 if test ! -e $pmgconf ; then
75 # if the config does not exist at all, fill with previous default configs
76 printf "section: admin\n\tadvfilter 1\n" > $pmgconf
77 printf "\nsection: spam\n\tuse_bayes 1\n\tuse_awl 1\n" >> $pmgconf
78 else
79 if ! grep -qP '\s+advfilter' $pmgconf ; then
80 echo "hard-code old default for 'advfilter'"
81 if ! grep -q '^section: admin$' $pmgconf ; then
82 printf "\nsection: admin" >> $pmgconf
83 fi
84 sed -i '/^section: admin$/a\\tadvfilter 1' $pmgconf
85 fi
86
87 if ! grep -q '^section: spam$' $pmgconf ; then
88 printf "\nsection: spam" >> $pmgconf
89 fi
90 if ! grep -qP '^\s+use_bayes\s' $pmgconf ; then
91 echo "hard-code old default for 'use_bayes'"
92 sed -i '/^section: spam$/a\\tuse_bayes 1' $pmgconf
93 fi
94 if ! grep -qP '^\s+use_awl\s' $pmgconf ; then
95 echo "hard-code old default for 'use_awl'"
96 sed -i '/^section: spam$/a\\tuse_awl 1' $pmgconf
97 fi
98 fi
99 fi
100
101 pmgconfig init || true
102 pmgdb init || true
103
104 ucf_register_templates
105 pmgconfig sync --restart || true
106
107 if [ -z "$2" ]; then
108 if systemctl --quiet is-active pmgpolicy.service ; then
109 deb-systemd-invoke reload-or-try-restart postgresql.service >/dev/null || true
110 fi
111 deb-systemd-invoke restart postfix.service >/dev/null || true
112 fi
113
114 pmgdb update >/dev/null 2>&1 &
115
116 update-mime-database /usr/share/mime
117
118 else
119 # rewrite banner
120 pmgbanner || true
121 fi
122
123 if test ! -e /proxmox_install_mode && test -n "$2" && dpkg --compare-versions "$2" 'lt' '7.1-7~'; then
124 if test -e /etc/apt/auth.conf ; then
125 migrate_apt_auth_conf
126 fi
127 fi
128 ;;
129
130 abort-upgrade)
131 ucf_register_templates
132 ;;
133
134 abort-remove|abort-deconfigure)
135 ;;
136
137 *)
138 echo "postinst called with unknown argument \`$1'" >&2
139 exit 1
140 ;;
141 esac
142
143 # dh_installdeb will replace this with shell code automatically
144 # generated by other debhelper scripts.
145
146 #DEBHELPER#
147
148 if test ! -e /proxmox_install_mode ; then
149 for service in pmgdaemon pmgproxy; do
150 if [ -n "$2" ]; then
151 # Note: reload-or-try-restart fails if service is not active
152 if systemctl --quiet is-active $service.service ; then
153 deb-systemd-invoke reload-or-try-restart $service.service >/dev/null || true
154 fi
155 else
156 deb-systemd-invoke start $service.service > /dev/null || true
157 fi
158 done
159 fi
160
161 exit 0