1 |
#!/bin/bash |
#!/bin/bash |
2 |
|
# $Id$ |
3 |
#depwalker |
# dependeny walker |
|
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/depwalker.sh,v 1.8 2008-01-13 21:42:16 niro Exp $ |
|
4 |
|
|
5 |
# default die function |
# default die function |
6 |
die() |
die() |
9 |
exit 1 |
exit 1 |
10 |
} |
} |
11 |
|
|
12 |
|
decho() |
13 |
|
{ |
14 |
|
if [[ ${DEBUG} = 1 ]] |
15 |
|
then |
16 |
|
echo "DEBUG: $@" >&2 |
17 |
|
fi |
18 |
|
} |
19 |
|
|
20 |
# include all needed files |
# include all needed files |
21 |
[ -f /etc/mage.rc.global ] && \ |
[ -f /etc/mage.rc.global ] && \ |
22 |
source /etc/mage.rc.global || \ |
source /etc/mage.rc.global || \ |
29 |
source ${MLIBDIR}/mage4.functions.sh || \ |
source ${MLIBDIR}/mage4.functions.sh || \ |
30 |
die "mage functions missing" |
die "mage functions missing" |
31 |
|
|
|
# for tests only |
|
|
# source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage.rc.global |
|
|
# source /etc/mage.rc |
|
|
# source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh |
|
|
# MLIBDIR=/home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage |
|
|
|
|
|
# not serious if missing, only needed for colors |
|
|
[ -f /etc/init.d/functions ] && source /etc/init.d/functions |
|
|
|
|
|
# disable colors if wanted |
|
|
if [[ ${NOCOLORS} = true ]] |
|
|
then |
|
|
COLRED="" |
|
|
COLGREEN="" |
|
|
COLYELLOW="" |
|
|
COLBLUE="" |
|
|
COLMAGENTA="" |
|
|
COLWHITE="" |
|
|
COLDEFAULT="" |
|
|
fi |
|
|
|
|
32 |
usage() |
usage() |
33 |
{ |
{ |
34 |
echo |
echo |
35 |
echo "Usage: $(basename $0) [command] [arg] ..." |
echo "Usage: $(basename $0) [command] [arg] ..." |
36 |
echo |
echo |
37 |
echo " -h --help shows this help" |
echo " -h --help shows this help" |
38 |
echo " -c --pcat categorie of the package" |
echo " -c --pcat category of the package" |
39 |
echo " -n --pname name of the package" |
echo " -n --pname name of the package" |
40 |
echo " -v --pver version number of the package" |
echo " -v --pver version number of the package" |
41 |
echo " -b --pbuild build number of the package" |
echo " -b --pbuild build number of the package" |
42 |
echo " -m --method which calc method should be used:" |
echo " -m --method which calc method should be used:" |
43 |
echo " install, srcinstall, depend, srcdepend" |
echo " install, srcinstall, depend, srcdepend" |
44 |
echo " upgrade, srcupgrade" |
echo " upgrade, srcupgrade," |
45 |
|
echo " install-build-prerequisites," |
46 |
|
echo " pretend-build-prerequisites" |
47 |
|
echo " -d --debug enable debug mode" |
48 |
echo |
echo |
49 |
echo "method,name, version and build must be given !" |
echo "method, category, name, version and build must be given !" |
50 |
echo |
echo |
51 |
exit 1 |
exit 1 |
52 |
} |
} |
53 |
|
|
54 |
|
# always default debug=0 |
55 |
|
DEBUG=0 |
56 |
|
|
57 |
# very basic getops |
# very basic getops |
58 |
for i in $* |
for i in $* |
59 |
do |
do |
63 |
--pver|-v) shift; PVER="$1" ;; |
--pver|-v) shift; PVER="$1" ;; |
64 |
--pbuild|-b) shift; PBUILD="$1" ;; |
--pbuild|-b) shift; PBUILD="$1" ;; |
65 |
--method|-m) shift; METHOD="$1" ;; |
--method|-m) shift; METHOD="$1" ;; |
66 |
|
--debug|-d) shift; DEBUG=1 ;; |
67 |
--help|-h) usage ;; |
--help|-h) usage ;; |
68 |
esac |
esac |
69 |
shift |
shift |
113 |
} |
} |
114 |
|
|
115 |
##################### |
##################### |
116 |
## rumwandern /path/to/mage/file/.mage |
## depwalking /path/to/mage/file/.mage |
117 |
rumwandern() |
depwalking() |
118 |
{ |
{ |
119 |
unset DEPEND |
unset DEPEND |
120 |
unset SDEPEND |
unset SDEPEND |
135 |
|
|
136 |
DFILE="$1" |
DFILE="$1" |
137 |
|
|
138 |
|
# debug info |
139 |
|
decho "depwalking magefile '${DFILE}'" |
140 |
|
decho |
141 |
|
|
142 |
source ${DFILE} |
source ${DFILE} |
143 |
|
|
144 |
|
# forced nodeps |
145 |
|
if [[ ${NODEPS} = true ]] |
146 |
|
then |
147 |
|
DEPEND="" |
148 |
|
SDEPEND="" |
149 |
|
fi |
150 |
|
|
151 |
MY_DEPEND="${DEPEND}" |
MY_DEPEND="${DEPEND}" |
152 |
|
|
153 |
# for srcinstall & srcdepend only; SDEPEND also needed |
# for srcinstall & srcdepend only; SDEPEND also needed |
154 |
if [[ ${METHOD} = srcinstall ]] || \ |
if [[ ${METHOD} = srcinstall ]] || |
155 |
[[ ${METHOD} = srcpretend ]] || \ |
[[ ${METHOD} = srcpretend ]] || |
156 |
[[ ${METHOD} = srcupgrade ]] || \ |
[[ ${METHOD} = srcupgrade ]] || |
157 |
[[ ${METHOD} = srcuppretend ]] |
[[ ${METHOD} = srcuppretend ]] || |
158 |
|
[[ ${METHOD} = install-build-prerequisites ]] || |
159 |
|
[[ ${METHOD} = pretend-build-prerequisites ]] |
160 |
then |
then |
161 |
# only if SDEPEND is not zero |
# only if SDEPEND is not zero |
162 |
if [ -n "${SDEPEND}" ] |
if [ -n "${SDEPEND}" ] |
177 |
|
|
178 |
if [ -z "${MY_DEPEND}" ] |
if [ -z "${MY_DEPEND}" ] |
179 |
then |
then |
180 |
|
decho "MY_DEPEND is empty; deps of '${DFILE}' ignored" |
181 |
return 1 |
return 1 |
182 |
fi |
fi |
183 |
|
|
184 |
while read SYM DEPNAME |
while read SYM DEPNAME |
185 |
do |
do |
186 |
|
# debug info |
187 |
|
decho "DEPNAME='${DEPNAME}'" |
188 |
|
|
189 |
# exclude empty depnames |
# exclude empty depnames |
190 |
[[ -z ${DEPNAME} ]] && continue |
[[ -z ${DEPNAME} ]] && continue |
191 |
|
|
196 |
fi |
fi |
197 |
|
|
198 |
# mark depfile as processed to prevent double runs -without version |
# mark depfile as processed to prevent double runs -without version |
199 |
PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}" |
# but do not add any virtuals to PROCESSEDDEPS or their resolved |
200 |
|
# pkgnames will be ignored and they are missing on the dependecy-list |
201 |
|
if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]] |
202 |
|
then |
203 |
|
PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}" |
204 |
|
fi |
205 |
|
|
206 |
HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") |
HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") |
207 |
|
if [[ -z ${HIGHEST_DEPFILE} ]] |
208 |
|
then |
209 |
|
INVALID_DEPS+=" ${DEPNAME}:${DFILE}" |
210 |
|
continue |
211 |
|
fi |
212 |
|
|
213 |
PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" |
PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" |
214 |
PNAME="$(magename2pname ${HIGHEST_DEPFILE})" |
PNAME="$(magename2pname ${HIGHEST_DEPFILE})" |
215 |
PVER="$(magename2pver ${HIGHEST_DEPFILE})" |
PVER="$(magename2pver ${HIGHEST_DEPFILE})" |
216 |
PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})" |
PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})" |
217 |
|
|
218 |
## check ob schon in ALLDEPS enthalten dann mach weiter |
## dep already in ALLDEPS? then going on |
219 |
|
|
220 |
# usage of fgrep is extremly slow and consumes a lot of cpu power |
# usage of fgrep is extremly slow and consumes a lot of cpu power |
221 |
#if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ] |
#if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ] |
222 |
if checklist_alldeps "${HIGHEST_DEPFILE}" |
if checklist_alldeps "${HIGHEST_DEPFILE}" |
223 |
then |
then |
224 |
### check ob DFILE schon installiert ist ### |
### check if the dependency is already installed ### |
225 |
if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
226 |
then |
then |
227 |
rumwandern ${HIGHEST_DEPFILE} |
depwalking ${HIGHEST_DEPFILE} |
228 |
ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}" |
ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}" |
229 |
|
decho "added '${HIGHEST_DEPFILE}' to ALLDEPS" |
230 |
fi |
fi |
231 |
fi |
fi |
232 |
done << EOF |
done << EOF |
235 |
return 0 |
return 0 |
236 |
} |
} |
237 |
|
|
|
|
|
|
### abort if this package is already installed (retval 3) |
|
|
# maybe later ? |
|
|
#[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3 |
|
|
|
|
238 |
[[ ${METHOD} = pretend ]] || \ |
[[ ${METHOD} = pretend ]] || \ |
239 |
[[ ${METHOD} = srcpretend ]] || \ |
[[ ${METHOD} = srcpretend ]] || \ |
240 |
[[ ${METHOD} = uppretend ]] || \ |
[[ ${METHOD} = uppretend ]] || \ |
241 |
[[ ${METHOD} = srcuppretend ]] && \ |
[[ ${METHOD} = srcuppretend ]] || \ |
242 |
|
[[ ${METHOD} = pretend-build-prerequisites ]] && \ |
243 |
echo -n "Calculating dependencies ... " |
echo -n "Calculating dependencies ... " |
244 |
|
|
245 |
|
|
257 |
# get the highest mage file from mage-db |
# get the highest mage file from mage-db |
258 |
MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" |
MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" |
259 |
|
|
260 |
|
# debug info |
261 |
|
decho "dep='${dep}'" |
262 |
|
decho "PCAT='${PCAT}'" |
263 |
|
decho "PNAME='${PNAME}'" |
264 |
|
decho "MAGEFILE='${MAGEFILE}'" |
265 |
|
|
266 |
|
# if no install candidate was found, record this |
267 |
|
# and process with the next one |
268 |
|
if [[ -z ${MAGEFILE} ]] |
269 |
|
then |
270 |
|
NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}" |
271 |
|
decho "added to NO_UPGRADE_CANDIDATE" |
272 |
|
continue |
273 |
|
fi |
274 |
|
|
275 |
# now get the pver&pbuild from the new file |
# now get the pver&pbuild from the new file |
276 |
PVER="$(magename2pver ${MAGEFILE})" |
PVER="$(magename2pver ${MAGEFILE})" |
277 |
PBUILD="$(magename2pbuild ${MAGEFILE})" |
PBUILD="$(magename2pbuild ${MAGEFILE})" |
278 |
|
|
279 |
# do not wander files which are installed |
# debug info |
280 |
|
decho "PVER='${PVER}'" |
281 |
|
decho "PBUILD='${PBUILD}'" |
282 |
|
|
283 |
|
# do not walk files which are installed |
284 |
if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
285 |
then |
then |
286 |
# get dependencies the package |
# get dependencies the package |
287 |
rumwandern ${MAGEFILE} |
depwalking ${MAGEFILE} |
288 |
|
|
289 |
# now add the package itself to the dependencies |
# now add the package itself to the dependencies |
290 |
# (if not exists already) |
# (if not exists already) |
|
#if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ] |
|
291 |
if checklist_alldeps "${MAGEFILE}" |
if checklist_alldeps "${MAGEFILE}" |
292 |
then |
then |
293 |
|
decho "added '${MAGEFILE}' to ALLDEPS" |
294 |
ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
295 |
fi |
fi |
296 |
|
else |
297 |
|
# debug info |
298 |
|
decho "ignored package" |
299 |
|
decho |
300 |
|
fi |
301 |
fi |
fi |
302 |
done |
done |
303 |
else |
else |
304 |
# get dependencies the package |
LOOP_COUNTER=0 |
305 |
rumwandern ${MAGEFILE} |
# get all dependencies of the package |
306 |
|
depwalking ${MAGEFILE} |
307 |
|
fi |
308 |
|
|
309 |
|
if [[ ${METHOD} != install-build-prerequisites ]] && |
310 |
|
[[ ${METHOD} != pretend-build-prerequisites ]] && |
311 |
|
[[ ${METHOD} != upgrade ]] && |
312 |
|
[[ ${METHOD} != uppretend ]] && |
313 |
|
[[ ${METHOD} != srcupgrade ]] && |
314 |
|
[[ ${METHOD} != srcuppretend ]] |
315 |
|
then |
316 |
# now add the package itself to the dependencies |
# now add the package itself to the dependencies |
317 |
ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
# (if not exists already) |
318 |
|
if checklist_alldeps "${MAGEFILE}" |
319 |
|
then |
320 |
|
decho "added '${MAGEFILE}' to ALLDEPS" |
321 |
|
ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
322 |
|
fi |
323 |
fi |
fi |
324 |
|
|
325 |
[[ ${METHOD} = pretend ]] || \ |
[[ ${METHOD} = pretend ]] || \ |
326 |
[[ ${METHOD} = srcpretend ]] || \ |
[[ ${METHOD} = srcpretend ]] || \ |
327 |
[[ ${METHOD} = uppretend ]] || \ |
[[ ${METHOD} = uppretend ]] || \ |
328 |
[[ ${METHOD} = srcuppretend ]] && \ |
[[ ${METHOD} = srcuppretend ]] || \ |
329 |
|
[[ ${METHOD} = pretend-build-prerequisites ]] && \ |
330 |
echo "done" |
echo "done" |
331 |
|
|
332 |
|
|
334 |
if [[ ${METHOD} = pretend ]] || \ |
if [[ ${METHOD} = pretend ]] || \ |
335 |
[[ ${METHOD} = srcpretend ]] || \ |
[[ ${METHOD} = srcpretend ]] || \ |
336 |
[[ ${METHOD} = uppretend ]] || \ |
[[ ${METHOD} = uppretend ]] || \ |
337 |
[[ ${METHOD} = srcuppretend ]] |
[[ ${METHOD} = srcuppretend ]] || \ |
338 |
|
[[ ${METHOD} = pretend-build-prerequisites ]] |
339 |
then |
then |
340 |
# this is a little bit faster |
# this is a little bit faster |
341 |
declare -i x=0 |
declare -i x=0 |
352 |
PBUILD="$(magename2pbuild ${i})" |
PBUILD="$(magename2pbuild ${i})" |
353 |
if [ -z "${list}" ] |
if [ -z "${list}" ] |
354 |
then |
then |
355 |
list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
356 |
else |
else |
357 |
list="${list} |
list="${list} |
358 |
\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
362 |
echo "done" |
echo "done" |
363 |
echo -e "${list}" |
echo -e "${list}" |
364 |
echo |
echo |
365 |
|
|
366 |
|
if [[ ! -z ${INVALID_DEPS} ]] |
367 |
|
then |
368 |
|
echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}" |
369 |
|
for i in ${INVALID_DEPS} |
370 |
|
do |
371 |
|
_dep="${i%%:*}" |
372 |
|
_mage="${i##*:}" |
373 |
|
echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}" |
374 |
|
done |
375 |
|
echo |
376 |
|
fi |
377 |
|
|
378 |
|
if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]] |
379 |
|
then |
380 |
|
echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}" |
381 |
|
for i in ${NO_UPGRADE_CANDIDATE} |
382 |
|
do |
383 |
|
echo -e "${COLRED} ${i}${COLDEFAULT}" |
384 |
|
done |
385 |
|
echo |
386 |
|
echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}" |
387 |
|
echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}" |
388 |
|
echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}" |
389 |
|
echo |
390 |
|
fi |
391 |
fi |
fi |
392 |
|
|
393 |
## return output from src/install deps |
## return output from src/install deps |
394 |
[[ ${METHOD} = install ]] || \ |
[[ ${METHOD} = install ]] || \ |
395 |
[[ ${METHOD} = srcinstall ]] || \ |
[[ ${METHOD} = srcinstall ]] || \ |
396 |
[[ ${METHOD} = upgrade ]] || \ |
[[ ${METHOD} = upgrade ]] || \ |
397 |
[[ ${METHOD} = srcupgrade ]] && \ |
[[ ${METHOD} = srcupgrade ]] || \ |
398 |
|
[[ ${METHOD} = install-build-prerequisites ]] && \ |
399 |
echo "${ALLDEPS}" |
echo "${ALLDEPS}" |
|
|
|
|
# delete ${BUILDDIR}/virtuals if exists as not needed anymore |
|
|
#[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals |
|