2009-12-11 07:23:49 +01:00
|
|
|
#!/bin/sh -e -e
|
2009-05-04 23:16:41 +02:00
|
|
|
#
|
|
|
|
# Registers or unregisters OpenRC services into the specified
|
|
|
|
# runlevel.
|
|
|
|
#
|
2009-12-11 07:23:49 +01:00
|
|
|
# Arguments: $ACTION = [run/targets]
|
|
|
|
# $TARGET = [post-install/pre-remove]
|
|
|
|
# $PKGNAME
|
|
|
|
# $VERSION
|
|
|
|
# $UPDATE = [yes/no]
|
2009-05-04 23:16:41 +02:00
|
|
|
#
|
2009-10-02 17:29:17 +02:00
|
|
|
ACTION="$1"
|
|
|
|
TARGET="$2"
|
|
|
|
PKGNAME="$3"
|
|
|
|
VERSION="$4"
|
|
|
|
UPDATE="$5"
|
|
|
|
|
2009-08-12 00:26:29 +02:00
|
|
|
initdir=etc/init.d
|
2009-10-02 17:29:17 +02:00
|
|
|
metadatadir=var/db/xbps/metadata/${PKGNAME}
|
2009-08-12 00:26:29 +02:00
|
|
|
|
2009-10-02 17:29:17 +02:00
|
|
|
case "$ACTION" in
|
2009-05-04 23:16:41 +02:00
|
|
|
targets)
|
|
|
|
echo "post-install pre-remove"
|
|
|
|
;;
|
|
|
|
run)
|
|
|
|
[ ! -x sbin/rc-update ] && exit 0
|
|
|
|
[ ! -x sbin/rc-service ] && exit 0
|
|
|
|
[ -z "$openrc_services" ] && exit 1
|
|
|
|
|
2009-10-02 17:29:17 +02:00
|
|
|
if [ "$TARGET" = "pre-remove" ]; then
|
2009-05-04 23:16:41 +02:00
|
|
|
rcupdate_args="del"
|
2009-10-02 17:29:17 +02:00
|
|
|
elif [ "$TARGET" = "post-install" ]; then
|
2009-05-04 23:16:41 +02:00
|
|
|
rcupdate_args="add"
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2009-05-05 00:47:58 +02:00
|
|
|
[ ! -f etc/fstab ] && touch etc/fstab
|
|
|
|
|
2009-05-04 23:16:41 +02:00
|
|
|
set -- ${openrc_services}
|
|
|
|
while [ $# -gt 0 ]; do
|
2009-10-02 17:29:17 +02:00
|
|
|
srv_restart=$metadatadir/.$1_srv_restart
|
|
|
|
if [ "$TARGET" = "post-install" ]; then
|
|
|
|
if [ -f $srv_restart ]; then
|
|
|
|
# Restart service if it was running previously.
|
|
|
|
$initdir/$1 start
|
|
|
|
rm -f $srv_restart
|
|
|
|
else
|
|
|
|
# Register service.
|
|
|
|
if sbin/rc-service -e ${1}; then
|
|
|
|
sbin/rc-update add ${1} ${2}
|
2009-08-12 00:26:29 +02:00
|
|
|
fi
|
|
|
|
fi
|
2009-10-02 17:29:17 +02:00
|
|
|
else
|
|
|
|
# While removing always stop the service if running.
|
|
|
|
$initdir/$1 -q status
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
$initdir/$1 stop
|
|
|
|
fi
|
|
|
|
#
|
|
|
|
# While upgrading a package, don't remove the service.
|
|
|
|
#
|
|
|
|
if [ "$UPDATE" = "yes" ]; then
|
|
|
|
touch -f $srv_restart
|
|
|
|
else
|
|
|
|
# Unregister the service.
|
|
|
|
sbin/rc-update del ${1} ${2}
|
|
|
|
fi
|
2009-05-04 23:16:41 +02:00
|
|
|
fi
|
2009-10-02 17:29:17 +02:00
|
|
|
unset srv_restart
|
2009-05-04 23:16:41 +02:00
|
|
|
shift; shift;
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|