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