2009-12-11 12:03:21 +01:00
|
|
|
#!/bin/sh
|
2009-05-04 23:16:41 +02:00
|
|
|
#
|
|
|
|
# Registers or unregisters OpenRC services into the specified
|
2010-04-16 20:09:14 +02:00
|
|
|
# runlevel. This works by specifying three arguments as follows:
|
|
|
|
#
|
|
|
|
# service_name runlevel register
|
|
|
|
# --------------------------------------------------
|
|
|
|
# dbus default boolean
|
|
|
|
# --------------------------------------------------
|
2009-05-04 23:16:41 +02:00
|
|
|
#
|
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
|
2010-04-16 20:09:14 +02:00
|
|
|
unset skip_service
|
2009-10-02 17:29:17 +02:00
|
|
|
srv_restart=$metadatadir/.$1_srv_restart
|
|
|
|
if [ "$TARGET" = "post-install" ]; then
|
2010-04-16 20:09:14 +02:00
|
|
|
# The service shouldn't be registered, so just show a message
|
|
|
|
# explaining how to add it in the future.
|
|
|
|
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
|
|
|
|
cat <<_EOF
|
|
|
|
================================================================
|
|
|
|
|
|
|
|
The system service '${1}' won't be added into the runlevel
|
|
|
|
'${2}' by default, so it will remain disabled at boot.
|
|
|
|
|
|
|
|
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}
|
|
|
|
|
|
|
|
================================================================
|
|
|
|
_EOF
|
|
|
|
shift; shift; shift;
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
echo "Registering '${1}' service to start at boot."
|
|
|
|
fi
|
2009-10-02 17:29:17 +02:00
|
|
|
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
|
2010-04-16 20:09:14 +02:00
|
|
|
shift; shift; shift;
|
2009-05-04 23:16:41 +02:00
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|