]> git.proxmox.com Git - pve-manager.git/blob - debian/postinst
d/control: bump versioned deps for widget-toolkit and access-control
[pve-manager.git] / debian / postinst
1 #!/bin/sh
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 package.
7 # All the package's files are in place, dpkg has already done its automatic
8 # conffile handling, and all the packages we depend of are already fully
9 # installed and configured.
10
11 set_lvm_conf() {
12 local FORCE="$1"
13 LVM_CONF_MARKER="# added by pve-manager to avoid scanning"
14
15 # keep user changes afterwards provided marker is still there..
16 if grep -qLF "$LVM_CONF_MARKER" /etc/lvm/lvm.conf && test -z "$FORCE"; then
17 return 0 # only do these changes once
18 fi
19
20 export LVM_SUPPRESS_FD_WARNINGS=1
21
22 OLD_VALUE="$(lvmconfig --typeconfig diff devices/global_filter || true)"
23 NEW_VALUE='global_filter=["r|/dev/zd.*|","r|/dev/rbd.*|"]'
24
25 # update global_filter if:
26 # it is empty and there is no marker OR exactly the one we set before 8.1.4
27 if (! grep -qF "$LVM_CONF_MARKER" /etc/lvm/lvm.conf && test -z "$OLD_VALUE")\
28 || (echo "$OLD_VALUE" | grep -qF '="r|/dev/zd.*|"');
29 then
30 SET_FILTER=1
31 BACKUP=1
32 # print warning if global_filter is set but not our old/new default
33 elif test -n "$OLD_VALUE"\
34 && ! echo "$OLD_VALUE" | grep -qF '="r|/dev/zd.*|"'\
35 && ! echo "$OLD_VALUE" | grep -qF "$NEW_VALUE";
36 then
37 echo "non-default 'global_filter' value '$OLD_VALUE' in /etc/lvm/lvm.conf, not setting '$NEW_VALUE' automatically"
38 echo "consider adapting your 'global_filter' manually."
39 fi
40 # should be the default since bullseye
41 if lvmconfig --typeconfig full devices/scan_lvs | grep -qv 'scan_lvs=0'; then
42 SET_SCAN_LVS=1
43 BACKUP=1
44 fi
45 if test -n "$BACKUP"; then
46 echo "Backing up lvm.conf before setting pve-manager specific settings.."
47 cp -vb /etc/lvm/lvm.conf /etc/lvm/lvm.conf.bak
48 fi
49 if test -n "$SET_FILTER"; then
50 echo "Setting 'global_filter' in /etc/lvm/lvm.conf to prevent zvols and rbds from being scanned:"
51 echo "$OLD_VALUE => $NEW_VALUE"
52 if test -n "$OLD_VALUE"; then
53 sed -i -e "s/$LVM_CONF_MARKER ZFS zvols/$LVM_CONF_MARKER ZFS zvols and Ceph rbds/" /etc/lvm/lvm.conf
54 sed -i -e "s!^\([[:space:]]*\)\(global_filter[[:space:]]*=.*\)\$!\1# \2\n\1$NEW_VALUE!" /etc/lvm/lvm.conf
55 else
56 cat >> /etc/lvm/lvm.conf <<EOF
57 devices {
58 $LVM_CONF_MARKER ZFS zvols and Ceph rbds
59 $NEW_VALUE
60 }
61 EOF
62 fi
63 fi
64 if test -n "$SET_SCAN_LVS"; then
65 echo "Adding scan_lvs=0 setting to /etc/lvm/lvm.conf to prevent LVs from being scanned."
66 # comment out existing setting
67 sed -i -e 's/^\([[:space:]]*scan_lvs[[:space:]]*=\)/#\1/' /etc/lvm/lvm.conf
68 # add new section with our setting
69 cat >> /etc/lvm/lvm.conf <<EOF
70 devices {
71 $LVM_CONF_MARKER LVM volumes
72 scan_lvs=0
73 }
74 EOF
75 fi
76
77 if ! lvmconfig --validate; then
78 echo "Invalid LVM config detected - restoring from /etc/lvm/lvm.conf.bak"
79 mv /etc/lvm/lvm.conf.bak /etc/lvm/lvm.conf
80 fi
81 }
82
83 migrate_apt_auth_conf() {
84 output=""
85 removed=""
86 match=0
87
88 while read -r l; do
89 if echo "$l" | grep -q "^machine enterprise.proxmox.com/debian/pve"; then
90 match=1
91 elif echo "$l" | grep -q "machine"; then
92 match=0
93 fi
94
95 if test "$match" = "1"; then
96 removed="$removed\n$l"
97 else
98 output="$output\n$l"
99 fi
100 done < /etc/apt/auth.conf
101
102 if test -n "$removed"; then
103 if test ! -e /etc/apt/auth.conf.d/pve.conf; then
104 echo "Migrating APT auth config for enterprise.proxmox.com to /etc/apt/auth.conf.d/pve.conf .."
105 echo "$removed" > /etc/apt/auth.conf.d/pve.conf
106 else
107 echo "Removing stale APT auth config from /etc/apt/auth.conf"
108 fi
109 echo "$output" > /etc/apt/auth.conf
110 fi
111 }
112
113 case "$1" in
114 triggered)
115 # We don't print a status message here, as dpkg already said
116 # "Processing triggers for ...".
117
118 # test if /etc/pve is mounted; else simple exit to avoid
119 # error during updates
120 test -f /etc/pve/local/pve-ssl.pem || exit 0;
121 test -e /proxmox_install_mode && exit 0;
122
123 # the ExecStartPre doesn't triggers on service reload, so just in case
124 pvecm updatecerts --silent || true
125
126 deb-systemd-invoke reload-or-try-restart pvedaemon.service
127 deb-systemd-invoke reload-or-try-restart pvestatd.service
128 deb-systemd-invoke reload-or-try-restart pveproxy.service
129 deb-systemd-invoke reload-or-try-restart spiceproxy.service
130 deb-systemd-invoke reload-or-try-restart pvescheduler.service
131
132 exit 0;;
133
134 configure)
135 # Configure this package. If the package must prompt the user for
136 # information, do it here.
137
138 mkdir /etc/pve 2>/dev/null || true
139
140 if test ! -e /var/lib/pve-manager/apl-info/download.proxmox.com; then
141 mkdir -p /var/lib/pve-manager/apl-info
142 cp /usr/share/doc/pve-manager/aplinfo.dat /var/lib/pve-manager/apl-info/download.proxmox.com
143 pveam update || true
144 fi
145
146 # Always try to clean old entry, even when proxmox-mail-forward entry is already present.
147 # This ensures it will still be cleaned after an upgrade following a downgrade.
148 if test -f /root/.forward; then
149 sed -i '\!|/usr/bin/pvemailforward!d' /root/.forward
150 fi
151
152 if ! test -f /root/.forward || ! grep -q '|/usr/bin/proxmox-mail-forward' /root/.forward; then
153 echo '|/usr/bin/proxmox-mail-forward' >>/root/.forward
154 fi
155
156 systemctl --system daemon-reload >/dev/null || true
157
158 # same as dh_systemd_enable (code copied)
159
160 UNITS="pvedaemon.service pveproxy.service spiceproxy.service pvestatd.service pvebanner.service pvescheduler.service pve-daily-update.timer"
161 NO_RESTART_UNITS="pvenetcommit.service pve-guests.service"
162
163 for unit in ${UNITS} ${NO_RESTART_UNITS}; do
164 deb-systemd-helper unmask "$unit" >/dev/null || true
165
166 # was-enabled defaults to true, so new installations run enable.
167 if deb-systemd-helper --quiet was-enabled "$unit"; then
168 # Enables the unit on first installation, creates new
169 # symlinks on upgrades if the unit file has changed.
170 deb-systemd-helper enable "$unit" >/dev/null || true
171 else
172 # Update the statefile to add new symlinks (if any), which need to be
173 # cleaned up on purge. Also remove old symlinks.
174 deb-systemd-helper update-state "$unit" >/dev/null || true
175 fi
176 done
177
178 # FIXME: remove after beta is over and add hunk to actively remove the repo
179 BETA_SOURCES="/etc/apt/sources.list.d/pvetest-for-beta.list"
180 if test -f "$BETA_SOURCES" && dpkg --compare-versions "$2" 'lt' '8.0.2' && dpkg --compare-versions "$2" 'gt' '8.0~'; then
181 echo "Removing the during beta added pvetest repository file again"
182 rm -v "$BETA_SOURCES" || true
183 fi
184
185 if test ! -e /proxmox_install_mode && test -n "$2" && dpkg --compare-versions "$2" 'lt' '8.1.4~'; then
186 if test -e /etc/lvm/lvm.conf ; then
187 set_lvm_conf 1
188 fi
189 fi
190
191 set_lvm_conf
192
193 if test ! -e /proxmox_install_mode; then
194 # modeled after code generated by dh_start
195 for unit in ${UNITS}; do
196 if test -n "$2"; then
197 dh_action="reload-or-restart";
198 else
199 dh_action="start"
200 fi
201 if systemctl -q is-enabled "$unit"; then
202 deb-systemd-invoke $dh_action "$unit"
203 fi
204 done
205 fi
206
207 if test ! -e /proxmox_install_mode && test -n "$2" && dpkg --compare-versions "$2" 'lt' '7.2-11~'; then
208 if test -e /etc/apt/auth.conf ; then
209 migrate_apt_auth_conf
210 fi
211 fi
212 ;;
213
214 abort-upgrade|abort-remove|abort-deconfigure)
215 ;;
216
217 *) echo "$0: didn't understand being called with \`$1'" 1>&2
218 exit 0;;
219 esac
220
221 exit 0