debian: use systemd-preset logic from rpm package
It is more robust, especially handle "# Units below this line will be re-preset on package upgrade" part of 75-qubes-vm.preset file. This is needed to fix system configuration without the need to rebuild the whole template. QubesOS/qubes-issues#2913
This commit is contained in:
parent
a95aa43864
commit
47e6a84f79
81
debian/qubes-core-agent.postinst
vendored
81
debian/qubes-core-agent.postinst
vendored
@ -26,31 +26,70 @@ debug() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
systemdPreload() {
|
is_static() {
|
||||||
# Debian systemd helper does not yet honour preset, therefore use
|
[ -f "/lib/sytemd/system/$1" ] && ! grep -q '^[[].nstall]' "/lib/systemd/system/$1"
|
||||||
# systemctl preset on each unit file (not using preset-all either since
|
}
|
||||||
# wheezy does not support it) listed in 75-qubes-vm.preset.
|
|
||||||
|
|
||||||
systemctl --no-reload preset-all > /dev/null 2>&1 && PRESET_FAILED=0 || PRESET_FAILED=1
|
is_masked() {
|
||||||
|
if [ ! -L /etc/systemd/system/"$1" ]
|
||||||
|
then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
target=$(readlink /etc/systemd/system/"$1" 2>/dev/null || :)
|
||||||
|
if [ "$target" = "/dev/null" ]
|
||||||
|
then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# Mask any static unit files that are marked to be disabled
|
mask() {
|
||||||
grep '^[[:space:]]*[^#;]' /lib/systemd/system-preset/75-qubes-vm.preset | while read -r action unit_name; do
|
ln -sf /dev/null /etc/systemd/system/"$1"
|
||||||
case "${action}" in
|
}
|
||||||
disable)
|
|
||||||
if [ -e "/lib/systemd/system/${unit_name}" ]; then
|
unmask() {
|
||||||
if ! grep -F -q '[Install]' "/lib/systemd/system/${unit_name}"; then
|
if ! is_masked "$1"
|
||||||
|
then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
rm -f /etc/systemd/system/"$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
preset_units() {
|
||||||
|
local represet=
|
||||||
|
while read -r action unit_name
|
||||||
|
do
|
||||||
|
if [ "$action" = "#" ] && [ "$unit_name" = "Units below this line will be re-preset on package upgrade" ]
|
||||||
|
then
|
||||||
|
represet=1
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
echo "$action $unit_name" | grep -q '^[[:space:]]*[^#;]' || continue
|
||||||
|
if ! [ -n "$action" ] || ! [ -n "$unit_name" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$2" = "initial" ] || [ "$represet" = "1" ]
|
||||||
|
then
|
||||||
|
if [ "$action" = "disable" ] && is_static "$unit_name"
|
||||||
|
then
|
||||||
|
if ! is_masked "$unit_name"
|
||||||
|
then
|
||||||
|
# We must effectively mask these units, even if they are static.
|
||||||
deb-systemd-helper mask "${unit_name}" > /dev/null 2>&1 || true
|
deb-systemd-helper mask "${unit_name}" > /dev/null 2>&1 || true
|
||||||
fi
|
fi
|
||||||
|
elif [ "$action" = "enable" ] && is_static "$unit_name"
|
||||||
|
then
|
||||||
|
if is_masked "$unit_name"
|
||||||
|
then
|
||||||
|
# We masked this static unit before, now we unmask it.
|
||||||
|
deb-systemd-helper unmask "${unit_name}" > /dev/null 2>&1 || true
|
||||||
fi
|
fi
|
||||||
;;
|
systemctl --no-reload preset "$unit_name" >/dev/null 2>&1 || :
|
||||||
*)
|
else
|
||||||
# preset-all is not available in wheezy; so preset each unit file listed in 75-qubes-vm.preset
|
systemctl --no-reload preset "$unit_name" >/dev/null 2>&1 || :
|
||||||
if [ "${PRESET_FAILED}" -eq 1 ]; then
|
|
||||||
systemctl --no-reload preset "${unit_name}" > /dev/null 2>&1 || true
|
|
||||||
fi
|
fi
|
||||||
;;
|
fi
|
||||||
esac
|
done < "$1"
|
||||||
done
|
|
||||||
|
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
}
|
}
|
||||||
@ -97,10 +136,12 @@ case "${1}" in
|
|||||||
ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
|
ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
|
||||||
|
|
||||||
# Systemd preload-all
|
# Systemd preload-all
|
||||||
systemdPreload
|
preset_units /lib/systemd/system-preset/75-qubes-vm.preset initial
|
||||||
|
|
||||||
# Maybe install overridden serial.conf init script
|
# Maybe install overridden serial.conf init script
|
||||||
installSerialConf
|
installSerialConf
|
||||||
|
else
|
||||||
|
preset_units /lib/systemd/system-preset/75-qubes-vm.preset upgrade
|
||||||
fi
|
fi
|
||||||
systemctl reenable haveged
|
systemctl reenable haveged
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user