Magellan Linux

Annotation of /tags/init-0_4_8-r1/magellan-initscripts/sbin/rc-config

Parent Directory Parent Directory | Revision Log Revision Log


Revision 141 - (hide annotations) (download)
Sun Jul 3 13:54:15 2005 UTC (18 years, 10 months ago) by niro
Original Path: trunk/magellan-initscripts/sbin/rc-config
File size: 4656 byte(s)
cosmetics

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

Properties

Name Value
svn:executable *