vp-build/triggers/openrc-service

59 lines
1.1 KiB
Plaintext
Raw Normal View History

#!/bin/sh
#
# Registers or unregisters OpenRC services into the specified
# runlevel.
#
# Arguments: $1 = action [run/targets]
# $2 = target [post-install/pre-remove]
# $3 = pkgname
#
initdir=etc/init.d
case "$1" in
targets)
echo "post-install pre-remove"
;;
run)
[ ! -x sbin/rc-update ] && exit 0
[ ! -x sbin/rc-service ] && exit 0
[ -z "$openrc_services" ] && exit 1
target=$2
if [ "$target" = "pre-remove" ]; then
text="Unr"
rcupdate_args="del"
elif [ "$target" = "post-install" ]; then
text="R"
rcupdate_args="add"
else
exit 1
fi
[ ! -f etc/fstab ] && touch etc/fstab
set -- ${openrc_services}
while [ $# -gt 0 ]; do
if sbin/rc-service -e ${1}; then
# Stop the service if it's running.
if [ "$target" = "pre-remove" -a -f $initdir/$1 ]; then
$initdir/$1 -q status
if [ $? -eq 0 ]; then
$initdir/$1 stop
fi
fi
# (Un)register the service.
echo "${text}egistering ${1} OpenRC service..."
sbin/rc-update ${rcupdate_args} ${1} ${2}
fi
shift; shift;
done
sbin/rc-update -u
;;
*)
exit 1
;;
esac
exit 0