2 |
# $Id$ |
# $Id$ |
3 |
# dependeny walker |
# dependeny walker |
4 |
|
|
5 |
# default die function |
decho() |
|
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 /etc/mage.rc.global ] && \ |
source ${MLIBDIR}/common.functions.sh || exit 1 |
15 |
source /etc/mage.rc.global || \ |
source @@SYSCONFDIR@@/mage.rc.global || die "@@SYSCONFDIR@@/mage.rc.global missing" |
16 |
die "/etc/mage.rc.global missing" |
source ${MAGERC} || die "Your ${MAGERC} is missing. Aborting." |
17 |
|
source ${MLIBDIR}/mage4.functions.sh || die "mage functions missing" |
18 |
[ -f ${MAGERC} ] && source ${MAGERC} || \ |
source ${MLIBDIR}/smage2.functions.sh || die "smage functions missing" |
|
die "Your ${MAGERC} is missing. Aborting." |
|
|
|
|
|
[ -f ${MLIBDIR}/mage4.functions.sh ] && \ |
|
|
source ${MLIBDIR}/mage4.functions.sh || \ |
|
|
die "mage functions missing" |
|
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" |
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 |
# much faster than fgrep |
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 |
# forced nodeps |
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 ]] || \ |
if [[ ${METHOD} = srcinstall ]] || |
157 |
[[ ${METHOD} = srcpretend ]] || \ |
[[ ${METHOD} = srcpretend ]] || |
158 |
[[ ${METHOD} = srcupgrade ]] || \ |
[[ ${METHOD} = srcupgrade ]] || |
159 |
[[ ${METHOD} = srcuppretend ]] |
[[ ${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 |
# exclude empty depnames |
192 |
[[ -z ${DEPNAME} ]] && continue |
[[ -z ${DEPNAME} ]] && continue |
193 |
|
|
228 |
then |
then |
229 |
depwalking ${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 |
240 |
[[ ${METHOD} = pretend ]] || \ |
[[ ${METHOD} = pretend ]] || \ |
241 |
[[ ${METHOD} = srcpretend ]] || \ |
[[ ${METHOD} = srcpretend ]] || \ |
242 |
[[ ${METHOD} = uppretend ]] || \ |
[[ ${METHOD} = uppretend ]] || \ |
243 |
[[ ${METHOD} = srcuppretend ]] && \ |
[[ ${METHOD} = srcuppretend ]] || \ |
244 |
|
[[ ${METHOD} = pretend-build-prerequisites ]] && \ |
245 |
echo -n "Calculating dependencies ... " |
echo -n "Calculating dependencies ... " |
246 |
|
|
247 |
|
|
259 |
# get the highest mage file from mage-db |
# get the highest mage file from mage-db |
260 |
MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" |
MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" |
261 |
|
|
262 |
|
# 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 |
# if no install candidate was found, record this |
269 |
# and process with the next one |
# and process with the next one |
270 |
if [[ -z ${MAGEFILE} ]] |
if [[ -z ${MAGEFILE} ]] |
271 |
then |
then |
272 |
NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}" |
NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}" |
273 |
|
decho "added to NO_UPGRADE_CANDIDATE" |
274 |
continue |
continue |
275 |
fi |
fi |
276 |
|
|
278 |
PVER="$(magename2pver ${MAGEFILE})" |
PVER="$(magename2pver ${MAGEFILE})" |
279 |
PBUILD="$(magename2pbuild ${MAGEFILE})" |
PBUILD="$(magename2pbuild ${MAGEFILE})" |
280 |
|
|
281 |
|
# debug info |
282 |
|
decho "PVER='${PVER}'" |
283 |
|
decho "PBUILD='${PBUILD}'" |
284 |
|
|
285 |
# do not walk files which are installed |
# do not walk files which are installed |
286 |
if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
287 |
then |
then |
288 |
# get dependencies the package |
# get dependencies the package |
289 |
depwalking ${MAGEFILE} |
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 |
fi |
303 |
done |
done |
304 |
else |
else |
305 |
# get all dependencies of the package |
# get all dependencies of the package |
306 |
depwalking ${MAGEFILE} |
if [[ -n ${SMAGEFILE} ]] |
307 |
|
then |
308 |
|
depwalking "${SMAGEFILE}" |
309 |
|
else |
310 |
|
depwalking "${MAGEFILE}" |
311 |
|
fi |
312 |
fi |
fi |
313 |
|
|
314 |
# now add the package itself to the dependencies |
if [[ ${METHOD} != install-build-prerequisites ]] && |
315 |
# (if not exists already) |
[[ ${METHOD} != pretend-build-prerequisites ]] && |
316 |
if checklist_alldeps "${MAGEFILE}" |
[[ ${METHOD} != upgrade ]] && |
317 |
|
[[ ${METHOD} != uppretend ]] && |
318 |
|
[[ ${METHOD} != srcupgrade ]] && |
319 |
|
[[ ${METHOD} != srcuppretend ]] |
320 |
then |
then |
321 |
ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
# 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 |
fi |
329 |
|
|
330 |
[[ ${METHOD} = pretend ]] || \ |
[[ ${METHOD} = pretend ]] || \ |
331 |
[[ ${METHOD} = srcpretend ]] || \ |
[[ ${METHOD} = srcpretend ]] || \ |
332 |
[[ ${METHOD} = uppretend ]] || \ |
[[ ${METHOD} = uppretend ]] || \ |
333 |
[[ ${METHOD} = srcuppretend ]] && \ |
[[ ${METHOD} = srcuppretend ]] || \ |
334 |
|
[[ ${METHOD} = pretend-build-prerequisites ]] && \ |
335 |
echo "done" |
echo "done" |
336 |
|
|
337 |
|
|
339 |
if [[ ${METHOD} = pretend ]] || \ |
if [[ ${METHOD} = pretend ]] || \ |
340 |
[[ ${METHOD} = srcpretend ]] || \ |
[[ ${METHOD} = srcpretend ]] || \ |
341 |
[[ ${METHOD} = uppretend ]] || \ |
[[ ${METHOD} = uppretend ]] || \ |
342 |
[[ ${METHOD} = srcuppretend ]] |
[[ ${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}" |
399 |
[[ ${METHOD} = install ]] || \ |
[[ ${METHOD} = install ]] || \ |
400 |
[[ ${METHOD} = srcinstall ]] || \ |
[[ ${METHOD} = srcinstall ]] || \ |
401 |
[[ ${METHOD} = upgrade ]] || \ |
[[ ${METHOD} = upgrade ]] || \ |
402 |
[[ ${METHOD} = srcupgrade ]] && \ |
[[ ${METHOD} = srcupgrade ]] || \ |
403 |
|
[[ ${METHOD} = install-build-prerequisites ]] && \ |
404 |
echo "${ALLDEPS}" |
echo "${ALLDEPS}" |