/[baselayout]/trunk/sbin/rc-update
Gentoo

Contents of /trunk/sbin/rc-update

Parent Directory Parent Directory | Revision Log Revision Log


Revision 399 - (show annotations) (download)
Mon Aug 4 21:39:17 2003 UTC (15 years, 8 months ago) by azarah
File size: 3541 byte(s)
Last minute fixes

1 #!/bin/bash
2 # Copyright 1999-2003 Gentoo Technologies, Inc.
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header$
5
6 source /sbin/functions.sh
7 if [ "${EUID}" -ne 0 ]
8 then
9 eerror "$0: must be root."
10 exit 1
11 fi
12
13 usage() {
14 cat << FOO
15 usage: rc-update -a|add script runlevel2 [runlevel2...]
16 rc-update -d|del script [runlevel1...]
17 rc-update -s|show [runlevel1...]
18
19 note:
20 After rc-update executes, the script dependency cache is automatically
21 updated.
22
23 examples:
24 rc-update add net.eth0 default
25 Adds the net.eth0 script (in /etc/init.d) to the "default" runlevel.
26
27 rc-update del sysklogd
28 Deletes the sysklogd script from all runlevels. The original script
29 is not deleted, just any symlinks to the script in /etc/runlevels/*.
30
31 rc-update del net.eth2 default wumpus
32 Delete the net.eth2 script from the default and wumpus runlevels.
33 All other runlevels are unaffected. Again, the net.eth2 script
34 residing in /etc/init.d is not deleted, just any symlinks in
35 /etc/runlevels/default and /etc/runlevels/wumpus.
36
37 rc-update show
38 Show all the available scripts and list at which runlevels they
39 will execute.
40
41 FOO
42 exit 1
43 }
44
45 add() {
46 local x=
47 local myscript=
48
49 if [ $# -lt 3 ]
50 then
51 eerror "${0}: at least two arguments expected after \"$1\"."
52 exit 1
53 fi
54 shift
55 myscript="$1"
56 if [ ! -e "/etc/init.d/${myscript}" ]
57 then
58 eerror "$0: /etc/init.d/${myscript} not found; aborting."
59 exit 1
60 fi
61 shift
62 for x in $*
63 do
64 if [ ! -e "/etc/runlevels/${x}" ]
65 then
66 ewarn "runlevel ${x} not found; skipping"
67 continue
68 fi
69 if [ -L "/etc/runlevels/${x}/${myscript}" ]
70 then
71 ewarn "${myscript} already installed in runlevel ${x}; skipping"
72 continue
73 fi
74 if [ ! -x "/etc/init.d/${myscript}" ]
75 then
76 ewarn "${myscript} not executable; skipping"
77 continue
78 fi
79 ln -snf "/etc/init.d/${myscript}" "/etc/runlevels/${x}/${myscript}"
80 if [ "$?" -ne 0 ]
81 then
82 eerror "$0: failed to add ${myscript} to ${x}."
83 exit 1
84 fi
85 regen=1
86 einfo "${myscript} added to runlevel ${x}"
87 done
88 }
89
90 del() {
91 local x=
92 local mylevels=
93 local myscript=
94 local remlevels=
95
96 if [ $# -lt 2 ]
97 then
98 eerror "$0: at least one argument expected after \"$1\"."
99 exit 1
100 fi
101 shift
102 myscript=$1
103 shift
104 if [ $# -eq 0 ]
105 then
106 mylevels="`( cd /etc/runlevels; ls )`"
107 else
108 mylevels="$*"
109 fi
110 remlevels=""
111 for x in ${mylevels}
112 do
113 if [ -L "/etc/runlevels/${x}/${myscript}" ]
114 then
115 regen=1
116 rm -f "/etc/runlevels/${x}/${myscript}"
117 remlevels="${remlevels} ${x}"
118 fi
119 done
120 if [ "${remlevels}" = "" ]
121 then
122 einfo "${myscript} not found in any of the specified runlevels."
123 else
124 einfo "${myscript} removed from the following runlevels:${remlevels}"
125 fi
126 }
127
128 show() {
129 local x=
130 local y=
131 local mylevels=
132 local myscripts=
133
134 shift
135 if [ $# -eq 0 ]
136 then
137 mylevels="`( cd /etc/runlevels; ls )`"
138 else
139 mylevels="$*"
140 fi
141 myscripts="`( cd /etc/init.d; ls )`"
142
143 for x in ${myscripts}
144 do
145 if [ "${x%%.sh}" = "${x}" ]
146 then
147 printf "%20s | " ${x:0:19}
148 for y in ${mylevels}
149 do
150 if [ -L "/etc/runlevels/${y}/${x}" ]
151 then
152 echo -n "${y} "
153 else
154 printf "%${#y}s " " "
155 fi
156 done
157 echo ""
158 fi
159 done
160 }
161
162 if [ $# -lt 1 ]
163 then
164 usage
165 exit 1
166 fi
167
168 regen=0
169
170 case "$1" in
171 add|-a)
172 add "$@"
173 ;;
174 del|delete|-d)
175 del "$@"
176 ;;
177 show|-s)
178 show "$@"
179 ;;
180 *)
181 usage
182 exit 1
183 ;;
184 esac
185
186 if [ "${regen}" -eq 1 ]
187 then
188 /sbin/depscan.sh
189 einfo "rc-update complete."
190 fi
191
192
193 # vim:ts=4

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20