Magellan Linux

Contents of /trunk/mage/usr/lib/mage/depwalker.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2195 - (show annotations) (download) (as text)
Thu Oct 10 11:05:34 2013 UTC (10 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 7605 byte(s)
-depwalker: do not add loop dependencies to the install list twice
1 #!/bin/bash
2 # $Id$
3 # dependeny walker
4
5 # default die function
6 die()
7 {
8 echo ${COLRED}"$@"${COLDEFAULT}
9 exit 1
10 }
11
12 # include all needed files
13 [ -f /etc/mage.rc.global ] && \
14 source /etc/mage.rc.global || \
15 die "/etc/mage.rc.global missing"
16
17 [ -f ${MAGERC} ] && source ${MAGERC} || \
18 die "Your ${MAGERC} is missing. Aborting."
19
20 [ -f ${MLIBDIR}/mage4.functions.sh ] && \
21 source ${MLIBDIR}/mage4.functions.sh || \
22 die "mage functions missing"
23
24 usage()
25 {
26 echo
27 echo "Usage: $(basename $0) [command] [arg] ..."
28 echo
29 echo " -h --help shows this help"
30 echo " -c --pcat categorie of the package"
31 echo " -n --pname name of the package"
32 echo " -v --pver version number of the package"
33 echo " -b --pbuild build number of the package"
34 echo " -m --method which calc method should be used:"
35 echo " install, srcinstall, depend, srcdepend"
36 echo " upgrade, srcupgrade"
37 echo
38 echo "method, name, version and build must be given !"
39 echo
40 exit 1
41 }
42
43 # very basic getops
44 for i in $*
45 do
46 case $1 in
47 --pcat|-c) shift; PCAT="$1" ;;
48 --pname|-n) shift; PNAME="$1" ;;
49 --pver|-v) shift; PVER="$1" ;;
50 --pbuild|-b) shift; PBUILD="$1" ;;
51 --method|-m) shift; METHOD="$1" ;;
52 --help|-h) usage ;;
53 esac
54 shift
55 done
56
57 # sanity checks; abort if not given
58 [ -z "${PCAT}" ] && usage
59 [ -z "${PNAME}" ] && usage
60 [ -z "${PVER}" ] && usage
61 [ -z "${PBUILD}" ] && usage
62 [ -z "${METHOD}" ] && usage
63
64 # check needed global vars
65 [ -z "${MAGEDIR}" ] && die "\$MAGEDIR not set."
66 [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set."
67 [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set."
68
69 # other needed vars
70 ALLDEPS=""
71 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 ## depwalking /path/to/mage/file/.mage
102 depwalking()
103 {
104 unset DEPEND
105 unset SDEPEND
106 unset MY_DEPEND
107
108 local DFILE
109 local SYM
110 local DEPNAME
111 local HIGHEST_DEPFILE
112 local MY_DEPEND
113 local REAL_PGKNAME
114 local VIRTUAL_NAME
115 local INSTALL_VIRTUAL
116 local PNAME
117 local PCAT
118 local PVER
119 local PBUILD
120
121 DFILE="$1"
122
123 source ${DFILE}
124
125 # forced nodeps
126 if [[ ${NODEPS} = true ]]
127 then
128 DEPEND=""
129 SDEPEND=""
130 fi
131
132 MY_DEPEND="${DEPEND}"
133
134 # for srcinstall & srcdepend only; SDEPEND also needed
135 if [[ ${METHOD} = srcinstall ]] || \
136 [[ ${METHOD} = srcpretend ]] || \
137 [[ ${METHOD} = srcupgrade ]] || \
138 [[ ${METHOD} = srcuppretend ]]
139 then
140 # only if SDEPEND is not zero
141 if [ -n "${SDEPEND}" ]
142 then
143 # crlf is substantly needed !!
144 if [ -n "${MY_DEPEND}" ]
145 then
146 MY_DEPEND="${MY_DEPEND}
147 ${SDEPEND}"
148 else
149 MY_DEPEND="${SDEPEND}"
150 fi
151 fi
152 fi
153
154 unset DEPEND
155 unset SDEPEND
156
157 if [ -z "${MY_DEPEND}" ]
158 then
159 return 1
160 fi
161
162 while read SYM DEPNAME
163 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}")
182 if [[ -z ${HIGHEST_DEPFILE} ]]
183 then
184 INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
185 continue
186 fi
187
188 PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
189 PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
190 PVER="$(magename2pver ${HIGHEST_DEPFILE})"
191 PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
192
193 ## dep already in ALLDEPS? then going on
194
195 # usage of fgrep is extremly slow and consumes a lot of cpu power
196 #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
197 if checklist_alldeps "${HIGHEST_DEPFILE}"
198 then
199 ### check if the dependency is already installed ###
200 if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
201 then
202 depwalking ${HIGHEST_DEPFILE}
203 ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
204 fi
205 fi
206 done << EOF
207 ${MY_DEPEND}
208 EOF
209 return 0
210 }
211
212 [[ ${METHOD} = pretend ]] || \
213 [[ ${METHOD} = srcpretend ]] || \
214 [[ ${METHOD} = uppretend ]] || \
215 [[ ${METHOD} = srcuppretend ]] && \
216 echo -n "Calculating dependencies ... "
217
218
219 if [[ ${METHOD} = upgrade ]] || \
220 [[ ${METHOD} = srcupgrade ]] || \
221 [[ ${METHOD} = uppretend ]] || \
222 [[ ${METHOD} = srcuppretend ]]
223 then
224 INSTDEPS="$(${MLIBDIR}/magequery.sh -i)"
225 for dep in ${INSTDEPS}
226 do
227 PCAT="$(magename2pcat ${dep} installdb)"
228 PNAME="$(magename2pname ${dep})"
229
230 # get the highest mage file from mage-db
231 MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
232
233 # if no install candidate was found, record this
234 # and process with the next one
235 if [[ -z ${MAGEFILE} ]]
236 then
237 NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
238 continue
239 fi
240
241 # now get the pver&pbuild from the new file
242 PVER="$(magename2pver ${MAGEFILE})"
243 PBUILD="$(magename2pbuild ${MAGEFILE})"
244
245 # do not walk files which are installed
246 if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
247 then
248 # get dependencies the package
249 depwalking ${MAGEFILE}
250 fi
251 done
252 else
253 # get all dependencies of the package
254 depwalking ${MAGEFILE}
255 fi
256
257 # now add the package itself to the dependencies
258 # (if not exists already)
259 if checklist_alldeps "${MAGEFILE}"
260 then
261 ALLDEPS="${ALLDEPS} ${MAGEFILE}"
262 fi
263
264 [[ ${METHOD} = pretend ]] || \
265 [[ ${METHOD} = srcpretend ]] || \
266 [[ ${METHOD} = uppretend ]] || \
267 [[ ${METHOD} = srcuppretend ]] && \
268 echo "done"
269
270
271 ## show output of pretend
272 if [[ ${METHOD} = pretend ]] || \
273 [[ ${METHOD} = srcpretend ]] || \
274 [[ ${METHOD} = uppretend ]] || \
275 [[ ${METHOD} = srcuppretend ]]
276 then
277 # this is a little bit faster
278 declare -i x=0
279 echo -n "Building dependencies list ... "
280 for i in ${ALLDEPS}
281 do
282 (( x++ ))
283 k="$x"
284 [ ${x} -le 9 ] && k="0${k}"
285 #[ ${x} -le 99 ] && k="0${k}"
286 PCAT="$(magename2pcat ${i})"
287 PNAME="$(magename2pname ${i})"
288 PVER="$(magename2pver ${i})"
289 PBUILD="$(magename2pbuild ${i})"
290 if [ -z "${list}" ]
291 then
292 list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
293 else
294 list="${list}
295 \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
296 fi
297 unset PCAT PNAME PVER PBUILD
298 done
299 echo "done"
300 echo -e "${list}"
301 echo
302
303 if [[ ! -z ${INVALID_DEPS} ]]
304 then
305 echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}"
306 for i in ${INVALID_DEPS}
307 do
308 _dep="${i%%:*}"
309 _mage="${i##*:}"
310 echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}"
311 done
312 echo
313 fi
314
315 if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
316 then
317 echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
318 for i in ${NO_UPGRADE_CANDIDATE}
319 do
320 echo -e "${COLRED} ${i}${COLDEFAULT}"
321 done
322 echo
323 echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"
324 echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"
325 echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
326 echo
327 fi
328 fi
329
330 ## return output from src/install deps
331 [[ ${METHOD} = install ]] || \
332 [[ ${METHOD} = srcinstall ]] || \
333 [[ ${METHOD} = upgrade ]] || \
334 [[ ${METHOD} = srcupgrade ]] && \
335 echo "${ALLDEPS}"

Properties

Name Value
svn:executable *