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