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