]> git.proxmox.com Git - pve-manager.git/blame - debian/postinst
/etc/cron.d/pveupdate: always write file in postinstall
[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
11# The following idempotent stuff doesn't generally need protecting
12# against being run in the abort-* cases.
13
14# Use debconf. (installs templates)
15. /usr/share/debconf/confmodule
16# all done with debconf here.
17db_stop
18
19case "$1" in
20 triggered)
21 # We don't print a status message here, as dpkg already said
22 # "Processing triggers for ...".
23
099e5477
DM
24 # test if /etc/pve is mounted; else simple exit to avoid
25 # error during updates
26 test -f /etc/pve/local/pve-ssl.pem || exit 0;
6675a064 27 test -e /proxmox_install_mode && exit 0;
81019d9d
DM
28
29 # Note: reload-or-try-restart fails if service is not active
30 systemctl --quiet is-active pvedaemon.service && deb-systemd-invoke reload-or-try-restart pvedaemon.service
31 systemctl --quiet is-active pvestatd.service && deb-systemd-invoke reload-or-try-restart pvestatd.service
32 systemctl --quiet is-active pveproxy.service && deb-systemd-invoke reload-or-try-restart pveproxy.service
33 systemctl --quiet is-active spiceproxy.service && deb-systemd-invoke reload-or-try-restart spiceproxy.service
aff192e6
DM
34
35 exit 0;;
36
37 configure)
38 # Configure this package. If the package must prompt the user for
39 # information, do it here.
40
41 mkdir /etc/pve 2>/dev/null || true
42
c9164975
DM
43 # remove old APL dir
44 rm -rf /var/lib/pve-manager/apl-available
782bc232 45
c9355915
WL
46 # remove old cron.daily update job to randomize it
47 if test -e /etc/cron.daily/pve; then
48 echo "Remove old update script from cron.daily"
49 rm /etc/cron.daily/pve
50 fi
51
52 # create new daily randomize update cronjob if not exist
8891d66f
DM
53 MIN="$(shuf -i 0-59 -n 1)"
54 HOUR="$(shuf -i 6-10 -n 1)"
55 echo "Create cron job for daily update"
56 cat <<EOF >/etc/cron.d/pveupdate
57# automatically generated - do not edit
58${MIN} ${HOUR} * * * root /usr/bin/pveupdate
59EOF
c9355915 60
75a6a7f5
DM
61 if test ! -e /var/lib/pve-manager/apl-info/download.proxmox.com; then
62 mkdir -p /var/lib/pve-manager/apl-info
63 cp /usr/share/doc/pve-manager/aplinfo.dat /var/lib/pve-manager/apl-info/download.proxmox.com
64 pveam update || true
65 fi
66
782bc232
DM
67 if test -f /root/.forward; then
68 if ! grep -q '|/usr/bin/pvemailforward' /root/.forward; then
341e4b0b 69 echo -e "|/usr/bin/pvemailforward\n$(cat /root/.forward)" >/root/.forward.tmp
782bc232
DM
70 mv /root/.forward.tmp /root/.forward
71 fi
72 else
73 echo '|/usr/bin/pvemailforward' >/root/.forward
74 fi
d0e55a85
DM
75
76 # disable fancy init messages (bad with bootlogd)
6675a064
DM
77 test -f /etc/lsb-base-logging.sh || echo "FANCYTTY=0" >/etc/lsb-base-logging.sh
78
79
80 systemctl --system daemon-reload >/dev/null || true
81
82 # same as dh_systemd_enable (code copied)
83
84 for service in pvedaemon pveproxy spiceproxy pvestatd pvebanner pvenetcommit pve-manager; do
85 deb-systemd-helper unmask $service.service >/dev/null || true
86
87 # was-enabled defaults to true, so new installations run enable.
88 if deb-systemd-helper --quiet was-enabled $service.service; then
89 # Enables the unit on first installation, creates new
90 # symlinks on upgrades if the unit file has changed.
91 deb-systemd-helper enable $service.service >/dev/null || true
92 else
93 # Update the statefile to add new symlinks (if any), which need to be
94 # cleaned up on purge. Also remove old symlinks.
95 deb-systemd-helper update-state $service.service >/dev/null || true
96 fi
97 done
98
99 if test ! -e /proxmox_install_mode; then
100
101 for service in pvedaemon pveproxy spiceproxy pvestatd; do
a55fbccc 102 deb-systemd-invoke reload-or-restart $service
6675a064
DM
103 done
104 fi
ad2c9763
DM
105
106 # rewrite banner
6675a064 107 test -e /proxmox_install_mode || pvebanner || true
aff192e6 108
0c308a03 109 #a2ensite pve.conf >/dev/null 2>&1
aff192e6
DM
110
111 # There are three sub-cases:
112 if test "${2+set}" != set; then
113 # We're being installed by an ancient dpkg which doesn't remember
114 # which version was most recently configured, or even whether
115 # there is a most recently configured version.
116 :
117
118 elif test -z "$2" -o "$2" = "<unknown>"; then
119 # The package has not ever been configured on this system, or was
120 # purged since it was last configured.
121 :
122
123 else
124 # Version $2 is the most recently configured version of this
125 # package.
126 :
127
128 fi ;;
129 abort-upgrade)
130 # Back out of an attempt to upgrade this package FROM THIS VERSION
131 # to version $2. Undo the effects of "prerm upgrade $2".
132 :
133
134 ;;
135 abort-remove)
136 if test "$2" != in-favour; then
137 echo "$0: undocumented call to \`postinst $*'" 1>&2
138 exit 0
139 fi
140 # Back out of an attempt to remove this package, which was due to
141 # a conflict with package $3 (version $4). Undo the effects of
142 # "prerm remove in-favour $3 $4".
143 :
144
145 ;;
146 abort-deconfigure)
147 if test "$2" != in-favour -o "$5" != removing; then
148 echo "$0: undocumented call to \`postinst $*'" 1>&2
149 exit 0
150 fi
151 # Back out of an attempt to deconfigure this package, which was
152 # due to package $6 (version $7) which we depend on being removed
153 # to make way for package $3 (version $4). Undo the effects of
154 # "prerm deconfigure in-favour $3 $4 removing $6 $7".
155 :
156
157 ;;
158 *) echo "$0: didn't understand being called with \`$1'" 1>&2
159 exit 0;;
160esac
161
162exit 0