Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *