Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 598 - (hide annotations) (download) (as text)
Mon Nov 5 16:49:33 2007 UTC (16 years, 6 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/depwalker.sh
File MIME type: application/x-sh
File size: 6889 byte(s)
-some performance fixes

1 niro 226 #!/bin/bash
2    
3     #depwalker
4 niro 598 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/depwalker.sh,v 1.6 2007-11-05 16:49:33 niro Exp $
5 niro 226
6     # default die function
7     die()
8     {
9     echo ${COLRED}"$@"${COLDEFAULT}
10     exit 1
11     }
12    
13 niro 231 # include all needed files
14 niro 235 [ -f /etc/mage.rc.global ] && \
15     source /etc/mage.rc.global || \
16     die "/etc/mage.rc.global missing"
17 niro 226
18 niro 419 [ -f ${MAGERC} ] && source ${MAGERC} || \
19     die "Your ${MAGERC} is missing. Aborting."
20 niro 231
21 niro 235 [ -f ${MLIBDIR}/mage4.functions.sh ] && \
22     source ${MLIBDIR}/mage4.functions.sh || \
23 niro 231 die "mage functions missing"
24    
25 niro 226 # for tests only
26 niro 231 # source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage.rc.global
27     # source /etc/mage.rc
28     # source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh
29     # MLIBDIR=/home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage
30 niro 226
31 niro 231 # not serious if missing, only needed for colors
32 niro 226 [ -f /etc/init.d/functions ] && source /etc/init.d/functions
33    
34     # disable colors if wanted
35     if [[ ${NOCOLORS} = true ]]
36     then
37     COLRED=""
38     COLGREEN=""
39     COLYELLOW=""
40     COLBLUE=""
41     COLMAGENTA=""
42     COLWHITE=""
43     COLDEFAULT=""
44     fi
45    
46     usage()
47     {
48     echo
49     echo "Usage: $(basename $0) [command] [arg] ..."
50     echo
51     echo " -h --help shows this help"
52     echo " -c --pcat categorie of the package"
53     echo " -n --pname name of the package"
54     echo " -v --pver version number of the package"
55     echo " -b --pbuild build number of the package"
56     echo " -m --method which calc method should be used:"
57 niro 231 echo " install, srcinstall, depend, srcdepend"
58     echo " upgrade, srcupgrade"
59 niro 226 echo
60     echo "method,name, version and build must be given !"
61     echo
62     exit 1
63     }
64    
65     # very basic getops
66     for i in $*
67     do
68     case $1 in
69     --pcat|-c) shift; PCAT="$1" ;;
70     --pname|-n) shift; PNAME="$1" ;;
71     --pver|-v) shift; PVER="$1" ;;
72     --pbuild|-b) shift; PBUILD="$1" ;;
73     --method|-m) shift; METHOD="$1" ;;
74     --help|-h) usage ;;
75     esac
76     shift
77     done
78    
79     # sanity checks; abort if not given
80     [ -z "${PCAT}" ] && usage
81     [ -z "${PNAME}" ] && usage
82     [ -z "${PVER}" ] && usage
83     [ -z "${PBUILD}" ] && usage
84     [ -z "${METHOD}" ] && usage
85    
86     # check needed global vars
87     [ -z "${MAGEDIR}" ] && die "\$MAGEDIR not set."
88     [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set."
89     [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set."
90    
91     # other needed vars
92     ALLDEPS=""
93     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 226 #####################
110     ## rumwandern /path/to/mage/file/.mage
111     rumwandern()
112     {
113     unset DEPEND
114     unset SDEPEND
115     unset MY_DEPEND
116    
117     local DFILE
118     local SYM
119     local DEPNAME
120     local HIGHEST_DEPFILE
121     local MY_DEPEND
122     local REAL_PGKNAME
123     local VIRTUAL_NAME
124     local INSTALL_VIRTUAL
125     local PNAME
126     local PCAT
127 niro 250 local PVER
128     local PBUILD
129 niro 226
130     DFILE="$1"
131    
132     source ${DFILE}
133     MY_DEPEND="${DEPEND}"
134    
135     # for srcinstall & srcdepend only; SDEPEND also needed
136 niro 231 if [[ ${METHOD} = srcinstall ]] || \
137     [[ ${METHOD} = srcpretend ]] || \
138     [[ ${METHOD} = srcupgrade ]] || \
139     [[ ${METHOD} = srcuppretend ]]
140 niro 226 then
141     # only if SDEPEND is not zero
142     if [ -n "${SDEPEND}" ]
143     then
144     # crlf is substantly needed !!
145     if [ -n "${MY_DEPEND}" ]
146     then
147     MY_DEPEND="${MY_DEPEND}
148     ${SDEPEND}"
149     else
150     MY_DEPEND="${SDEPEND}"
151     fi
152     fi
153     fi
154    
155     unset DEPEND
156     unset SDEPEND
157    
158     if [ -z "${MY_DEPEND}" ]
159     then
160     return 1
161     fi
162    
163     while read SYM DEPNAME
164     do
165     HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
166    
167     PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
168     PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
169     PVER="$(magename2pver ${HIGHEST_DEPFILE})"
170     PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
171    
172     ## check ob schon in ALLDEPS enthalten dann mach weiter
173 niro 598
174     # usage of fgrep is extremly slow and consumes a lot of cpu power
175     #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
176     if checklist_alldeps "${HIGHEST_DEPFILE}"
177 niro 226 then
178     ### check ob DFILE schon installiert ist ###
179     if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
180     then
181     rumwandern ${HIGHEST_DEPFILE}
182     ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
183     fi
184     fi
185     done << EOF
186     ${MY_DEPEND}
187     EOF
188     return 0
189     }
190    
191    
192     ### abort if this package is already installed (retval 3)
193     # maybe later ?
194     #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3
195    
196 niro 231 [[ ${METHOD} = pretend ]] || \
197     [[ ${METHOD} = srcpretend ]] || \
198     [[ ${METHOD} = uppretend ]] || \
199     [[ ${METHOD} = srcuppretend ]] && \
200 niro 226 echo -n "Calculating dependencies ... "
201    
202    
203 niro 231 if [[ ${METHOD} = upgrade ]] || \
204     [[ ${METHOD} = srcupgrade ]] || \
205     [[ ${METHOD} = uppretend ]] || \
206     [[ ${METHOD} = srcuppretend ]]
207     then
208     INSTDEPS="$(${MLIBDIR}/magequery.sh -i)"
209     for dep in ${INSTDEPS}
210     do
211     PCAT="$(magename2pcat ${dep} installdb)"
212     PNAME="$(magename2pname ${dep})"
213 niro 226
214 niro 250 # get the highest mage file from mage-db
215     MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
216 niro 226
217 niro 250 # now get the pver&pbuild from the new file
218     PVER="$(magename2pver ${MAGEFILE})"
219     PBUILD="$(magename2pbuild ${MAGEFILE})"
220    
221     # do not wander files which are installed
222     if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
223     then
224     # get dependencies the package
225     rumwandern ${MAGEFILE}
226    
227     # now add the package itself to the dependencies
228     # (if not exists already)
229 niro 598 #if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ]
230     if checklist_alldeps "${MAGEFILE}"
231 niro 250 then
232     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
233     fi
234     fi
235 niro 231 done
236     else
237     # get dependencies the package
238     rumwandern ${MAGEFILE}
239 niro 226
240 niro 231 # now add the package itself to the dependencies
241     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
242     fi
243    
244     [[ ${METHOD} = pretend ]] || \
245     [[ ${METHOD} = srcpretend ]] || \
246     [[ ${METHOD} = uppretend ]] || \
247     [[ ${METHOD} = srcuppretend ]] && \
248     echo "done"
249    
250    
251 niro 226 ## show output of pretend
252 niro 231 if [[ ${METHOD} = pretend ]] || \
253     [[ ${METHOD} = srcpretend ]] || \
254     [[ ${METHOD} = uppretend ]] || \
255     [[ ${METHOD} = srcuppretend ]]
256 niro 226 then
257     # this is a little bit faster
258     declare -i x=0
259     echo -n "Building dependencies list ... "
260     for i in ${ALLDEPS}
261     do
262     (( x++ ))
263     k="$x"
264     [ ${x} -le 9 ] && k="0${k}"
265     #[ ${x} -le 99 ] && k="0${k}"
266     PCAT="$(magename2pcat ${i})"
267     PNAME="$(magename2pname ${i})"
268     PVER="$(magename2pver ${i})"
269     PBUILD="$(magename2pbuild ${i})"
270     if [ -z "${list}" ]
271     then
272     list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
273     else
274     list="${list}
275     \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
276     fi
277     unset PCAT PNAME PVER PBUILD
278     done
279     echo "done"
280     echo -e "${list}"
281     echo
282     fi
283    
284     ## return output from src/install deps
285 niro 231 [[ ${METHOD} = install ]] || \
286     [[ ${METHOD} = srcinstall ]] || \
287     [[ ${METHOD} = upgrade ]] || \
288     [[ ${METHOD} = srcupgrade ]] && \
289     echo "${ALLDEPS}"
290 niro 226
291     # delete ${BUILDDIR}/virtuals if exists as not needed anymore
292     #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals

Properties

Name Value
svn:executable *