Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *