Annotation of /branches/mage-next/src/depwalker.in
Parent Directory | Revision Log
Revision 2627 -
(hide annotations)
(download)
Wed Mar 5 08:18:22 2014 UTC (10 years, 6 months ago) by niro
File size: 9701 byte(s)
Wed Mar 5 08:18:22 2014 UTC (10 years, 6 months ago) by niro
File size: 9701 byte(s)
-set some required default variables
1 | niro | 226 | #!/bin/bash |
2 | niro | 1559 | # $Id$ |
3 | # dependeny walker | ||
4 | niro | 226 | |
5 | niro | 2285 | decho() |
6 | { | ||
7 | if [[ ${DEBUG} = 1 ]] | ||
8 | then | ||
9 | echo "DEBUG: $@" >&2 | ||
10 | fi | ||
11 | } | ||
12 | |||
13 | niro | 2627 | # set default variables |
14 | : ${MAGERC="@@SYSCONFDIR@@/mage.rc"} | ||
15 | : ${MLIBDIR="@@MAGELIBDIR@@"} | ||
16 | |||
17 | niro | 2626 | # first of all include common functions |
18 | source ${MLIBDIR}/common.functions.sh || exit 1 | ||
19 | niro | 2625 | source @@SYSCONFDIR@@/mage.rc.global || die "@@SYSCONFDIR@@/mage.rc.global missing" |
20 | source ${MAGERC} || die "Your ${MAGERC} is missing. Aborting." | ||
21 | source ${MLIBDIR}/mage4.functions.sh || die "mage functions missing" | ||
22 | source ${MLIBDIR}/smage2.functions.sh || die "smage functions missing" | ||
23 | niro | 226 | |
24 | 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 | 2221 | # always default debug=0 |
48 | DEBUG=0 | ||
49 | |||
50 | niro | 226 | # 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 | niro | 2221 | --debug|-d) shift; DEBUG=1 ;; |
60 | niro | 2360 | --smage|-s) shift; SMAGEFILE="$1"; SILENT=1; FVERBOSE=off ;; |
61 | niro | 226 | --help|-h) usage ;; |
62 | esac | ||
63 | shift | ||
64 | done | ||
65 | |||
66 | # sanity checks; abort if not given | ||
67 | niro | 2360 | if [[ -z ${SMAGEFILE} ]] |
68 | then | ||
69 | [ -z "${PCAT}" ] && usage | ||
70 | [ -z "${PNAME}" ] && usage | ||
71 | [ -z "${PVER}" ] && usage | ||
72 | [ -z "${PBUILD}" ] && usage | ||
73 | fi | ||
74 | niro | 226 | [ -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 | niro | 2360 | 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 | niro | 226 | MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage" |
93 | |||
94 | niro | 598 | # 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 | niro | 654 | 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 | niro | 226 | ##################### |
122 | niro | 1563 | ## depwalking /path/to/mage/file/.mage |
123 | depwalking() | ||
124 | niro | 226 | { |
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 | niro | 250 | local PVER |
140 | local PBUILD | ||
141 | niro | 226 | |
142 | DFILE="$1" | ||
143 | |||
144 | niro | 2285 | # debug info |
145 | decho "depwalking magefile '${DFILE}'" | ||
146 | decho | ||
147 | niro | 2281 | |
148 | niro | 226 | source ${DFILE} |
149 | niro | 778 | |
150 | # forced nodeps | ||
151 | if [[ ${NODEPS} = true ]] | ||
152 | then | ||
153 | DEPEND="" | ||
154 | SDEPEND="" | ||
155 | fi | ||
156 | |||
157 | niro | 226 | MY_DEPEND="${DEPEND}" |
158 | |||
159 | # for srcinstall & srcdepend only; SDEPEND also needed | ||
160 | niro | 2286 | if [[ ${METHOD} = srcinstall ]] || |
161 | [[ ${METHOD} = srcpretend ]] || | ||
162 | [[ ${METHOD} = srcupgrade ]] || | ||
163 | [[ ${METHOD} = srcuppretend ]] || | ||
164 | [[ ${METHOD} = install-build-prerequisites ]] || | ||
165 | [[ ${METHOD} = pretend-build-prerequisites ]] | ||
166 | niro | 226 | 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 | niro | 2285 | decho "MY_DEPEND is empty; deps of '${DFILE}' ignored" |
187 | niro | 226 | return 1 |
188 | fi | ||
189 | |||
190 | while read SYM DEPNAME | ||
191 | do | ||
192 | niro | 2285 | # debug info |
193 | decho "DEPNAME='${DEPNAME}'" | ||
194 | niro | 2221 | |
195 | niro | 656 | # exclude empty depnames |
196 | [[ -z ${DEPNAME} ]] && continue | ||
197 | |||
198 | niro | 654 | # 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 | niro | 677 | # but do not add any virtuals to PROCESSEDDEPS or their resolved |
206 | # pkgnames will be ignored and they are missing on the dependecy-list | ||
207 | if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]] | ||
208 | then | ||
209 | PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}" | ||
210 | fi | ||
211 | niro | 654 | |
212 | niro | 226 | HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") |
213 | niro | 2141 | if [[ -z ${HIGHEST_DEPFILE} ]] |
214 | then | ||
215 | INVALID_DEPS+=" ${DEPNAME}:${DFILE}" | ||
216 | continue | ||
217 | fi | ||
218 | niro | 226 | |
219 | PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" | ||
220 | PNAME="$(magename2pname ${HIGHEST_DEPFILE})" | ||
221 | PVER="$(magename2pver ${HIGHEST_DEPFILE})" | ||
222 | PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})" | ||
223 | |||
224 | niro | 1562 | ## dep already in ALLDEPS? then going on |
225 | niro | 598 | |
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 | niro | 226 | then |
230 | niro | 1564 | ### check if the dependency is already installed ### |
231 | niro | 226 | if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
232 | then | ||
233 | niro | 1563 | depwalking ${HIGHEST_DEPFILE} |
234 | niro | 226 | ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}" |
235 | niro | 2285 | decho "added '${HIGHEST_DEPFILE}' to ALLDEPS" |
236 | niro | 226 | fi |
237 | fi | ||
238 | done << EOF | ||
239 | ${MY_DEPEND} | ||
240 | EOF | ||
241 | return 0 | ||
242 | } | ||
243 | |||
244 | niro | 231 | [[ ${METHOD} = pretend ]] || \ |
245 | [[ ${METHOD} = srcpretend ]] || \ | ||
246 | [[ ${METHOD} = uppretend ]] || \ | ||
247 | niro | 2210 | [[ ${METHOD} = srcuppretend ]] || \ |
248 | [[ ${METHOD} = pretend-build-prerequisites ]] && \ | ||
249 | niro | 226 | echo -n "Calculating dependencies ... " |
250 | |||
251 | |||
252 | niro | 231 | if [[ ${METHOD} = upgrade ]] || \ |
253 | [[ ${METHOD} = srcupgrade ]] || \ | ||
254 | [[ ${METHOD} = uppretend ]] || \ | ||
255 | [[ ${METHOD} = srcuppretend ]] | ||
256 | then | ||
257 | INSTDEPS="$(${MLIBDIR}/magequery.sh -i)" | ||
258 | for dep in ${INSTDEPS} | ||
259 | do | ||
260 | PCAT="$(magename2pcat ${dep} installdb)" | ||
261 | PNAME="$(magename2pname ${dep})" | ||
262 | niro | 226 | |
263 | niro | 250 | # get the highest mage file from mage-db |
264 | MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" | ||
265 | niro | 226 | |
266 | niro | 2285 | # debug info |
267 | decho "dep='${dep}'" | ||
268 | decho "PCAT='${PCAT}'" | ||
269 | decho "PNAME='${PNAME}'" | ||
270 | decho "MAGEFILE='${MAGEFILE}'" | ||
271 | niro | 2281 | |
272 | niro | 701 | # if no install candidate was found, record this |
273 | # and process with the next one | ||
274 | if [[ -z ${MAGEFILE} ]] | ||
275 | then | ||
276 | NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}" | ||
277 | niro | 2285 | decho "added to NO_UPGRADE_CANDIDATE" |
278 | niro | 701 | continue |
279 | fi | ||
280 | |||
281 | niro | 250 | # now get the pver&pbuild from the new file |
282 | PVER="$(magename2pver ${MAGEFILE})" | ||
283 | PBUILD="$(magename2pbuild ${MAGEFILE})" | ||
284 | |||
285 | niro | 2285 | # debug info |
286 | decho "PVER='${PVER}'" | ||
287 | decho "PBUILD='${PBUILD}'" | ||
288 | niro | 2281 | |
289 | niro | 1562 | # do not walk files which are installed |
290 | niro | 250 | if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
291 | then | ||
292 | # get dependencies the package | ||
293 | niro | 1563 | depwalking ${MAGEFILE} |
294 | niro | 2280 | |
295 | # now add the package itself to the dependencies | ||
296 | # (if not exists already) | ||
297 | if checklist_alldeps "${MAGEFILE}" | ||
298 | then | ||
299 | niro | 2285 | decho "added '${MAGEFILE}' to ALLDEPS" |
300 | niro | 2280 | ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
301 | fi | ||
302 | niro | 2281 | else |
303 | niro | 2376 | # debug info |
304 | decho "ignored package" | ||
305 | decho | ||
306 | niro | 250 | fi |
307 | niro | 231 | done |
308 | else | ||
309 | niro | 1562 | # get all dependencies of the package |
310 | niro | 2360 | if [[ -n ${SMAGEFILE} ]] |
311 | then | ||
312 | depwalking "${SMAGEFILE}" | ||
313 | else | ||
314 | depwalking "${MAGEFILE}" | ||
315 | fi | ||
316 | niro | 2195 | fi |
317 | niro | 226 | |
318 | niro | 2210 | if [[ ${METHOD} != install-build-prerequisites ]] && |
319 | niro | 2280 | [[ ${METHOD} != pretend-build-prerequisites ]] && |
320 | [[ ${METHOD} != upgrade ]] && | ||
321 | [[ ${METHOD} != uppretend ]] && | ||
322 | [[ ${METHOD} != srcupgrade ]] && | ||
323 | [[ ${METHOD} != srcuppretend ]] | ||
324 | niro | 2195 | then |
325 | niro | 2210 | # now add the package itself to the dependencies |
326 | # (if not exists already) | ||
327 | if checklist_alldeps "${MAGEFILE}" | ||
328 | then | ||
329 | niro | 2285 | decho "added '${MAGEFILE}' to ALLDEPS" |
330 | niro | 2210 | ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
331 | fi | ||
332 | niro | 231 | fi |
333 | |||
334 | [[ ${METHOD} = pretend ]] || \ | ||
335 | [[ ${METHOD} = srcpretend ]] || \ | ||
336 | [[ ${METHOD} = uppretend ]] || \ | ||
337 | niro | 2210 | [[ ${METHOD} = srcuppretend ]] || \ |
338 | [[ ${METHOD} = pretend-build-prerequisites ]] && \ | ||
339 | niro | 231 | echo "done" |
340 | |||
341 | |||
342 | niro | 226 | ## show output of pretend |
343 | niro | 231 | if [[ ${METHOD} = pretend ]] || \ |
344 | [[ ${METHOD} = srcpretend ]] || \ | ||
345 | [[ ${METHOD} = uppretend ]] || \ | ||
346 | niro | 2210 | [[ ${METHOD} = srcuppretend ]] || \ |
347 | [[ ${METHOD} = pretend-build-prerequisites ]] | ||
348 | niro | 226 | then |
349 | # this is a little bit faster | ||
350 | declare -i x=0 | ||
351 | echo -n "Building dependencies list ... " | ||
352 | for i in ${ALLDEPS} | ||
353 | do | ||
354 | (( x++ )) | ||
355 | k="$x" | ||
356 | [ ${x} -le 9 ] && k="0${k}" | ||
357 | #[ ${x} -le 99 ] && k="0${k}" | ||
358 | PCAT="$(magename2pcat ${i})" | ||
359 | PNAME="$(magename2pname ${i})" | ||
360 | PVER="$(magename2pver ${i})" | ||
361 | PBUILD="$(magename2pbuild ${i})" | ||
362 | if [ -z "${list}" ] | ||
363 | then | ||
364 | niro | 2220 | list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
365 | niro | 226 | else |
366 | list="${list} | ||
367 | \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" | ||
368 | fi | ||
369 | unset PCAT PNAME PVER PBUILD | ||
370 | done | ||
371 | echo "done" | ||
372 | echo -e "${list}" | ||
373 | echo | ||
374 | niro | 701 | |
375 | niro | 2141 | if [[ ! -z ${INVALID_DEPS} ]] |
376 | then | ||
377 | echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}" | ||
378 | for i in ${INVALID_DEPS} | ||
379 | do | ||
380 | _dep="${i%%:*}" | ||
381 | _mage="${i##*:}" | ||
382 | echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}" | ||
383 | done | ||
384 | echo | ||
385 | fi | ||
386 | |||
387 | niro | 701 | if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]] |
388 | then | ||
389 | echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}" | ||
390 | for i in ${NO_UPGRADE_CANDIDATE} | ||
391 | do | ||
392 | echo -e "${COLRED} ${i}${COLDEFAULT}" | ||
393 | done | ||
394 | echo | ||
395 | echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}" | ||
396 | echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}" | ||
397 | niro | 887 | echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}" |
398 | niro | 701 | echo |
399 | fi | ||
400 | niro | 226 | fi |
401 | |||
402 | ## return output from src/install deps | ||
403 | niro | 231 | [[ ${METHOD} = install ]] || \ |
404 | [[ ${METHOD} = srcinstall ]] || \ | ||
405 | [[ ${METHOD} = upgrade ]] || \ | ||
406 | niro | 2210 | [[ ${METHOD} = srcupgrade ]] || \ |
407 | [[ ${METHOD} = install-build-prerequisites ]] && \ | ||
408 | niro | 231 | echo "${ALLDEPS}" |