Contents of /branches/mage-next/src/depwalker.in
Parent Directory | Revision Log
Revision 2285 -
(show annotations)
(download)
(as text)
Mon Dec 2 10:11:10 2013 UTC (10 years, 9 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, 9 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 | #!/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 | decho() |
13 | { |
14 | if [[ ${DEBUG} = 1 ]] |
15 | then |
16 | echo "DEBUG: $@" >&2 |
17 | fi |
18 | } |
19 | |
20 | # include all needed files |
21 | [ -f /etc/mage.rc.global ] && \ |
22 | source /etc/mage.rc.global || \ |
23 | die "/etc/mage.rc.global missing" |
24 | |
25 | [ -f ${MAGERC} ] && source ${MAGERC} || \ |
26 | die "Your ${MAGERC} is missing. Aborting." |
27 | |
28 | [ -f ${MLIBDIR}/mage4.functions.sh ] && \ |
29 | source ${MLIBDIR}/mage4.functions.sh || \ |
30 | die "mage functions missing" |
31 | |
32 | usage() |
33 | { |
34 | echo |
35 | echo "Usage: $(basename $0) [command] [arg] ..." |
36 | echo |
37 | echo " -h --help shows this help" |
38 | echo " -c --pcat category of the package" |
39 | 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 | echo " install, srcinstall, depend, srcdepend" |
44 | echo " upgrade, srcupgrade," |
45 | echo " install-build-prerequisites," |
46 | echo " pretend-build-prerequisites" |
47 | echo " -d --debug enable debug mode" |
48 | echo |
49 | echo "method, category, name, version and build must be given !" |
50 | echo |
51 | exit 1 |
52 | } |
53 | |
54 | # always default debug=0 |
55 | DEBUG=0 |
56 | |
57 | # 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 | --debug|-d) shift; DEBUG=1 ;; |
67 | --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 | # 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 | 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 | ##################### |
116 | ## depwalking /path/to/mage/file/.mage |
117 | depwalking() |
118 | { |
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 | local PVER |
134 | local PBUILD |
135 | |
136 | DFILE="$1" |
137 | |
138 | # debug info |
139 | decho "depwalking magefile '${DFILE}'" |
140 | decho |
141 | |
142 | source ${DFILE} |
143 | |
144 | # forced nodeps |
145 | if [[ ${NODEPS} = true ]] |
146 | then |
147 | DEPEND="" |
148 | SDEPEND="" |
149 | fi |
150 | |
151 | MY_DEPEND="${DEPEND}" |
152 | |
153 | # for srcinstall & srcdepend only; SDEPEND also needed |
154 | if [[ ${METHOD} = srcinstall ]] || \ |
155 | [[ ${METHOD} = srcpretend ]] || \ |
156 | [[ ${METHOD} = srcupgrade ]] || \ |
157 | [[ ${METHOD} = srcuppretend ]] |
158 | 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 | 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 | unset DEPEND |
196 | unset SDEPEND |
197 | |
198 | if [ -z "${MY_DEPEND}" ] |
199 | then |
200 | decho "MY_DEPEND is empty; deps of '${DFILE}' ignored" |
201 | return 1 |
202 | fi |
203 | |
204 | while read SYM DEPNAME |
205 | do |
206 | # debug info |
207 | decho "DEPNAME='${DEPNAME}'" |
208 | |
209 | # exclude empty depnames |
210 | [[ -z ${DEPNAME} ]] && continue |
211 | |
212 | # 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 | # 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 | |
226 | HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") |
227 | if [[ -z ${HIGHEST_DEPFILE} ]] |
228 | then |
229 | INVALID_DEPS+=" ${DEPNAME}:${DFILE}" |
230 | continue |
231 | fi |
232 | |
233 | PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" |
234 | PNAME="$(magename2pname ${HIGHEST_DEPFILE})" |
235 | PVER="$(magename2pver ${HIGHEST_DEPFILE})" |
236 | PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})" |
237 | |
238 | ## dep already in ALLDEPS? then going on |
239 | |
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 | then |
244 | ### check if the dependency is already installed ### |
245 | if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
246 | then |
247 | depwalking ${HIGHEST_DEPFILE} |
248 | ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}" |
249 | decho "added '${HIGHEST_DEPFILE}' to ALLDEPS" |
250 | fi |
251 | fi |
252 | done << EOF |
253 | ${MY_DEPEND} |
254 | EOF |
255 | return 0 |
256 | } |
257 | |
258 | [[ ${METHOD} = pretend ]] || \ |
259 | [[ ${METHOD} = srcpretend ]] || \ |
260 | [[ ${METHOD} = uppretend ]] || \ |
261 | [[ ${METHOD} = srcuppretend ]] || \ |
262 | [[ ${METHOD} = pretend-build-prerequisites ]] && \ |
263 | echo -n "Calculating dependencies ... " |
264 | |
265 | |
266 | 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 | |
277 | # get the highest mage file from mage-db |
278 | MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" |
279 | |
280 | # debug info |
281 | decho "dep='${dep}'" |
282 | decho "PCAT='${PCAT}'" |
283 | decho "PNAME='${PNAME}'" |
284 | decho "MAGEFILE='${MAGEFILE}'" |
285 | |
286 | # 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 | decho "added to NO_UPGRADE_CANDIDATE" |
292 | continue |
293 | fi |
294 | |
295 | # now get the pver&pbuild from the new file |
296 | PVER="$(magename2pver ${MAGEFILE})" |
297 | PBUILD="$(magename2pbuild ${MAGEFILE})" |
298 | |
299 | # debug info |
300 | decho "PVER='${PVER}'" |
301 | decho "PBUILD='${PBUILD}'" |
302 | |
303 | # do not walk files which are installed |
304 | if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
305 | then |
306 | # get dependencies the package |
307 | depwalking ${MAGEFILE} |
308 | |
309 | # now add the package itself to the dependencies |
310 | # (if not exists already) |
311 | if checklist_alldeps "${MAGEFILE}" |
312 | then |
313 | decho "added '${MAGEFILE}' to ALLDEPS" |
314 | ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
315 | fi |
316 | else |
317 | # debug info |
318 | decho "ignored package" |
319 | decho |
320 | fi |
321 | fi |
322 | done |
323 | else |
324 | LOOP_COUNTER=0 |
325 | # get all dependencies of the package |
326 | depwalking ${MAGEFILE} |
327 | fi |
328 | |
329 | if [[ ${METHOD} != install-build-prerequisites ]] && |
330 | [[ ${METHOD} != pretend-build-prerequisites ]] && |
331 | [[ ${METHOD} != upgrade ]] && |
332 | [[ ${METHOD} != uppretend ]] && |
333 | [[ ${METHOD} != srcupgrade ]] && |
334 | [[ ${METHOD} != srcuppretend ]] |
335 | then |
336 | # now add the package itself to the dependencies |
337 | # (if not exists already) |
338 | if checklist_alldeps "${MAGEFILE}" |
339 | then |
340 | decho "added '${MAGEFILE}' to ALLDEPS" |
341 | ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
342 | fi |
343 | fi |
344 | |
345 | [[ ${METHOD} = pretend ]] || \ |
346 | [[ ${METHOD} = srcpretend ]] || \ |
347 | [[ ${METHOD} = uppretend ]] || \ |
348 | [[ ${METHOD} = srcuppretend ]] || \ |
349 | [[ ${METHOD} = pretend-build-prerequisites ]] && \ |
350 | echo "done" |
351 | |
352 | |
353 | ## show output of pretend |
354 | if [[ ${METHOD} = pretend ]] || \ |
355 | [[ ${METHOD} = srcpretend ]] || \ |
356 | [[ ${METHOD} = uppretend ]] || \ |
357 | [[ ${METHOD} = srcuppretend ]] || \ |
358 | [[ ${METHOD} = pretend-build-prerequisites ]] |
359 | 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 | list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
376 | 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 | |
386 | 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 | 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 | echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}" |
409 | echo |
410 | fi |
411 | fi |
412 | |
413 | ## return output from src/install deps |
414 | [[ ${METHOD} = install ]] || \ |
415 | [[ ${METHOD} = srcinstall ]] || \ |
416 | [[ ${METHOD} = upgrade ]] || \ |
417 | [[ ${METHOD} = srcupgrade ]] || \ |
418 | [[ ${METHOD} = install-build-prerequisites ]] && \ |
419 | echo "${ALLDEPS}" |
Properties
Name | Value |
---|---|
svn:executable | * |