Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 104 - (hide annotations) (download)
Fri Jul 1 18:07:21 2005 UTC (18 years, 10 months ago) by niro
Original Path: trunk/magellan-initscripts/sbin/rc-config
File size: 4535 byte(s)
cleaned

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

Properties

Name Value
svn:executable *