Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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