fedora: reduce code duplication in systemd triggers

This commit is contained in:
Marek Marczykowski-Górecki 2015-01-14 02:27:34 +01:00
parent 898f223cd4
commit 5590445319

View File

@ -72,6 +72,27 @@ BuildRequires: qubes-libvchan-%{backend_vmm}-devel
%define kde_service_dir /usr/share/kde4/services
%define installOverridenServices() \
UNITDIR=/lib/systemd/system\
OVERRIDEDIR=/usr/lib/qubes/init\
# Install overriden services only when original exists\
for srv in %*; do\
if [ -f $UNITDIR/$srv.service ]; then\
cp $OVERRIDEDIR/$srv.service /etc/systemd/system/\
/bin/systemctl is-enabled $srv.service >/dev/null && /bin/systemctl --no-reload reenable $srv.service 2>/dev/null\
fi\
if [ -f $UNITDIR/$srv.socket -a -f $OVERRIDEDIR/$srv.socket ]; then\
cp $OVERRIDEDIR/$srv.socket /etc/systemd/system/\
/bin/systemctl is-enabled $srv.socket >/dev/null && /bin/systemctl --no-reload reenable $srv.socket 2>/dev/null\
fi\
if [ -f $UNITDIR/$srv.path -a -f $OVERRIDEDIR/$srv.path ]; then\
cp $OVERRIDEDIR/$srv.path /etc/systemd/system/\
/bin/systemctl is-enabled $srv.path >/dev/null && /bin/systemctl --no-reload reenable $srv.path 2>/dev/null\
fi\
done\
/bin/systemctl daemon-reload\
%{nil}
%description
The Qubes core files for installation inside a Qubes VM.
@ -555,22 +576,6 @@ done
/bin/systemctl enable qubes-update-check.timer 2> /dev/null
UNITDIR=/lib/systemd/system
OVERRIDEDIR=/usr/lib/qubes/init
# Install overriden services only when original exists
for srv in cups ModemManager NetworkManager NetworkManager-wait-online ntpd chronyd; do
if [ -f $UNITDIR/$srv.service ]; then
cp $OVERRIDEDIR/$srv.service /etc/systemd/system/
fi
if [ -f $UNITDIR/$srv.socket -a -f $OVERRIDEDIR/$srv.socket ]; then
cp $OVERRIDEDIR/$srv.socket /etc/systemd/system/
fi
if [ -f $UNITDIR/$srv.path -a -f $OVERRIDEDIR/$srv.path ]; then
cp $OVERRIDEDIR/$srv.path /etc/systemd/system/
fi
done
# Set default "runlevel"
rm -f /etc/systemd/system/default.target
ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
@ -606,50 +611,15 @@ rm -f /etc/systemd/system/getty.target.wants/getty@tty*.service
exit 0
%triggerin systemd -- NetworkManager
UNITDIR=/lib/systemd/system
OVERRIDEDIR=/usr/lib/qubes/init
# Install overriden services only when original exists
for srv in ModemManager NetworkManager NetworkManager-wait-online; do
if [ -f $UNITDIR/$srv.service ]; then
cp $OVERRIDEDIR/$srv.service /etc/systemd/system/
fi
if [ -f $UNITDIR/$srv.socket -a -f $OVERRIDEDIR/$srv.socket ]; then
cp $OVERRIDEDIR/$srv.socket /etc/systemd/system/
fi
if [ -f $UNITDIR/$srv.path -a -f $OVERRIDEDIR/$srv.path ]; then
cp $OVERRIDEDIR/$srv.path /etc/systemd/system/
fi
done
# Disable original service to enable overriden one
/bin/systemctl disable ModemManager.service 2> /dev/null
/bin/systemctl disable NetworkManager.service 2> /dev/null
%installOverridenServices ModemManager NetworkManager NetworkManager-wait-online
# Disable D-BUS activation of NetworkManager - in AppVm it causes problems (eg PackageKit timeouts)
/bin/systemctl mask dbus-org.freedesktop.NetworkManager.service 2> /dev/null
/bin/systemctl enable ModemManager.service 2> /dev/null
/bin/systemctl enable NetworkManager.service 2> /dev/null
# Fix for https://bugzilla.redhat.com/show_bug.cgi?id=974811
/bin/systemctl enable NetworkManager-dispatcher.service 2> /dev/null
exit 0
%triggerin systemd -- cups
UNITDIR=/lib/systemd/system
OVERRIDEDIR=/usr/lib/qubes/init
# Install overriden services only when original exists
for srv in cups; do
if [ -f $UNITDIR/$srv.service ]; then
cp $OVERRIDEDIR/$srv.service /etc/systemd/system/
fi
if [ -f $UNITDIR/$srv.socket -a -f $OVERRIDEDIR/$srv.socket ]; then
cp $OVERRIDEDIR/$srv.socket /etc/systemd/system/
fi
if [ -f $UNITDIR/$srv.path -a -f $OVERRIDEDIR/$srv.path ]; then
cp $OVERRIDEDIR/$srv.path /etc/systemd/system/
fi
done
# Enable cups only when it is real SystemD service
[ -e /lib/systemd/system/cups.service ] && /bin/systemctl enable cups.service 2> /dev/null
%installOverridenServices cups
exit 0
%triggerin systemd -- haveged