summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/rc-update')
-rwxr-xr-xsbin/rc-update162
1 files changed, 162 insertions, 0 deletions
diff --git a/sbin/rc-update b/sbin/rc-update
new file mode 100755
index 0000000..b13e406
--- /dev/null
+++ b/sbin/rc-update
@@ -0,0 +1,162 @@
+#!/bin/bash
+# Copyright 1999-2004 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+source /sbin/functions.sh
+if [[ ${EUID} -ne 0 ]] ; then
+ eerror "$0: must be root."
+ exit 1
+fi
+
+usage() {
+cat << FOO
+usage: rc-update -a|add script runlevel2 [runlevel2 ...]
+ rc-update -d|del script [runlevel1 ...]
+ rc-update -s|show [runlevel1 ...]
+
+examples:
+ # rc-update add net.eth0 default
+ Adds the net.eth0 script (in /etc/init.d) to the "default" runlevel.
+
+ # rc-update del sysklogd
+ Deletes the sysklogd script from all runlevels. The original script
+ is not deleted, just any symlinks to the script in /etc/runlevels/*.
+
+ # rc-update del net.eth2 default wumpus
+ Delete the net.eth2 script from the default and wumpus runlevels.
+ All other runlevels are unaffected. Again, the net.eth2 script
+ residing in /etc/init.d is not deleted, just any symlinks in
+ /etc/runlevels/default and /etc/runlevels/wumpus.
+
+ # rc-update show
+ Show all the available scripts and list at which runlevels they
+ will execute.
+FOO
+ exit 1
+}
+
+add() {
+ local x=
+ local myscript=
+
+ if [[ $# -lt 3 ]] ; then
+ eerror "${0}: at least two arguments expected after \"$1\"."
+ exit 1
+ fi
+ shift
+ myscript="$1"
+ if [[ ! -e /etc/init.d/${myscript} ]] ; then
+ eerror "$0: /etc/init.d/${myscript} not found; aborting."
+ exit 1
+ fi
+ shift
+ for x in $* ; do
+ if [[ ! -e /etc/runlevels/${x} ]] ; then
+ ewarn "runlevel ${x} not found; skipping"
+ continue
+ fi
+ if [[ -L /etc/runlevels/${x}/${myscript} ]] ; then
+ ewarn "${myscript} already installed in runlevel ${x}; skipping"
+ continue
+ fi
+ if [[ ! -x /etc/init.d/${myscript} ]] ; then
+ ewarn "${myscript} not executable; skipping"
+ continue
+ fi
+ ln -snf "/etc/init.d/${myscript}" "/etc/runlevels/${x}/${myscript}"
+ if [[ $? -ne 0 ]] ; then
+ eerror "$0: failed to add ${myscript} to ${x}."
+ exit 1
+ fi
+ regen=1
+ einfo "${myscript} added to runlevel ${x}"
+ done
+}
+
+del() {
+ local x=
+ local mylevels=
+ local myscript=
+ local remlevels=
+
+ if [[ $# -lt 2 ]] ; then
+ eerror "$0: at least one argument expected after \"$1\"."
+ exit 1
+ fi
+ shift
+ myscript=$1
+ shift
+ if [[ $# -eq 0 ]] ; then
+ mylevels=$(cd /etc/runlevels/; ls)
+ else
+ mylevels="$*"
+ fi
+ remlevels=""
+ for x in ${mylevels} ; do
+ if [[ -L /etc/runlevels/${x}/${myscript} ]] ; then
+ regen=1
+ rm -f "/etc/runlevels/${x}/${myscript}"
+ remlevels="${remlevels} ${x}"
+ fi
+ done
+ if [[ -z ${remlevels} ]] ; then
+ einfo "${myscript} not found in any of the specified runlevels."
+ else
+ einfo "${myscript} removed from the following runlevels:${remlevels}"
+ fi
+}
+
+show() {
+ local x=
+ local y=
+ local mylevels=
+ local myscripts=
+
+ shift
+ if [[ $# -eq 0 ]] ; then
+ mylevels=$(cd /etc/runlevels/; ls)
+ else
+ mylevels="$*"
+ fi
+ myscripts=$(cd /etc/init.d; ls)
+
+ for x in ${myscripts} ; do
+ if [[ ${x%%.sh} = "${x}" ]] ; then
+ printf "%20s | " ${x:0:19}
+ for y in ${mylevels} ; do
+ if [[ -L /etc/runlevels/${y}/${x} ]] ; then
+ echo -n "${y} "
+ else
+ printf "%${#y}s " " "
+ fi
+ done
+ echo ""
+ fi
+ done
+}
+
+if [[ $# -lt 1 ]] ; then
+ usage
+ exit 1
+fi
+
+regen=0
+
+case "$1" in
+ add|-a)
+ add "$@"
+ ;;
+ del|delete|-d)
+ del "$@"
+ ;;
+ show|-s)
+ show "$@"
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+esac
+
+
+# vim:ts=4