Magellan Linux

Annotation of /branches/mage-next/src/depwalker.in

Parent Directory Parent Directory | Revision Log Revision Log


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