Annotation of /trunk/mage/usr/lib/mage/depwalker.sh
Parent Directory | Revision Log
Revision 2269 -
(hide annotations)
(download)
(as text)
Fri Oct 25 06:55:11 2013 UTC (10 years, 11 months ago) by niro
File MIME type: application/x-sh
File size: 8676 byte(s)
Fri Oct 25 06:55:11 2013 UTC (10 years, 11 months ago) by niro
File MIME type: application/x-sh
File size: 8676 byte(s)
-fixed usage
1 | niro | 226 | #!/bin/bash |
2 | niro | 1559 | # $Id$ |
3 | # dependeny walker | ||
4 | niro | 226 | |
5 | # default die function | ||
6 | die() | ||
7 | { | ||
8 | echo ${COLRED}"$@"${COLDEFAULT} | ||
9 | exit 1 | ||
10 | } | ||
11 | |||
12 | niro | 231 | # include all needed files |
13 | niro | 235 | [ -f /etc/mage.rc.global ] && \ |
14 | source /etc/mage.rc.global || \ | ||
15 | die "/etc/mage.rc.global missing" | ||
16 | niro | 226 | |
17 | niro | 419 | [ -f ${MAGERC} ] && source ${MAGERC} || \ |
18 | die "Your ${MAGERC} is missing. Aborting." | ||
19 | niro | 231 | |
20 | niro | 235 | [ -f ${MLIBDIR}/mage4.functions.sh ] && \ |
21 | source ${MLIBDIR}/mage4.functions.sh || \ | ||
22 | niro | 231 | die "mage functions missing" |
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 | echo " -c --pcat categorie 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 | niro | 231 | echo " install, srcinstall, depend, srcdepend" |
36 | niro | 2210 | echo " upgrade, srcupgrade," |
37 | echo " install-build-prerequisites, pretend-build-prerequisites" | ||
38 | niro | 2269 | echo " -d --debug enable debug mode" |
39 | niro | 226 | echo |
40 | niro | 701 | echo "method, name, version and build must be given !" |
41 | niro | 226 | echo |
42 | exit 1 | ||
43 | } | ||
44 | |||
45 | niro | 2221 | # always default debug=0 |
46 | DEBUG=0 | ||
47 | |||
48 | niro | 226 | # very basic getops |
49 | for i in $* | ||
50 | do | ||
51 | case $1 in | ||
52 | --pcat|-c) shift; PCAT="$1" ;; | ||
53 | --pname|-n) shift; PNAME="$1" ;; | ||
54 | --pver|-v) shift; PVER="$1" ;; | ||
55 | --pbuild|-b) shift; PBUILD="$1" ;; | ||
56 | --method|-m) shift; METHOD="$1" ;; | ||
57 | niro | 2221 | --debug|-d) shift; DEBUG=1 ;; |
58 | niro | 226 | --help|-h) usage ;; |
59 | esac | ||
60 | shift | ||
61 | done | ||
62 | |||
63 | # sanity checks; abort if not given | ||
64 | [ -z "${PCAT}" ] && usage | ||
65 | [ -z "${PNAME}" ] && usage | ||
66 | [ -z "${PVER}" ] && usage | ||
67 | [ -z "${PBUILD}" ] && usage | ||
68 | [ -z "${METHOD}" ] && usage | ||
69 | |||
70 | # check needed global vars | ||
71 | [ -z "${MAGEDIR}" ] && die "\$MAGEDIR not set." | ||
72 | [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set." | ||
73 | [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set." | ||
74 | |||
75 | # other needed vars | ||
76 | ALLDEPS="" | ||
77 | MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage" | ||
78 | |||
79 | niro | 598 | # much faster than fgrep |
80 | checklist_alldeps() | ||
81 | { | ||
82 | local i | ||
83 | local item="$1" | ||
84 | |||
85 | for i in ${ALLDEPS} | ||
86 | do | ||
87 | [[ ${i} = ${item} ]] && return 1 | ||
88 | done | ||
89 | |||
90 | return 0 | ||
91 | } | ||
92 | |||
93 | niro | 654 | checklist_processeddeps() |
94 | { | ||
95 | local i | ||
96 | local item="$1" | ||
97 | |||
98 | for i in ${PROCESSEDDEPS} | ||
99 | do | ||
100 | [[ ${i} = ${item} ]] && return 1 | ||
101 | done | ||
102 | |||
103 | return 0 | ||
104 | } | ||
105 | |||
106 | niro | 226 | ##################### |
107 | niro | 1563 | ## depwalking /path/to/mage/file/.mage |
108 | depwalking() | ||
109 | niro | 226 | { |
110 | unset DEPEND | ||
111 | unset SDEPEND | ||
112 | unset MY_DEPEND | ||
113 | |||
114 | local DFILE | ||
115 | local SYM | ||
116 | local DEPNAME | ||
117 | local HIGHEST_DEPFILE | ||
118 | local MY_DEPEND | ||
119 | local REAL_PGKNAME | ||
120 | local VIRTUAL_NAME | ||
121 | local INSTALL_VIRTUAL | ||
122 | local PNAME | ||
123 | local PCAT | ||
124 | niro | 250 | local PVER |
125 | local PBUILD | ||
126 | niro | 226 | |
127 | DFILE="$1" | ||
128 | |||
129 | source ${DFILE} | ||
130 | niro | 778 | |
131 | # forced nodeps | ||
132 | if [[ ${NODEPS} = true ]] | ||
133 | then | ||
134 | DEPEND="" | ||
135 | SDEPEND="" | ||
136 | fi | ||
137 | |||
138 | niro | 226 | MY_DEPEND="${DEPEND}" |
139 | |||
140 | # for srcinstall & srcdepend only; SDEPEND also needed | ||
141 | niro | 231 | if [[ ${METHOD} = srcinstall ]] || \ |
142 | [[ ${METHOD} = srcpretend ]] || \ | ||
143 | [[ ${METHOD} = srcupgrade ]] || \ | ||
144 | [[ ${METHOD} = srcuppretend ]] | ||
145 | niro | 226 | then |
146 | # only if SDEPEND is not zero | ||
147 | if [ -n "${SDEPEND}" ] | ||
148 | then | ||
149 | # crlf is substantly needed !! | ||
150 | if [ -n "${MY_DEPEND}" ] | ||
151 | then | ||
152 | MY_DEPEND="${MY_DEPEND} | ||
153 | ${SDEPEND}" | ||
154 | else | ||
155 | MY_DEPEND="${SDEPEND}" | ||
156 | fi | ||
157 | fi | ||
158 | fi | ||
159 | |||
160 | niro | 2210 | if [[ ${METHOD} = install-build-prerequisites ]] || \ |
161 | [[ ${METHOD} = pretend-build-prerequisites ]] | ||
162 | then | ||
163 | # only one time | ||
164 | if [[ ${LOOP_COUNTER} -lt 1 ]] | ||
165 | then | ||
166 | # only if SDEPEND is not zero | ||
167 | if [ -n "${SDEPEND}" ] | ||
168 | then | ||
169 | # crlf is substantly needed !! | ||
170 | if [ -n "${MY_DEPEND}" ] | ||
171 | then | ||
172 | MY_DEPEND="${MY_DEPEND} | ||
173 | ${SDEPEND}" | ||
174 | else | ||
175 | MY_DEPEND="${SDEPEND}" | ||
176 | fi | ||
177 | fi | ||
178 | fi | ||
179 | LOOP_COUNTER=${LOOP_COUNTER}+1 | ||
180 | fi | ||
181 | |||
182 | niro | 226 | unset DEPEND |
183 | unset SDEPEND | ||
184 | |||
185 | if [ -z "${MY_DEPEND}" ] | ||
186 | then | ||
187 | return 1 | ||
188 | fi | ||
189 | |||
190 | while read SYM DEPNAME | ||
191 | do | ||
192 | niro | 2221 | if [[ ${DEBUG} = 1 ]] |
193 | then | ||
194 | echo "DEBUG: DEPNAME='${DEPNAME}'" >&2 | ||
195 | fi | ||
196 | |||
197 | niro | 656 | # exclude empty depnames |
198 | [[ -z ${DEPNAME} ]] && continue | ||
199 | |||
200 | niro | 654 | # 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 | niro | 677 | # 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 | niro | 654 | |
214 | niro | 226 | HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") |
215 | niro | 2141 | if [[ -z ${HIGHEST_DEPFILE} ]] |
216 | then | ||
217 | INVALID_DEPS+=" ${DEPNAME}:${DFILE}" | ||
218 | continue | ||
219 | fi | ||
220 | niro | 226 | |
221 | PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" | ||
222 | PNAME="$(magename2pname ${HIGHEST_DEPFILE})" | ||
223 | PVER="$(magename2pver ${HIGHEST_DEPFILE})" | ||
224 | PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})" | ||
225 | |||
226 | niro | 1562 | ## dep already in ALLDEPS? then going on |
227 | niro | 598 | |
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 | niro | 226 | then |
232 | niro | 1564 | ### check if the dependency is already installed ### |
233 | niro | 226 | if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
234 | then | ||
235 | niro | 1563 | depwalking ${HIGHEST_DEPFILE} |
236 | niro | 226 | ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}" |
237 | fi | ||
238 | fi | ||
239 | done << EOF | ||
240 | ${MY_DEPEND} | ||
241 | EOF | ||
242 | return 0 | ||
243 | } | ||
244 | |||
245 | niro | 231 | [[ ${METHOD} = pretend ]] || \ |
246 | [[ ${METHOD} = srcpretend ]] || \ | ||
247 | [[ ${METHOD} = uppretend ]] || \ | ||
248 | niro | 2210 | [[ ${METHOD} = srcuppretend ]] || \ |
249 | [[ ${METHOD} = pretend-build-prerequisites ]] && \ | ||
250 | niro | 226 | echo -n "Calculating dependencies ... " |
251 | |||
252 | |||
253 | niro | 231 | 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 | niro | 226 | |
264 | niro | 250 | # get the highest mage file from mage-db |
265 | MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" | ||
266 | niro | 226 | |
267 | niro | 701 | # if no install candidate was found, record this |
268 | # and process with the next one | ||
269 | if [[ -z ${MAGEFILE} ]] | ||
270 | then | ||
271 | NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}" | ||
272 | continue | ||
273 | fi | ||
274 | |||
275 | niro | 250 | # now get the pver&pbuild from the new file |
276 | PVER="$(magename2pver ${MAGEFILE})" | ||
277 | PBUILD="$(magename2pbuild ${MAGEFILE})" | ||
278 | |||
279 | niro | 1562 | # do not walk files which are installed |
280 | niro | 250 | if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
281 | then | ||
282 | # get dependencies the package | ||
283 | niro | 1563 | depwalking ${MAGEFILE} |
284 | niro | 250 | fi |
285 | niro | 231 | done |
286 | else | ||
287 | niro | 2210 | LOOP_COUNTER=0 |
288 | niro | 1562 | # get all dependencies of the package |
289 | niro | 1563 | depwalking ${MAGEFILE} |
290 | niro | 2195 | fi |
291 | niro | 226 | |
292 | niro | 2210 | if [[ ${METHOD} != install-build-prerequisites ]] && |
293 | [[ ${METHOD} != pretend-build-prerequisites ]] | ||
294 | niro | 2195 | then |
295 | niro | 2210 | # now add the package itself to the dependencies |
296 | # (if not exists already) | ||
297 | if checklist_alldeps "${MAGEFILE}" | ||
298 | then | ||
299 | ALLDEPS="${ALLDEPS} ${MAGEFILE}" | ||
300 | fi | ||
301 | niro | 231 | fi |
302 | |||
303 | [[ ${METHOD} = pretend ]] || \ | ||
304 | [[ ${METHOD} = srcpretend ]] || \ | ||
305 | [[ ${METHOD} = uppretend ]] || \ | ||
306 | niro | 2210 | [[ ${METHOD} = srcuppretend ]] || \ |
307 | [[ ${METHOD} = pretend-build-prerequisites ]] && \ | ||
308 | niro | 231 | echo "done" |
309 | |||
310 | |||
311 | niro | 226 | ## show output of pretend |
312 | niro | 231 | if [[ ${METHOD} = pretend ]] || \ |
313 | [[ ${METHOD} = srcpretend ]] || \ | ||
314 | [[ ${METHOD} = uppretend ]] || \ | ||
315 | niro | 2210 | [[ ${METHOD} = srcuppretend ]] || \ |
316 | [[ ${METHOD} = pretend-build-prerequisites ]] | ||
317 | niro | 226 | then |
318 | # this is a little bit faster | ||
319 | declare -i x=0 | ||
320 | echo -n "Building dependencies list ... " | ||
321 | for i in ${ALLDEPS} | ||
322 | do | ||
323 | (( x++ )) | ||
324 | k="$x" | ||
325 | [ ${x} -le 9 ] && k="0${k}" | ||
326 | #[ ${x} -le 99 ] && k="0${k}" | ||
327 | PCAT="$(magename2pcat ${i})" | ||
328 | PNAME="$(magename2pname ${i})" | ||
329 | PVER="$(magename2pver ${i})" | ||
330 | PBUILD="$(magename2pbuild ${i})" | ||
331 | if [ -z "${list}" ] | ||
332 | then | ||
333 | niro | 2220 | list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
334 | niro | 226 | else |
335 | list="${list} | ||
336 | \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" | ||
337 | fi | ||
338 | unset PCAT PNAME PVER PBUILD | ||
339 | done | ||
340 | echo "done" | ||
341 | echo -e "${list}" | ||
342 | echo | ||
343 | niro | 701 | |
344 | niro | 2141 | if [[ ! -z ${INVALID_DEPS} ]] |
345 | then | ||
346 | echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}" | ||
347 | for i in ${INVALID_DEPS} | ||
348 | do | ||
349 | _dep="${i%%:*}" | ||
350 | _mage="${i##*:}" | ||
351 | echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}" | ||
352 | done | ||
353 | echo | ||
354 | fi | ||
355 | |||
356 | niro | 701 | if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]] |
357 | then | ||
358 | echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}" | ||
359 | for i in ${NO_UPGRADE_CANDIDATE} | ||
360 | do | ||
361 | echo -e "${COLRED} ${i}${COLDEFAULT}" | ||
362 | done | ||
363 | echo | ||
364 | echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}" | ||
365 | echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}" | ||
366 | niro | 887 | echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}" |
367 | niro | 701 | echo |
368 | fi | ||
369 | niro | 226 | fi |
370 | |||
371 | ## return output from src/install deps | ||
372 | niro | 231 | [[ ${METHOD} = install ]] || \ |
373 | [[ ${METHOD} = srcinstall ]] || \ | ||
374 | [[ ${METHOD} = upgrade ]] || \ | ||
375 | niro | 2210 | [[ ${METHOD} = srcupgrade ]] || \ |
376 | [[ ${METHOD} = install-build-prerequisites ]] && \ | ||
377 | niro | 231 | echo "${ALLDEPS}" |
Properties
Name | Value |
---|---|
svn:executable | * |