Magellan Linux

Contents of /trunk/mage/usr/lib/mage/depwalker.sh

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *