mirror of
https://git.proxmox.com/git/systemd
synced 2026-01-16 23:07:14 +00:00
The recommended check is [ -d /run/systemd/system ] as this will also work with a standalone systemd-logind.
75 lines
2.0 KiB
Bash
Executable File
75 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
static_blacklist=/usr/share/systemd/unit.blacklist
|
|
enabled_units=/var/lib/systemd/enabled-units
|
|
statedir=/var/lib/systemd
|
|
unitdir=/lib/systemd/system
|
|
|
|
# If a package is installed using init-system-helpers, do nothing.
|
|
# We don't want to interfere in such a case
|
|
if [ -x /usr/bin/deb-systemd-helper ] ; then
|
|
exit 0
|
|
fi
|
|
|
|
# If systemd is not running, schedule a run on next boot
|
|
if ! [ -d /run/systemd/system ] ; then
|
|
touch $statedir/run-debian-enable-units
|
|
exit 0
|
|
else
|
|
rm -f $statedir/run-debian-enable-units
|
|
fi
|
|
|
|
# Get all installed service and socket unit files
|
|
installed=$(mktemp)
|
|
find $unitdir -type f \( -name "*.socket" -o -name "*.service" \) -printf "%f\n" | sort -u > $installed
|
|
|
|
|
|
# Generate a blacklist from previously enabled units and
|
|
# static ones, like the one in systemd itself while ignoring comments
|
|
blacklist=$(mktemp)
|
|
cat $static_blacklist $enabled_units 2>/dev/null | sed '/^#.*/d' | sort -u > $blacklist
|
|
|
|
|
|
# Skip blacklisted entries
|
|
while read unit ; do
|
|
sed -i "/$unit/d" $installed
|
|
done < $blacklist
|
|
|
|
|
|
# Get entries which need to be enabled
|
|
needs_enable=$(mktemp)
|
|
while read unit ; do
|
|
if systemctl is-enabled "$unit" 2> /dev/null | grep -q "disabled"; then
|
|
echo "$unit" >> $needs_enable
|
|
fi
|
|
done < $installed
|
|
|
|
|
|
# Enable entries and record their state
|
|
while read unit ; do
|
|
echo "systemctl: enabling $unit"
|
|
systemctl enable "$unit" 2>&1 | awk '{print $4}' | sed s/\'//g > "$statedir/${unit}.symlinks"
|
|
echo "$unit" >> $enabled_units
|
|
done < $needs_enable
|
|
|
|
|
|
# Cleanup phase
|
|
# Find deleted units and remove their symlinks
|
|
if [ -f $enabled_units ] ; then
|
|
while read unit ; do
|
|
if ! [ -f "$unitdir/$unit" ] ; then
|
|
echo "systemctl: disabling $unit"
|
|
while read symlink ; do
|
|
rm -f "$symlink"
|
|
done < "$statedir/${unit}.symlinks"
|
|
rm -f "$statedir/${unit}.symlinks"
|
|
sed -i "/$unit/d" $enabled_units
|
|
fi
|
|
done < $enabled_units
|
|
fi
|
|
|
|
rm -f $installed
|
|
rm -f $blacklist
|
|
rm -f $needs_enable
|
|
|