Magellan Linux

Contents of /trunk/initscripts/sysvinit/sbin/rc-config

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1356 - (show annotations) (download)
Sat Jun 4 21:05:01 2011 UTC (12 years, 10 months ago) by niro
File size: 4601 byte(s)
-copied
1 #!/bin/bash
2 # $Id$
3
4 RC_INIT_BASE=${MROOT}/etc/init.d
5 RC_EXCLUDE="rc functions template splash-functions udev mdev"
6
7 VERSION=0.4
8
9 get_run_levels()
10 {
11 local SCRIPT
12 local ALL_LEVELS
13
14 SCRIPT=${RC_INIT_BASE}/$1
15 ALL_LEVELS=$(grep -i "#%rlevels:" ${SCRIPT} | sed -e 's/#%rlevels://g')
16
17 echo ${ALL_LEVELS}
18
19 return 0
20 }
21
22
23 get_needs()
24 {
25 local SCRIPT
26 local ALL_LEVELS
27
28 SCRIPT=${RC_INIT_BASE}/$1
29 ALL_LEVELS=$(grep -i "#%needs:" ${SCRIPT} | sed -e 's/#%needs://g')
30
31 echo ${ALL_LEVELS}
32
33 return 0
34 }
35
36 get_before()
37 {
38 local SCRIPT
39 local ALL_LEVELS
40
41 SCRIPT=${RC_INIT_BASE}/$1
42 ALL_LEVELS=$(grep -i "#%before:" ${SCRIPT} | sed -e 's/#%before://g')
43
44 echo ${ALL_LEVELS}
45
46 return 0
47 }
48
49 get_after()
50 {
51 local SCRIPT
52 local ALL_LEVELS
53
54 SCRIPT=${RC_INIT_BASE}/$1
55 ALL_LEVELS=$(grep -i "#%after:" ${SCRIPT} | sed -e 's/#%after://g')
56
57 echo ${ALL_LEVELS}
58
59 return 0
60 }
61
62 get_start()
63 {
64 local SCRIPT
65 local ALL_LEVELS
66
67 SCRIPT=${RC_INIT_BASE}/$1
68 ALL_LEVELS=$(grep -i "#%start:" ${SCRIPT} | sed -e 's/#%start://g')
69
70 echo ${ALL_LEVELS}
71
72 return 0
73 }
74
75 get_stop()
76 {
77 local SCRIPT
78 local ALL_LEVELS
79
80 SCRIPT=${RC_INIT_BASE}/$1
81 ALL_LEVELS=$(grep -i "#%stop:" ${SCRIPT} | sed -e 's/#%stop://g')
82
83 echo ${ALL_LEVELS}
84
85 return 0
86 }
87
88
89
90 rc_service_add()
91 {
92 RC_SERVICE=$1
93 RC_START=$(get_start ${RC_SERVICE})
94 RC_STOP=$(get_stop ${RC_SERVICE})
95
96 echo "Adding ${RC_SERVICE} to:"
97 for i in $(get_run_levels ${RC_SERVICE})
98 do
99 case ${i} in
100 # start
101 ?:s)
102 [[ ${i} = 7:s ]] && i="sysinit:s"
103 echo -e "\t\t[rc${i/:s/}.d -> S${RC_START}]"
104 ln -snf ../init.d/${RC_SERVICE} \
105 ${MROOT}/etc/rc.d/rc${i/:s/}.d/S${RC_START}${RC_SERVICE}
106 ;;
107 # stop
108 ?:k)
109 [[ ${i} = 7:k ]] && i="sysinit:k"
110 echo -e "\t\t[rc${i/:k/}.d -> K${RC_STOP}]"
111 ln -snf ../init.d/${RC_SERVICE} \
112 ${MROOT}/etc/rc.d/rc${i/:k/}.d/K${RC_STOP}${RC_SERVICE}
113 ;;
114 *)
115 echo "error"
116 exit 1
117 ;;
118 esac
119 done
120 }
121
122 rc_service_del()
123 {
124 RC_SERVICE=$1
125
126 echo "Deleting ${RC_SERVICE} from all runlevels:"
127 for i in 0 1 2 3 4 5 6 sysinit
128 do
129 for z in 00 01 02 03 04 05 06 07 08 09 $(seq 10 99)
130 do
131 if [ -L "${MROOT}/etc/rc.d/rc${i}.d/S${z}${RC_SERVICE}" ]
132 then
133 echo -e "\t\t[rc${i}.d <- S${z}]"
134 rm ${MROOT}/etc/rc.d/rc${i}.d/S${z}${RC_SERVICE}
135 fi
136
137 if [ -L "${MROOT}/etc/rc.d/rc${i}.d/K${z}${RC_SERVICE}" ]
138 then
139 echo -e "\t\t[rc${i}.d <- K${z}]"
140 rm ${MROOT}/etc/rc.d/rc${i}.d/K${z}${RC_SERVICE}
141 fi
142 done
143 done
144 }
145
146 rc_service_show()
147 {
148 RC_SERVICE=$1
149
150 local ALL_RUNLEVELS
151
152 # read'em (single)
153 for i in $(seq 0 7)
154 do
155 level=${i}
156 [[ ${i} = 7 ]] && level=sysinit
157
158 for script in ${MROOT}/etc/rc.d/rc${level}.d/*
159 do
160 x="$(basename ${script})"
161 [[ ${x/???/} = ${RC_SERVICE} ]] &&
162 ALL_RUNLEVELS[${i}]=${x/${RC_SERVICE}/}
163 done
164 done
165
166 # show them (single)
167 echo -n "${RC_SERVICE}: "
168 for i in $(seq 0 7)
169 do
170 [[ ! -z ${ALL_RUNLEVELS[${i}]} ]] &&
171 echo -n "[${i}:${ALL_RUNLEVELS[${i}]}] "
172 done
173 echo
174 }
175
176 check_not_excluded()
177 {
178 local SCRIPT
179 SCRIPT=$1
180
181 for i in ${RC_EXCLUDE}
182 do
183 [[ ${SCRIPT} = ${i} ]] && return 1
184 done
185
186 return 0
187 }
188
189
190 chg_initdefault()
191 {
192 local newinitdef
193 declare -i newinitdef="$1"
194
195 if [[ -z ${newinitdef} ]]
196 then
197 echo "You must give an initlevel."
198 exit 1
199 fi
200
201 if [ ${newinitdef} -le 0 -a ${newinitdef} -ge 6 ]
202 then
203 echo "You can only choose initlevels between 1-5."
204 exit 1
205 fi
206
207 current=$(cat ${MROOT}/etc/inittab | grep initdefault)
208
209 cp ${MROOT}/etc/inittab ${MROOT}/etc/inittab-orig
210 sed -e "s/${current}/id:${newinitdef}:initdefault:/g" \
211 ${MROOT}/etc/inittab-orig > ${MROOT}/etc/inittab
212 if [[ $? = 0 ]]
213 then
214 rm -f ${MROOT}/etc/inittab-orig
215 echo "Changed default initlevel to ${newinitdef} successfully."
216 exit 0
217 else
218 echo "Error: original inittab was saved to /etc/inittab-orig"
219 exit 1
220 fi
221 }
222
223 usage()
224 {
225 echo "Magellan RC Configurator v${VERSION} -- Niels Rogalla (niro@magellan-linux.de)"
226 echo -e "\nUsage: $(basename $0) [Option] [File] ..."
227 echo -e " add adds script to runlevel"
228 echo -e " del deletes script from runlevel"
229 echo -e " show shows current runlevel settings"
230 echo -e " default x changes default runlevel to x"
231 echo -e "\n"
232 }
233
234 case $1 in
235 add)
236 rc_service_add $2
237 ;;
238 del)
239 rc_service_del $2
240 ;;
241 show)
242 # show all
243 if [[ -z $2 ]]
244 then
245 echo "Currently configured Services:"
246 for i in ${RC_INIT_BASE}/*
247 do
248 x=$(basename ${i})
249 if check_not_excluded ${x}
250 then
251 rc_service_show ${x}
252 fi
253 done
254 else
255 echo "Currently configured Services:"
256 rc_service_show $2
257 fi
258 ;;
259 default)
260 chg_initdefault $2
261 ;;
262 *)
263 usage
264 ;;
265 esac

Properties

Name Value
svn:executable *