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