]> git.proxmox.com Git - pmg-api.git/blame - debian/postinst
dkim: add QID in warnings
[pmg-api.git] / debian / postinst
CommitLineData
0854fb22
DM
1#!/bin/sh
2
3set -e
4
ac81f7c9
SI
5ucf_register_templates() {
6 for template in /etc/pmg/templates/*; do
31a236e1
TL
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
ac81f7c9
SI
18 done
19}
20
57e033cd
FG
21migrate_apt_auth_conf() {
22 output=""
23 removed=""
24 match=0
25
26 while read -r l; do
31a236e1
TL
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
57e033cd
FG
38 done < /etc/apt/auth.conf
39
40 if test -n "$removed"; then
31a236e1
TL
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
57e033cd
FG
48 fi
49}
50
0854fb22 51case "$1" in
3cf7a549
DM
52 triggered)
53
31a236e1 54 test -e /proxmox_install_mode && exit 0;
3cf7a549 55
31a236e1
TL
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
07f15aa3 62
31a236e1 63 exit 0
3cf7a549
DM
64 ;;
65
0854fb22 66 configure)
31a236e1
TL
67
68 if test ! -e /proxmox_install_mode ; then
69
5fc3c148 70 pmgconf="/etc/pmg/pmg.conf"
a4297436 71 if test -n "$2" && dpkg --compare-versions "$2" 'lt' '8.0.2'; then
5fc3c148
DC
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
a4297436 79 if ! grep -qP '\s+advfilter' $pmgconf ; then
d35703a7 80 echo "hard-code old default for 'advfilter'"
a4297436 81 if ! grep -q '^section: admin$' $pmgconf ; then
d35703a7
TL
82 printf "\nsection: admin" >> $pmgconf
83 fi
a4297436 84 sed -i '/^section: admin$/a\\tadvfilter 1' $pmgconf
5fc3c148
DC
85 fi
86
a4297436 87 if ! grep -q '^section: spam$' $pmgconf ; then
5fc3c148
DC
88 printf "\nsection: spam" >> $pmgconf
89 fi
a4297436 90 if ! grep -qP '^\s+use_bayes\s' $pmgconf ; then
d35703a7 91 echo "hard-code old default for 'use_bayes'"
a4297436 92 sed -i '/^section: spam$/a\\tuse_bayes 1' $pmgconf
5fc3c148 93 fi
a4297436 94 if ! grep -qP '^\s+use_awl\s' $pmgconf ; then
d35703a7 95 echo "hard-code old default for 'use_awl'"
a4297436 96 sed -i '/^section: spam$/a\\tuse_awl 1' $pmgconf
5fc3c148
DC
97 fi
98 fi
99 fi
100
e53e4134
SI
101 pmgconfig init || true
102 pmgdb init || true
31a236e1
TL
103
104 ucf_register_templates
e53e4134 105 pmgconfig sync --restart || true
31a236e1
TL
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
0854fb22
DM
128 ;;
129
ac81f7c9 130 abort-upgrade)
31a236e1 131 ucf_register_templates
ac81f7c9
SI
132 ;;
133
134 abort-remove|abort-deconfigure)
0854fb22
DM
135 ;;
136
137 *)
138 echo "postinst called with unknown argument \`$1'" >&2
139 exit 1
140 ;;
141esac
142
143# dh_installdeb will replace this with shell code automatically
144# generated by other debhelper scripts.
145
146#DEBHELPER#
147
2305fb86
DM
148if test ! -e /proxmox_install_mode ; then
149 for service in pmgdaemon pmgproxy; do
31a236e1
TL
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
2305fb86
DM
158 done
159fi
160
0854fb22 161exit 0