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