--- /sbin/rc-update 2004-06-07 09:45:11.000000000 +0300 +++ rc-update 2004-06-11 00:47:34.668083312 +0300 @@ -1,7 +1,7 @@ #!/bin/bash -# Copyright 1999-2004 Gentoo Technologies, Inc. +# Copyright 1999-2003 Gentoo Technologies, Inc. # Distributed under the terms of the GNU General Public License v2 -# $Header: /home/cvsroot/gentoo-src/rc-scripts/sbin/rc-update,v 1.17 2004/04/21 17:09:18 vapier Exp $ +# $Header: /home/cvsroot/gentoo-src/rc-scripts/sbin/rc-update,v 1.16 2003/08/04 21:39:17 azarah Exp $ source /sbin/functions.sh if [ "${EUID}" -ne 0 ] @@ -12,11 +12,13 @@ usage() { cat << FOO -usage: rc-update -a|add script runlevel2 [runlevel2...] +usage: rc-update -a|add script runlevel1 [runlevel2...] rc-update -d|del script [runlevel1...] rc-update -s|show [runlevel1...] + rc-update -c|current [runlevel] -note: After rc-update executes, the script dependency cache is automatically +note: + After rc-update executes, the script dependency cache is automatically updated. examples: @@ -36,6 +38,12 @@ rc-update show Show all the available scripts and list at which runlevels they will execute. + + rc-update current default + Synchornize current running services with the "default" runlevel, + creating "default" if it doesn't exist. + use without any argument to sync to current runlevel. + FOO exit 1 } @@ -157,6 +165,50 @@ done } +current() { + + local x= + local mylevel= + + shift + if [ $# -eq 0 ] + then + mylevel=$(cat /var/lib/init.d/softlevel) + ewarn "Using current runlevel: ${mylevel}" + echo + else + mylevel=$1 + fi + + if [ ! -e "/etc/runlevels/${mylevel}" ] + then + einfo Creating runlevel ${mylevel} + echo + mkdir "/etc/runlevels/${mylevel}" + fi + + # Scan current started services and add them to current runlevel + + for x in $( cd /var/lib/init.d/started/ ; ls ) + do + if [ ! -L "/etc/runlevels/${mylevel}/${x}" ] + then + add shift ${x} ${mylevel} + fi + done + + # Scan current runlevel for non-running services, and remove them + + for x in $( cd /etc/runlevels/${mylevel} ; ls ) + do + if [ ! -L "/var/lib/init.d/started/${x}" ] + then + del shift ${x} ${mylevel} + fi + done + +} + if [ $# -lt 1 ] then usage @@ -175,6 +227,9 @@ show|-s) show "$@" ;; + current|-c) + current "$@" + ;; *) usage exit 1