Annotation of /branches/mage-next/src/depwalker.in
Parent Directory | Revision Log
Revision 1559 -
(hide annotations)
(download)
(as text)
Wed Dec 28 09:54:25 2011 UTC (12 years, 9 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/depwalker.sh
File MIME type: application/x-sh
File size: 8209 byte(s)
Wed Dec 28 09:54:25 2011 UTC (12 years, 9 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/depwalker.sh
File MIME type: application/x-sh
File size: 8209 byte(s)
-fixed header
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 | # for tests only |
25 | niro | 231 | # source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage.rc.global |
26 | # source /etc/mage.rc | ||
27 | # source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh | ||
28 | # MLIBDIR=/home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage | ||
29 | niro | 226 | |
30 | niro | 231 | # not serious if missing, only needed for colors |
31 | niro | 226 | [ -f /etc/init.d/functions ] && source /etc/init.d/functions |
32 | |||
33 | # disable colors if wanted | ||
34 | if [[ ${NOCOLORS} = true ]] | ||
35 | then | ||
36 | COLRED="" | ||
37 | COLGREEN="" | ||
38 | COLYELLOW="" | ||
39 | COLBLUE="" | ||
40 | COLMAGENTA="" | ||
41 | COLWHITE="" | ||
42 | COLDEFAULT="" | ||
43 | fi | ||
44 | |||
45 | usage() | ||
46 | { | ||
47 | echo | ||
48 | echo "Usage: $(basename $0) [command] [arg] ..." | ||
49 | echo | ||
50 | echo " -h --help shows this help" | ||
51 | echo " -c --pcat categorie of the package" | ||
52 | echo " -n --pname name of the package" | ||
53 | echo " -v --pver version number of the package" | ||
54 | echo " -b --pbuild build number of the package" | ||
55 | echo " -m --method which calc method should be used:" | ||
56 | niro | 231 | echo " install, srcinstall, depend, srcdepend" |
57 | echo " upgrade, srcupgrade" | ||
58 | niro | 226 | echo |
59 | niro | 701 | echo "method, name, version and build must be given !" |
60 | niro | 226 | echo |
61 | exit 1 | ||
62 | } | ||
63 | |||
64 | # very basic getops | ||
65 | for i in $* | ||
66 | do | ||
67 | case $1 in | ||
68 | --pcat|-c) shift; PCAT="$1" ;; | ||
69 | --pname|-n) shift; PNAME="$1" ;; | ||
70 | --pver|-v) shift; PVER="$1" ;; | ||
71 | --pbuild|-b) shift; PBUILD="$1" ;; | ||
72 | --method|-m) shift; METHOD="$1" ;; | ||
73 | --help|-h) usage ;; | ||
74 | esac | ||
75 | shift | ||
76 | done | ||
77 | |||
78 | # sanity checks; abort if not given | ||
79 | [ -z "${PCAT}" ] && usage | ||
80 | [ -z "${PNAME}" ] && usage | ||
81 | [ -z "${PVER}" ] && usage | ||
82 | [ -z "${PBUILD}" ] && usage | ||
83 | [ -z "${METHOD}" ] && usage | ||
84 | |||
85 | # check needed global vars | ||
86 | [ -z "${MAGEDIR}" ] && die "\$MAGEDIR not set." | ||
87 | [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set." | ||
88 | [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set." | ||
89 | |||
90 | # other needed vars | ||
91 | ALLDEPS="" | ||
92 | 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 | ## rumwandern /path/to/mage/file/.mage | ||
123 | rumwandern() | ||
124 | { | ||
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 | source ${DFILE} | ||
145 | niro | 778 | |
146 | # forced nodeps | ||
147 | if [[ ${NODEPS} = true ]] | ||
148 | then | ||
149 | DEPEND="" | ||
150 | SDEPEND="" | ||
151 | fi | ||
152 | |||
153 | niro | 226 | MY_DEPEND="${DEPEND}" |
154 | |||
155 | # for srcinstall & srcdepend only; SDEPEND also needed | ||
156 | niro | 231 | if [[ ${METHOD} = srcinstall ]] || \ |
157 | [[ ${METHOD} = srcpretend ]] || \ | ||
158 | [[ ${METHOD} = srcupgrade ]] || \ | ||
159 | [[ ${METHOD} = srcuppretend ]] | ||
160 | niro | 226 | 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 | |||
175 | unset DEPEND | ||
176 | unset SDEPEND | ||
177 | |||
178 | if [ -z "${MY_DEPEND}" ] | ||
179 | then | ||
180 | return 1 | ||
181 | fi | ||
182 | |||
183 | while read SYM DEPNAME | ||
184 | do | ||
185 | niro | 656 | # exclude empty depnames |
186 | [[ -z ${DEPNAME} ]] && continue | ||
187 | |||
188 | niro | 654 | # exclude all already processed deps -without version |
189 | if ! checklist_processeddeps "${DEPNAME%-*}" | ||
190 | then | ||
191 | continue | ||
192 | fi | ||
193 | |||
194 | # mark depfile as processed to prevent double runs -without version | ||
195 | niro | 677 | # but do not add any virtuals to PROCESSEDDEPS or their resolved |
196 | # pkgnames will be ignored and they are missing on the dependecy-list | ||
197 | if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]] | ||
198 | then | ||
199 | PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}" | ||
200 | fi | ||
201 | niro | 654 | |
202 | niro | 226 | HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") |
203 | |||
204 | PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" | ||
205 | PNAME="$(magename2pname ${HIGHEST_DEPFILE})" | ||
206 | PVER="$(magename2pver ${HIGHEST_DEPFILE})" | ||
207 | PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})" | ||
208 | |||
209 | ## check ob schon in ALLDEPS enthalten dann mach weiter | ||
210 | niro | 598 | |
211 | # usage of fgrep is extremly slow and consumes a lot of cpu power | ||
212 | #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ] | ||
213 | if checklist_alldeps "${HIGHEST_DEPFILE}" | ||
214 | niro | 226 | then |
215 | ### check ob DFILE schon installiert ist ### | ||
216 | if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] | ||
217 | then | ||
218 | rumwandern ${HIGHEST_DEPFILE} | ||
219 | ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}" | ||
220 | fi | ||
221 | fi | ||
222 | done << EOF | ||
223 | ${MY_DEPEND} | ||
224 | EOF | ||
225 | return 0 | ||
226 | } | ||
227 | |||
228 | |||
229 | ### abort if this package is already installed (retval 3) | ||
230 | # maybe later ? | ||
231 | #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3 | ||
232 | |||
233 | niro | 231 | [[ ${METHOD} = pretend ]] || \ |
234 | [[ ${METHOD} = srcpretend ]] || \ | ||
235 | [[ ${METHOD} = uppretend ]] || \ | ||
236 | [[ ${METHOD} = srcuppretend ]] && \ | ||
237 | niro | 226 | echo -n "Calculating dependencies ... " |
238 | |||
239 | |||
240 | niro | 231 | if [[ ${METHOD} = upgrade ]] || \ |
241 | [[ ${METHOD} = srcupgrade ]] || \ | ||
242 | [[ ${METHOD} = uppretend ]] || \ | ||
243 | [[ ${METHOD} = srcuppretend ]] | ||
244 | then | ||
245 | INSTDEPS="$(${MLIBDIR}/magequery.sh -i)" | ||
246 | for dep in ${INSTDEPS} | ||
247 | do | ||
248 | PCAT="$(magename2pcat ${dep} installdb)" | ||
249 | PNAME="$(magename2pname ${dep})" | ||
250 | niro | 226 | |
251 | niro | 250 | # get the highest mage file from mage-db |
252 | MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" | ||
253 | niro | 226 | |
254 | niro | 701 | # if no install candidate was found, record this |
255 | # and process with the next one | ||
256 | if [[ -z ${MAGEFILE} ]] | ||
257 | then | ||
258 | NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}" | ||
259 | continue | ||
260 | fi | ||
261 | |||
262 | niro | 250 | # now get the pver&pbuild from the new file |
263 | PVER="$(magename2pver ${MAGEFILE})" | ||
264 | PBUILD="$(magename2pbuild ${MAGEFILE})" | ||
265 | |||
266 | # do not wander files which are installed | ||
267 | if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] | ||
268 | then | ||
269 | # get dependencies the package | ||
270 | rumwandern ${MAGEFILE} | ||
271 | |||
272 | # now add the package itself to the dependencies | ||
273 | # (if not exists already) | ||
274 | niro | 598 | #if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ] |
275 | if checklist_alldeps "${MAGEFILE}" | ||
276 | niro | 250 | then |
277 | ALLDEPS="${ALLDEPS} ${MAGEFILE}" | ||
278 | fi | ||
279 | fi | ||
280 | niro | 231 | done |
281 | else | ||
282 | # get dependencies the package | ||
283 | rumwandern ${MAGEFILE} | ||
284 | niro | 226 | |
285 | niro | 231 | # now add the package itself to the dependencies |
286 | ALLDEPS="${ALLDEPS} ${MAGEFILE}" | ||
287 | fi | ||
288 | |||
289 | [[ ${METHOD} = pretend ]] || \ | ||
290 | [[ ${METHOD} = srcpretend ]] || \ | ||
291 | [[ ${METHOD} = uppretend ]] || \ | ||
292 | [[ ${METHOD} = srcuppretend ]] && \ | ||
293 | echo "done" | ||
294 | |||
295 | |||
296 | niro | 226 | ## show output of pretend |
297 | niro | 231 | if [[ ${METHOD} = pretend ]] || \ |
298 | [[ ${METHOD} = srcpretend ]] || \ | ||
299 | [[ ${METHOD} = uppretend ]] || \ | ||
300 | [[ ${METHOD} = srcuppretend ]] | ||
301 | niro | 226 | then |
302 | # this is a little bit faster | ||
303 | declare -i x=0 | ||
304 | echo -n "Building dependencies list ... " | ||
305 | for i in ${ALLDEPS} | ||
306 | do | ||
307 | (( x++ )) | ||
308 | k="$x" | ||
309 | [ ${x} -le 9 ] && k="0${k}" | ||
310 | #[ ${x} -le 99 ] && k="0${k}" | ||
311 | PCAT="$(magename2pcat ${i})" | ||
312 | PNAME="$(magename2pname ${i})" | ||
313 | PVER="$(magename2pver ${i})" | ||
314 | PBUILD="$(magename2pbuild ${i})" | ||
315 | if [ -z "${list}" ] | ||
316 | then | ||
317 | list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" | ||
318 | else | ||
319 | list="${list} | ||
320 | \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" | ||
321 | fi | ||
322 | unset PCAT PNAME PVER PBUILD | ||
323 | done | ||
324 | echo "done" | ||
325 | echo -e "${list}" | ||
326 | echo | ||
327 | niro | 701 | |
328 | if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]] | ||
329 | then | ||
330 | echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}" | ||
331 | for i in ${NO_UPGRADE_CANDIDATE} | ||
332 | do | ||
333 | echo -e "${COLRED} ${i}${COLDEFAULT}" | ||
334 | done | ||
335 | echo | ||
336 | echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}" | ||
337 | echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}" | ||
338 | niro | 887 | echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}" |
339 | niro | 701 | echo |
340 | fi | ||
341 | niro | 226 | fi |
342 | |||
343 | ## return output from src/install deps | ||
344 | niro | 231 | [[ ${METHOD} = install ]] || \ |
345 | [[ ${METHOD} = srcinstall ]] || \ | ||
346 | [[ ${METHOD} = upgrade ]] || \ | ||
347 | [[ ${METHOD} = srcupgrade ]] && \ | ||
348 | echo "${ALLDEPS}" | ||
349 | niro | 226 | |
350 | # delete ${BUILDDIR}/virtuals if exists as not needed anymore | ||
351 | #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals |
Properties
Name | Value |
---|---|
svn:executable | * |