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