Contents of /branches/mage-next/src/depwalker.in
Parent Directory | Revision Log
Revision 2281 -
(show annotations)
(download)
(as text)
Wed Nov 20 12:21:28 2013 UTC (10 years, 5 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/depwalker.sh
File MIME type: application/x-sh
File size: 10000 byte(s)
Wed Nov 20 12:21:28 2013 UTC (10 years, 5 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/depwalker.sh
File MIME type: application/x-sh
File size: 10000 byte(s)
-provide enhanced debug information
1 | #!/bin/bash |
2 | # $Id$ |
3 | # dependeny walker |
4 | |
5 | # default die function |
6 | die() |
7 | { |
8 | echo ${COLRED}"$@"${COLDEFAULT} |
9 | exit 1 |
10 | } |
11 | |
12 | # include all needed files |
13 | [ -f /etc/mage.rc.global ] && \ |
14 | source /etc/mage.rc.global || \ |
15 | die "/etc/mage.rc.global missing" |
16 | |
17 | [ -f ${MAGERC} ] && source ${MAGERC} || \ |
18 | die "Your ${MAGERC} is missing. Aborting." |
19 | |
20 | [ -f ${MLIBDIR}/mage4.functions.sh ] && \ |
21 | source ${MLIBDIR}/mage4.functions.sh || \ |
22 | die "mage functions missing" |
23 | |
24 | usage() |
25 | { |
26 | echo |
27 | echo "Usage: $(basename $0) [command] [arg] ..." |
28 | echo |
29 | echo " -h --help shows this help" |
30 | echo " -c --pcat category of the package" |
31 | echo " -n --pname name of the package" |
32 | echo " -v --pver version number of the package" |
33 | echo " -b --pbuild build number of the package" |
34 | echo " -m --method which calc method should be used:" |
35 | echo " install, srcinstall, depend, srcdepend" |
36 | echo " upgrade, srcupgrade," |
37 | echo " install-build-prerequisites," |
38 | echo " pretend-build-prerequisites" |
39 | echo " -d --debug enable debug mode" |
40 | echo |
41 | echo "method, category, name, version and build must be given !" |
42 | echo |
43 | exit 1 |
44 | } |
45 | |
46 | # always default debug=0 |
47 | DEBUG=0 |
48 | |
49 | # very basic getops |
50 | for i in $* |
51 | do |
52 | case $1 in |
53 | --pcat|-c) shift; PCAT="$1" ;; |
54 | --pname|-n) shift; PNAME="$1" ;; |
55 | --pver|-v) shift; PVER="$1" ;; |
56 | --pbuild|-b) shift; PBUILD="$1" ;; |
57 | --method|-m) shift; METHOD="$1" ;; |
58 | --debug|-d) shift; DEBUG=1 ;; |
59 | --help|-h) usage ;; |
60 | esac |
61 | shift |
62 | done |
63 | |
64 | # sanity checks; abort if not given |
65 | [ -z "${PCAT}" ] && usage |
66 | [ -z "${PNAME}" ] && usage |
67 | [ -z "${PVER}" ] && usage |
68 | [ -z "${PBUILD}" ] && usage |
69 | [ -z "${METHOD}" ] && usage |
70 | |
71 | # check needed global vars |
72 | [ -z "${MAGEDIR}" ] && die "\$MAGEDIR not set." |
73 | [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set." |
74 | [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set." |
75 | |
76 | # other needed vars |
77 | ALLDEPS="" |
78 | MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage" |
79 | |
80 | # much faster than fgrep |
81 | checklist_alldeps() |
82 | { |
83 | local i |
84 | local item="$1" |
85 | |
86 | for i in ${ALLDEPS} |
87 | do |
88 | [[ ${i} = ${item} ]] && return 1 |
89 | done |
90 | |
91 | return 0 |
92 | } |
93 | |
94 | checklist_processeddeps() |
95 | { |
96 | local i |
97 | local item="$1" |
98 | |
99 | for i in ${PROCESSEDDEPS} |
100 | do |
101 | [[ ${i} = ${item} ]] && return 1 |
102 | done |
103 | |
104 | return 0 |
105 | } |
106 | |
107 | ##################### |
108 | ## depwalking /path/to/mage/file/.mage |
109 | depwalking() |
110 | { |
111 | unset DEPEND |
112 | unset SDEPEND |
113 | unset MY_DEPEND |
114 | |
115 | local DFILE |
116 | local SYM |
117 | local DEPNAME |
118 | local HIGHEST_DEPFILE |
119 | local MY_DEPEND |
120 | local REAL_PGKNAME |
121 | local VIRTUAL_NAME |
122 | local INSTALL_VIRTUAL |
123 | local PNAME |
124 | local PCAT |
125 | local PVER |
126 | local PBUILD |
127 | |
128 | DFILE="$1" |
129 | |
130 | if [[ ${DEBUG} = 1 ]] |
131 | then |
132 | echo "DEBUG: depwalking magefile '${DFILE}'" >&2 |
133 | echo >&2 |
134 | fi |
135 | |
136 | source ${DFILE} |
137 | |
138 | # forced nodeps |
139 | if [[ ${NODEPS} = true ]] |
140 | then |
141 | DEPEND="" |
142 | SDEPEND="" |
143 | fi |
144 | |
145 | MY_DEPEND="${DEPEND}" |
146 | |
147 | # for srcinstall & srcdepend only; SDEPEND also needed |
148 | if [[ ${METHOD} = srcinstall ]] || \ |
149 | [[ ${METHOD} = srcpretend ]] || \ |
150 | [[ ${METHOD} = srcupgrade ]] || \ |
151 | [[ ${METHOD} = srcuppretend ]] |
152 | then |
153 | # only if SDEPEND is not zero |
154 | if [ -n "${SDEPEND}" ] |
155 | then |
156 | # crlf is substantly needed !! |
157 | if [ -n "${MY_DEPEND}" ] |
158 | then |
159 | MY_DEPEND="${MY_DEPEND} |
160 | ${SDEPEND}" |
161 | else |
162 | MY_DEPEND="${SDEPEND}" |
163 | fi |
164 | fi |
165 | fi |
166 | |
167 | if [[ ${METHOD} = install-build-prerequisites ]] || \ |
168 | [[ ${METHOD} = pretend-build-prerequisites ]] |
169 | then |
170 | # only one time |
171 | if [[ ${LOOP_COUNTER} -lt 1 ]] |
172 | then |
173 | # only if SDEPEND is not zero |
174 | if [ -n "${SDEPEND}" ] |
175 | then |
176 | # crlf is substantly needed !! |
177 | if [ -n "${MY_DEPEND}" ] |
178 | then |
179 | MY_DEPEND="${MY_DEPEND} |
180 | ${SDEPEND}" |
181 | else |
182 | MY_DEPEND="${SDEPEND}" |
183 | fi |
184 | fi |
185 | fi |
186 | LOOP_COUNTER=${LOOP_COUNTER}+1 |
187 | fi |
188 | |
189 | unset DEPEND |
190 | unset SDEPEND |
191 | |
192 | if [ -z "${MY_DEPEND}" ] |
193 | then |
194 | if [[ ${DEBUG} = 1 ]] |
195 | then |
196 | echo "DEBUG: MY_DEPEND is empty; deps of '${DFILE}' ignored" >&2 |
197 | fi |
198 | return 1 |
199 | fi |
200 | |
201 | while read SYM DEPNAME |
202 | do |
203 | if [[ ${DEBUG} = 1 ]] |
204 | then |
205 | echo "DEBUG: DEPNAME='${DEPNAME}'" >&2 |
206 | fi |
207 | |
208 | # exclude empty depnames |
209 | [[ -z ${DEPNAME} ]] && continue |
210 | |
211 | # exclude all already processed deps -without version |
212 | if ! checklist_processeddeps "${DEPNAME%-*}" |
213 | then |
214 | continue |
215 | fi |
216 | |
217 | # mark depfile as processed to prevent double runs -without version |
218 | # but do not add any virtuals to PROCESSEDDEPS or their resolved |
219 | # pkgnames will be ignored and they are missing on the dependecy-list |
220 | if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]] |
221 | then |
222 | PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}" |
223 | fi |
224 | |
225 | HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") |
226 | if [[ -z ${HIGHEST_DEPFILE} ]] |
227 | then |
228 | INVALID_DEPS+=" ${DEPNAME}:${DFILE}" |
229 | continue |
230 | fi |
231 | |
232 | PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" |
233 | PNAME="$(magename2pname ${HIGHEST_DEPFILE})" |
234 | PVER="$(magename2pver ${HIGHEST_DEPFILE})" |
235 | PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})" |
236 | |
237 | ## dep already in ALLDEPS? then going on |
238 | |
239 | # usage of fgrep is extremly slow and consumes a lot of cpu power |
240 | #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ] |
241 | if checklist_alldeps "${HIGHEST_DEPFILE}" |
242 | then |
243 | ### check if the dependency is already installed ### |
244 | if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
245 | then |
246 | depwalking ${HIGHEST_DEPFILE} |
247 | ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}" |
248 | if [[ ${DEBUG} = 1 ]] |
249 | then |
250 | echo "DEBUG: added '${HIGHEST_DEPFILE}' to ALLDEPS" >&2 |
251 | fi |
252 | fi |
253 | fi |
254 | done << EOF |
255 | ${MY_DEPEND} |
256 | EOF |
257 | return 0 |
258 | } |
259 | |
260 | [[ ${METHOD} = pretend ]] || \ |
261 | [[ ${METHOD} = srcpretend ]] || \ |
262 | [[ ${METHOD} = uppretend ]] || \ |
263 | [[ ${METHOD} = srcuppretend ]] || \ |
264 | [[ ${METHOD} = pretend-build-prerequisites ]] && \ |
265 | echo -n "Calculating dependencies ... " |
266 | |
267 | |
268 | if [[ ${METHOD} = upgrade ]] || \ |
269 | [[ ${METHOD} = srcupgrade ]] || \ |
270 | [[ ${METHOD} = uppretend ]] || \ |
271 | [[ ${METHOD} = srcuppretend ]] |
272 | then |
273 | INSTDEPS="$(${MLIBDIR}/magequery.sh -i)" |
274 | for dep in ${INSTDEPS} |
275 | do |
276 | PCAT="$(magename2pcat ${dep} installdb)" |
277 | PNAME="$(magename2pname ${dep})" |
278 | |
279 | # get the highest mage file from mage-db |
280 | MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" |
281 | |
282 | if [[ ${DEBUG} = 1 ]] |
283 | then |
284 | echo "DEBUG: dep='${dep}'" >&2 |
285 | echo "DEBUG: PCAT='${PCAT}'" >&2 |
286 | echo "DEBUG: PNAME='${PNAME}'" >&2 |
287 | echo "DEBUG: MAGEFILE='${MAGEFILE}'" >&2 |
288 | fi |
289 | |
290 | # if no install candidate was found, record this |
291 | # and process with the next one |
292 | if [[ -z ${MAGEFILE} ]] |
293 | then |
294 | NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}" |
295 | if [[ ${DEBUG} = 1 ]] |
296 | then |
297 | echo "DEBUG: added to NO_UPGRADE_CANDIDATE" >&2 |
298 | fi |
299 | continue |
300 | fi |
301 | |
302 | # now get the pver&pbuild from the new file |
303 | PVER="$(magename2pver ${MAGEFILE})" |
304 | PBUILD="$(magename2pbuild ${MAGEFILE})" |
305 | |
306 | if [[ ${DEBUG} = 1 ]] |
307 | then |
308 | echo "DEBUG: PVER='${PVER}'" >&2 |
309 | echo "DEBUG: PBUILD='${PBUILD}'" >&2 |
310 | fi |
311 | |
312 | # do not walk files which are installed |
313 | if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
314 | then |
315 | # get dependencies the package |
316 | depwalking ${MAGEFILE} |
317 | |
318 | # now add the package itself to the dependencies |
319 | # (if not exists already) |
320 | if checklist_alldeps "${MAGEFILE}" |
321 | then |
322 | if [[ ${DEBUG} = 1 ]] |
323 | then |
324 | echo "DEBUG: added '${MAGEFILE}' to ALLDEPS" >&2 |
325 | fi |
326 | ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
327 | fi |
328 | else |
329 | if [[ ${DEBUG} = 1 ]] |
330 | then |
331 | echo "DEBUG: ignored package" >&2 |
332 | echo >&2 |
333 | fi |
334 | fi |
335 | done |
336 | else |
337 | LOOP_COUNTER=0 |
338 | # get all dependencies of the package |
339 | depwalking ${MAGEFILE} |
340 | fi |
341 | |
342 | if [[ ${METHOD} != install-build-prerequisites ]] && |
343 | [[ ${METHOD} != pretend-build-prerequisites ]] && |
344 | [[ ${METHOD} != upgrade ]] && |
345 | [[ ${METHOD} != uppretend ]] && |
346 | [[ ${METHOD} != srcupgrade ]] && |
347 | [[ ${METHOD} != srcuppretend ]] |
348 | then |
349 | # now add the package itself to the dependencies |
350 | # (if not exists already) |
351 | if checklist_alldeps "${MAGEFILE}" |
352 | then |
353 | if [[ ${DEBUG} = 1 ]] |
354 | then |
355 | echo "DEBUG: added '${MAGEFILE}' to ALLDEPS" >&2 |
356 | fi |
357 | ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
358 | fi |
359 | fi |
360 | |
361 | [[ ${METHOD} = pretend ]] || \ |
362 | [[ ${METHOD} = srcpretend ]] || \ |
363 | [[ ${METHOD} = uppretend ]] || \ |
364 | [[ ${METHOD} = srcuppretend ]] || \ |
365 | [[ ${METHOD} = pretend-build-prerequisites ]] && \ |
366 | echo "done" |
367 | |
368 | |
369 | ## show output of pretend |
370 | if [[ ${METHOD} = pretend ]] || \ |
371 | [[ ${METHOD} = srcpretend ]] || \ |
372 | [[ ${METHOD} = uppretend ]] || \ |
373 | [[ ${METHOD} = srcuppretend ]] || \ |
374 | [[ ${METHOD} = pretend-build-prerequisites ]] |
375 | then |
376 | # this is a little bit faster |
377 | declare -i x=0 |
378 | echo -n "Building dependencies list ... " |
379 | for i in ${ALLDEPS} |
380 | do |
381 | (( x++ )) |
382 | k="$x" |
383 | [ ${x} -le 9 ] && k="0${k}" |
384 | #[ ${x} -le 99 ] && k="0${k}" |
385 | PCAT="$(magename2pcat ${i})" |
386 | PNAME="$(magename2pname ${i})" |
387 | PVER="$(magename2pver ${i})" |
388 | PBUILD="$(magename2pbuild ${i})" |
389 | if [ -z "${list}" ] |
390 | then |
391 | list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
392 | else |
393 | list="${list} |
394 | \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
395 | fi |
396 | unset PCAT PNAME PVER PBUILD |
397 | done |
398 | echo "done" |
399 | echo -e "${list}" |
400 | echo |
401 | |
402 | if [[ ! -z ${INVALID_DEPS} ]] |
403 | then |
404 | echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}" |
405 | for i in ${INVALID_DEPS} |
406 | do |
407 | _dep="${i%%:*}" |
408 | _mage="${i##*:}" |
409 | echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}" |
410 | done |
411 | echo |
412 | fi |
413 | |
414 | if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]] |
415 | then |
416 | echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}" |
417 | for i in ${NO_UPGRADE_CANDIDATE} |
418 | do |
419 | echo -e "${COLRED} ${i}${COLDEFAULT}" |
420 | done |
421 | echo |
422 | echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}" |
423 | echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}" |
424 | echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}" |
425 | echo |
426 | fi |
427 | fi |
428 | |
429 | ## return output from src/install deps |
430 | [[ ${METHOD} = install ]] || \ |
431 | [[ ${METHOD} = srcinstall ]] || \ |
432 | [[ ${METHOD} = upgrade ]] || \ |
433 | [[ ${METHOD} = srcupgrade ]] || \ |
434 | [[ ${METHOD} = install-build-prerequisites ]] && \ |
435 | echo "${ALLDEPS}" |
Properties
Name | Value |
---|---|
svn:executable | * |