Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 932 - (hide annotations) (download)
Thu Nov 5 12:57:25 2009 UTC (14 years, 6 months ago) by niro
File size: 4596 byte(s)
-fixed header
1 niro 2 #!/bin/bash
2 niro 932 # $Id$
3 niro 2
4 niro 223 RC_INIT_BASE=${MROOT}/etc/init.d
5 niro 874 RC_EXCLUDE="rc functions template splash-functions udev"
6 niro 2
7 niro 223 VERSION=0.3
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 355 usage()
224     {
225 niro 2 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 niro 104 # show all
243 niro 355 if [[ -z $2 ]]
244 niro 2 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 *