]> git.proxmox.com Git - pve-manager.git/blame - debian/postinst
postinst: simplify root's mail .forward check
[pve-manager.git] / debian / postinst
CommitLineData
7aa2bc3b 1#!/bin/bash
aff192e6
DM
2
3# Abort if any command returns an error value
4set -e
5
6# This script is called as the last step of the installation of the
7# package. All the package's files are in place, dpkg has already
8# done its automatic conffile handling, and all the packages we depend
9# of are already fully installed and configured.
10
aff192e6
DM
11case "$1" in
12 triggered)
13 # We don't print a status message here, as dpkg already said
14 # "Processing triggers for ...".
15
099e5477
DM
16 # test if /etc/pve is mounted; else simple exit to avoid
17 # error during updates
18 test -f /etc/pve/local/pve-ssl.pem || exit 0;
6675a064 19 test -e /proxmox_install_mode && exit 0;
81019d9d
DM
20
21 # Note: reload-or-try-restart fails if service is not active
22 systemctl --quiet is-active pvedaemon.service && deb-systemd-invoke reload-or-try-restart pvedaemon.service
23 systemctl --quiet is-active pvestatd.service && deb-systemd-invoke reload-or-try-restart pvestatd.service
24 systemctl --quiet is-active pveproxy.service && deb-systemd-invoke reload-or-try-restart pveproxy.service
25 systemctl --quiet is-active spiceproxy.service && deb-systemd-invoke reload-or-try-restart spiceproxy.service
aff192e6
DM
26
27 exit 0;;
28
29 configure)
30 # Configure this package. If the package must prompt the user for
31 # information, do it here.
32
33 mkdir /etc/pve 2>/dev/null || true
34
c9355915
WL
35 # remove old cron.daily update job to randomize it
36 if test -e /etc/cron.daily/pve; then
37 echo "Remove old update script from cron.daily"
38 rm /etc/cron.daily/pve
39 fi
40
70767f68
TL
41 if dpkg --compare-versions "$2" '<=' '5.1-47'; then
42 # remove old/unused init.d files
43 OLD_INITD_FILES="pvebanner pvenetcommit pve-manager pvedaemon pveproxy pvestatd spiceproxy"
44 for f in ${OLD_INITD_FILES}; do rm -f "/etc/init.d/$f"; done
45 fi
f13b9540 46
c9355915 47 # create new daily randomize update cronjob if not exist
8891d66f 48 MIN="$(shuf -i 0-59 -n 1)"
e1f0dcce 49 HOUR="$(shuf -i 2-5 -n 1)"
8891d66f
DM
50 cat <<EOF >/etc/cron.d/pveupdate
51# automatically generated - do not edit
52${MIN} ${HOUR} * * * root /usr/bin/pveupdate
53EOF
c9355915 54
75a6a7f5
DM
55 if test ! -e /var/lib/pve-manager/apl-info/download.proxmox.com; then
56 mkdir -p /var/lib/pve-manager/apl-info
57 cp /usr/share/doc/pve-manager/aplinfo.dat /var/lib/pve-manager/apl-info/download.proxmox.com
58 pveam update || true
59 fi
60
544221fa
TL
61 if ! test -f /root/.forward || ! grep -q '|/usr/bin/pvemailforward' /root/.forward; then
62 echo '|/usr/bin/pvemailforward' >>/root/.forward
782bc232 63 fi
d0e55a85 64
2bde88fb
FG
65 if [ -f /etc/systemd/system/ceph.service ]; then
66 md5=$(md5sum /etc/systemd/system/ceph.service)
67 if [[ "$md5" == "21b2e7a7c4ffcf92ad0ec2c905e88e5b /etc/systemd/system/ceph.service" ]]; then
68 echo "Updating PVE ceph.service to correct install target.."
69 cp /usr/share/doc/pve-manager/examples/ceph.service /etc/systemd/system/ceph.service
70 systemctl --system daemon-reload >/dev/null || true
71 systemctl --system disable ceph.service
72 systemctl --system enable ceph.service
73 echo " done"
74 fi
75 fi
6675a064
DM
76
77 systemctl --system daemon-reload >/dev/null || true
78
79 # same as dh_systemd_enable (code copied)
80
0dfd4a94
WL
81 for timer in pvesr; do
82 deb-systemd-helper unmask $timer.timer >/dev/null || true
83
84 # was-enabled defaults to true, so new installations run enable.
85 if deb-systemd-helper --quiet was-enabled $timer.timer; then
86 # Enables the unit on first installation, creates new
87 # symlinks on upgrades if the unit file has changed.
88 deb-systemd-helper enable $timer.timer >/dev/null || true
89 else
90 # Update the statefile to add new symlinks (if any), which need to be
91 # cleaned up on purge. Also remove old symlinks.
92 deb-systemd-helper update-state $timer.timer >/dev/null || true
93 fi
94 done
95
57de747b 96 for service in pvedaemon pveproxy spiceproxy pvestatd pvebanner pvenetcommit pve-guests; do
6675a064
DM
97 deb-systemd-helper unmask $service.service >/dev/null || true
98
99 # was-enabled defaults to true, so new installations run enable.
100 if deb-systemd-helper --quiet was-enabled $service.service; then
101 # Enables the unit on first installation, creates new
102 # symlinks on upgrades if the unit file has changed.
103 deb-systemd-helper enable $service.service >/dev/null || true
104 else
105 # Update the statefile to add new symlinks (if any), which need to be
106 # cleaned up on purge. Also remove old symlinks.
107 deb-systemd-helper update-state $service.service >/dev/null || true
108 fi
109 done
110
111 if test ! -e /proxmox_install_mode; then
112
113 for service in pvedaemon pveproxy spiceproxy pvestatd; do
a55fbccc 114 deb-systemd-invoke reload-or-restart $service
6675a064 115 done
0dfd4a94
WL
116
117 deb-systemd-invoke start pvesr.timer >/dev/null || true
6675a064 118 fi
12fe9183 119
ad2c9763 120 # rewrite banner
6675a064 121 test -e /proxmox_install_mode || pvebanner || true
aff192e6 122
0c308a03 123 #a2ensite pve.conf >/dev/null 2>&1
aff192e6
DM
124
125 # There are three sub-cases:
126 if test "${2+set}" != set; then
127 # We're being installed by an ancient dpkg which doesn't remember
128 # which version was most recently configured, or even whether
129 # there is a most recently configured version.
130 :
131
132 elif test -z "$2" -o "$2" = "<unknown>"; then
133 # The package has not ever been configured on this system, or was
134 # purged since it was last configured.
135 :
136
137 else
138 # Version $2 is the most recently configured version of this
139 # package.
85fd9b52
WB
140 if dpkg --compare-versions "$2" '<=' '5.0-23'; then
141 # 5.0-23 temporarily reverted the removal of the startcom CA in
142 # ca-certificates; we've since switched to let's encrypt
143 update-ca-certificates >/dev/null 2>&1
144 fi
aff192e6
DM
145
146 fi ;;
147 abort-upgrade)
148 # Back out of an attempt to upgrade this package FROM THIS VERSION
149 # to version $2. Undo the effects of "prerm upgrade $2".
150 :
151
152 ;;
153 abort-remove)
154 if test "$2" != in-favour; then
155 echo "$0: undocumented call to \`postinst $*'" 1>&2
156 exit 0
157 fi
158 # Back out of an attempt to remove this package, which was due to
159 # a conflict with package $3 (version $4). Undo the effects of
160 # "prerm remove in-favour $3 $4".
161 :
162
163 ;;
164 abort-deconfigure)
165 if test "$2" != in-favour -o "$5" != removing; then
166 echo "$0: undocumented call to \`postinst $*'" 1>&2
167 exit 0
168 fi
169 # Back out of an attempt to deconfigure this package, which was
170 # due to package $6 (version $7) which we depend on being removed
171 # to make way for package $3 (version $4). Undo the effects of
172 # "prerm deconfigure in-favour $3 $4 removing $6 $7".
173 :
174
175 ;;
176 *) echo "$0: didn't understand being called with \`$1'" 1>&2
177 exit 0;;
178esac
179
180exit 0