/[baselayout]/branches/baselayout-1_12/sbin/depscan.sh
Gentoo

Contents of /branches/baselayout-1_12/sbin/depscan.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 167 - (show annotations) (download) (as text)
Sun Apr 21 19:27:07 2002 UTC (12 years ago) by azarah
Original Path: trunk/sbin/depscan.sh
File MIME type: text/x-sh
File size: 6872 byte(s)
more fixes

1 #!/bin/bash
2 # Copyright 1999-2002 Gentoo Technologies, Inc.
3 # Distributed under the terms of the GNU General Public License, v2 or later
4 # $Header$
5
6
7 source /sbin/functions.sh
8
9 if [ ! -d ${svcdir} ]
10 then
11 install -d -m0755 ${svcdir}
12 fi
13 for x in softscripts cache snapshot options broken started provide ${deptypes} ${ordtypes}
14 do
15 if [ ! -d ${svcdir}/${x} ]
16 then
17 install -d -m0755 ${svcdir}/${x}
18 if [ "$?" -ne 0 ]
19 then
20 #there is a problem creating the directories, so quit with fail
21 #status
22 exit 1
23 fi
24 fi
25 done
26
27 #call: depend_dbadd dep_type service deps....
28 depend_dbadd() {
29 local mytype="${1}"
30 local myservice="${2}"
31 local x=""
32 shift 2
33 for x in $*
34 do
35 if [ ! -e ${svcdir}/cache/${myservice}.depend ]
36 then
37 continue
38 fi
39 if [ ! -e ${svcdir}/cache/${x}.depend ]
40 then
41 #handle 'need', as it is the only dependency type that
42 #should handle invalid database entries currently. The only
43 #other type of interest is 'pretend' which *should* add
44 #invalid database entries (no virtual depend should ever
45 #actually have a matching rc-script).
46 if [ "${mytype}" = "need" ] && \
47 [ ! -d ${svcdir}/provide/${x} ] && \
48 [ "${x}" != "net" ]
49 then
50 ewarn "NEED: can't find service \"${x}\" needed by \"${myservice}\";"
51 ewarn " continuing..."
52
53 #$myservice is broken due to missing 'need' dependancies
54 if [ ! -d ${svcdir}/broken/${myservice} ]
55 then
56 install -d -m0755 ${svcdir}/broken/${myservice}
57 fi
58 if [ ! -e ${svcdir}/broken/${myservice}/${x} ]
59 then
60 touch ${svcdir}/broken/${myservice}/${x}
61 fi
62 continue
63 elif [ "${mytype}" != "provide" ] && \
64 [ ! -d ${svcdir}/provide/${x} ] && \
65 [ "${x}" != "net" ]
66 then
67 continue
68 fi
69 fi
70
71 #ugly bug ... if a service depends on itself, it creates
72 #a 'mini fork bomb' effect, and breaks things...
73 if [ "${x}" = "${myservice}" ]
74 then
75 #dont work too well with the '*' use and need
76 if [ "${mytype}" != "before" ] && [ "${mytype}" != "after" ]
77 then
78 ewarn "DEPEND: service \"${x}\" can't depend on itself;"
79 ewarn " continuing..."
80 fi
81 continue
82 fi
83
84 # NEED and USE override BEFORE and AFTER
85 if (([ "${mytype}" = "before" ] && \
86 [ ! -L ${svcdir}/need/${x}/${myservice} ]) && \
87 ([ "${mytype}" = "before" ] && \
88 [ ! -L ${svcdir}/use/${x}/${myservice} ])) || \
89 (([ "${mytype}" = "after" ] && \
90 [ ! -L ${svcdir}/need/${myservice}/${x} ]) && \
91 ([ "${mytype}" = "after" ] && \
92 [ ! -L ${svcdir}/use/${myservice}/${x} ])) || \
93 ([ "${mytype}" = "need" ] || [ "${mytype}" = "use" ] || \
94 [ "${mytype}" = "provide" ])
95 then
96 if [ ! -d ${svcdir}/${mytype}/${x} ]
97 then
98 install -d -m0755 ${svcdir}/${mytype}/${x}
99 fi
100 if [ ! -L ${svcdir}/${mytype}/${x}/${myservice} ]
101 then
102 ln -sf /etc/init.d/${myservice} ${svcdir}/${mytype}/${x}/${myservice}
103 fi
104 fi
105 done
106 }
107
108 check_rcscript() {
109 [ ! -e ${1} ] && return 1
110
111 [ "${1##*.}" = "sh" ] && return 1
112 [ "${1##*.}" = "c" ] && return 1
113
114 local IFS='!'
115 local hash=""
116 local shell=""
117 (cat ${1}) | { read hash shell
118 if [ "${hash}" = "#" ] && [ "${shell}" = "/sbin/runscript" ]
119 then
120 return 0
121 else
122 return 1
123 fi
124 }
125 }
126
127 cache_depend() {
128 [ ! -e ${1} ] && return 1
129
130 #the cached file should not be empty
131 echo "echo foo >/dev/null 2>&1" > ${svcdir}/cache/${1##*/}.depend
132
133 local myline=""
134 local dowrite=1
135 (cat ${1}) | { while read myline
136 do
137 if [ "${myline/depend*()/}" != "${myline}" ]
138 then
139 dowrite=0
140 fi
141 if [ "${dowrite}" -eq 0 ]
142 then
143 echo "${myline}" >> ${svcdir}/cache/${1##*/}.depend
144 fi
145 if [ "${myline/\}/}" != "${myline}" ] && [ "${dowrite}" -eq 0 ]
146 then
147 dowrite=1
148 break
149 fi
150 done
151 }
152 return 0
153 }
154
155 need() {
156 NEED="${*}"
157 }
158
159 use() {
160 USE="${*}"
161 }
162
163 before() {
164 BEFORE="${*}"
165 }
166
167 after() {
168 AFTER="${*}"
169 }
170
171 provide() {
172 PROVIDE="${*}"
173 }
174
175 ebegin "Caching service dependencies"
176
177 #cleanup and fix a problem with 'for x in foo/*' if foo/ is empty
178 rm -rf ${svcdir}/need/*
179 rm -rf ${svcdir}/use/*
180 rm -rf ${svcdir}/before/*
181 rm -rf ${svcdir}/after/*
182 rm -rf ${svcdir}/broken/*
183 rm -rf ${svcdir}/provide/*
184 rm -rf ${svcdir}/cache/*
185
186 #for the '*' need and use types to work
187 pushd /etc/init.d &>/dev/null
188
189 #first cache the depend lines, and calculate all the provides
190 for x in $(dolisting /etc/init.d/)
191 do
192 check_rcscript ${x} || continue
193
194 #set to "" else we get problems
195 PROVIDE=""
196
197 myservice="${x##*/}"
198 depend() {
199 PROVIDE=""
200 return 0
201 }
202 cache_depend ${x}
203 wrap_rcscript ${svcdir}/cache/${myservice}.depend || {
204 einfo "ERROR: ${x} has syntax errors in it, please fix this before"
205 einfo " trying to execute this script..."
206 einfo "NOTE: the dependancies for this script has not been calculated!"
207 continue
208 }
209 depend
210 if [ -n "${PROVIDE}" ]
211 then
212 depend_dbadd provide "${myservice}" ${PROVIDE}
213 fi
214 done
215
216 #now do NEED and USE
217 for x in $(dolisting /etc/init.d/)
218 do
219 [ ! -e ${svcdir}/cache/${x##*/}.depend ] && continue
220
221 #set to "" else we get problems
222 NEED=""
223 USE=""
224
225 myservice="${x##*/}"
226 depend() {
227 NEED=""
228 USE=""
229 return 0
230 }
231 #we already warn about the error in the provide loop
232 wrap_rcscript "${svcdir}/cache/${myservice}.depend" || continue
233 depend
234 if [ -n "${NEED}" ]
235 then
236 depend_dbadd need "${myservice}" ${NEED}
237 fi
238 if [ -n "${USE}" ]
239 then
240 depend_dbadd use "${myservice}" ${USE}
241 fi
242 done
243
244 #now do BEFORE and AFTER (we do them in a seperate cycle to
245 #so that we can check for NEED or USE)
246 for x in $(dolisting /etc/init.d/)
247 do
248 [ ! -e ${svcdir}/cache/${x##*/}.depend ] && continue
249
250 #set to "" else we get problems
251 BEFORE=""
252 AFTER=""
253
254 myservice="${x##*/}"
255 depend() {
256 BEFORE=""
257 AFTER=""
258 return 0
259 }
260 #we already warn about the error in the provide loop
261 wrap_rcscript "${svcdir}/cache/${myservice}.depend" || continue
262 depend
263 if [ -n "${BEFORE}" ]
264 then
265 depend_dbadd before "${myservice}" ${BEFORE}
266 for y in ${BEFORE}
267 do
268 depend_dbadd after "${y}" "${myservice}"
269 done
270 fi
271 if [ -n "${AFTER}" ]
272 then
273 depend_dbadd after "${myservice}" ${AFTER}
274 for y in ${AFTER}
275 do
276 depend_dbadd before "${y}" "${myservice}"
277 done
278 fi
279 done
280
281 #resolve provides
282 dblprovide="no"
283 for x in $(dolisting ${svcdir}/provide/)
284 do
285 for mytype in ${deptypes}
286 do
287 if [ -d ${svcdir}/${mytype}/${x##*/} ]
288 then
289 for y in $(dolisting ${svcdir}/${mytype}/${x##*/}/)
290 do
291 depend_dbadd "${mytype}" "${y##*/}" $(ls ${x})
292 done
293 rm -rf ${svcdir}/${mytype}/${x##*/}
294 fi
295 done
296
297 counter=0
298 for y in $(dolisting ${x})
299 do
300 counter=$((counter + 1))
301 done
302 if [ "${counter}" -gt 1 ] && [ "${x##*/}" != "net" ]
303 then
304 dblprovide="yes"
305 errstr="${x##*/}"
306 fi
307 done
308 if [ "${dblprovide}" = "yes" ]
309 then
310 ewarn "PROVIDE: it usually is not a good idea to have more than one"
311 ewarn " service provide the same virtual service (${errstr})!"
312 fi
313
314 popd &>/dev/null
315
316 eend
317
318
319 # vim:ts=4

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20