Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 677 - (show annotations) (download) (as text)
Tue Feb 26 19:51:40 2008 UTC (16 years, 2 months ago) by niro
File MIME type: application/x-sh
File size: 7538 byte(s)
-do not add virtuals to PROCESSEDDEPS or their resolved pkgnames will be ignored and are missing on the dependecy list

1 #!/bin/bash
2
3 #depwalker
4 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/depwalker.sh,v 1.9 2008-02-26 19:51:40 niro Exp $
5
6 # default die function
7 die()
8 {
9 echo ${COLRED}"$@"${COLDEFAULT}
10 exit 1
11 }
12
13 # include all needed files
14 [ -f /etc/mage.rc.global ] && \
15 source /etc/mage.rc.global || \
16 die "/etc/mage.rc.global missing"
17
18 [ -f ${MAGERC} ] && source ${MAGERC} || \
19 die "Your ${MAGERC} is missing. Aborting."
20
21 [ -f ${MLIBDIR}/mage4.functions.sh ] && \
22 source ${MLIBDIR}/mage4.functions.sh || \
23 die "mage functions missing"
24
25 # for tests only
26 # 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
31 # not serious if missing, only needed for colors
32 [ -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 echo " install, srcinstall, depend, srcdepend"
58 echo " upgrade, srcupgrade"
59 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 # 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 checklist_processeddeps()
110 {
111 local i
112 local item="$1"
113
114 for i in ${PROCESSEDDEPS}
115 do
116 [[ ${i} = ${item} ]] && return 1
117 done
118
119 return 0
120 }
121
122 #####################
123 ## rumwandern /path/to/mage/file/.mage
124 rumwandern()
125 {
126 unset DEPEND
127 unset SDEPEND
128 unset MY_DEPEND
129
130 local DFILE
131 local SYM
132 local DEPNAME
133 local HIGHEST_DEPFILE
134 local MY_DEPEND
135 local REAL_PGKNAME
136 local VIRTUAL_NAME
137 local INSTALL_VIRTUAL
138 local PNAME
139 local PCAT
140 local PVER
141 local PBUILD
142
143 DFILE="$1"
144
145 source ${DFILE}
146 MY_DEPEND="${DEPEND}"
147
148 # for srcinstall & srcdepend only; SDEPEND also needed
149 if [[ ${METHOD} = srcinstall ]] || \
150 [[ ${METHOD} = srcpretend ]] || \
151 [[ ${METHOD} = srcupgrade ]] || \
152 [[ ${METHOD} = srcuppretend ]]
153 then
154 # only if SDEPEND is not zero
155 if [ -n "${SDEPEND}" ]
156 then
157 # crlf is substantly needed !!
158 if [ -n "${MY_DEPEND}" ]
159 then
160 MY_DEPEND="${MY_DEPEND}
161 ${SDEPEND}"
162 else
163 MY_DEPEND="${SDEPEND}"
164 fi
165 fi
166 fi
167
168 unset DEPEND
169 unset SDEPEND
170
171 if [ -z "${MY_DEPEND}" ]
172 then
173 return 1
174 fi
175
176 while read SYM DEPNAME
177 do
178 # exclude empty depnames
179 [[ -z ${DEPNAME} ]] && continue
180
181 # exclude all already processed deps -without version
182 if ! checklist_processeddeps "${DEPNAME%-*}"
183 then
184 continue
185 fi
186
187 # mark depfile as processed to prevent double runs -without version
188 # but do not add any virtuals to PROCESSEDDEPS or their resolved
189 # pkgnames will be ignored and they are missing on the dependecy-list
190 if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
191 then
192 PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
193 fi
194
195 HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
196
197 PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
198 PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
199 PVER="$(magename2pver ${HIGHEST_DEPFILE})"
200 PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
201
202 ## check ob schon in ALLDEPS enthalten dann mach weiter
203
204 # usage of fgrep is extremly slow and consumes a lot of cpu power
205 #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
206 if checklist_alldeps "${HIGHEST_DEPFILE}"
207 then
208 ### check ob DFILE schon installiert ist ###
209 if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
210 then
211 rumwandern ${HIGHEST_DEPFILE}
212 ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
213 fi
214 fi
215 done << EOF
216 ${MY_DEPEND}
217 EOF
218 return 0
219 }
220
221
222 ### abort if this package is already installed (retval 3)
223 # maybe later ?
224 #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3
225
226 [[ ${METHOD} = pretend ]] || \
227 [[ ${METHOD} = srcpretend ]] || \
228 [[ ${METHOD} = uppretend ]] || \
229 [[ ${METHOD} = srcuppretend ]] && \
230 echo -n "Calculating dependencies ... "
231
232
233 if [[ ${METHOD} = upgrade ]] || \
234 [[ ${METHOD} = srcupgrade ]] || \
235 [[ ${METHOD} = uppretend ]] || \
236 [[ ${METHOD} = srcuppretend ]]
237 then
238 INSTDEPS="$(${MLIBDIR}/magequery.sh -i)"
239 for dep in ${INSTDEPS}
240 do
241 PCAT="$(magename2pcat ${dep} installdb)"
242 PNAME="$(magename2pname ${dep})"
243
244 # get the highest mage file from mage-db
245 MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
246
247 # now get the pver&pbuild from the new file
248 PVER="$(magename2pver ${MAGEFILE})"
249 PBUILD="$(magename2pbuild ${MAGEFILE})"
250
251 # do not wander files which are installed
252 if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
253 then
254 # get dependencies the package
255 rumwandern ${MAGEFILE}
256
257 # now add the package itself to the dependencies
258 # (if not exists already)
259 #if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ]
260 if checklist_alldeps "${MAGEFILE}"
261 then
262 ALLDEPS="${ALLDEPS} ${MAGEFILE}"
263 fi
264 fi
265 done
266 else
267 # get dependencies the package
268 rumwandern ${MAGEFILE}
269
270 # now add the package itself to the dependencies
271 ALLDEPS="${ALLDEPS} ${MAGEFILE}"
272 fi
273
274 [[ ${METHOD} = pretend ]] || \
275 [[ ${METHOD} = srcpretend ]] || \
276 [[ ${METHOD} = uppretend ]] || \
277 [[ ${METHOD} = srcuppretend ]] && \
278 echo "done"
279
280
281 ## show output of pretend
282 if [[ ${METHOD} = pretend ]] || \
283 [[ ${METHOD} = srcpretend ]] || \
284 [[ ${METHOD} = uppretend ]] || \
285 [[ ${METHOD} = srcuppretend ]]
286 then
287 # this is a little bit faster
288 declare -i x=0
289 echo -n "Building dependencies list ... "
290 for i in ${ALLDEPS}
291 do
292 (( x++ ))
293 k="$x"
294 [ ${x} -le 9 ] && k="0${k}"
295 #[ ${x} -le 99 ] && k="0${k}"
296 PCAT="$(magename2pcat ${i})"
297 PNAME="$(magename2pname ${i})"
298 PVER="$(magename2pver ${i})"
299 PBUILD="$(magename2pbuild ${i})"
300 if [ -z "${list}" ]
301 then
302 list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
303 else
304 list="${list}
305 \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
306 fi
307 unset PCAT PNAME PVER PBUILD
308 done
309 echo "done"
310 echo -e "${list}"
311 echo
312 fi
313
314 ## return output from src/install deps
315 [[ ${METHOD} = install ]] || \
316 [[ ${METHOD} = srcinstall ]] || \
317 [[ ${METHOD} = upgrade ]] || \
318 [[ ${METHOD} = srcupgrade ]] && \
319 echo "${ALLDEPS}"
320
321 # delete ${BUILDDIR}/virtuals if exists as not needed anymore
322 #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals

Properties

Name Value
svn:executable *