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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 127 - (hide annotations) (download) (as text)
Sun Feb 17 02:24:47 2002 UTC (18 years, 9 months ago) by azarah
File MIME type: text/x-sh
File size: 4586 byte(s)
misc fixes

1 drobbins 2 #!/bin/bash
2 azarah 85 # Copyright 1999-2002 Gentoo Technologies, Inc.
3     # Distributed under the terms of the GNU General Public License, v2 or later
4     # $Header$
5 drobbins 2
6 azarah 85
7 drobbins 2 source /etc/init.d/functions.sh
8    
9     if [ ! -d $svcdir ]
10     then
11     install -d -m0755 $svcdir
12     fi
13 azarah 124 for x in softscripts snapshot options broken started provide ${deptypes} ${ordtypes}
14 drobbins 2 do
15     if [ ! -d ${svcdir}/${x} ]
16     then
17     install -d -m0755 ${svcdir}/${x}
18     fi
19     done
20    
21 drobbins 51 #call: depend_dbadd dep_type service deps....
22     depend_dbadd() {
23 azarah 124 local mytype=$1
24     local myservice=$2
25 drobbins 2 local x
26 drobbins 51 shift 2
27 drobbins 2 for x in $*
28     do
29 azarah 124 check_rcscript /etc/init.d/${x}
30     local retval=$?
31     if [ $retval -ne 0 ]
32 drobbins 51 then
33 azarah 124 #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 drobbins 2 then
42 drobbins 51 einfo "need: can't find service \"${x}\" needed by \"${myservice}\"; continuing..."
43 azarah 124
44 azarah 93 #$myservice is broken due to missing 'need' dependancies
45 azarah 124 if [ ! -d ${svcdir}/broken/${myservice} ]
46 azarah 93 then
47 azarah 124 install -d -m0755 ${svcdir}/broken/${myservice}
48 azarah 93 fi
49 azarah 124 if [ ! -e ${svcdir}/broken/${myservice}/${x} ]
50     then
51     touch ${svcdir}/broken/${myservice}/${x}
52     fi
53 drobbins 51 continue
54 azarah 124 elif [ "$mytype" != "provide" ] && \
55     [ ! -d ${svcdir}/provide/${x} ] && \
56     [ "$x" != "net" ]
57     then
58     continue
59 drobbins 2 fi
60 drobbins 51 fi
61 drobbins 65
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 azarah 124 #dont work too well with the '*' use and need
67     #einfo "depend: service \"${x}\" can't depend on itself; continuing..."
68 drobbins 65 continue
69     fi
70 azarah 124
71 drobbins 51 if [ ! -d ${svcdir}/${mytype}/${x} ]
72     then
73     install -d -m0755 ${svcdir}/${mytype}/${x}
74     fi
75 azarah 124
76 drobbins 51 if [ ! -L ${svcdir}/${mytype}/${x}/${myservice} ]
77     then
78     ln -sf /etc/init.d/${myservice} ${svcdir}/${mytype}/${x}/${myservice}
79     fi
80 drobbins 2 done
81     }
82    
83 azarah 124 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 drobbins 2 need() {
102     NEED="$*"
103     }
104    
105 drobbins 51 use() {
106     USE="$*"
107     }
108    
109 azarah 124 before() {
110     BEFORE="$*"
111     }
112    
113     after() {
114     AFTER="$*"
115     }
116    
117     provide() {
118     PROVIDE="$*"
119     }
120    
121 drobbins 2 ebegin "Caching service dependencies"
122 azarah 124
123     #cleanup and fix a problem with 'for x in foo/*'
124 drobbins 2 rm -rf ${svcdir}/need/*
125 azarah 124 touch ${svcdir}/need/dummy
126 drobbins 51 rm -rf ${svcdir}/use/*
127 azarah 124 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 drobbins 65 for x in /etc/init.d/*
143 drobbins 2 do
144 azarah 124 check_rcscript $x || continue
145    
146 drobbins 51 #set to "" else we get problems
147 azarah 124 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 drobbins 51 NEED=""
169     USE=""
170 azarah 124 BEFORE=""
171     AFTER=""
172 jerrya 64
173 drobbins 2 myservice=${x##*/}
174     depend() {
175     NEED=""
176 drobbins 51 USE=""
177 azarah 124 BEFORE=""
178     AFTER=""
179 jerrya 64 return
180 drobbins 2 }
181     source ${x}
182     depend
183 azarah 124 if [ -n "$NEED" ]
184 drobbins 2 then
185 drobbins 51 depend_dbadd need $myservice $NEED
186     fi
187 azarah 124 if [ -n "$USE" ]
188 drobbins 51 then
189     depend_dbadd use $myservice $USE
190     fi
191 azarah 124 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 drobbins 2 done
208 azarah 124
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 drobbins 2 eend
241 azarah 124
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