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.1 2005-09-09 16:35:27 niro Exp $ |
|
4 |
|
|
5 |
# default die function |
# default die function |
6 |
die() |
die() |
9 |
exit 1 |
exit 1 |
10 |
} |
} |
11 |
|
|
12 |
# # include all needed files |
# include all needed files |
13 |
# [ -f ${MLIBDIR}/conf/mage.rc.global ] && \ |
[ -f /etc/mage.rc.global ] && \ |
14 |
# source ${MLIBDIR}/conf/mage.rc.global || \ |
source /etc/mage.rc.global || \ |
15 |
# die "${MLIBDIR}/conf/mage.rc.global missing" |
die "/etc/mage.rc.global missing" |
16 |
# |
|
17 |
# [ -f /etc/mage.rc ] && source /etc/mage.rc || \ |
[ -f ${MAGERC} ] && source ${MAGERC} || \ |
18 |
# die "Your /etc/mage.rc is missing. Aborting." |
die "Your ${MAGERC} is missing. Aborting." |
19 |
# |
|
20 |
# [ -f ${MLIBDIR}/mage.functions.sh ] && \ |
[ -f ${MLIBDIR}/mage4.functions.sh ] && \ |
21 |
# source ${MLIBDIR}/mage.functions.sh || \ |
source ${MLIBDIR}/mage4.functions.sh || \ |
22 |
# die "mage functions missing" |
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 |
|
23 |
|
|
24 |
usage() |
usage() |
25 |
{ |
{ |
32 |
echo " -v --pver version number of the package" |
echo " -v --pver version number of the package" |
33 |
echo " -b --pbuild build number of the package" |
echo " -b --pbuild build number of the package" |
34 |
echo " -m --method which calc method should be used:" |
echo " -m --method which calc method should be used:" |
35 |
echo " install srcinstall depend srcdepend" |
echo " install, srcinstall, depend, srcdepend" |
36 |
|
echo " upgrade, srcupgrade" |
37 |
echo |
echo |
38 |
echo "method,name, version and build must be given !" |
echo "method, name, version and build must be given !" |
39 |
echo |
echo |
40 |
exit 1 |
exit 1 |
41 |
} |
} |
70 |
ALLDEPS="" |
ALLDEPS="" |
71 |
MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage" |
MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage" |
72 |
|
|
73 |
|
# much faster than fgrep |
74 |
|
checklist_alldeps() |
75 |
|
{ |
76 |
|
local i |
77 |
|
local item="$1" |
78 |
|
|
79 |
|
for i in ${ALLDEPS} |
80 |
|
do |
81 |
|
[[ ${i} = ${item} ]] && return 1 |
82 |
|
done |
83 |
|
|
84 |
|
return 0 |
85 |
|
} |
86 |
|
|
87 |
|
checklist_processeddeps() |
88 |
|
{ |
89 |
|
local i |
90 |
|
local item="$1" |
91 |
|
|
92 |
|
for i in ${PROCESSEDDEPS} |
93 |
|
do |
94 |
|
[[ ${i} = ${item} ]] && return 1 |
95 |
|
done |
96 |
|
|
97 |
|
return 0 |
98 |
|
} |
99 |
|
|
100 |
##################### |
##################### |
101 |
## rumwandern /path/to/mage/file/.mage |
## rumwandern /path/to/mage/file/.mage |
102 |
rumwandern() |
rumwandern() |
115 |
local INSTALL_VIRTUAL |
local INSTALL_VIRTUAL |
116 |
local PNAME |
local PNAME |
117 |
local PCAT |
local PCAT |
118 |
|
local PVER |
119 |
|
local PBUILD |
120 |
|
|
121 |
DFILE="$1" |
DFILE="$1" |
122 |
|
|
123 |
source ${DFILE} |
source ${DFILE} |
124 |
|
|
125 |
|
# forced nodeps |
126 |
|
if [[ ${NODEPS} = true ]] |
127 |
|
then |
128 |
|
DEPEND="" |
129 |
|
SDEPEND="" |
130 |
|
fi |
131 |
|
|
132 |
MY_DEPEND="${DEPEND}" |
MY_DEPEND="${DEPEND}" |
133 |
|
|
134 |
# for srcinstall & srcdepend only; SDEPEND also needed |
# for srcinstall & srcdepend only; SDEPEND also needed |
135 |
if [[ ${METHOD} = srcinstall ]] || [[ ${METHOD} = srcpretend ]] |
if [[ ${METHOD} = srcinstall ]] || \ |
136 |
|
[[ ${METHOD} = srcpretend ]] || \ |
137 |
|
[[ ${METHOD} = srcupgrade ]] || \ |
138 |
|
[[ ${METHOD} = srcuppretend ]] |
139 |
then |
then |
140 |
# only if SDEPEND is not zero |
# only if SDEPEND is not zero |
141 |
if [ -n "${SDEPEND}" ] |
if [ -n "${SDEPEND}" ] |
161 |
|
|
162 |
while read SYM DEPNAME |
while read SYM DEPNAME |
163 |
do |
do |
164 |
|
# exclude empty depnames |
165 |
|
[[ -z ${DEPNAME} ]] && continue |
166 |
|
|
167 |
|
# exclude all already processed deps -without version |
168 |
|
if ! checklist_processeddeps "${DEPNAME%-*}" |
169 |
|
then |
170 |
|
continue |
171 |
|
fi |
172 |
|
|
173 |
|
# mark depfile as processed to prevent double runs -without version |
174 |
|
# but do not add any virtuals to PROCESSEDDEPS or their resolved |
175 |
|
# pkgnames will be ignored and they are missing on the dependecy-list |
176 |
|
if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]] |
177 |
|
then |
178 |
|
PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}" |
179 |
|
fi |
180 |
|
|
181 |
HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") |
HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") |
182 |
|
|
183 |
PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" |
PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" |
185 |
PVER="$(magename2pver ${HIGHEST_DEPFILE})" |
PVER="$(magename2pver ${HIGHEST_DEPFILE})" |
186 |
PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})" |
PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})" |
187 |
|
|
188 |
## check ob schon in ALLDEPS enthalten dann mach weiter |
## dep already in ALLDEPS? then going on |
189 |
if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ] |
|
190 |
|
# usage of fgrep is extremly slow and consumes a lot of cpu power |
191 |
|
#if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ] |
192 |
|
if checklist_alldeps "${HIGHEST_DEPFILE}" |
193 |
then |
then |
194 |
### check ob DFILE schon installiert ist ### |
### check ob DFILE schon installiert ist ### |
195 |
if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
204 |
return 0 |
return 0 |
205 |
} |
} |
206 |
|
|
207 |
|
[[ ${METHOD} = pretend ]] || \ |
208 |
|
[[ ${METHOD} = srcpretend ]] || \ |
209 |
|
[[ ${METHOD} = uppretend ]] || \ |
210 |
|
[[ ${METHOD} = srcuppretend ]] && \ |
211 |
|
echo -n "Calculating dependencies ... " |
212 |
|
|
|
### abort if this package is already installed (retval 3) |
|
|
# maybe later ? |
|
|
#[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3 |
|
213 |
|
|
214 |
[[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]] && \ |
if [[ ${METHOD} = upgrade ]] || \ |
215 |
echo -n "Calculating dependencies ... " |
[[ ${METHOD} = srcupgrade ]] || \ |
216 |
|
[[ ${METHOD} = uppretend ]] || \ |
217 |
|
[[ ${METHOD} = srcuppretend ]] |
218 |
|
then |
219 |
|
INSTDEPS="$(${MLIBDIR}/magequery.sh -i)" |
220 |
|
for dep in ${INSTDEPS} |
221 |
|
do |
222 |
|
PCAT="$(magename2pcat ${dep} installdb)" |
223 |
|
PNAME="$(magename2pname ${dep})" |
224 |
|
|
225 |
# get dependencies the package |
# get the highest mage file from mage-db |
226 |
rumwandern ${MAGEFILE} |
MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" |
227 |
|
|
228 |
[[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]] && echo "done" |
# if no install candidate was found, record this |
229 |
|
# and process with the next one |
230 |
|
if [[ -z ${MAGEFILE} ]] |
231 |
|
then |
232 |
|
NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}" |
233 |
|
continue |
234 |
|
fi |
235 |
|
|
236 |
|
# now get the pver&pbuild from the new file |
237 |
|
PVER="$(magename2pver ${MAGEFILE})" |
238 |
|
PBUILD="$(magename2pbuild ${MAGEFILE})" |
239 |
|
|
240 |
|
# do not walk files which are installed |
241 |
|
if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] |
242 |
|
then |
243 |
|
# get dependencies the package |
244 |
|
rumwandern ${MAGEFILE} |
245 |
|
|
246 |
|
# now add the package itself to the dependencies |
247 |
|
# (if not exists already) |
248 |
|
#if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ] |
249 |
|
if checklist_alldeps "${MAGEFILE}" |
250 |
|
then |
251 |
|
ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
252 |
|
fi |
253 |
|
fi |
254 |
|
done |
255 |
|
else |
256 |
|
# get all dependencies of the package |
257 |
|
rumwandern ${MAGEFILE} |
258 |
|
|
259 |
|
# now add the package itself to the dependencies |
260 |
|
ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
261 |
|
fi |
262 |
|
|
263 |
|
[[ ${METHOD} = pretend ]] || \ |
264 |
|
[[ ${METHOD} = srcpretend ]] || \ |
265 |
|
[[ ${METHOD} = uppretend ]] || \ |
266 |
|
[[ ${METHOD} = srcuppretend ]] && \ |
267 |
|
echo "done" |
268 |
|
|
|
# now add the package itself to the dependencies |
|
|
ALLDEPS="${ALLDEPS} ${MAGEFILE}" |
|
269 |
|
|
270 |
## show output of pretend |
## show output of pretend |
271 |
if [[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]] |
if [[ ${METHOD} = pretend ]] || \ |
272 |
|
[[ ${METHOD} = srcpretend ]] || \ |
273 |
|
[[ ${METHOD} = uppretend ]] || \ |
274 |
|
[[ ${METHOD} = srcuppretend ]] |
275 |
then |
then |
276 |
# this is a little bit faster |
# this is a little bit faster |
277 |
declare -i x=0 |
declare -i x=0 |
298 |
echo "done" |
echo "done" |
299 |
echo -e "${list}" |
echo -e "${list}" |
300 |
echo |
echo |
301 |
|
|
302 |
|
if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]] |
303 |
|
then |
304 |
|
echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}" |
305 |
|
for i in ${NO_UPGRADE_CANDIDATE} |
306 |
|
do |
307 |
|
echo -e "${COLRED} ${i}${COLDEFAULT}" |
308 |
|
done |
309 |
|
echo |
310 |
|
echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}" |
311 |
|
echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}" |
312 |
|
echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}" |
313 |
|
echo |
314 |
|
fi |
315 |
fi |
fi |
316 |
|
|
317 |
## return output from src/install deps |
## return output from src/install deps |
318 |
[[ ${METHOD} = install ]] || [[ ${METHOD} = srcinstall ]] && echo "${ALLDEPS}" |
[[ ${METHOD} = install ]] || \ |
319 |
|
[[ ${METHOD} = srcinstall ]] || \ |
320 |
# delete ${BUILDDIR}/virtuals if exists as not needed anymore |
[[ ${METHOD} = upgrade ]] || \ |
321 |
#[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals |
[[ ${METHOD} = srcupgrade ]] && \ |
322 |
|
echo "${ALLDEPS}" |