/[baselayout]/trunk/init.d/depscan.sh
Gentoo

Contents of /trunk/init.d/depscan.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 127 - (show annotations) (download) (as text)
Sun Feb 17 02:24:47 2002 UTC (18 years, 8 months ago) by azarah
File MIME type: text/x-sh
File size: 4586 byte(s)
misc 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 /etc/init.d/functions.sh
8
9 if [ ! -d $svcdir ]
10 then
11 install -d -m0755 $svcdir
12 fi
13 for x in softscripts snapshot options broken started provide ${deptypes} ${ordtypes}
14 do
15 if [ ! -d ${svcdir}/${x} ]
16 then
17 install -d -m0755 ${svcdir}/${x}
18 fi
19 done
20
21 #call: depend_dbadd dep_type service deps....
22 depend_dbadd() {
23 local mytype=$1
24 local myservice=$2
25 local x
26 shift 2
27 for x in $*
28 do
29 check_rcscript /etc/init.d/${x}
30 local retval=$?
31 if [ $retval -ne 0 ]
32 then
33 #handle 'need', as it is the only dependency type that
34 #should handle invalid database entries currently. The only
35 #other type of interest is 'pretend' which *should* add
36 #invalid database entries (no virtual depend should ever
37 #actually have a matching rc-script).
38 if [ "$mytype" = "need" ] && \
39 [ ! -d ${svcdir}/provide/${x} ] && \
40 [ "$x" != "net" ]
41 then
42 einfo "need: can't find service \"${x}\" needed by \"${myservice}\"; continuing..."
43
44 #$myservice is broken due to missing 'need' dependancies
45 if [ ! -d ${svcdir}/broken/${myservice} ]
46 then
47 install -d -m0755 ${svcdir}/broken/${myservice}
48 fi
49 if [ ! -e ${svcdir}/broken/${myservice}/${x} ]
50 then
51 touch ${svcdir}/broken/${myservice}/${x}
52 fi
53 continue
54 elif [ "$mytype" != "provide" ] && \
55 [ ! -d ${svcdir}/provide/${x} ] && \
56 [ "$x" != "net" ]
57 then
58 continue
59 fi
60 fi
61
62 #ugly bug ... if a service depends on itself, it creates
63 #a 'mini fork bomb' effect, and breaks things...
64 if [ "$x" = "$myservice" ]
65 then
66 #dont work too well with the '*' use and need
67 #einfo "depend: service \"${x}\" can't depend on itself; continuing..."
68 continue
69 fi
70
71 if [ ! -d ${svcdir}/${mytype}/${x} ]
72 then
73 install -d -m0755 ${svcdir}/${mytype}/${x}
74 fi
75
76 if [ ! -L ${svcdir}/${mytype}/${x}/${myservice} ]
77 then
78 ln -sf /etc/init.d/${myservice} ${svcdir}/${mytype}/${x}/${myservice}
79 fi
80 done
81 }
82
83 check_rcscript() {
84 [ ! -e $1 ] && return 1
85
86 [ "${1##*.}" = "sh" ] && return 1
87 [ "${1##*.}" = "c" ] && return 1
88
89 local IFS='!'
90 local hash shell
91 (cat $1) | { read hash shell
92 if [ "$hash" = "#" ] && [ "$shell" = "/sbin/runscript" ]
93 then
94 return 0
95 else
96 return 1
97 fi
98 }
99 }
100
101 need() {
102 NEED="$*"
103 }
104
105 use() {
106 USE="$*"
107 }
108
109 before() {
110 BEFORE="$*"
111 }
112
113 after() {
114 AFTER="$*"
115 }
116
117 provide() {
118 PROVIDE="$*"
119 }
120
121 ebegin "Caching service dependencies"
122
123 #cleanup and fix a problem with 'for x in foo/*'
124 rm -rf ${svcdir}/need/*
125 touch ${svcdir}/need/dummy
126 rm -rf ${svcdir}/use/*
127 touch ${svcdir}/use/dummy
128 rm -rf ${svcdir}/before/*
129 touch ${svcdir}/before/dummy
130 rm -rf ${svcdir}/after/*
131 touch ${svcdir}/after/dummy
132 rm -rf ${svcdir}/broken/*
133 touch ${svcdir}/broken/dummy
134 rm -rf ${svcdir}/provide/*
135 touch ${svcdir}/provide/dummy
136
137 #for the '*' need and use types to work
138 oldpwd=`pwd`
139 cd /etc/init.d
140
141 #first calculate all the provides
142 for x in /etc/init.d/*
143 do
144 check_rcscript $x || continue
145
146 #set to "" else we get problems
147 PROVIDE=""
148
149 myservice=${x##*/}
150 depend() {
151 PROVIDE=""
152 return
153 }
154 source ${x}
155 depend
156 if [ -n "$PROVIDE" ]
157 then
158 depend_dbadd provide $myservice $PROVIDE
159 fi
160 done
161
162 #now do the rest
163 for x in /etc/init.d/*
164 do
165 check_rcscript $x || continue
166
167 #set to "" else we get problems
168 NEED=""
169 USE=""
170 BEFORE=""
171 AFTER=""
172
173 myservice=${x##*/}
174 depend() {
175 NEED=""
176 USE=""
177 BEFORE=""
178 AFTER=""
179 return
180 }
181 source ${x}
182 depend
183 if [ -n "$NEED" ]
184 then
185 depend_dbadd need $myservice $NEED
186 fi
187 if [ -n "$USE" ]
188 then
189 depend_dbadd use $myservice $USE
190 fi
191 if [ -n "$BEFORE" ]
192 then
193 depend_dbadd before $myservice $BEFORE
194 for x in $BEFORE
195 do
196 depend_dbadd after ${x} $myservice
197 done
198 fi
199 if [ -n "$AFTER" ]
200 then
201 depend_dbadd after $myservice $AFTER
202 for x in $AFTER
203 do
204 depend_dbadd before ${x} $myservice
205 done
206 fi
207 done
208
209 #resolve provides
210 for x in ${svcdir}/provide/*
211 do
212 for mytype in ${deptypes}
213 do
214 if [ -d ${svcdir}/${mytype}/${x##*/} ]
215 then
216 for y in ${svcdir}/${mytype}/${x##*/}/*
217 do
218 depend_dbadd ${mytype} ${y##*/} `ls ${x}/`
219 done
220 rm -rf ${svcdir}/${mytype}/${x##*/}
221 fi
222 done
223
224 counter=0
225 for y in ${x}/*
226 do
227 counter=$((counter + 1))
228 errstr="${x##*/}"
229 done
230 done
231 if [ $counter -ne 1 ] && [ "${x##*/}" != "net" ]
232 then
233 einfo "provide: it usually is not a good idea to have more than one"
234 einfo " service providing the same virtual service (${errstr})!"
235 cerror="yes"
236 fi
237
238 cd $oldpwd
239
240 eend
241
242
243 # 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