]> git.proxmox.com Git - pve-manager.git/blob - debian/postinst
6aac8f85a3346d29e18d821d0a0b005a624be89a
[pve-manager.git] / debian / postinst
1 #!/bin/bash
2
3 # Abort if any command returns an error value
4 set -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.
17 db_stop
18
19 case "$1" in
20 triggered)
21 # We don't print a status message here, as dpkg already said
22 # "Processing triggers for ...".
23
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;
27 test -e /proxmox_install_mode && exit 0;
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
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
43 # remove old APL dir
44 rm -rf /var/lib/pve-manager/apl-available
45
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 # remove old/usused init.d files
53 rm -f /etc/init.d/pvebanner
54 rm -f /etc/init.d/pvenetcommit
55
56 # create new daily randomize update cronjob if not exist
57 MIN="$(shuf -i 0-59 -n 1)"
58 HOUR="$(shuf -i 2-5 -n 1)"
59 cat <<EOF >/etc/cron.d/pveupdate
60 # automatically generated - do not edit
61 ${MIN} ${HOUR} * * * root /usr/bin/pveupdate
62 EOF
63
64 if test ! -e /var/lib/pve-manager/apl-info/download.proxmox.com; then
65 mkdir -p /var/lib/pve-manager/apl-info
66 cp /usr/share/doc/pve-manager/aplinfo.dat /var/lib/pve-manager/apl-info/download.proxmox.com
67 pveam update || true
68 fi
69
70 if test -f /root/.forward; then
71 if ! grep -q '|/usr/bin/pvemailforward' /root/.forward; then
72 echo -e "|/usr/bin/pvemailforward\n$(cat /root/.forward)" >/root/.forward.tmp
73 mv /root/.forward.tmp /root/.forward
74 fi
75 else
76 echo '|/usr/bin/pvemailforward' >/root/.forward
77 fi
78
79 # disable fancy init messages (bad with bootlogd)
80 test -f /etc/lsb-base-logging.sh || echo "FANCYTTY=0" >/etc/lsb-base-logging.sh
81
82 if [ -f /etc/systemd/system/ceph.service ]; then
83 md5=$(md5sum /etc/systemd/system/ceph.service)
84 if [[ "$md5" == "21b2e7a7c4ffcf92ad0ec2c905e88e5b /etc/systemd/system/ceph.service" ]]; then
85 echo "Updating PVE ceph.service to correct install target.."
86 cp /usr/share/doc/pve-manager/examples/ceph.service /etc/systemd/system/ceph.service
87 systemctl --system daemon-reload >/dev/null || true
88 systemctl --system disable ceph.service
89 systemctl --system enable ceph.service
90 echo " done"
91 fi
92 fi
93
94 systemctl --system daemon-reload >/dev/null || true
95
96 # same as dh_systemd_enable (code copied)
97
98 for service in pvedaemon pveproxy spiceproxy pvestatd pvebanner pvenetcommit pve-manager; do
99 deb-systemd-helper unmask $service.service >/dev/null || true
100
101 # was-enabled defaults to true, so new installations run enable.
102 if deb-systemd-helper --quiet was-enabled $service.service; then
103 # Enables the unit on first installation, creates new
104 # symlinks on upgrades if the unit file has changed.
105 deb-systemd-helper enable $service.service >/dev/null || true
106 else
107 # Update the statefile to add new symlinks (if any), which need to be
108 # cleaned up on purge. Also remove old symlinks.
109 deb-systemd-helper update-state $service.service >/dev/null || true
110 fi
111 done
112
113 if test ! -e /proxmox_install_mode; then
114
115 for service in pvedaemon pveproxy spiceproxy pvestatd; do
116 deb-systemd-invoke reload-or-restart $service
117 done
118 fi
119
120 # rewrite banner
121 test -e /proxmox_install_mode || pvebanner || true
122
123 #a2ensite pve.conf >/dev/null 2>&1
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.
140 :
141
142 fi ;;
143 abort-upgrade)
144 # Back out of an attempt to upgrade this package FROM THIS VERSION
145 # to version $2. Undo the effects of "prerm upgrade $2".
146 :
147
148 ;;
149 abort-remove)
150 if test "$2" != in-favour; then
151 echo "$0: undocumented call to \`postinst $*'" 1>&2
152 exit 0
153 fi
154 # Back out of an attempt to remove this package, which was due to
155 # a conflict with package $3 (version $4). Undo the effects of
156 # "prerm remove in-favour $3 $4".
157 :
158
159 ;;
160 abort-deconfigure)
161 if test "$2" != in-favour -o "$5" != removing; then
162 echo "$0: undocumented call to \`postinst $*'" 1>&2
163 exit 0
164 fi
165 # Back out of an attempt to deconfigure this package, which was
166 # due to package $6 (version $7) which we depend on being removed
167 # to make way for package $3 (version $4). Undo the effects of
168 # "prerm deconfigure in-favour $3 $4 removing $6 $7".
169 :
170
171 ;;
172 *) echo "$0: didn't understand being called with \`$1'" 1>&2
173 exit 0;;
174 esac
175
176 exit 0