/[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 204 - (hide annotations) (download) (as text)
Mon Jul 22 00:21:21 2002 UTC (11 years, 11 months ago) by azarah
Original Path: trunk/sbin/depscan.sh
File MIME type: text/x-sh
File size: 7420 byte(s)
small fixes; add user cyrus

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