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