Annotation of /branches/mage-sql/usr/lib/mage/sqlwalker.sh
Parent Directory | Revision Log
Revision 1116 -
(hide annotations)
(download)
(as text)
Sat Jul 17 10:48:59 2010 UTC (13 years, 10 months ago) by niro
File MIME type: application/x-sh
File size: 10059 byte(s)
Sat Jul 17 10:48:59 2010 UTC (13 years, 10 months ago) by niro
File MIME type: application/x-sh
File size: 10059 byte(s)
-added sqlwalker, a sql variant of depwalker
1 | niro | 1116 | #!/bin/bash |
2 | |||
3 | #depwalker | ||
4 | # $Id$ | ||
5 | |||
6 | # default die function | ||
7 | die() | ||
8 | { | ||
9 | echo ${COLRED}"$@"${COLDEFAULT} | ||
10 | exit 1 | ||
11 | } | ||
12 | |||
13 | # include all needed files | ||
14 | [ -f /etc/mage.rc.global ] && \ | ||
15 | source /etc/mage.rc.global || \ | ||
16 | die "/etc/mage.rc.global missing" | ||
17 | |||
18 | [ -f ${MAGERC} ] && source ${MAGERC} || \ | ||
19 | die "Your ${MAGERC} is missing. Aborting." | ||
20 | |||
21 | #### fixups #### | ||
22 | MLIBDIR="/home/tjoke/svn/magellan-source/branches/mage-sql/usr/lib/mage" | ||
23 | INSTALLDB="/var/db/mage" | ||
24 | #DBFILE="${MLIBDIR}/mage.db" | ||
25 | DBFILE="${MLIBDIR}/main.db" | ||
26 | MAGE_INSTALL_DB="${MLIBDIR}/install.db" | ||
27 | ################# | ||
28 | |||
29 | |||
30 | [ -f ${MLIBDIR}/mage4.functions.sh ] && \ | ||
31 | source ${MLIBDIR}/mage4.functions.sh || \ | ||
32 | die "mage functions missing" | ||
33 | |||
34 | [ -f ${MLIBDIR}/sql_functions.sh ] && \ | ||
35 | source ${MLIBDIR}/sql_functions.sh || \ | ||
36 | die "sql functions missing" | ||
37 | |||
38 | # not serious if missing, only needed for colors | ||
39 | [ -f /etc/init.d/functions ] && source /etc/init.d/functions | ||
40 | |||
41 | # disable colors if wanted | ||
42 | if [[ ${NOCOLORS} = true ]] | ||
43 | then | ||
44 | COLRED="" | ||
45 | COLGREEN="" | ||
46 | COLYELLOW="" | ||
47 | COLBLUE="" | ||
48 | COLMAGENTA="" | ||
49 | COLWHITE="" | ||
50 | COLDEFAULT="" | ||
51 | fi | ||
52 | |||
53 | usage() | ||
54 | { | ||
55 | echo | ||
56 | echo "Usage: $(basename $0) [command] [arg] ..." | ||
57 | echo | ||
58 | echo " -h --help shows this help" | ||
59 | echo " -c --pcat categorie of the package" | ||
60 | echo " -n --pname name of the package" | ||
61 | echo " -v --pver version number of the package" | ||
62 | echo " -b --pbuild build number of the package" | ||
63 | echo " -m --method which calc method should be used:" | ||
64 | echo " install, srcinstall, depend, srcdepend" | ||
65 | echo " upgrade, srcupgrade" | ||
66 | echo | ||
67 | echo "method, name, version and build must be given !" | ||
68 | echo | ||
69 | exit 1 | ||
70 | } | ||
71 | |||
72 | # very basic getops | ||
73 | for i in $* | ||
74 | do | ||
75 | case $1 in | ||
76 | --pcat|-c) shift; PCAT="$1" ;; | ||
77 | --pname|-n) shift; PNAME="$1" ;; | ||
78 | --pver|-v) shift; PVER="$1" ;; | ||
79 | --pbuild|-b) shift; PBUILD="$1" ;; | ||
80 | --method|-m) shift; METHOD="$1" ;; | ||
81 | --help|-h) usage ;; | ||
82 | esac | ||
83 | shift | ||
84 | done | ||
85 | |||
86 | # sanity checks; abort if not given | ||
87 | [ -z "${PCAT}" ] && usage | ||
88 | [ -z "${PNAME}" ] && usage | ||
89 | [ -z "${PVER}" ] && usage | ||
90 | [ -z "${PBUILD}" ] && usage | ||
91 | [ -z "${METHOD}" ] && usage | ||
92 | |||
93 | # check needed global vars | ||
94 | [ -z "${MAGEDIR}" ] && die "\$MAGEDIR not set." | ||
95 | [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set." | ||
96 | [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set." | ||
97 | |||
98 | # other needed vars | ||
99 | ALLDEPS="" | ||
100 | MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage" | ||
101 | |||
102 | # much faster than fgrep | ||
103 | checklist_alldeps() | ||
104 | { | ||
105 | local i | ||
106 | local item="$1" | ||
107 | |||
108 | for i in ${ALLDEPS} | ||
109 | do | ||
110 | [[ ${i} = ${item} ]] && return 1 | ||
111 | done | ||
112 | |||
113 | return 0 | ||
114 | } | ||
115 | |||
116 | checklist_processeddeps() | ||
117 | { | ||
118 | local i | ||
119 | local item="$1" | ||
120 | |||
121 | for i in ${PROCESSEDDEPS} | ||
122 | do | ||
123 | [[ ${i} = ${item} ]] && return 1 | ||
124 | done | ||
125 | |||
126 | return 0 | ||
127 | } | ||
128 | |||
129 | all_depends() | ||
130 | { | ||
131 | local pname="$1" | ||
132 | local pver="$2" | ||
133 | local pbuild="$3" | ||
134 | |||
135 | sql "select categories.pcat, | ||
136 | depends.pname, | ||
137 | depends.pver, | ||
138 | depends.pbuild | ||
139 | from depends | ||
140 | inner join packages | ||
141 | on depends.pkg_id=packages.id | ||
142 | and packages.pname='${pname}' | ||
143 | and packages.pver='${pver}' | ||
144 | and packages.pbuild='${pbuild}' | ||
145 | inner join categories | ||
146 | on depends.pcat_id=categories.id" | ||
147 | } | ||
148 | |||
149 | all_sdepends() | ||
150 | { | ||
151 | local pname="$1" | ||
152 | local pver="$2" | ||
153 | local pbuild="$3" | ||
154 | |||
155 | sql "select categories.pcat, | ||
156 | sdepends.pname, | ||
157 | sdepends.pver, | ||
158 | sdepends.pbuild | ||
159 | from sdepends | ||
160 | inner join packages | ||
161 | on sdepends.pkg_id=packages.id | ||
162 | and packages.pname='${pname}' | ||
163 | and packages.pver='${pver}' | ||
164 | and packages.pbuild='${pbuild}' | ||
165 | inner join categories | ||
166 | on sdepends.pcat_id=categories.id" | ||
167 | } | ||
168 | |||
169 | |||
170 | ##################### | ||
171 | ## rumwandern /path/to/mage/file/.mage | ||
172 | rumwandern() | ||
173 | { | ||
174 | unset DEPEND | ||
175 | unset SDEPEND | ||
176 | unset MY_DEPEND | ||
177 | |||
178 | local DFILE | ||
179 | local SYM | ||
180 | local DEPNAME | ||
181 | local HIGHEST_DEPFILE | ||
182 | local MY_DEPEND | ||
183 | local REAL_PGKNAME | ||
184 | local VIRTUAL_NAME | ||
185 | local INSTALL_VIRTUAL | ||
186 | local PNAME | ||
187 | local PCAT | ||
188 | local PVER | ||
189 | local PBUILD | ||
190 | |||
191 | local pname="$1" | ||
192 | local pver="$2" | ||
193 | local pbuild="$3" | ||
194 | local state="${MAGE_DISTRIBUTION}" | ||
195 | local retval | ||
196 | local fullname | ||
197 | |||
198 | # forced nodeps | ||
199 | if [[ ${NODEPS} = true ]] | ||
200 | then | ||
201 | DEPEND="" | ||
202 | SDEPEND="" | ||
203 | fi | ||
204 | |||
205 | MY_DEPEND="$(all_depends ${pname} ${pver} ${pbuild})" | ||
206 | |||
207 | # for srcinstall & srcdepend only; SDEPEND also needed | ||
208 | if [[ ${METHOD} = srcinstall ]] || \ | ||
209 | [[ ${METHOD} = srcpretend ]] || \ | ||
210 | [[ ${METHOD} = srcupgrade ]] || \ | ||
211 | [[ ${METHOD} = srcuppretend ]] | ||
212 | then | ||
213 | MY_DEPEND="${MY_DEPEND} | ||
214 | $(all_sdepends ${pname} ${pver} ${pbuild})" | ||
215 | fi | ||
216 | |||
217 | unset DEPEND | ||
218 | unset SDEPEND | ||
219 | |||
220 | if [ -z "${MY_DEPEND}" ] | ||
221 | then | ||
222 | return 1 | ||
223 | fi | ||
224 | |||
225 | for line in ${MY_DEPEND} | ||
226 | do | ||
227 | depcat="${line%%|*}" | ||
228 | depname="${line#*|}" | ||
229 | depname="${depname%%|*}" | ||
230 | |||
231 | # exclude empty depnames | ||
232 | [[ -z ${depname} ]] && continue | ||
233 | |||
234 | # exclude all already processed deps | ||
235 | if ! checklist_processeddeps "${depname}" | ||
236 | then | ||
237 | continue | ||
238 | fi | ||
239 | |||
240 | # mark depfile as processed to prevent double runs -without version | ||
241 | # but do not add any virtuals to PROCESSEDDEPS or their resolved | ||
242 | # pkgnames will be ignored and they are missing on the dependecy-list | ||
243 | if [[ ${depname/virtual\//} = ${depname} ]] | ||
244 | then | ||
245 | PROCESSEDDEPS="${PROCESSEDDEPS} ${depname}" | ||
246 | fi | ||
247 | |||
248 | if [[ ${depcat} = virtual ]] | ||
249 | then | ||
250 | retval=$(default_virtualname_to_pkgname "${depcat}" "${depname}") | ||
251 | depcat=${retval%%|*} | ||
252 | depname=${retval##*|} | ||
253 | fi | ||
254 | |||
255 | highest=$(highest_pkg ${depname} ${state}) | ||
256 | depver="${highest%|*}" | ||
257 | depbuild="${highest##*|}" | ||
258 | |||
259 | fullname="${depcat}/${depname}-${depver}-${depbuild}" | ||
260 | |||
261 | ## check ob schon in ALLDEPS enthalten dann mach weiter | ||
262 | if checklist_alldeps "${fullname}" | ||
263 | then | ||
264 | ## check ob DFILE schon installiert ist | ||
265 | if ! is_installed --pcat "${depcat}" --pname "${depname}" --pver "${depver}" --pbuild "${depbuild}" | ||
266 | then | ||
267 | rumwandern "${depname}" "${depver}" "${depbuild}" | ||
268 | ALLDEPS="${ALLDEPS} ${fullname}" | ||
269 | fi | ||
270 | fi | ||
271 | done | ||
272 | return 0 | ||
273 | } | ||
274 | |||
275 | |||
276 | ### abort if this package is already installed (retval 3) | ||
277 | # maybe later ? | ||
278 | #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3 | ||
279 | |||
280 | # # [[ ${METHOD} = pretend ]] || \ | ||
281 | # # [[ ${METHOD} = srcpretend ]] || \ | ||
282 | # # [[ ${METHOD} = uppretend ]] || \ | ||
283 | # # [[ ${METHOD} = srcuppretend ]] && \ | ||
284 | # # echo -n "Calculating dependencies ... " | ||
285 | # # | ||
286 | # # | ||
287 | # # if [[ ${METHOD} = upgrade ]] || \ | ||
288 | # # [[ ${METHOD} = srcupgrade ]] || \ | ||
289 | # # [[ ${METHOD} = uppretend ]] || \ | ||
290 | # # [[ ${METHOD} = srcuppretend ]] | ||
291 | # # then | ||
292 | # # INSTDEPS="$(${MLIBDIR}/magequery.sh -i)" | ||
293 | # # for dep in ${INSTDEPS} | ||
294 | # # do | ||
295 | # # PCAT="$(magename2pcat ${dep} installdb)" | ||
296 | # # PNAME="$(magename2pname ${dep})" | ||
297 | # # | ||
298 | # # # get the highest mage file from mage-db | ||
299 | # # MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" | ||
300 | # # | ||
301 | # # # if no install candidate was found, record this | ||
302 | # # # and process with the next one | ||
303 | # # if [[ -z ${MAGEFILE} ]] | ||
304 | # # then | ||
305 | # # NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}" | ||
306 | # # continue | ||
307 | # # fi | ||
308 | # # | ||
309 | # # # now get the pver&pbuild from the new file | ||
310 | # # PVER="$(magename2pver ${MAGEFILE})" | ||
311 | # # PBUILD="$(magename2pbuild ${MAGEFILE})" | ||
312 | # # | ||
313 | # # # do not wander files which are installed | ||
314 | # # if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] | ||
315 | # # then | ||
316 | # # # get dependencies the package | ||
317 | # # rumwandern ${MAGEFILE} | ||
318 | # # | ||
319 | # # # now add the package itself to the dependencies | ||
320 | # # # (if not exists already) | ||
321 | # # #if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ] | ||
322 | # # if checklist_alldeps "${MAGEFILE}" | ||
323 | # # then | ||
324 | # # ALLDEPS="${ALLDEPS} ${MAGEFILE}" | ||
325 | # # fi | ||
326 | # # fi | ||
327 | # # done | ||
328 | # # else | ||
329 | # # # get dependencies the package | ||
330 | # # rumwandern ${MAGEFILE} | ||
331 | # # | ||
332 | # # # now add the package itself to the dependencies | ||
333 | # # ALLDEPS="${ALLDEPS} ${MAGEFILE}" | ||
334 | # # fi | ||
335 | # # | ||
336 | # # [[ ${METHOD} = pretend ]] || \ | ||
337 | # # [[ ${METHOD} = srcpretend ]] || \ | ||
338 | # # [[ ${METHOD} = uppretend ]] || \ | ||
339 | # # [[ ${METHOD} = srcuppretend ]] && \ | ||
340 | # # echo "done" | ||
341 | # # | ||
342 | # # | ||
343 | # # ## show output of pretend | ||
344 | # # if [[ ${METHOD} = pretend ]] || \ | ||
345 | # # [[ ${METHOD} = srcpretend ]] || \ | ||
346 | # # [[ ${METHOD} = uppretend ]] || \ | ||
347 | # # [[ ${METHOD} = srcuppretend ]] | ||
348 | # # then | ||
349 | # # # this is a little bit faster | ||
350 | # # declare -i x=0 | ||
351 | # # echo -n "Building dependencies list ... " | ||
352 | # # for i in ${ALLDEPS} | ||
353 | # # do | ||
354 | # # (( x++ )) | ||
355 | # # k="$x" | ||
356 | # # [ ${x} -le 9 ] && k="0${k}" | ||
357 | # # #[ ${x} -le 99 ] && k="0${k}" | ||
358 | # # PCAT="$(magename2pcat ${i})" | ||
359 | # # PNAME="$(magename2pname ${i})" | ||
360 | # # PVER="$(magename2pver ${i})" | ||
361 | # # PBUILD="$(magename2pbuild ${i})" | ||
362 | # # if [ -z "${list}" ] | ||
363 | # # then | ||
364 | # # list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" | ||
365 | # # else | ||
366 | # # list="${list} | ||
367 | # # \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" | ||
368 | # # fi | ||
369 | # # unset PCAT PNAME PVER PBUILD | ||
370 | # # done | ||
371 | # # echo "done" | ||
372 | # # echo -e "${list}" | ||
373 | # # echo | ||
374 | # # | ||
375 | # # if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]] | ||
376 | # # then | ||
377 | # # echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}" | ||
378 | # # for i in ${NO_UPGRADE_CANDIDATE} | ||
379 | # # do | ||
380 | # # echo -e "${COLRED} ${i}${COLDEFAULT}" | ||
381 | # # done | ||
382 | # # echo | ||
383 | # # echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}" | ||
384 | # # echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}" | ||
385 | # # echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}" | ||
386 | # # echo | ||
387 | # # fi | ||
388 | # # fi | ||
389 | # # | ||
390 | # # ## return output from src/install deps | ||
391 | # # [[ ${METHOD} = install ]] || \ | ||
392 | # # [[ ${METHOD} = srcinstall ]] || \ | ||
393 | # # [[ ${METHOD} = upgrade ]] || \ | ||
394 | # # [[ ${METHOD} = srcupgrade ]] && \ | ||
395 | # # echo "${ALLDEPS}" | ||
396 | # # | ||
397 | # # # delete ${BUILDDIR}/virtuals if exists as not needed anymore | ||
398 | # # #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals | ||
399 | |||
400 | #all_depends "${PNAME}" "${PVER}" "${PBUILD}" | ||
401 | #all_depends "${PNAME}" "${MAGE_DISTRIBUTION}" | ||
402 | #retval=$(default_virtualname_to_pkgname "virtual" "opengl") | ||
403 | #depcat=${retval%%|*} | ||
404 | #depname=${retval##*|} | ||
405 | #echo "depcat='${depcat}'" | ||
406 | #echo "depname='${depname}'" | ||
407 | |||
408 | rumwandern "${PNAME}" "${PVER}" "${PBUILD}" | ||
409 | # add the package itself | ||
410 | ALLDEPS="${ALLDEPS} ${PCAT}/${PNAME}-${PVER}-${PBUILD}" | ||
411 | declare -i x=0 | ||
412 | for i in ${ALLDEPS} | ||
413 | do | ||
414 | (( x++ )) | ||
415 | k="$x" | ||
416 | [ ${x} -le 9 ] && k="0${k}" | ||
417 | #[ ${x} -le 99 ] && k="0${k}" | ||
418 | echo -e "\t[${k}] ${i}" | ||
419 | done | ||
420 | echo |
Properties
Name | Value |
---|---|
svn:keywords | Id |