Annotation of /branches/mage-next/src/depwalker.in
Parent Directory | Revision Log
Revision 656 -
(hide annotations)
(download)
(as text)
Sun Jan 13 21:42:16 2008 UTC (16 years, 8 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/depwalker.sh
File MIME type: application/x-sh
File size: 7340 byte(s)
Sun Jan 13 21:42:16 2008 UTC (16 years, 8 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/depwalker.sh
File MIME type: application/x-sh
File size: 7340 byte(s)
-exclude empty depnames to improve dep-calculation speed
1 | niro | 226 | #!/bin/bash |
2 | |||
3 | #depwalker | ||
4 | niro | 656 | # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/depwalker.sh,v 1.8 2008-01-13 21:42:16 niro Exp $ |
5 | niro | 226 | |
6 | # default die function | ||
7 | die() | ||
8 | { | ||
9 | echo ${COLRED}"$@"${COLDEFAULT} | ||
10 | exit 1 | ||
11 | } | ||
12 | |||
13 | niro | 231 | # include all needed files |
14 | niro | 235 | [ -f /etc/mage.rc.global ] && \ |
15 | source /etc/mage.rc.global || \ | ||
16 | die "/etc/mage.rc.global missing" | ||
17 | niro | 226 | |
18 | niro | 419 | [ -f ${MAGERC} ] && source ${MAGERC} || \ |
19 | die "Your ${MAGERC} is missing. Aborting." | ||
20 | niro | 231 | |
21 | niro | 235 | [ -f ${MLIBDIR}/mage4.functions.sh ] && \ |
22 | source ${MLIBDIR}/mage4.functions.sh || \ | ||
23 | niro | 231 | die "mage functions missing" |
24 | |||
25 | niro | 226 | # for tests only |
26 | niro | 231 | # source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage.rc.global |
27 | # source /etc/mage.rc | ||
28 | # source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh | ||
29 | # MLIBDIR=/home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage | ||
30 | niro | 226 | |
31 | niro | 231 | # not serious if missing, only needed for colors |
32 | niro | 226 | [ -f /etc/init.d/functions ] && source /etc/init.d/functions |
33 | |||
34 | # disable colors if wanted | ||
35 | if [[ ${NOCOLORS} = true ]] | ||
36 | then | ||
37 | COLRED="" | ||
38 | COLGREEN="" | ||
39 | COLYELLOW="" | ||
40 | COLBLUE="" | ||
41 | COLMAGENTA="" | ||
42 | COLWHITE="" | ||
43 | COLDEFAULT="" | ||
44 | fi | ||
45 | |||
46 | usage() | ||
47 | { | ||
48 | echo | ||
49 | echo "Usage: $(basename $0) [command] [arg] ..." | ||
50 | echo | ||
51 | echo " -h --help shows this help" | ||
52 | echo " -c --pcat categorie of the package" | ||
53 | echo " -n --pname name of the package" | ||
54 | echo " -v --pver version number of the package" | ||
55 | echo " -b --pbuild build number of the package" | ||
56 | echo " -m --method which calc method should be used:" | ||
57 | niro | 231 | echo " install, srcinstall, depend, srcdepend" |
58 | echo " upgrade, srcupgrade" | ||
59 | niro | 226 | echo |
60 | echo "method,name, version and build must be given !" | ||
61 | echo | ||
62 | exit 1 | ||
63 | } | ||
64 | |||
65 | # very basic getops | ||
66 | for i in $* | ||
67 | do | ||
68 | case $1 in | ||
69 | --pcat|-c) shift; PCAT="$1" ;; | ||
70 | --pname|-n) shift; PNAME="$1" ;; | ||
71 | --pver|-v) shift; PVER="$1" ;; | ||
72 | --pbuild|-b) shift; PBUILD="$1" ;; | ||
73 | --method|-m) shift; METHOD="$1" ;; | ||
74 | --help|-h) usage ;; | ||
75 | esac | ||
76 | shift | ||
77 | done | ||
78 | |||
79 | # sanity checks; abort if not given | ||
80 | [ -z "${PCAT}" ] && usage | ||
81 | [ -z "${PNAME}" ] && usage | ||
82 | [ -z "${PVER}" ] && usage | ||
83 | [ -z "${PBUILD}" ] && usage | ||
84 | [ -z "${METHOD}" ] && usage | ||
85 | |||
86 | # check needed global vars | ||
87 | [ -z "${MAGEDIR}" ] && die "\$MAGEDIR not set." | ||
88 | [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set." | ||
89 | [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set." | ||
90 | |||
91 | # other needed vars | ||
92 | ALLDEPS="" | ||
93 | MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage" | ||
94 | |||
95 | niro | 598 | # much faster than fgrep |
96 | checklist_alldeps() | ||
97 | { | ||
98 | local i | ||
99 | local item="$1" | ||
100 | |||
101 | for i in ${ALLDEPS} | ||
102 | do | ||
103 | [[ ${i} = ${item} ]] && return 1 | ||
104 | done | ||
105 | |||
106 | return 0 | ||
107 | } | ||
108 | |||
109 | niro | 654 | checklist_processeddeps() |
110 | { | ||
111 | local i | ||
112 | local item="$1" | ||
113 | |||
114 | for i in ${PROCESSEDDEPS} | ||
115 | do | ||
116 | [[ ${i} = ${item} ]] && return 1 | ||
117 | done | ||
118 | |||
119 | return 0 | ||
120 | } | ||
121 | |||
122 | niro | 226 | ##################### |
123 | ## rumwandern /path/to/mage/file/.mage | ||
124 | rumwandern() | ||
125 | { | ||
126 | unset DEPEND | ||
127 | unset SDEPEND | ||
128 | unset MY_DEPEND | ||
129 | |||
130 | local DFILE | ||
131 | local SYM | ||
132 | local DEPNAME | ||
133 | local HIGHEST_DEPFILE | ||
134 | local MY_DEPEND | ||
135 | local REAL_PGKNAME | ||
136 | local VIRTUAL_NAME | ||
137 | local INSTALL_VIRTUAL | ||
138 | local PNAME | ||
139 | local PCAT | ||
140 | niro | 250 | local PVER |
141 | local PBUILD | ||
142 | niro | 226 | |
143 | DFILE="$1" | ||
144 | |||
145 | source ${DFILE} | ||
146 | MY_DEPEND="${DEPEND}" | ||
147 | |||
148 | # for srcinstall & srcdepend only; SDEPEND also needed | ||
149 | niro | 231 | if [[ ${METHOD} = srcinstall ]] || \ |
150 | [[ ${METHOD} = srcpretend ]] || \ | ||
151 | [[ ${METHOD} = srcupgrade ]] || \ | ||
152 | [[ ${METHOD} = srcuppretend ]] | ||
153 | niro | 226 | then |
154 | # only if SDEPEND is not zero | ||
155 | if [ -n "${SDEPEND}" ] | ||
156 | then | ||
157 | # crlf is substantly needed !! | ||
158 | if [ -n "${MY_DEPEND}" ] | ||
159 | then | ||
160 | MY_DEPEND="${MY_DEPEND} | ||
161 | ${SDEPEND}" | ||
162 | else | ||
163 | MY_DEPEND="${SDEPEND}" | ||
164 | fi | ||
165 | fi | ||
166 | fi | ||
167 | |||
168 | unset DEPEND | ||
169 | unset SDEPEND | ||
170 | |||
171 | if [ -z "${MY_DEPEND}" ] | ||
172 | then | ||
173 | return 1 | ||
174 | fi | ||
175 | |||
176 | while read SYM DEPNAME | ||
177 | do | ||
178 | niro | 656 | # exclude empty depnames |
179 | [[ -z ${DEPNAME} ]] && continue | ||
180 | |||
181 | niro | 654 | # exclude all already processed deps -without version |
182 | if ! checklist_processeddeps "${DEPNAME%-*}" | ||
183 | then | ||
184 | continue | ||
185 | fi | ||
186 | |||
187 | # mark depfile as processed to prevent double runs -without version | ||
188 | PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}" | ||
189 | |||
190 | niro | 226 | HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") |
191 | |||
192 | PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" | ||
193 | PNAME="$(magename2pname ${HIGHEST_DEPFILE})" | ||
194 | PVER="$(magename2pver ${HIGHEST_DEPFILE})" | ||
195 | PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})" | ||
196 | |||
197 | ## check ob schon in ALLDEPS enthalten dann mach weiter | ||
198 | niro | 598 | |
199 | # usage of fgrep is extremly slow and consumes a lot of cpu power | ||
200 | #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ] | ||
201 | if checklist_alldeps "${HIGHEST_DEPFILE}" | ||
202 | niro | 226 | then |
203 | ### check ob DFILE schon installiert ist ### | ||
204 | if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] | ||
205 | then | ||
206 | rumwandern ${HIGHEST_DEPFILE} | ||
207 | ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}" | ||
208 | fi | ||
209 | fi | ||
210 | done << EOF | ||
211 | ${MY_DEPEND} | ||
212 | EOF | ||
213 | return 0 | ||
214 | } | ||
215 | |||
216 | |||
217 | ### abort if this package is already installed (retval 3) | ||
218 | # maybe later ? | ||
219 | #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3 | ||
220 | |||
221 | niro | 231 | [[ ${METHOD} = pretend ]] || \ |
222 | [[ ${METHOD} = srcpretend ]] || \ | ||
223 | [[ ${METHOD} = uppretend ]] || \ | ||
224 | [[ ${METHOD} = srcuppretend ]] && \ | ||
225 | niro | 226 | echo -n "Calculating dependencies ... " |
226 | |||
227 | |||
228 | niro | 231 | if [[ ${METHOD} = upgrade ]] || \ |
229 | [[ ${METHOD} = srcupgrade ]] || \ | ||
230 | [[ ${METHOD} = uppretend ]] || \ | ||
231 | [[ ${METHOD} = srcuppretend ]] | ||
232 | then | ||
233 | INSTDEPS="$(${MLIBDIR}/magequery.sh -i)" | ||
234 | for dep in ${INSTDEPS} | ||
235 | do | ||
236 | PCAT="$(magename2pcat ${dep} installdb)" | ||
237 | PNAME="$(magename2pname ${dep})" | ||
238 | niro | 226 | |
239 | niro | 250 | # get the highest mage file from mage-db |
240 | MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" | ||
241 | niro | 226 | |
242 | niro | 250 | # now get the pver&pbuild from the new file |
243 | PVER="$(magename2pver ${MAGEFILE})" | ||
244 | PBUILD="$(magename2pbuild ${MAGEFILE})" | ||
245 | |||
246 | # do not wander files which are installed | ||
247 | if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] | ||
248 | then | ||
249 | # get dependencies the package | ||
250 | rumwandern ${MAGEFILE} | ||
251 | |||
252 | # now add the package itself to the dependencies | ||
253 | # (if not exists already) | ||
254 | niro | 598 | #if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ] |
255 | if checklist_alldeps "${MAGEFILE}" | ||
256 | niro | 250 | then |
257 | ALLDEPS="${ALLDEPS} ${MAGEFILE}" | ||
258 | fi | ||
259 | fi | ||
260 | niro | 231 | done |
261 | else | ||
262 | # get dependencies the package | ||
263 | rumwandern ${MAGEFILE} | ||
264 | niro | 226 | |
265 | niro | 231 | # now add the package itself to the dependencies |
266 | ALLDEPS="${ALLDEPS} ${MAGEFILE}" | ||
267 | fi | ||
268 | |||
269 | [[ ${METHOD} = pretend ]] || \ | ||
270 | [[ ${METHOD} = srcpretend ]] || \ | ||
271 | [[ ${METHOD} = uppretend ]] || \ | ||
272 | [[ ${METHOD} = srcuppretend ]] && \ | ||
273 | echo "done" | ||
274 | |||
275 | |||
276 | niro | 226 | ## show output of pretend |
277 | niro | 231 | if [[ ${METHOD} = pretend ]] || \ |
278 | [[ ${METHOD} = srcpretend ]] || \ | ||
279 | [[ ${METHOD} = uppretend ]] || \ | ||
280 | [[ ${METHOD} = srcuppretend ]] | ||
281 | niro | 226 | then |
282 | # this is a little bit faster | ||
283 | declare -i x=0 | ||
284 | echo -n "Building dependencies list ... " | ||
285 | for i in ${ALLDEPS} | ||
286 | do | ||
287 | (( x++ )) | ||
288 | k="$x" | ||
289 | [ ${x} -le 9 ] && k="0${k}" | ||
290 | #[ ${x} -le 99 ] && k="0${k}" | ||
291 | PCAT="$(magename2pcat ${i})" | ||
292 | PNAME="$(magename2pname ${i})" | ||
293 | PVER="$(magename2pver ${i})" | ||
294 | PBUILD="$(magename2pbuild ${i})" | ||
295 | if [ -z "${list}" ] | ||
296 | then | ||
297 | list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" | ||
298 | else | ||
299 | list="${list} | ||
300 | \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" | ||
301 | fi | ||
302 | unset PCAT PNAME PVER PBUILD | ||
303 | done | ||
304 | echo "done" | ||
305 | echo -e "${list}" | ||
306 | echo | ||
307 | fi | ||
308 | |||
309 | ## return output from src/install deps | ||
310 | niro | 231 | [[ ${METHOD} = install ]] || \ |
311 | [[ ${METHOD} = srcinstall ]] || \ | ||
312 | [[ ${METHOD} = upgrade ]] || \ | ||
313 | [[ ${METHOD} = srcupgrade ]] && \ | ||
314 | echo "${ALLDEPS}" | ||
315 | niro | 226 | |
316 | # delete ${BUILDDIR}/virtuals if exists as not needed anymore | ||
317 | #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals |
Properties
Name | Value |
---|---|
svn:executable | * |