Contents of /trunk/mage/usr/lib/mage/depwalker.sh
Parent Directory | Revision Log
Revision 887 -
(show annotations)
(download)
(as text)
Wed Jul 15 23:31:38 2009 UTC (15 years, 2 months ago) by niro
File MIME type: application/x-sh
File size: 8312 byte(s)
Wed Jul 15 23:31:38 2009 UTC (15 years, 2 months ago) by niro
File MIME type: application/x-sh
File size: 8312 byte(s)
-fixed spelling
1 | #!/bin/bash |
2 | |
3 | #depwalker |
4 | # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/depwalker.sh,v 1.11 2008-10-05 10:33:36 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 | |
147 | # forced nodeps |
148 | if [[ ${NODEPS} = true ]] |
149 | then |
150 | DEPEND="" |
151 | SDEPEND="" |
152 | fi |
153 | |
154 | MY_DEPEND="${DEPEND}" |
155 | |
156 | # for srcinstall & srcdepend only; SDEPEND also needed |
157 | if [[ ${METHOD} = srcinstall ]] || \ |
158 | [[ ${METHOD} = srcpretend ]] || \ |
159 | [[ ${METHOD} = srcupgrade ]] || \ |
160 | [[ ${METHOD} = srcuppretend ]] |
161 | then |
162 | # only if SDEPEND is not zero |
163 | if [ -n "${SDEPEND}" ] |
164 | then |
165 | # crlf is substantly needed !! |
166 | if [ -n "${MY_DEPEND}" ] |
167 | then |
168 | MY_DEPEND="${MY_DEPEND} |
169 | ${SDEPEND}" |
170 | else |
171 | MY_DEPEND="${SDEPEND}" |
172 | fi |
173 | fi |
174 | fi |
175 | |
176 | unset DEPEND |
177 | unset SDEPEND |
178 | |
179 | if [ -z "${MY_DEPEND}" ] |
180 | then |
181 | return 1 |
182 | fi |
183 | |
184 | while read SYM DEPNAME |
185 | do |
186 | # exclude empty depnames |
187 | [[ -z ${DEPNAME} ]] && continue |
188 | |
189 | # exclude all already processed deps -without version |
190 | if ! checklist_processeddeps "${DEPNAME%-*}" |
191 | then |
192 | continue |
193 | fi |
194 | |
195 | # mark depfile as processed to prevent double runs -without version |
196 | # but do not add any virtuals to PROCESSEDDEPS or their resolved |
197 | # pkgnames will be ignored and they are missing on the dependecy-list |
198 | if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]] |
199 | then |
200 | PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}" |
201 | fi |
202 | |
203 | HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") |
204 | |
205 | PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" |
206 | PNAME="$(magename2pname ${HIGHEST_DEPFILE})" |
207 | PVER="$(magename2pver ${HIGHEST_DEPFILE})" |
208 | PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})" |
209 | |
210 | ## check ob schon in ALLDEPS enthalten dann mach weiter |
211 | |
212 | # usage of fgrep is extremly slow and consumes a lot of cpu power |
213 | #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ] |
214 | if checklist_alldeps "${HIGHEST_DEPFILE}" |
215 | then |
216 | ### check ob DFILE schon installiert ist ### |
217 | if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
218 | then |
219 | rumwandern ${HIGHEST_DEPFILE} |
220 | ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}" |
221 | fi |
222 | fi |
223 | done << EOF |
224 | ${MY_DEPEND} |
225 | EOF |
226 | return 0 |
227 | } |
228 | |
229 | |
230 | ### abort if this package is already installed (retval 3) |
231 | # maybe later ? |
232 | #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3 |
233 | |
234 | [[ ${METHOD} = pretend ]] || \ |
235 | [[ ${METHOD} = srcpretend ]] || \ |
236 | [[ ${METHOD} = uppretend ]] || \ |
237 | [[ ${METHOD} = srcuppretend ]] && \ |
238 | echo -n "Calculating dependencies ... " |
239 | |
240 | |
241 | if [[ ${METHOD} = upgrade ]] || \ |
242 | [[ ${METHOD} = srcupgrade ]] || \ |
243 | [[ ${METHOD} = uppretend ]] || \ |
244 | [[ ${METHOD} = srcuppretend ]] |
245 | then |
246 | INSTDEPS="$(${MLIBDIR}/magequery.sh -i)" |
247 | for dep in ${INSTDEPS} |
248 | do |
249 | PCAT="$(magename2pcat ${dep} installdb)" |
250 | PNAME="$(magename2pname ${dep})" |
251 | |
252 | # get the highest mage file from mage-db |
253 | MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" |
254 | |
255 | # if no install candidate was found, record this |
256 | # and process with the next one |
257 | if [[ -z ${MAGEFILE} ]] |
258 | then |
259 | NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}" |
260 | continue |
261 | fi |
262 | |
263 | # now get the pver&pbuild from the new file |
264 | PVER="$(magename2pver ${MAGEFILE})" |
265 | PBUILD="$(magename2pbuild ${MAGEFILE})" |
266 | |
267 | # do not wander files which are installed |
268 | if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
269 | then |
270 | # get dependencies the package |
271 | rumwandern ${MAGEFILE} |
272 | |
273 | # now add the package itself to the dependencies |
274 | # (if not exists already) |
275 | #if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ] |
276 | if checklist_alldeps "${MAGEFILE}" |
277 | then |
278 | ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
279 | fi |
280 | fi |
281 | done |
282 | else |
283 | # get dependencies the package |
284 | rumwandern ${MAGEFILE} |
285 | |
286 | # now add the package itself to the dependencies |
287 | ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
288 | fi |
289 | |
290 | [[ ${METHOD} = pretend ]] || \ |
291 | [[ ${METHOD} = srcpretend ]] || \ |
292 | [[ ${METHOD} = uppretend ]] || \ |
293 | [[ ${METHOD} = srcuppretend ]] && \ |
294 | echo "done" |
295 | |
296 | |
297 | ## show output of pretend |
298 | if [[ ${METHOD} = pretend ]] || \ |
299 | [[ ${METHOD} = srcpretend ]] || \ |
300 | [[ ${METHOD} = uppretend ]] || \ |
301 | [[ ${METHOD} = srcuppretend ]] |
302 | then |
303 | # this is a little bit faster |
304 | declare -i x=0 |
305 | echo -n "Building dependencies list ... " |
306 | for i in ${ALLDEPS} |
307 | do |
308 | (( x++ )) |
309 | k="$x" |
310 | [ ${x} -le 9 ] && k="0${k}" |
311 | #[ ${x} -le 99 ] && k="0${k}" |
312 | PCAT="$(magename2pcat ${i})" |
313 | PNAME="$(magename2pname ${i})" |
314 | PVER="$(magename2pver ${i})" |
315 | PBUILD="$(magename2pbuild ${i})" |
316 | if [ -z "${list}" ] |
317 | then |
318 | list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
319 | else |
320 | list="${list} |
321 | \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
322 | fi |
323 | unset PCAT PNAME PVER PBUILD |
324 | done |
325 | echo "done" |
326 | echo -e "${list}" |
327 | echo |
328 | |
329 | if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]] |
330 | then |
331 | echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}" |
332 | for i in ${NO_UPGRADE_CANDIDATE} |
333 | do |
334 | echo -e "${COLRED} ${i}${COLDEFAULT}" |
335 | done |
336 | echo |
337 | echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}" |
338 | echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}" |
339 | echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}" |
340 | echo |
341 | fi |
342 | fi |
343 | |
344 | ## return output from src/install deps |
345 | [[ ${METHOD} = install ]] || \ |
346 | [[ ${METHOD} = srcinstall ]] || \ |
347 | [[ ${METHOD} = upgrade ]] || \ |
348 | [[ ${METHOD} = srcupgrade ]] && \ |
349 | echo "${ALLDEPS}" |
350 | |
351 | # delete ${BUILDDIR}/virtuals if exists as not needed anymore |
352 | #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals |
Properties
Name | Value |
---|---|
svn:executable | * |