2014-02-08 23:31:24 +04:00
#!/bin/sh
# this script piggybacks service status information
# into the system to be installed (instead of applying
# it to rootfs being formed immediately)
2016-02-10 09:32:23 +03:00
# NB: install2 is not a rootfs, handling differs either
2014-02-08 23:31:24 +04:00
STATUS=`mktemp`
2016-04-14 19:10:57 +03:00
CONFDIR=/usr/share/install2
CHECK_FILES=
2014-02-08 23:31:24 +04:00
. shell-config
switch() {
2019-12-12 17:44:18 +03:00
local sname="$1"
sname="${sname%.service}"
sname="${sname%.socket}"
2016-04-14 19:10:57 +03:00
[ -n "$CHECK_FILES" ] && \
2019-12-12 17:44:18 +03:00
egrep -qs "^[[:blank:]]*$sname(.service|.socket)?[[:blank:]]*$" \
2016-04-14 19:10:57 +03:00
$CHECK_FILES && return ||:
2019-12-12 17:44:18 +03:00
# avoid service duplication: drop sevice without unit type
[ "$sname" = "$1" ] || shell_config_del "$STATUS" "$sname"
2014-02-08 23:31:24 +04:00
case "$2" in
on|off)
shell_config_set "$STATUS" "$1" "$2";;
esac
}
2016-04-14 19:10:57 +03:00
for f in services-on services-off systemd-enabled systemd-disabled; do
[ -s "$CONFDIR/$f" ] || continue
CHECK_FILES="$CHECK_FILES $CONFDIR/$f"
done
2014-02-08 23:31:24 +04:00
# defaults (most likely features.in ones)
for i in $GLOBAL_DEFAULT_SERVICES_ENABLE; do switch $i on; done
for i in $GLOBAL_DEFAULT_SERVICES_DISABLE; do switch $i off; done
# explicitly specified behaviour (e.g. via conf.d)
for i in $GLOBAL_SERVICES_ENABLE; do switch $i on; done
for i in $GLOBAL_SERVICES_DISABLE; do switch $i off; done
2019-12-12 17:44:18 +03:00
# systemd services
for i in $GLOBAL_SYSTEMD_SERVICES_ENABLE; do switch $i on; done
for i in $GLOBAL_SYSTEMD_SERVICES_DISABLE; do switch $i off; done
2014-02-08 23:31:24 +04:00
SERVICES="$GLOBAL_DEFAULT_SERVICES_ENABLE $GLOBAL_DEFAULT_SERVICES_DISABLE"
SERVICES="$SERVICES $GLOBAL_SERVICES_ENABLE $GLOBAL_SERVICES_DISABLE"
2019-12-12 17:44:18 +03:00
SERVICES="$SERVICES $GLOBAL_SYSTEMD_SERVICES_ENABLE $GLOBAL_SYSTEMD_SERVICES_DISABLE"
2014-02-08 23:31:24 +04:00
SERVICES="$(echo $SERVICES | sort -u)"
for i in $SERVICES; do
onoff="$(shell_config_get "$STATUS" "$i")"
[ -n "$onoff" ] || continue
2016-04-14 19:10:57 +03:00
echo "$i" >> "$CONFDIR"/services-"$onoff"
2014-02-08 23:31:24 +04:00
done
2019-06-14 15:43:37 +03:00
if [ -s "$CONFDIR"/services-on ]; then
2019-12-12 17:44:18 +03:00
if [ -s "$CONFDIR"/systemd-enabled ] || [ -n "$GLOBAL_SYSTEMD_SERVICES_ENABLE" ]; then
2019-06-14 15:43:37 +03:00
cat "$CONFDIR"/services-on >>"$CONFDIR"/systemd-enabled
rm "$CONFDIR"/services-on
else
cp -a "$CONFDIR"/{services-on,systemd-enabled}
fi
fi
if [ -s "$CONFDIR"/services-off ]; then
2019-12-12 17:44:18 +03:00
if [ -s "$CONFDIR"/systemd-disabled ] || [ -n "$GLOBAL_SYSTEMD_SERVICES_DISABLE" ]; then
2019-06-14 15:43:37 +03:00
cat "$CONFDIR"/services-off >>"$CONFDIR"/systemd-disabled
rm "$CONFDIR"/services-off
else
cp -a "$CONFDIR"/{services-off,systemd-disabled}
fi
fi
2016-10-17 15:56:36 +03:00
2014-02-08 23:31:24 +04:00
rm "$STATUS"
: