Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1560 - (hide annotations) (download) (as text)
Wed Dec 28 09:55:37 2011 UTC (12 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 7686 byte(s)
-get colors and MLIBDIR from includes
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     echo " -c --pcat categorie of the package"
31     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     echo " upgrade, srcupgrade"
37 niro 226 echo
38 niro 701 echo "method, name, version and build must be given !"
39 niro 226 echo
40     exit 1
41     }
42    
43     # very basic getops
44     for i in $*
45     do
46     case $1 in
47     --pcat|-c) shift; PCAT="$1" ;;
48     --pname|-n) shift; PNAME="$1" ;;
49     --pver|-v) shift; PVER="$1" ;;
50     --pbuild|-b) shift; PBUILD="$1" ;;
51     --method|-m) shift; METHOD="$1" ;;
52     --help|-h) usage ;;
53     esac
54     shift
55     done
56    
57     # sanity checks; abort if not given
58     [ -z "${PCAT}" ] && usage
59     [ -z "${PNAME}" ] && usage
60     [ -z "${PVER}" ] && usage
61     [ -z "${PBUILD}" ] && usage
62     [ -z "${METHOD}" ] && usage
63    
64     # check needed global vars
65     [ -z "${MAGEDIR}" ] && die "\$MAGEDIR not set."
66     [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set."
67     [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set."
68    
69     # other needed vars
70     ALLDEPS=""
71     MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
72    
73 niro 598 # much faster than fgrep
74     checklist_alldeps()
75     {
76     local i
77     local item="$1"
78    
79     for i in ${ALLDEPS}
80     do
81     [[ ${i} = ${item} ]] && return 1
82     done
83    
84     return 0
85     }
86    
87 niro 654 checklist_processeddeps()
88     {
89     local i
90     local item="$1"
91    
92     for i in ${PROCESSEDDEPS}
93     do
94     [[ ${i} = ${item} ]] && return 1
95     done
96    
97     return 0
98     }
99    
100 niro 226 #####################
101     ## rumwandern /path/to/mage/file/.mage
102     rumwandern()
103     {
104     unset DEPEND
105     unset SDEPEND
106     unset MY_DEPEND
107    
108     local DFILE
109     local SYM
110     local DEPNAME
111     local HIGHEST_DEPFILE
112     local MY_DEPEND
113     local REAL_PGKNAME
114     local VIRTUAL_NAME
115     local INSTALL_VIRTUAL
116     local PNAME
117     local PCAT
118 niro 250 local PVER
119     local PBUILD
120 niro 226
121     DFILE="$1"
122    
123     source ${DFILE}
124 niro 778
125     # forced nodeps
126     if [[ ${NODEPS} = true ]]
127     then
128     DEPEND=""
129     SDEPEND=""
130     fi
131    
132 niro 226 MY_DEPEND="${DEPEND}"
133    
134     # for srcinstall & srcdepend only; SDEPEND also needed
135 niro 231 if [[ ${METHOD} = srcinstall ]] || \
136     [[ ${METHOD} = srcpretend ]] || \
137     [[ ${METHOD} = srcupgrade ]] || \
138     [[ ${METHOD} = srcuppretend ]]
139 niro 226 then
140     # only if SDEPEND is not zero
141     if [ -n "${SDEPEND}" ]
142     then
143     # crlf is substantly needed !!
144     if [ -n "${MY_DEPEND}" ]
145     then
146     MY_DEPEND="${MY_DEPEND}
147     ${SDEPEND}"
148     else
149     MY_DEPEND="${SDEPEND}"
150     fi
151     fi
152     fi
153    
154     unset DEPEND
155     unset SDEPEND
156    
157     if [ -z "${MY_DEPEND}" ]
158     then
159     return 1
160     fi
161    
162     while read SYM DEPNAME
163     do
164 niro 656 # exclude empty depnames
165     [[ -z ${DEPNAME} ]] && continue
166    
167 niro 654 # exclude all already processed deps -without version
168     if ! checklist_processeddeps "${DEPNAME%-*}"
169     then
170     continue
171     fi
172    
173     # mark depfile as processed to prevent double runs -without version
174 niro 677 # but do not add any virtuals to PROCESSEDDEPS or their resolved
175     # pkgnames will be ignored and they are missing on the dependecy-list
176     if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
177     then
178     PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
179     fi
180 niro 654
181 niro 226 HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
182    
183     PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
184     PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
185     PVER="$(magename2pver ${HIGHEST_DEPFILE})"
186     PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
187    
188     ## check ob schon in ALLDEPS enthalten dann mach weiter
189 niro 598
190     # usage of fgrep is extremly slow and consumes a lot of cpu power
191     #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
192     if checklist_alldeps "${HIGHEST_DEPFILE}"
193 niro 226 then
194     ### check ob DFILE schon installiert ist ###
195     if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
196     then
197     rumwandern ${HIGHEST_DEPFILE}
198     ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
199     fi
200     fi
201     done << EOF
202     ${MY_DEPEND}
203     EOF
204     return 0
205     }
206    
207    
208     ### abort if this package is already installed (retval 3)
209     # maybe later ?
210     #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3
211    
212 niro 231 [[ ${METHOD} = pretend ]] || \
213     [[ ${METHOD} = srcpretend ]] || \
214     [[ ${METHOD} = uppretend ]] || \
215     [[ ${METHOD} = srcuppretend ]] && \
216 niro 226 echo -n "Calculating dependencies ... "
217    
218    
219 niro 231 if [[ ${METHOD} = upgrade ]] || \
220     [[ ${METHOD} = srcupgrade ]] || \
221     [[ ${METHOD} = uppretend ]] || \
222     [[ ${METHOD} = srcuppretend ]]
223     then
224     INSTDEPS="$(${MLIBDIR}/magequery.sh -i)"
225     for dep in ${INSTDEPS}
226     do
227     PCAT="$(magename2pcat ${dep} installdb)"
228     PNAME="$(magename2pname ${dep})"
229 niro 226
230 niro 250 # get the highest mage file from mage-db
231     MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
232 niro 226
233 niro 701 # if no install candidate was found, record this
234     # and process with the next one
235     if [[ -z ${MAGEFILE} ]]
236     then
237     NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
238     continue
239     fi
240    
241 niro 250 # now get the pver&pbuild from the new file
242     PVER="$(magename2pver ${MAGEFILE})"
243     PBUILD="$(magename2pbuild ${MAGEFILE})"
244    
245     # do not wander files which are installed
246     if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
247     then
248     # get dependencies the package
249     rumwandern ${MAGEFILE}
250    
251     # now add the package itself to the dependencies
252     # (if not exists already)
253 niro 598 #if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ]
254     if checklist_alldeps "${MAGEFILE}"
255 niro 250 then
256     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
257     fi
258     fi
259 niro 231 done
260     else
261     # get dependencies the package
262     rumwandern ${MAGEFILE}
263 niro 226
264 niro 231 # now add the package itself to the dependencies
265     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
266     fi
267    
268     [[ ${METHOD} = pretend ]] || \
269     [[ ${METHOD} = srcpretend ]] || \
270     [[ ${METHOD} = uppretend ]] || \
271     [[ ${METHOD} = srcuppretend ]] && \
272     echo "done"
273    
274    
275 niro 226 ## show output of pretend
276 niro 231 if [[ ${METHOD} = pretend ]] || \
277     [[ ${METHOD} = srcpretend ]] || \
278     [[ ${METHOD} = uppretend ]] || \
279     [[ ${METHOD} = srcuppretend ]]
280 niro 226 then
281     # this is a little bit faster
282     declare -i x=0
283     echo -n "Building dependencies list ... "
284     for i in ${ALLDEPS}
285     do
286     (( x++ ))
287     k="$x"
288     [ ${x} -le 9 ] && k="0${k}"
289     #[ ${x} -le 99 ] && k="0${k}"
290     PCAT="$(magename2pcat ${i})"
291     PNAME="$(magename2pname ${i})"
292     PVER="$(magename2pver ${i})"
293     PBUILD="$(magename2pbuild ${i})"
294     if [ -z "${list}" ]
295     then
296     list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
297     else
298     list="${list}
299     \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
300     fi
301     unset PCAT PNAME PVER PBUILD
302     done
303     echo "done"
304     echo -e "${list}"
305     echo
306 niro 701
307     if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
308     then
309     echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
310     for i in ${NO_UPGRADE_CANDIDATE}
311     do
312     echo -e "${COLRED} ${i}${COLDEFAULT}"
313     done
314     echo
315     echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"
316     echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"
317 niro 887 echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
318 niro 701 echo
319     fi
320 niro 226 fi
321    
322     ## return output from src/install deps
323 niro 231 [[ ${METHOD} = install ]] || \
324     [[ ${METHOD} = srcinstall ]] || \
325     [[ ${METHOD} = upgrade ]] || \
326     [[ ${METHOD} = srcupgrade ]] && \
327     echo "${ALLDEPS}"
328 niro 226
329     # delete ${BUILDDIR}/virtuals if exists as not needed anymore
330     #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals

Properties

Name Value
svn:executable *