Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2831 - (hide annotations) (download) (as text)
Fri Sep 19 11:18:38 2014 UTC (9 years, 8 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 niro 226 #!/bin/bash
2 niro 1559 # $Id$
3 niro 2827 # dependency walker
4 niro 226
5     # default die function
6     die()
7     {
8     echo ${COLRED}"$@"${COLDEFAULT}
9     exit 1
10     }
11    
12 niro 2285 decho()
13     {
14     if [[ ${DEBUG} = 1 ]]
15     then
16     echo "DEBUG: $@" >&2
17     fi
18     }
19    
20 niro 231 # include all needed files
21 niro 235 [ -f /etc/mage.rc.global ] && \
22     source /etc/mage.rc.global || \
23     die "/etc/mage.rc.global missing"
24 niro 226
25 niro 419 [ -f ${MAGERC} ] && source ${MAGERC} || \
26     die "Your ${MAGERC} is missing. Aborting."
27 niro 231
28 niro 235 [ -f ${MLIBDIR}/mage4.functions.sh ] && \
29     source ${MLIBDIR}/mage4.functions.sh || \
30 niro 231 die "mage functions missing"
31    
32 niro 2360 [ -f ${MLIBDIR}/smage2.functions.sh ] && \
33     source ${MLIBDIR}/smage2.functions.sh || \
34     die "smage functions missing"
35    
36 niro 226 usage()
37     {
38     echo
39     echo "Usage: $(basename $0) [command] [arg] ..."
40     echo
41     echo " -h --help shows this help"
42 niro 2275 echo " -c --pcat category of the package"
43 niro 226 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 niro 2359 echo " install, srcinstall, pretend, srcpretend"
48 niro 2210 echo " upgrade, srcupgrade,"
49 niro 2274 echo " install-build-prerequisites,"
50     echo " pretend-build-prerequisites"
51 niro 2269 echo " -d --debug enable debug mode"
52 niro 2360 echo " -s --smage use a smage to calculate dependencies"
53 niro 226 echo
54 niro 2276 echo "method, category, name, version and build must be given !"
55 niro 226 echo
56     exit 1
57     }
58    
59 niro 2831 # set some sane defaults
60 niro 2221 DEBUG=0
61 niro 2831 SMAGE_DEPEND=0
62 niro 2221
63 niro 226 # 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 niro 2221 --debug|-d) shift; DEBUG=1 ;;
73 niro 2831 --smage|-s) shift; SMAGEFILE="$1"; SMAGE_DEPEND=1; SILENT=1; FVERBOSE=off ;;
74 niro 226 --help|-h) usage ;;
75     esac
76     shift
77     done
78    
79     # sanity checks; abort if not given
80 niro 2360 if [[ -z ${SMAGEFILE} ]]
81     then
82     [ -z "${PCAT}" ] && usage
83     [ -z "${PNAME}" ] && usage
84     [ -z "${PVER}" ] && usage
85     [ -z "${PBUILD}" ] && usage
86     fi
87 niro 226 [ -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 niro 2360 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 niro 226 MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
106    
107 niro 598 # 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 niro 654 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 niro 226 #####################
135 niro 1563 ## depwalking /path/to/mage/file/.mage
136     depwalking()
137 niro 226 {
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 niro 250 local PVER
153     local PBUILD
154 niro 226
155     DFILE="$1"
156    
157 niro 2285 # debug info
158     decho "depwalking magefile '${DFILE}'"
159     decho
160 niro 2281
161 niro 226 source ${DFILE}
162 niro 778
163     # forced nodeps
164     if [[ ${NODEPS} = true ]]
165     then
166     DEPEND=""
167     SDEPEND=""
168     fi
169    
170 niro 226 MY_DEPEND="${DEPEND}"
171    
172     # for srcinstall & srcdepend only; SDEPEND also needed
173 niro 2286 if [[ ${METHOD} = srcinstall ]] ||
174     [[ ${METHOD} = srcpretend ]] ||
175     [[ ${METHOD} = srcupgrade ]] ||
176     [[ ${METHOD} = srcuppretend ]] ||
177     [[ ${METHOD} = install-build-prerequisites ]] ||
178     [[ ${METHOD} = pretend-build-prerequisites ]]
179 niro 226 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 niro 2285 decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
200 niro 226 return 1
201     fi
202    
203     while read SYM DEPNAME
204     do
205 niro 2285 # debug info
206     decho "DEPNAME='${DEPNAME}'"
207 niro 2221
208 niro 656 # exclude empty depnames
209     [[ -z ${DEPNAME} ]] && continue
210    
211 niro 654 # 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 niro 677 # but do not add any virtuals to PROCESSEDDEPS or their resolved
219 niro 2738 # pkgnames will be ignored and they are missing on the dependency-list
220 niro 677 if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
221     then
222     PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
223     fi
224 niro 654
225 niro 226 HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
226 niro 2141 if [[ -z ${HIGHEST_DEPFILE} ]]
227     then
228     INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
229     continue
230     fi
231 niro 226
232     PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
233     PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
234     PVER="$(magename2pver ${HIGHEST_DEPFILE})"
235     PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
236    
237 niro 1562 ## dep already in ALLDEPS? then going on
238 niro 598
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 niro 226 then
243 niro 1564 ### check if the dependency is already installed ###
244 niro 226 if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
245     then
246 niro 2826 # but first get all deps of highest_depfile to catch all dependencies of it
247     depwalking ${HIGHEST_DEPFILE}
248 niro 226 ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
249 niro 2285 decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
250 niro 226 fi
251     fi
252     done << EOF
253     ${MY_DEPEND}
254     EOF
255     return 0
256     }
257    
258 niro 231 [[ ${METHOD} = pretend ]] || \
259     [[ ${METHOD} = srcpretend ]] || \
260     [[ ${METHOD} = uppretend ]] || \
261 niro 2210 [[ ${METHOD} = srcuppretend ]] || \
262     [[ ${METHOD} = pretend-build-prerequisites ]] && \
263 niro 226 echo -n "Calculating dependencies ... "
264    
265    
266 niro 231 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 niro 226
277 niro 250 # get the highest mage file from mage-db
278     MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
279 niro 226
280 niro 2285 # debug info
281     decho "dep='${dep}'"
282     decho "PCAT='${PCAT}'"
283     decho "PNAME='${PNAME}'"
284     decho "MAGEFILE='${MAGEFILE}'"
285 niro 2281
286 niro 701 # 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 niro 2285 decho "added to NO_UPGRADE_CANDIDATE"
292 niro 701 continue
293     fi
294    
295 niro 250 # now get the pver&pbuild from the new file
296     PVER="$(magename2pver ${MAGEFILE})"
297     PBUILD="$(magename2pbuild ${MAGEFILE})"
298    
299 niro 2285 # debug info
300     decho "PVER='${PVER}'"
301     decho "PBUILD='${PBUILD}'"
302 niro 2281
303 niro 1562 # do not walk files which are installed
304 niro 250 if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
305     then
306     # get dependencies the package
307 niro 1563 depwalking ${MAGEFILE}
308 niro 2280
309     # now add the package itself to the dependencies
310     # (if not exists already)
311     if checklist_alldeps "${MAGEFILE}"
312     then
313 niro 2285 decho "added '${MAGEFILE}' to ALLDEPS"
314 niro 2280 ALLDEPS="${ALLDEPS} ${MAGEFILE}"
315     fi
316 niro 2281 else
317 niro 2376 # debug info
318     decho "ignored package"
319     decho
320 niro 250 fi
321 niro 231 done
322     else
323 niro 1562 # get all dependencies of the package
324 niro 2360 if [[ -n ${SMAGEFILE} ]]
325     then
326     depwalking "${SMAGEFILE}"
327     else
328     depwalking "${MAGEFILE}"
329     fi
330 niro 2195 fi
331 niro 226
332 niro 2210 if [[ ${METHOD} != install-build-prerequisites ]] &&
333 niro 2280 [[ ${METHOD} != pretend-build-prerequisites ]] &&
334     [[ ${METHOD} != upgrade ]] &&
335     [[ ${METHOD} != uppretend ]] &&
336     [[ ${METHOD} != srcupgrade ]] &&
337     [[ ${METHOD} != srcuppretend ]]
338 niro 2195 then
339 niro 2210 # now add the package itself to the dependencies
340     # (if not exists already)
341     if checklist_alldeps "${MAGEFILE}"
342     then
343 niro 2285 decho "added '${MAGEFILE}' to ALLDEPS"
344 niro 2210 ALLDEPS="${ALLDEPS} ${MAGEFILE}"
345     fi
346 niro 231 fi
347    
348     [[ ${METHOD} = pretend ]] || \
349     [[ ${METHOD} = srcpretend ]] || \
350     [[ ${METHOD} = uppretend ]] || \
351 niro 2210 [[ ${METHOD} = srcuppretend ]] || \
352     [[ ${METHOD} = pretend-build-prerequisites ]] && \
353 niro 231 echo "done"
354    
355    
356 niro 226 ## show output of pretend
357 niro 231 if [[ ${METHOD} = pretend ]] || \
358     [[ ${METHOD} = srcpretend ]] || \
359     [[ ${METHOD} = uppretend ]] || \
360 niro 2210 [[ ${METHOD} = srcuppretend ]] || \
361     [[ ${METHOD} = pretend-build-prerequisites ]]
362 niro 226 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 niro 2220 list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
379 niro 226 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 niro 701
389 niro 2141 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 niro 701 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 niro 887 echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
412 niro 701 echo
413     fi
414 niro 226 fi
415    
416     ## return output from src/install deps
417 niro 231 [[ ${METHOD} = install ]] || \
418     [[ ${METHOD} = srcinstall ]] || \
419     [[ ${METHOD} = upgrade ]] || \
420 niro 2210 [[ ${METHOD} = srcupgrade ]] || \
421     [[ ${METHOD} = install-build-prerequisites ]] && \
422 niro 231 echo "${ALLDEPS}"

Properties

Name Value
svn:executable *