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

Contents of /trunk/sbin/rc-update

Parent Directory Parent Directory | Revision Log Revision Log


Revision 484 - (show annotations) (download)
Wed Apr 21 17:09:18 2004 UTC (15 years, 2 months ago) by vapier
File size: 3534 byte(s)
update copyright years

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