2010-11-04 13:53:46 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Registers or unregisters OpenRC services into the specified
|
|
|
|
# runlevel. This works by specifying three arguments as follows:
|
|
|
|
#
|
|
|
|
# service_name runlevel register
|
|
|
|
# --------------------------------------------------
|
|
|
|
# dbus default boolean
|
|
|
|
# --------------------------------------------------
|
|
|
|
#
|
|
|
|
# Arguments: $ACTION = [run/targets]
|
|
|
|
# $TARGET = [post-install/pre-remove]
|
|
|
|
# $PKGNAME
|
|
|
|
# $VERSION
|
|
|
|
# $UPDATE = [yes/no]
|
|
|
|
#
|
|
|
|
ACTION="$1"
|
|
|
|
TARGET="$2"
|
|
|
|
PKGNAME="$3"
|
|
|
|
VERSION="$4"
|
|
|
|
UPDATE="$5"
|
|
|
|
|
2011-07-01 15:22:10 +02:00
|
|
|
export PATH="$PATH:/usr/local/bin"
|
|
|
|
|
2010-11-04 13:53:46 +01:00
|
|
|
initdir=etc/init.d
|
|
|
|
metadatadir=var/db/xbps/metadata/${PKGNAME}
|
|
|
|
|
|
|
|
case "$ACTION" 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
|
|
|
|
|
|
|
|
if [ "$TARGET" = "pre-remove" ]; then
|
|
|
|
rcupdate_args="del"
|
|
|
|
elif [ "$TARGET" = "post-install" ]; then
|
|
|
|
rcupdate_args="add"
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ ! -f etc/fstab ] && touch etc/fstab
|
|
|
|
|
|
|
|
set -- ${openrc_services}
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
if [ "$TARGET" = "post-install" ]; then
|
|
|
|
case "$3" in
|
|
|
|
[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff]|0)
|
|
|
|
skip_service=1
|
|
|
|
;;
|
|
|
|
[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
|
|
|
|
unset skip_service
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
if [ -n "$skip_service" ]; then
|
2011-07-20 18:53:13 +02:00
|
|
|
# The service shouldn't be registered, so just show a message
|
|
|
|
# explaining how to add it in the future.
|
2010-11-04 13:53:46 +01:00
|
|
|
cat <<_EOF
|
2010-12-08 01:25:34 +01:00
|
|
|
=========================================================================
|
2010-11-04 13:53:46 +01:00
|
|
|
|
2011-07-20 18:53:13 +02:00
|
|
|
The service '${1}' from '${PKGNAME}-${VERSION}' won't be registered
|
|
|
|
into the runlevel '${2}', therefore it will remain disabled at boot.
|
2010-11-04 13:53:46 +01:00
|
|
|
|
|
|
|
To start it at boot time, use the following command:
|
|
|
|
|
|
|
|
$ rc-update add ${1} ${2}
|
|
|
|
|
|
|
|
To disable it again use:
|
|
|
|
|
|
|
|
$ rc-update del ${1} ${2}
|
|
|
|
|
2011-07-20 18:53:13 +02:00
|
|
|
To start the service:
|
|
|
|
|
|
|
|
$ rc-service start ${1}
|
|
|
|
|
2010-12-08 01:25:34 +01:00
|
|
|
=========================================================================
|
2010-11-04 13:53:46 +01:00
|
|
|
_EOF
|
|
|
|
shift; shift; shift;
|
|
|
|
continue
|
|
|
|
fi
|
2010-12-08 01:25:34 +01:00
|
|
|
# Register service.
|
2010-12-10 12:48:29 +01:00
|
|
|
if [ "$UPDATE" = "no" ]; then
|
2010-12-08 01:25:34 +01:00
|
|
|
sbin/rc-update add ${1} ${2}
|
2010-11-04 13:53:46 +01:00
|
|
|
fi
|
|
|
|
else
|
2011-07-20 18:53:13 +02:00
|
|
|
#
|
|
|
|
# pre-remove
|
|
|
|
#
|
2010-11-04 13:53:46 +01:00
|
|
|
$initdir/$1 -q status
|
2010-12-08 01:25:34 +01:00
|
|
|
rv=$?
|
|
|
|
|
|
|
|
if [ "$UPDATE" = "no" ]; then
|
|
|
|
#
|
|
|
|
# If the service is running inform the user that it should be
|
2011-07-20 18:53:13 +02:00
|
|
|
# stopped before removing the package!
|
2010-12-08 01:25:34 +01:00
|
|
|
#
|
|
|
|
if [ $rv -eq 0 ]; then
|
2011-07-20 18:53:13 +02:00
|
|
|
echo "ERROR: service '${1}' from '${PKGNAME}-${VERSION}' must be stopped!"
|
|
|
|
echo "ERROR: please stop the service with 'rc-service $1 stop' and try again."
|
|
|
|
error=1
|
2010-12-08 01:25:34 +01:00
|
|
|
else
|
|
|
|
# Unregister the service.
|
|
|
|
sbin/rc-update del ${1} ${2}
|
|
|
|
fi
|
2010-11-04 13:53:46 +01:00
|
|
|
else
|
2010-12-08 01:25:34 +01:00
|
|
|
if [ $rv -eq 0 ]; then
|
2011-07-20 18:53:13 +02:00
|
|
|
echo "WARNING: service '${1}' from '${PKGNAME}-${VERSION}' must be restarted!"
|
|
|
|
echo "WARNING: you can restart it with 'rc-service $1 restart'."
|
2010-12-08 01:25:34 +01:00
|
|
|
fi
|
2010-11-04 13:53:46 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
shift; shift; shift;
|
|
|
|
done
|
2011-07-20 18:53:13 +02:00
|
|
|
[ -n "$error" ] && exit $error
|
2010-11-04 13:53:46 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|