Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2034 - (hide annotations) (download)
Thu Jan 24 15:13:33 2013 UTC (11 years, 4 months ago) by niro
File size: 5489 byte(s)
-enable service controlling and added 'README' to exclude list
1 niro 2 #!/bin/bash
2 niro 932 # $Id$
3 niro 2
4 niro 223 RC_INIT_BASE=${MROOT}/etc/init.d
5 niro 2034 RC_EXCLUDE="rc functions template splash-functions udev mdev README"
6 niro 2
7 niro 2034 VERSION=0.5
8 niro 2
9 niro 355 get_run_levels()
10     {
11 niro 2 local SCRIPT
12     local ALL_LEVELS
13 niro 104
14 niro 2 SCRIPT=${RC_INIT_BASE}/$1
15     ALL_LEVELS=$(grep -i "#%rlevels:" ${SCRIPT} | sed -e 's/#%rlevels://g')
16 niro 104
17 niro 2 echo ${ALL_LEVELS}
18 niro 104
19 niro 2 return 0
20     }
21    
22    
23 niro 355 get_needs()
24     {
25 niro 2 local SCRIPT
26     local ALL_LEVELS
27 niro 104
28 niro 2 SCRIPT=${RC_INIT_BASE}/$1
29     ALL_LEVELS=$(grep -i "#%needs:" ${SCRIPT} | sed -e 's/#%needs://g')
30 niro 104
31 niro 2 echo ${ALL_LEVELS}
32 niro 104
33 niro 2 return 0
34     }
35    
36 niro 355 get_before()
37     {
38 niro 2 local SCRIPT
39     local ALL_LEVELS
40 niro 104
41 niro 2 SCRIPT=${RC_INIT_BASE}/$1
42     ALL_LEVELS=$(grep -i "#%before:" ${SCRIPT} | sed -e 's/#%before://g')
43 niro 104
44 niro 2 echo ${ALL_LEVELS}
45 niro 104
46 niro 2 return 0
47     }
48    
49 niro 355 get_after()
50     {
51 niro 2 local SCRIPT
52     local ALL_LEVELS
53 niro 104
54 niro 2 SCRIPT=${RC_INIT_BASE}/$1
55     ALL_LEVELS=$(grep -i "#%after:" ${SCRIPT} | sed -e 's/#%after://g')
56 niro 104
57 niro 2 echo ${ALL_LEVELS}
58 niro 104
59 niro 2 return 0
60     }
61    
62 niro 355 get_start()
63     {
64 niro 2 local SCRIPT
65     local ALL_LEVELS
66 niro 104
67 niro 2 SCRIPT=${RC_INIT_BASE}/$1
68     ALL_LEVELS=$(grep -i "#%start:" ${SCRIPT} | sed -e 's/#%start://g')
69 niro 104
70 niro 2 echo ${ALL_LEVELS}
71 niro 104
72 niro 2 return 0
73     }
74    
75 niro 355 get_stop()
76     {
77 niro 2 local SCRIPT
78     local ALL_LEVELS
79 niro 104
80 niro 2 SCRIPT=${RC_INIT_BASE}/$1
81     ALL_LEVELS=$(grep -i "#%stop:" ${SCRIPT} | sed -e 's/#%stop://g')
82 niro 104
83 niro 2 echo ${ALL_LEVELS}
84 niro 104
85 niro 2 return 0
86     }
87    
88    
89    
90 niro 355 rc_service_add()
91     {
92 niro 2 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 niro 104 # start
101 niro 2 ?:s)
102 niro 355 [[ ${i} = 7:s ]] && i="sysinit:s"
103 niro 2 echo -e "\t\t[rc${i/:s/}.d -> S${RC_START}]"
104     ln -snf ../init.d/${RC_SERVICE} \
105 niro 223 ${MROOT}/etc/rc.d/rc${i/:s/}.d/S${RC_START}${RC_SERVICE}
106 niro 2 ;;
107 niro 104 # stop
108 niro 2 ?:k)
109 niro 355 [[ ${i} = 7:k ]] && i="sysinit:k"
110 niro 2 echo -e "\t\t[rc${i/:k/}.d -> K${RC_STOP}]"
111     ln -snf ../init.d/${RC_SERVICE} \
112 niro 223 ${MROOT}/etc/rc.d/rc${i/:k/}.d/K${RC_STOP}${RC_SERVICE}
113 niro 2 ;;
114     *)
115     echo "error"
116     exit 1
117     ;;
118     esac
119     done
120     }
121    
122 niro 355 rc_service_del()
123     {
124 niro 2 RC_SERVICE=$1
125 niro 104
126 niro 2 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 niro 223 if [ -L "${MROOT}/etc/rc.d/rc${i}.d/S${z}${RC_SERVICE}" ]
132 niro 2 then
133     echo -e "\t\t[rc${i}.d <- S${z}]"
134 niro 223 rm ${MROOT}/etc/rc.d/rc${i}.d/S${z}${RC_SERVICE}
135 niro 2 fi
136 niro 104
137 niro 223 if [ -L "${MROOT}/etc/rc.d/rc${i}.d/K${z}${RC_SERVICE}" ]
138 niro 2 then
139     echo -e "\t\t[rc${i}.d <- K${z}]"
140 niro 223 rm ${MROOT}/etc/rc.d/rc${i}.d/K${z}${RC_SERVICE}
141 niro 2 fi
142     done
143     done
144     }
145    
146 niro 355 rc_service_show()
147     {
148 niro 2 RC_SERVICE=$1
149 niro 104
150 niro 2 local ALL_RUNLEVELS
151    
152 niro 104 # read'em (single)
153 niro 2 for i in $(seq 0 7)
154     do
155 niro 355 level=${i}
156     [[ ${i} = 7 ]] && level=sysinit
157 niro 2
158 niro 223 for script in ${MROOT}/etc/rc.d/rc${level}.d/*
159 niro 2 do
160     x="$(basename ${script})"
161 niro 355 [[ ${x/???/} = ${RC_SERVICE} ]] &&
162 niro 2 ALL_RUNLEVELS[${i}]=${x/${RC_SERVICE}/}
163     done
164     done
165 niro 104
166 niro 223 # show them (single)
167 niro 2 echo -n "${RC_SERVICE}: "
168     for i in $(seq 0 7)
169     do
170 niro 355 [[ ! -z ${ALL_RUNLEVELS[${i}]} ]] &&
171 niro 2 echo -n "[${i}:${ALL_RUNLEVELS[${i}]}] "
172     done
173     echo
174     }
175    
176 niro 355 check_not_excluded()
177     {
178 niro 2 local SCRIPT
179     SCRIPT=$1
180 niro 104
181 niro 2 for i in ${RC_EXCLUDE}
182     do
183 niro 355 [[ ${SCRIPT} = ${i} ]] && return 1
184 niro 2 done
185 niro 104
186 niro 2 return 0
187     }
188    
189    
190 niro 355 chg_initdefault()
191     {
192 niro 2 local newinitdef
193     declare -i newinitdef="$1"
194    
195 niro 355 if [[ -z ${newinitdef} ]]
196 niro 2 then
197     echo "You must give an initlevel."
198     exit 1
199     fi
200    
201 niro 355 if [ ${newinitdef} -le 0 -a ${newinitdef} -ge 6 ]
202 niro 2 then
203     echo "You can only choose initlevels between 1-5."
204     exit 1
205     fi
206    
207 niro 355 current=$(cat ${MROOT}/etc/inittab | grep initdefault)
208 niro 2
209 niro 223 cp ${MROOT}/etc/inittab ${MROOT}/etc/inittab-orig
210 niro 2 sed -e "s/${current}/id:${newinitdef}:initdefault:/g" \
211 niro 355 ${MROOT}/etc/inittab-orig > ${MROOT}/etc/inittab
212     if [[ $? = 0 ]]
213 niro 2 then
214 niro 223 rm -f ${MROOT}/etc/inittab-orig
215 niro 2 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 niro 2034 rc_service_control()
224     {
225     local cmd="$1"
226     local svc="$2"
227    
228     case ${cmd} in
229     start|stop|restart|reload|status) ;;
230     *) echo "unknown operation"; exit 1 ;;
231     esac
232    
233     if [ ! -e ${RC_INIT_BASE}/${svc} ]
234     then
235     echo "Service '${RC_INIT_BASE}/${svc}' does not exist."
236     exit 1
237     fi
238    
239     if [[ -n ${MROOT} ]]
240     then
241     echo "\${MROOT} is set, not starting service $2"
242     else
243     if [ -x ${RC_INIT_BASE}/${svc} ]
244     then
245     ${RC_INIT_BASE}/${svc} ${cmd}
246     else
247     echo "Service '${RC_INIT_BASE}/${svc}' is not executable."
248     exit 1
249     fi
250     fi
251     }
252    
253    
254 niro 355 usage()
255     {
256 niro 2 echo "Magellan RC Configurator v${VERSION} -- Niels Rogalla (niro@magellan-linux.de)"
257     echo -e "\nUsage: $(basename $0) [Option] [File] ..."
258     echo -e " add adds script to runlevel"
259     echo -e " del deletes script from runlevel"
260     echo -e " show shows current runlevel settings"
261     echo -e " default x changes default runlevel to x"
262 niro 2034 echo -e " start starts given runlevel script"
263     echo -e " stop stops given runlevel script"
264     echo -e " reload reloads given runlevel script"
265     echo -e " restart restarts given runlevel script"
266     echo -e " status prints status of given service"
267 niro 2 echo -e "\n"
268     }
269    
270     case $1 in
271     add)
272     rc_service_add $2
273     ;;
274     del)
275     rc_service_del $2
276     ;;
277     show)
278 niro 104 # show all
279 niro 355 if [[ -z $2 ]]
280 niro 2 then
281     echo "Currently configured Services:"
282     for i in ${RC_INIT_BASE}/*
283     do
284     x=$(basename ${i})
285     if check_not_excluded ${x}
286     then
287     rc_service_show ${x}
288     fi
289     done
290     else
291     echo "Currently configured Services:"
292     rc_service_show $2
293     fi
294     ;;
295 niro 2034 start|stop|reload|restart|status)
296     rc_service_control $1 $2
297     ;;
298 niro 2 default)
299     chg_initdefault $2
300     ;;
301     *)
302     usage
303     ;;
304     esac

Properties

Name Value
svn:executable *