Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2838 - (hide annotations) (download) (as text)
Wed Oct 22 12:26:49 2014 UTC (9 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 9948 byte(s)
-load mage-features to support them with the smagesource() function
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 niro 2838 # load mage-features to support them with smagesource()
95     load_mage_features
96    
97 niro 226 # other needed vars
98     ALLDEPS=""
99 niro 2360 if [[ -n ${SMAGEFILE} ]]
100     then
101     if [[ -e ${SMAGEFILE} ]]
102     then
103     smagesource "${SMAGEFILE}"
104     else
105     die "Smage file '${SMAGEFILE}' does not exist!"
106     fi
107     fi
108 niro 226 MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
109    
110 niro 598 # much faster than fgrep
111     checklist_alldeps()
112     {
113     local i
114     local item="$1"
115    
116     for i in ${ALLDEPS}
117     do
118     [[ ${i} = ${item} ]] && return 1
119     done
120    
121     return 0
122     }
123    
124 niro 654 checklist_processeddeps()
125     {
126     local i
127     local item="$1"
128    
129     for i in ${PROCESSEDDEPS}
130     do
131     [[ ${i} = ${item} ]] && return 1
132     done
133    
134     return 0
135     }
136    
137 niro 226 #####################
138 niro 1563 ## depwalking /path/to/mage/file/.mage
139     depwalking()
140 niro 226 {
141     unset DEPEND
142     unset SDEPEND
143     unset MY_DEPEND
144    
145     local DFILE
146     local SYM
147     local DEPNAME
148     local HIGHEST_DEPFILE
149     local MY_DEPEND
150     local REAL_PGKNAME
151     local VIRTUAL_NAME
152     local INSTALL_VIRTUAL
153     local PNAME
154     local PCAT
155 niro 250 local PVER
156     local PBUILD
157 niro 226
158     DFILE="$1"
159    
160 niro 2285 # debug info
161     decho "depwalking magefile '${DFILE}'"
162     decho
163 niro 2281
164 niro 226 source ${DFILE}
165 niro 778
166     # forced nodeps
167     if [[ ${NODEPS} = true ]]
168     then
169     DEPEND=""
170     SDEPEND=""
171     fi
172    
173 niro 226 MY_DEPEND="${DEPEND}"
174    
175     # for srcinstall & srcdepend only; SDEPEND also needed
176 niro 2286 if [[ ${METHOD} = srcinstall ]] ||
177     [[ ${METHOD} = srcpretend ]] ||
178     [[ ${METHOD} = srcupgrade ]] ||
179     [[ ${METHOD} = srcuppretend ]] ||
180     [[ ${METHOD} = install-build-prerequisites ]] ||
181     [[ ${METHOD} = pretend-build-prerequisites ]]
182 niro 226 then
183     # only if SDEPEND is not zero
184     if [ -n "${SDEPEND}" ]
185     then
186     # crlf is substantly needed !!
187     if [ -n "${MY_DEPEND}" ]
188     then
189     MY_DEPEND="${MY_DEPEND}
190     ${SDEPEND}"
191     else
192     MY_DEPEND="${SDEPEND}"
193     fi
194     fi
195     fi
196    
197     unset DEPEND
198     unset SDEPEND
199    
200     if [ -z "${MY_DEPEND}" ]
201     then
202 niro 2285 decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
203 niro 226 return 1
204     fi
205    
206     while read SYM DEPNAME
207     do
208 niro 2285 # debug info
209     decho "DEPNAME='${DEPNAME}'"
210 niro 2221
211 niro 656 # exclude empty depnames
212     [[ -z ${DEPNAME} ]] && continue
213    
214 niro 654 # exclude all already processed deps -without version
215     if ! checklist_processeddeps "${DEPNAME%-*}"
216     then
217     continue
218     fi
219    
220     # mark depfile as processed to prevent double runs -without version
221 niro 677 # but do not add any virtuals to PROCESSEDDEPS or their resolved
222 niro 2738 # pkgnames will be ignored and they are missing on the dependency-list
223 niro 677 if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
224     then
225     PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
226     fi
227 niro 654
228 niro 226 HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
229 niro 2141 if [[ -z ${HIGHEST_DEPFILE} ]]
230     then
231     INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
232     continue
233     fi
234 niro 226
235     PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
236     PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
237     PVER="$(magename2pver ${HIGHEST_DEPFILE})"
238     PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
239    
240 niro 1562 ## dep already in ALLDEPS? then going on
241 niro 598
242     # usage of fgrep is extremly slow and consumes a lot of cpu power
243     #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
244     if checklist_alldeps "${HIGHEST_DEPFILE}"
245 niro 226 then
246 niro 1564 ### check if the dependency is already installed ###
247 niro 226 if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
248     then
249 niro 2826 # but first get all deps of highest_depfile to catch all dependencies of it
250     depwalking ${HIGHEST_DEPFILE}
251 niro 226 ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
252 niro 2285 decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
253 niro 226 fi
254     fi
255     done << EOF
256     ${MY_DEPEND}
257     EOF
258     return 0
259     }
260    
261 niro 231 [[ ${METHOD} = pretend ]] || \
262     [[ ${METHOD} = srcpretend ]] || \
263     [[ ${METHOD} = uppretend ]] || \
264 niro 2210 [[ ${METHOD} = srcuppretend ]] || \
265     [[ ${METHOD} = pretend-build-prerequisites ]] && \
266 niro 226 echo -n "Calculating dependencies ... "
267    
268    
269 niro 231 if [[ ${METHOD} = upgrade ]] || \
270     [[ ${METHOD} = srcupgrade ]] || \
271     [[ ${METHOD} = uppretend ]] || \
272     [[ ${METHOD} = srcuppretend ]]
273     then
274     INSTDEPS="$(${MLIBDIR}/magequery.sh -i)"
275     for dep in ${INSTDEPS}
276     do
277     PCAT="$(magename2pcat ${dep} installdb)"
278     PNAME="$(magename2pname ${dep})"
279 niro 226
280 niro 250 # get the highest mage file from mage-db
281     MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
282 niro 226
283 niro 2285 # debug info
284     decho "dep='${dep}'"
285     decho "PCAT='${PCAT}'"
286     decho "PNAME='${PNAME}'"
287     decho "MAGEFILE='${MAGEFILE}'"
288 niro 2281
289 niro 701 # if no install candidate was found, record this
290     # and process with the next one
291     if [[ -z ${MAGEFILE} ]]
292     then
293     NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
294 niro 2285 decho "added to NO_UPGRADE_CANDIDATE"
295 niro 701 continue
296     fi
297    
298 niro 250 # now get the pver&pbuild from the new file
299     PVER="$(magename2pver ${MAGEFILE})"
300     PBUILD="$(magename2pbuild ${MAGEFILE})"
301    
302 niro 2285 # debug info
303     decho "PVER='${PVER}'"
304     decho "PBUILD='${PBUILD}'"
305 niro 2281
306 niro 1562 # do not walk files which are installed
307 niro 250 if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
308     then
309     # get dependencies the package
310 niro 1563 depwalking ${MAGEFILE}
311 niro 2280
312     # now add the package itself to the dependencies
313     # (if not exists already)
314     if checklist_alldeps "${MAGEFILE}"
315     then
316 niro 2285 decho "added '${MAGEFILE}' to ALLDEPS"
317 niro 2280 ALLDEPS="${ALLDEPS} ${MAGEFILE}"
318     fi
319 niro 2281 else
320 niro 2376 # debug info
321     decho "ignored package"
322     decho
323 niro 250 fi
324 niro 231 done
325     else
326 niro 1562 # get all dependencies of the package
327 niro 2360 if [[ -n ${SMAGEFILE} ]]
328     then
329     depwalking "${SMAGEFILE}"
330     else
331     depwalking "${MAGEFILE}"
332     fi
333 niro 2195 fi
334 niro 226
335 niro 2210 if [[ ${METHOD} != install-build-prerequisites ]] &&
336 niro 2280 [[ ${METHOD} != pretend-build-prerequisites ]] &&
337     [[ ${METHOD} != upgrade ]] &&
338     [[ ${METHOD} != uppretend ]] &&
339     [[ ${METHOD} != srcupgrade ]] &&
340     [[ ${METHOD} != srcuppretend ]]
341 niro 2195 then
342 niro 2210 # now add the package itself to the dependencies
343     # (if not exists already)
344     if checklist_alldeps "${MAGEFILE}"
345     then
346 niro 2285 decho "added '${MAGEFILE}' to ALLDEPS"
347 niro 2210 ALLDEPS="${ALLDEPS} ${MAGEFILE}"
348     fi
349 niro 231 fi
350    
351     [[ ${METHOD} = pretend ]] || \
352     [[ ${METHOD} = srcpretend ]] || \
353     [[ ${METHOD} = uppretend ]] || \
354 niro 2210 [[ ${METHOD} = srcuppretend ]] || \
355     [[ ${METHOD} = pretend-build-prerequisites ]] && \
356 niro 231 echo "done"
357    
358    
359 niro 226 ## show output of pretend
360 niro 231 if [[ ${METHOD} = pretend ]] || \
361     [[ ${METHOD} = srcpretend ]] || \
362     [[ ${METHOD} = uppretend ]] || \
363 niro 2210 [[ ${METHOD} = srcuppretend ]] || \
364     [[ ${METHOD} = pretend-build-prerequisites ]]
365 niro 226 then
366     # this is a little bit faster
367     declare -i x=0
368     echo -n "Building dependencies list ... "
369     for i in ${ALLDEPS}
370     do
371     (( x++ ))
372     k="$x"
373     [ ${x} -le 9 ] && k="0${k}"
374     #[ ${x} -le 99 ] && k="0${k}"
375     PCAT="$(magename2pcat ${i})"
376     PNAME="$(magename2pname ${i})"
377     PVER="$(magename2pver ${i})"
378     PBUILD="$(magename2pbuild ${i})"
379     if [ -z "${list}" ]
380     then
381 niro 2220 list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
382 niro 226 else
383     list="${list}
384     \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
385     fi
386     unset PCAT PNAME PVER PBUILD
387     done
388     echo "done"
389     echo -e "${list}"
390     echo
391 niro 701
392 niro 2141 if [[ ! -z ${INVALID_DEPS} ]]
393     then
394     echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}"
395     for i in ${INVALID_DEPS}
396     do
397     _dep="${i%%:*}"
398     _mage="${i##*:}"
399     echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}"
400     done
401     echo
402     fi
403    
404 niro 701 if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
405     then
406     echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
407     for i in ${NO_UPGRADE_CANDIDATE}
408     do
409     echo -e "${COLRED} ${i}${COLDEFAULT}"
410     done
411     echo
412     echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"
413     echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"
414 niro 887 echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
415 niro 701 echo
416     fi
417 niro 226 fi
418    
419     ## return output from src/install deps
420 niro 231 [[ ${METHOD} = install ]] || \
421     [[ ${METHOD} = srcinstall ]] || \
422     [[ ${METHOD} = upgrade ]] || \
423 niro 2210 [[ ${METHOD} = srcupgrade ]] || \
424     [[ ${METHOD} = install-build-prerequisites ]] && \
425 niro 231 echo "${ALLDEPS}"

Properties

Name Value
svn:executable *