]> git.proxmox.com Git - pve-manager.git/blame - debian/postinst
d/postinst: set_lvm_conf: early return to avoid indentation level
[pve-manager.git] / debian / postinst
CommitLineData
28e6daaa 1#!/bin/sh
aff192e6 2
60b5e2d8 3# Abort if any command returns an error value
aff192e6
DM
4set -e
5
60b5e2d8
TL
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.
aff192e6 10
c6908859
FG
11set_lvm_conf() {
12 LVM_CONF_MARKER="# added by pve-manager to avoid scanning"
13
c6908859 14 # keep user changes afterwards provided marker is still there..
2833e1e1
TL
15 if grep -qLF "$LVM_CONF_MARKER" /etc/lvm/lvm.conf; then
16 return 0 # only do these changes once
17 fi
60b5e2d8 18
2833e1e1
TL
19 OLD_VALUE="$(lvmconfig --typeconfig full devices/global_filter)"
20 NEW_VALUE='global_filter=["r|/dev/zd.*|"]'
60b5e2d8 21
2833e1e1
TL
22 export LVM_SUPPRESS_FD_WARNINGS=1
23
24 # check global_filter
25 # keep previous setting from our custom packaging if it is still there
26 if echo "$OLD_VALUE" | grep -qvF 'r|/dev/zd.*|'; then
27 SET_FILTER=1
28 BACKUP=1
29 fi
30 # should be the default since bullseye
31 if lvmconfig --typeconfig full devices/scan_lvs | grep -qv 'scan_lvs=0'; then
32 SET_SCAN_LVS=1
33 BACKUP=1
34 fi
35 if test -n "$BACKUP"; then
36 echo "Backing up lvm.conf before setting pve-manager specific settings.."
37 cp -vb /etc/lvm/lvm.conf /etc/lvm/lvm.conf.bak
38 fi
39 if test -n "$SET_FILTER"; then
40 echo "Setting 'global_filter' in /etc/lvm/lvm.conf to prevent zvols from being scanned:"
41 echo "$OLD_VALUE => $NEW_VALUE"
42 # comment out existing setting
43 sed -i -e 's/^\([[:space:]]*global_filter[[:space:]]*=\)/#\1/' /etc/lvm/lvm.conf
44 # add new section with our setting
45 cat >> /etc/lvm/lvm.conf <<EOF
c6908859 46devices {
60b5e2d8
TL
47 $LVM_CONF_MARKER ZFS zvols
48 $NEW_VALUE
49 }
c6908859 50EOF
2833e1e1
TL
51 fi
52 if test -n "$SET_SCAN_LVS"; then
53 echo "Adding scan_lvs=0 setting to /etc/lvm/lvm.conf to prevent LVs from being scanned."
54 # comment out existing setting
55 sed -i -e 's/^\([[:space:]]*scan_lvs[[:space:]]*=\)/#\1/' /etc/lvm/lvm.conf
56 # add new section with our setting
57 cat >> /etc/lvm/lvm.conf <<EOF
c6908859 58devices {
60b5e2d8
TL
59 $LVM_CONF_MARKER LVM volumes
60 scan_lvs=0
61 }
c6908859 62EOF
c6908859
FG
63 fi
64}
65
bf09acfe
FG
66migrate_apt_auth_conf() {
67 output=""
68 removed=""
69 match=0
70
71 while read -r l; do
60b5e2d8
TL
72 if echo "$l" | grep -q "^machine enterprise.proxmox.com/debian/pve"; then
73 match=1
74 elif echo "$l" | grep -q "machine"; then
75 match=0
76 fi
77
78 if test "$match" = "1"; then
79 removed="$removed\n$l"
80 else
81 output="$output\n$l"
82 fi
bf09acfe
FG
83 done < /etc/apt/auth.conf
84
85 if test -n "$removed"; then
60b5e2d8
TL
86 if test ! -e /etc/apt/auth.conf.d/pve.conf; then
87 echo "Migrating APT auth config for enterprise.proxmox.com to /etc/apt/auth.conf.d/pve.conf .."
88 echo "$removed" > /etc/apt/auth.conf.d/pve.conf
89 else
90 echo "Removing stale APT auth config from /etc/apt/auth.conf"
91 fi
92 echo "$output" > /etc/apt/auth.conf
bf09acfe
FG
93 fi
94}
95
aff192e6
DM
96case "$1" in
97 triggered)
98 # We don't print a status message here, as dpkg already said
99 # "Processing triggers for ...".
100
099e5477
DM
101 # test if /etc/pve is mounted; else simple exit to avoid
102 # error during updates
103 test -f /etc/pve/local/pve-ssl.pem || exit 0;
6675a064 104 test -e /proxmox_install_mode && exit 0;
81019d9d 105
ea067f42 106 # the ExecStartPre doesn't triggers on service reload, so just in case
9efc89f6 107 pvecm updatecerts --silent || true
ea067f42 108
15c72102
FG
109 deb-systemd-invoke reload-or-try-restart pvedaemon.service
110 deb-systemd-invoke reload-or-try-restart pvestatd.service
111 deb-systemd-invoke reload-or-try-restart pveproxy.service
112 deb-systemd-invoke reload-or-try-restart spiceproxy.service
6385fb81 113 deb-systemd-invoke reload-or-try-restart pvescheduler.service
aff192e6
DM
114
115 exit 0;;
116
117 configure)
118 # Configure this package. If the package must prompt the user for
119 # information, do it here.
120
121 mkdir /etc/pve 2>/dev/null || true
122
75a6a7f5 123 if test ! -e /var/lib/pve-manager/apl-info/download.proxmox.com; then
60b5e2d8
TL
124 mkdir -p /var/lib/pve-manager/apl-info
125 cp /usr/share/doc/pve-manager/aplinfo.dat /var/lib/pve-manager/apl-info/download.proxmox.com
126 pveam update || true
75a6a7f5
DM
127 fi
128
544221fa 129 if ! test -f /root/.forward || ! grep -q '|/usr/bin/pvemailforward' /root/.forward; then
60b5e2d8 130 echo '|/usr/bin/pvemailforward' >>/root/.forward
782bc232 131 fi
d0e55a85 132
6675a064
DM
133 systemctl --system daemon-reload >/dev/null || true
134
135 # same as dh_systemd_enable (code copied)
136
6385fb81 137 UNITS="pvedaemon.service pveproxy.service spiceproxy.service pvestatd.service pvebanner.service pvescheduler.service pve-daily-update.timer"
aad80361 138 NO_RESTART_UNITS="pvenetcommit.service pve-guests.service"
0dfd4a94 139
aad80361 140 for unit in ${UNITS} ${NO_RESTART_UNITS}; do
60b5e2d8
TL
141 deb-systemd-helper unmask "$unit" >/dev/null || true
142
143 # was-enabled defaults to true, so new installations run enable.
144 if deb-systemd-helper --quiet was-enabled "$unit"; then
145 # Enables the unit on first installation, creates new
146 # symlinks on upgrades if the unit file has changed.
147 deb-systemd-helper enable "$unit" >/dev/null || true
148 else
149 # Update the statefile to add new symlinks (if any), which need to be
150 # cleaned up on purge. Also remove old symlinks.
151 deb-systemd-helper update-state "$unit" >/dev/null || true
152 fi
6675a064
DM
153 done
154
6e3ca3d3
TL
155 # FIXME: remove after beta is over and add hunk to actively remove the repo
156 BETA_SOURCES="/etc/apt/sources.list.d/pvetest-for-beta.list"
e8fed6b6 157 if test -f "$BETA_SOURCES" && dpkg --compare-versions "$2" 'lt' '7.0-9~' && dpkg --compare-versions "$2" 'gt' '7.0~'; then
60b5e2d8
TL
158 echo "Removing the during beta added pvetest repository file again"
159 rm -v "$BETA_SOURCES" || true
6e3ca3d3
TL
160 fi
161
891ea8e8 162 # FIXME: remove in PVE 8.0
4c5bb367 163 if test ! -e /proxmox_install_mode && test -n "$2" && dpkg --compare-versions "$2" 'lt' '7.0-6~'; then
60b5e2d8
TL
164 # PVE 4.0 beta to 5.4 ISO had a bug and did not generated a unique machine-id. below is a
165 # very relaxed machine-id list from all ISOs (released, tests & internal) possibly affected
166 if grep -q \
167 -e a0ee88c29b764c46a579dd89c86c2d84 \
168 -e ecbf104295bd4f8b90bb82dc2fa5e9e5 \
169 -e c8fa51cd0c254ea08b0e37c1e37afbb9 \
170 -e 2ec24eda629a4c8d8c1f8dac50a9ee5f \
171 -e ef8db290720047159b426bd322839d70 \
172 -e bd94244c0da6419a82a383e62dc03b51 \
173 -e 45d4e7046c3d4c26af8acd589f358ac6 \
174 -e 8c445f96b3064ff79f825ea78a3eefde \
175 -e 6f9fae0f0a794fd4b89b3abecfd7f182 \
176 -e 6f9fae0f0a794fd4b89b3abecfd7f182 \
177 -e 285de85759894b3f9ad9844a89045af6 \
178 -e 89971dede7b04c98b2b0bc8845f53320 \
179 -e 4e3b6e9550f24d638bc26211a7b37df5 \
180 -e bc2f684e31ee4daf95e45c62410a95b1 \
181 -e 8cc7bc883fd048b78a4af7433c48e341 \
182 -e 9b46d99712854566bb02a656a3ff9191 \
183 -e e7fc055af47048ee884dcb88a7474336 \
184 -e 13d879f75e6447a69ed85179bd93759a \
185 -e 5b59e448c3e74029af2ac91f572d68a7 \
186 -e 5a2bd0d11a6c41f9a33fd527751224ea \
187 -e 516afc72013c4b9da85b309aad987df2 \
188 -e b0ce8d24684845e8ac337c588a7715cb \
189 -e e0af064c16e9463e9fa980eac66427c1 \
190 -e 6e925d11b497446e8e7f2ff38e7cf891 \
191 -e eec280213051474d8bfe7e089a86744a \
192 -e 708ded6ee82a46c08b77fecda2284c6c \
193 -e 615cb2b78b2240289fef74da610c146f \
194 -e b965b329a7e246d5be66a8d367f5760d \
195 -e 5472a49c6436426fbebd7881f7b7f13b \
196 /etc/machine-id
197 then
198 echo "found static machine-id bug from Proxmox VE ISO installer <= 5.4, regenerating machine-id"
199 systemd-id128 new | tee /etc/machine-id.new /var/lib/dbus/machine-id.new
200 # atomically replace
201 mv /etc/machine-id.new /etc/machine-id
202 mv /var/lib/dbus/machine-id.new /var/lib/dbus/machine-id
203 echo "new machine-id generated, a reboot is recommended"
204 else
205 echo "machine-id check OK"
206 fi
5fb7a28a
TL
207 fi
208
c6908859
FG
209 set_lvm_conf
210
6675a064 211 if test ! -e /proxmox_install_mode; then
60b5e2d8
TL
212 # modeled after code generated by dh_start
213 for unit in ${UNITS}; do
214 if test -n "$2"; then
215 dh_action="reload-or-restart";
216 else
217 dh_action="start"
218 fi
219 if systemctl -q is-enabled "$unit"; then
220 deb-systemd-invoke $dh_action "$unit"
221 fi
222 done
6675a064 223 fi
bf09acfe
FG
224
225 if test ! -e /proxmox_install_mode && test -n "$2" && dpkg --compare-versions "$2" 'lt' '7.2.11~'; then
60b5e2d8
TL
226 if test -e /etc/apt/auth.conf ; then
227 migrate_apt_auth_conf
228 fi
bf09acfe 229 fi
01fe34e0 230 ;;
aff192e6 231
e3ffd2c0 232 abort-upgrade|abort-remove|abort-deconfigure)
aff192e6 233 ;;
aff192e6 234
aff192e6
DM
235 *) echo "$0: didn't understand being called with \`$1'" 1>&2
236 exit 0;;
237esac
238
239exit 0