1 |
#!/bin/bash |
#!/bin/bash |
2 |
|
# $Id$ |
3 |
|
# dependeny walker |
4 |
|
|
5 |
#depwalker |
decho() |
|
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/depwalker.sh,v 1.1 2005-09-09 16:35:27 niro Exp $ |
|
|
|
|
|
# default die function |
|
|
die() |
|
6 |
{ |
{ |
7 |
echo ${COLRED}"$@"${COLDEFAULT} |
if [[ ${DEBUG} = 1 ]] |
8 |
exit 1 |
then |
9 |
|
echo "DEBUG: $@" >&2 |
10 |
|
fi |
11 |
} |
} |
12 |
|
|
13 |
# # include all needed files |
# first of all include common functions |
14 |
# [ -f ${MLIBDIR}/conf/mage.rc.global ] && \ |
source ${MLIBDIR}/common.functions.sh || exit 1 |
15 |
# source ${MLIBDIR}/conf/mage.rc.global || \ |
source @@SYSCONFDIR@@/mage.rc.global || die "@@SYSCONFDIR@@/mage.rc.global missing" |
16 |
# die "${MLIBDIR}/conf/mage.rc.global missing" |
source ${MAGERC} || die "Your ${MAGERC} is missing. Aborting." |
17 |
# |
source ${MLIBDIR}/mage4.functions.sh || die "mage functions missing" |
18 |
# [ -f /etc/mage.rc ] && source /etc/mage.rc || \ |
source ${MLIBDIR}/smage2.functions.sh || die "smage functions missing" |
|
# die "Your /etc/mage.rc is missing. Aborting." |
|
|
# |
|
|
# [ -f ${MLIBDIR}/mage.functions.sh ] && \ |
|
|
# source ${MLIBDIR}/mage.functions.sh || \ |
|
|
# die "mage functions missing" |
|
|
|
|
|
# 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 |
|
|
|
|
|
# not serios if missing, only 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 |
|
19 |
|
|
20 |
usage() |
usage() |
21 |
{ |
{ |
23 |
echo "Usage: $(basename $0) [command] [arg] ..." |
echo "Usage: $(basename $0) [command] [arg] ..." |
24 |
echo |
echo |
25 |
echo " -h --help shows this help" |
echo " -h --help shows this help" |
26 |
echo " -c --pcat categorie of the package" |
echo " -c --pcat category of the package" |
27 |
echo " -n --pname name of the package" |
echo " -n --pname name of the package" |
28 |
echo " -v --pver version number of the package" |
echo " -v --pver version number of the package" |
29 |
echo " -b --pbuild build number of the package" |
echo " -b --pbuild build number of the package" |
30 |
echo " -m --method which calc method should be used:" |
echo " -m --method which calc method should be used:" |
31 |
echo " install srcinstall depend srcdepend" |
echo " install, srcinstall, pretend, srcpretend" |
32 |
|
echo " upgrade, srcupgrade," |
33 |
|
echo " install-build-prerequisites," |
34 |
|
echo " pretend-build-prerequisites" |
35 |
|
echo " -d --debug enable debug mode" |
36 |
|
echo " -s --smage use a smage to calculate dependencies" |
37 |
echo |
echo |
38 |
echo "method,name, version and build must be given !" |
echo "method, category, name, version and build must be given !" |
39 |
echo |
echo |
40 |
exit 1 |
exit 1 |
41 |
} |
} |
42 |
|
|
43 |
|
# always default debug=0 |
44 |
|
DEBUG=0 |
45 |
|
|
46 |
# very basic getops |
# very basic getops |
47 |
for i in $* |
for i in $* |
48 |
do |
do |
52 |
--pver|-v) shift; PVER="$1" ;; |
--pver|-v) shift; PVER="$1" ;; |
53 |
--pbuild|-b) shift; PBUILD="$1" ;; |
--pbuild|-b) shift; PBUILD="$1" ;; |
54 |
--method|-m) shift; METHOD="$1" ;; |
--method|-m) shift; METHOD="$1" ;; |
55 |
|
--debug|-d) shift; DEBUG=1 ;; |
56 |
|
--smage|-s) shift; SMAGEFILE="$1"; SILENT=1; FVERBOSE=off ;; |
57 |
--help|-h) usage ;; |
--help|-h) usage ;; |
58 |
esac |
esac |
59 |
shift |
shift |
60 |
done |
done |
61 |
|
|
62 |
# sanity checks; abort if not given |
# sanity checks; abort if not given |
63 |
[ -z "${PCAT}" ] && usage |
if [[ -z ${SMAGEFILE} ]] |
64 |
[ -z "${PNAME}" ] && usage |
then |
65 |
[ -z "${PVER}" ] && usage |
[ -z "${PCAT}" ] && usage |
66 |
[ -z "${PBUILD}" ] && usage |
[ -z "${PNAME}" ] && usage |
67 |
|
[ -z "${PVER}" ] && usage |
68 |
|
[ -z "${PBUILD}" ] && usage |
69 |
|
fi |
70 |
[ -z "${METHOD}" ] && usage |
[ -z "${METHOD}" ] && usage |
71 |
|
|
72 |
# check needed global vars |
# check needed global vars |
76 |
|
|
77 |
# other needed vars |
# other needed vars |
78 |
ALLDEPS="" |
ALLDEPS="" |
79 |
|
if [[ -n ${SMAGEFILE} ]] |
80 |
|
then |
81 |
|
if [[ -e ${SMAGEFILE} ]] |
82 |
|
then |
83 |
|
smagesource "${SMAGEFILE}" |
84 |
|
else |
85 |
|
die "Smage file '${SMAGEFILE}' does not exist!" |
86 |
|
fi |
87 |
|
fi |
88 |
MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage" |
MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage" |
89 |
|
|
90 |
|
# much faster than fgrep |
91 |
|
checklist_alldeps() |
92 |
|
{ |
93 |
|
local i |
94 |
|
local item="$1" |
95 |
|
|
96 |
|
for i in ${ALLDEPS} |
97 |
|
do |
98 |
|
[[ ${i} = ${item} ]] && return 1 |
99 |
|
done |
100 |
|
|
101 |
|
return 0 |
102 |
|
} |
103 |
|
|
104 |
|
checklist_processeddeps() |
105 |
|
{ |
106 |
|
local i |
107 |
|
local item="$1" |
108 |
|
|
109 |
|
for i in ${PROCESSEDDEPS} |
110 |
|
do |
111 |
|
[[ ${i} = ${item} ]] && return 1 |
112 |
|
done |
113 |
|
|
114 |
|
return 0 |
115 |
|
} |
116 |
|
|
117 |
##################### |
##################### |
118 |
## rumwandern /path/to/mage/file/.mage |
## depwalking /path/to/mage/file/.mage |
119 |
rumwandern() |
depwalking() |
120 |
{ |
{ |
121 |
unset DEPEND |
unset DEPEND |
122 |
unset SDEPEND |
unset SDEPEND |
132 |
local INSTALL_VIRTUAL |
local INSTALL_VIRTUAL |
133 |
local PNAME |
local PNAME |
134 |
local PCAT |
local PCAT |
135 |
|
local PVER |
136 |
|
local PBUILD |
137 |
|
|
138 |
DFILE="$1" |
DFILE="$1" |
139 |
|
|
140 |
|
# debug info |
141 |
|
decho "depwalking magefile '${DFILE}'" |
142 |
|
decho |
143 |
|
|
144 |
source ${DFILE} |
source ${DFILE} |
145 |
|
|
146 |
|
# forced nodeps |
147 |
|
if [[ ${NODEPS} = true ]] |
148 |
|
then |
149 |
|
DEPEND="" |
150 |
|
SDEPEND="" |
151 |
|
fi |
152 |
|
|
153 |
MY_DEPEND="${DEPEND}" |
MY_DEPEND="${DEPEND}" |
154 |
|
|
155 |
# for srcinstall & srcdepend only; SDEPEND also needed |
# for srcinstall & srcdepend only; SDEPEND also needed |
156 |
if [[ ${METHOD} = srcinstall ]] || [[ ${METHOD} = srcpretend ]] |
if [[ ${METHOD} = srcinstall ]] || |
157 |
|
[[ ${METHOD} = srcpretend ]] || |
158 |
|
[[ ${METHOD} = srcupgrade ]] || |
159 |
|
[[ ${METHOD} = srcuppretend ]] || |
160 |
|
[[ ${METHOD} = install-build-prerequisites ]] || |
161 |
|
[[ ${METHOD} = pretend-build-prerequisites ]] |
162 |
then |
then |
163 |
# only if SDEPEND is not zero |
# only if SDEPEND is not zero |
164 |
if [ -n "${SDEPEND}" ] |
if [ -n "${SDEPEND}" ] |
179 |
|
|
180 |
if [ -z "${MY_DEPEND}" ] |
if [ -z "${MY_DEPEND}" ] |
181 |
then |
then |
182 |
|
decho "MY_DEPEND is empty; deps of '${DFILE}' ignored" |
183 |
return 1 |
return 1 |
184 |
fi |
fi |
185 |
|
|
186 |
while read SYM DEPNAME |
while read SYM DEPNAME |
187 |
do |
do |
188 |
|
# debug info |
189 |
|
decho "DEPNAME='${DEPNAME}'" |
190 |
|
|
191 |
|
# exclude empty depnames |
192 |
|
[[ -z ${DEPNAME} ]] && continue |
193 |
|
|
194 |
|
# exclude all already processed deps -without version |
195 |
|
if ! checklist_processeddeps "${DEPNAME%-*}" |
196 |
|
then |
197 |
|
continue |
198 |
|
fi |
199 |
|
|
200 |
|
# mark depfile as processed to prevent double runs -without version |
201 |
|
# but do not add any virtuals to PROCESSEDDEPS or their resolved |
202 |
|
# pkgnames will be ignored and they are missing on the dependecy-list |
203 |
|
if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]] |
204 |
|
then |
205 |
|
PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}" |
206 |
|
fi |
207 |
|
|
208 |
HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") |
HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") |
209 |
|
if [[ -z ${HIGHEST_DEPFILE} ]] |
210 |
|
then |
211 |
|
INVALID_DEPS+=" ${DEPNAME}:${DFILE}" |
212 |
|
continue |
213 |
|
fi |
214 |
|
|
215 |
PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" |
PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" |
216 |
PNAME="$(magename2pname ${HIGHEST_DEPFILE})" |
PNAME="$(magename2pname ${HIGHEST_DEPFILE})" |
217 |
PVER="$(magename2pver ${HIGHEST_DEPFILE})" |
PVER="$(magename2pver ${HIGHEST_DEPFILE})" |
218 |
PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})" |
PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})" |
219 |
|
|
220 |
## check ob schon in ALLDEPS enthalten dann mach weiter |
## dep already in ALLDEPS? then going on |
221 |
if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ] |
|
222 |
|
# usage of fgrep is extremly slow and consumes a lot of cpu power |
223 |
|
#if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ] |
224 |
|
if checklist_alldeps "${HIGHEST_DEPFILE}" |
225 |
then |
then |
226 |
### check ob DFILE schon installiert ist ### |
### check if the dependency is already installed ### |
227 |
if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
228 |
then |
then |
229 |
rumwandern ${HIGHEST_DEPFILE} |
depwalking ${HIGHEST_DEPFILE} |
230 |
ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}" |
ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}" |
231 |
|
decho "added '${HIGHEST_DEPFILE}' to ALLDEPS" |
232 |
fi |
fi |
233 |
fi |
fi |
234 |
done << EOF |
done << EOF |
237 |
return 0 |
return 0 |
238 |
} |
} |
239 |
|
|
240 |
|
[[ ${METHOD} = pretend ]] || \ |
241 |
|
[[ ${METHOD} = srcpretend ]] || \ |
242 |
|
[[ ${METHOD} = uppretend ]] || \ |
243 |
|
[[ ${METHOD} = srcuppretend ]] || \ |
244 |
|
[[ ${METHOD} = pretend-build-prerequisites ]] && \ |
245 |
|
echo -n "Calculating dependencies ... " |
246 |
|
|
|
### abort if this package is already installed (retval 3) |
|
|
# maybe later ? |
|
|
#[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3 |
|
247 |
|
|
248 |
[[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]] && \ |
if [[ ${METHOD} = upgrade ]] || \ |
249 |
echo -n "Calculating dependencies ... " |
[[ ${METHOD} = srcupgrade ]] || \ |
250 |
|
[[ ${METHOD} = uppretend ]] || \ |
251 |
|
[[ ${METHOD} = srcuppretend ]] |
252 |
|
then |
253 |
|
INSTDEPS="$(${MLIBDIR}/magequery.sh -i)" |
254 |
|
for dep in ${INSTDEPS} |
255 |
|
do |
256 |
|
PCAT="$(magename2pcat ${dep} installdb)" |
257 |
|
PNAME="$(magename2pname ${dep})" |
258 |
|
|
259 |
# get dependencies the package |
# get the highest mage file from mage-db |
260 |
rumwandern ${MAGEFILE} |
MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" |
261 |
|
|
262 |
[[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]] && echo "done" |
# debug info |
263 |
|
decho "dep='${dep}'" |
264 |
|
decho "PCAT='${PCAT}'" |
265 |
|
decho "PNAME='${PNAME}'" |
266 |
|
decho "MAGEFILE='${MAGEFILE}'" |
267 |
|
|
268 |
|
# if no install candidate was found, record this |
269 |
|
# and process with the next one |
270 |
|
if [[ -z ${MAGEFILE} ]] |
271 |
|
then |
272 |
|
NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}" |
273 |
|
decho "added to NO_UPGRADE_CANDIDATE" |
274 |
|
continue |
275 |
|
fi |
276 |
|
|
277 |
|
# now get the pver&pbuild from the new file |
278 |
|
PVER="$(magename2pver ${MAGEFILE})" |
279 |
|
PBUILD="$(magename2pbuild ${MAGEFILE})" |
280 |
|
|
281 |
|
# debug info |
282 |
|
decho "PVER='${PVER}'" |
283 |
|
decho "PBUILD='${PBUILD}'" |
284 |
|
|
285 |
|
# do not walk files which are installed |
286 |
|
if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
287 |
|
then |
288 |
|
# get dependencies the package |
289 |
|
depwalking ${MAGEFILE} |
290 |
|
|
291 |
|
# now add the package itself to the dependencies |
292 |
|
# (if not exists already) |
293 |
|
if checklist_alldeps "${MAGEFILE}" |
294 |
|
then |
295 |
|
decho "added '${MAGEFILE}' to ALLDEPS" |
296 |
|
ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
297 |
|
fi |
298 |
|
else |
299 |
|
# debug info |
300 |
|
decho "ignored package" |
301 |
|
decho |
302 |
|
fi |
303 |
|
done |
304 |
|
else |
305 |
|
# get all dependencies of the package |
306 |
|
if [[ -n ${SMAGEFILE} ]] |
307 |
|
then |
308 |
|
depwalking "${SMAGEFILE}" |
309 |
|
else |
310 |
|
depwalking "${MAGEFILE}" |
311 |
|
fi |
312 |
|
fi |
313 |
|
|
314 |
|
if [[ ${METHOD} != install-build-prerequisites ]] && |
315 |
|
[[ ${METHOD} != pretend-build-prerequisites ]] && |
316 |
|
[[ ${METHOD} != upgrade ]] && |
317 |
|
[[ ${METHOD} != uppretend ]] && |
318 |
|
[[ ${METHOD} != srcupgrade ]] && |
319 |
|
[[ ${METHOD} != srcuppretend ]] |
320 |
|
then |
321 |
|
# now add the package itself to the dependencies |
322 |
|
# (if not exists already) |
323 |
|
if checklist_alldeps "${MAGEFILE}" |
324 |
|
then |
325 |
|
decho "added '${MAGEFILE}' to ALLDEPS" |
326 |
|
ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
327 |
|
fi |
328 |
|
fi |
329 |
|
|
330 |
|
[[ ${METHOD} = pretend ]] || \ |
331 |
|
[[ ${METHOD} = srcpretend ]] || \ |
332 |
|
[[ ${METHOD} = uppretend ]] || \ |
333 |
|
[[ ${METHOD} = srcuppretend ]] || \ |
334 |
|
[[ ${METHOD} = pretend-build-prerequisites ]] && \ |
335 |
|
echo "done" |
336 |
|
|
|
# now add the package itself to the dependencies |
|
|
ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
|
337 |
|
|
338 |
## show output of pretend |
## show output of pretend |
339 |
if [[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]] |
if [[ ${METHOD} = pretend ]] || \ |
340 |
|
[[ ${METHOD} = srcpretend ]] || \ |
341 |
|
[[ ${METHOD} = uppretend ]] || \ |
342 |
|
[[ ${METHOD} = srcuppretend ]] || \ |
343 |
|
[[ ${METHOD} = pretend-build-prerequisites ]] |
344 |
then |
then |
345 |
# this is a little bit faster |
# this is a little bit faster |
346 |
declare -i x=0 |
declare -i x=0 |
357 |
PBUILD="$(magename2pbuild ${i})" |
PBUILD="$(magename2pbuild ${i})" |
358 |
if [ -z "${list}" ] |
if [ -z "${list}" ] |
359 |
then |
then |
360 |
list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
361 |
else |
else |
362 |
list="${list} |
list="${list} |
363 |
\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
367 |
echo "done" |
echo "done" |
368 |
echo -e "${list}" |
echo -e "${list}" |
369 |
echo |
echo |
370 |
|
|
371 |
|
if [[ ! -z ${INVALID_DEPS} ]] |
372 |
|
then |
373 |
|
echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}" |
374 |
|
for i in ${INVALID_DEPS} |
375 |
|
do |
376 |
|
_dep="${i%%:*}" |
377 |
|
_mage="${i##*:}" |
378 |
|
echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}" |
379 |
|
done |
380 |
|
echo |
381 |
|
fi |
382 |
|
|
383 |
|
if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]] |
384 |
|
then |
385 |
|
echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}" |
386 |
|
for i in ${NO_UPGRADE_CANDIDATE} |
387 |
|
do |
388 |
|
echo -e "${COLRED} ${i}${COLDEFAULT}" |
389 |
|
done |
390 |
|
echo |
391 |
|
echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}" |
392 |
|
echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}" |
393 |
|
echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}" |
394 |
|
echo |
395 |
|
fi |
396 |
fi |
fi |
397 |
|
|
398 |
## return output from src/install deps |
## return output from src/install deps |
399 |
[[ ${METHOD} = install ]] || [[ ${METHOD} = srcinstall ]] && echo "${ALLDEPS}" |
[[ ${METHOD} = install ]] || \ |
400 |
|
[[ ${METHOD} = srcinstall ]] || \ |
401 |
# delete ${BUILDDIR}/virtuals if exists as not needed anymore |
[[ ${METHOD} = upgrade ]] || \ |
402 |
#[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals |
[[ ${METHOD} = srcupgrade ]] || \ |
403 |
|
[[ ${METHOD} = install-build-prerequisites ]] && \ |
404 |
|
echo "${ALLDEPS}" |