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