Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *