Annotation of /branches/mage-sql/usr/lib/mage/sqlwalker.sh
Parent Directory | Revision Log
Revision 1120 -
(hide annotations)
(download)
(as text)
Thu Jul 22 07:26:50 2010 UTC (13 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 8209 byte(s)
Thu Jul 22 07:26:50 2010 UTC (13 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 8209 byte(s)
-removed unneded variables -removed all_{s,}depends() functions, use them from sqlfunctions.sh instead -added upgrade|uppretend|{src,}install|{src,}pretend logic to be fully compatible to 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 | |||
101 | # much faster than fgrep | ||
102 | checklist_alldeps() | ||
103 | { | ||
104 | local i | ||
105 | local item="$1" | ||
106 | |||
107 | for i in ${ALLDEPS} | ||
108 | do | ||
109 | [[ ${i} = ${item} ]] && return 1 | ||
110 | done | ||
111 | |||
112 | return 0 | ||
113 | } | ||
114 | |||
115 | checklist_processeddeps() | ||
116 | { | ||
117 | local i | ||
118 | local item="$1" | ||
119 | |||
120 | for i in ${PROCESSEDDEPS} | ||
121 | do | ||
122 | [[ ${i} = ${item} ]] && return 1 | ||
123 | done | ||
124 | |||
125 | return 0 | ||
126 | } | ||
127 | |||
128 | ##################### | ||
129 | ## rumwandern /path/to/mage/file/.mage | ||
130 | rumwandern() | ||
131 | { | ||
132 | unset DEPEND | ||
133 | unset SDEPEND | ||
134 | unset MY_DEPEND | ||
135 | |||
136 | local DFILE | ||
137 | local SYM | ||
138 | local DEPNAME | ||
139 | local HIGHEST_DEPFILE | ||
140 | local MY_DEPEND | ||
141 | local REAL_PGKNAME | ||
142 | local VIRTUAL_NAME | ||
143 | local INSTALL_VIRTUAL | ||
144 | local PNAME | ||
145 | local PCAT | ||
146 | local PVER | ||
147 | local PBUILD | ||
148 | |||
149 | local pname="$1" | ||
150 | local pver="$2" | ||
151 | local pbuild="$3" | ||
152 | local state="${MAGE_DISTRIBUTION}" | ||
153 | local retval | ||
154 | local fullname | ||
155 | |||
156 | # forced nodeps | ||
157 | if [[ ${NODEPS} = true ]] | ||
158 | then | ||
159 | DEPEND="" | ||
160 | SDEPEND="" | ||
161 | fi | ||
162 | |||
163 | MY_DEPEND="$(all_depends ${pname} ${pver} ${pbuild})" | ||
164 | |||
165 | # for srcinstall & srcdepend only; SDEPEND also needed | ||
166 | if [[ ${METHOD} = srcinstall ]] || \ | ||
167 | [[ ${METHOD} = srcpretend ]] || \ | ||
168 | [[ ${METHOD} = srcupgrade ]] || \ | ||
169 | [[ ${METHOD} = srcuppretend ]] | ||
170 | then | ||
171 | MY_DEPEND="${MY_DEPEND} | ||
172 | $(all_sdepends ${pname} ${pver} ${pbuild})" | ||
173 | fi | ||
174 | |||
175 | unset DEPEND | ||
176 | unset SDEPEND | ||
177 | |||
178 | if [ -z "${MY_DEPEND}" ] | ||
179 | then | ||
180 | return 1 | ||
181 | fi | ||
182 | |||
183 | for line in ${MY_DEPEND} | ||
184 | do | ||
185 | depcat="${line%%|*}" | ||
186 | depname="${line#*|}" | ||
187 | depname="${depname%%|*}" | ||
188 | |||
189 | # exclude empty depnames | ||
190 | [[ -z ${depname} ]] && continue | ||
191 | |||
192 | # exclude all already processed deps | ||
193 | if ! checklist_processeddeps "${depname}" | ||
194 | then | ||
195 | continue | ||
196 | fi | ||
197 | |||
198 | # mark depfile as processed to prevent double runs -without version | ||
199 | # but do not add any virtuals to PROCESSEDDEPS or their resolved | ||
200 | # pkgnames will be ignored and they are missing on the dependecy-list | ||
201 | if [[ ${depname/virtual\//} = ${depname} ]] | ||
202 | then | ||
203 | PROCESSEDDEPS="${PROCESSEDDEPS} ${depname}" | ||
204 | fi | ||
205 | |||
206 | if [[ ${depcat} = virtual ]] | ||
207 | then | ||
208 | retval=$(default_virtualname_to_pkgname "${depcat}" "${depname}") | ||
209 | depcat=${retval%%|*} | ||
210 | depname=${retval##*|} | ||
211 | fi | ||
212 | |||
213 | highest=$(highest_pkg ${depname} ${state}) | ||
214 | depver="${highest%|*}" | ||
215 | depbuild="${highest##*|}" | ||
216 | |||
217 | fullname="${depcat}/${depname}-${depver}-${depbuild}" | ||
218 | |||
219 | ## check ob schon in ALLDEPS enthalten dann mach weiter | ||
220 | if checklist_alldeps "${fullname}" | ||
221 | then | ||
222 | ## check ob DFILE schon installiert ist | ||
223 | if ! is_installed --pcat "${depcat}" --pname "${depname}" --pver "${depver}" --pbuild "${depbuild}" | ||
224 | then | ||
225 | rumwandern "${depname}" "${depver}" "${depbuild}" | ||
226 | ALLDEPS="${ALLDEPS} ${fullname}" | ||
227 | fi | ||
228 | fi | ||
229 | done | ||
230 | return 0 | ||
231 | } | ||
232 | |||
233 | |||
234 | ### abort if this package is already installed (retval 3) | ||
235 | # maybe later ? | ||
236 | #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3 | ||
237 | |||
238 | niro | 1120 | [[ ${METHOD} = pretend ]] || \ |
239 | [[ ${METHOD} = srcpretend ]] || \ | ||
240 | [[ ${METHOD} = uppretend ]] || \ | ||
241 | [[ ${METHOD} = srcuppretend ]] && \ | ||
242 | echo -n "Calculating dependencies ... " | ||
243 | niro | 1116 | |
244 | |||
245 | niro | 1120 | if [[ ${METHOD} = upgrade ]] || \ |
246 | [[ ${METHOD} = srcupgrade ]] || \ | ||
247 | [[ ${METHOD} = uppretend ]] || \ | ||
248 | [[ ${METHOD} = srcuppretend ]] | ||
249 | then | ||
250 | INSTDEPS=$(DBFILE="${MAGE_INSTALL_DB}" sql "select categories.pcat,packages.pname,packages.pver,packages.pbuild from packages inner join categories on categories.id=packages.pcat_id") | ||
251 | for dep in ${INSTDEPS} | ||
252 | do | ||
253 | PCAT="$(echo ${dep} | cut -d'|' -f1)" | ||
254 | PNAME="$(echo ${dep} | cut -d'|' -f2)" | ||
255 | |||
256 | # get the highest mage file from mage-db | ||
257 | state="${MAGE_DISTRIBUTION}" | ||
258 | highest=$(highest_pkg ${PNAME} ${state}) | ||
259 | |||
260 | # if no install candidate was found, record this | ||
261 | # and process with the next one | ||
262 | if [[ -z ${highest} ]] | ||
263 | then | ||
264 | NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}" | ||
265 | continue | ||
266 | fi | ||
267 | |||
268 | # now get the pver&pbuild from the new file | ||
269 | PVER="${highest%%|*}" | ||
270 | PBUILD="${highest##*|}" | ||
271 | |||
272 | # do not walk through files which are already installed | ||
273 | if ! is_installed --pcat "${PCAT}" --pname "${PNAME}" --pver "${PVER}" --pbuild "${PBUILD}" | ||
274 | then | ||
275 | # get dependencies the package | ||
276 | rumwandern "${PNAME}" "${PVER}" "${PBUILD}" | ||
277 | |||
278 | # now add the package itself to the dependencies | ||
279 | # (if not exists already) | ||
280 | fullname="${PCAT}/${PNAME}-${PVER}-${PBUILD}" | ||
281 | if checklist_alldeps "${fullname}" | ||
282 | then | ||
283 | ALLDEPS="${ALLDEPS} ${fullname}" | ||
284 | fi | ||
285 | fi | ||
286 | done | ||
287 | else | ||
288 | # get dependencies the package | ||
289 | rumwandern "${PNAME}" "${PVER}" "${PBUILD}" | ||
290 | |||
291 | # now add the package itself to the dependencies | ||
292 | ALLDEPS="${ALLDEPS} ${PCAT}/${PNAME}-${PVER}-${PBUILD}" | ||
293 | fi | ||
294 | |||
295 | [[ ${METHOD} = pretend ]] || \ | ||
296 | [[ ${METHOD} = srcpretend ]] || \ | ||
297 | [[ ${METHOD} = uppretend ]] || \ | ||
298 | [[ ${METHOD} = srcuppretend ]] && \ | ||
299 | echo "done" | ||
300 | |||
301 | |||
302 | ## show output of pretend | ||
303 | if [[ ${METHOD} = pretend ]] || \ | ||
304 | [[ ${METHOD} = srcpretend ]] || \ | ||
305 | [[ ${METHOD} = uppretend ]] || \ | ||
306 | [[ ${METHOD} = srcuppretend ]] | ||
307 | then | ||
308 | # this is a little bit faster | ||
309 | declare -i x=0 | ||
310 | echo -n "Building dependencies list ... " | ||
311 | for i in ${ALLDEPS} | ||
312 | do | ||
313 | (( x++ )) | ||
314 | k="$x" | ||
315 | [ ${x} -le 9 ] && k="0${k}" | ||
316 | #[ ${x} -le 99 ] && k="0${k}" | ||
317 | if [ -z "${list}" ] | ||
318 | then | ||
319 | list="\t${COLBLUE}[${k}] ${COLGREEN}${i}${COLDEFAULT}" | ||
320 | else | ||
321 | list="${list} | ||
322 | \t${COLBLUE}[${k}] ${COLGREEN}${i}${COLDEFAULT}" | ||
323 | fi | ||
324 | done | ||
325 | echo "done" | ||
326 | echo -e "${list}" | ||
327 | echo | ||
328 | |||
329 | if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]] | ||
330 | then | ||
331 | echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}" | ||
332 | for i in ${NO_UPGRADE_CANDIDATE} | ||
333 | do | ||
334 | echo -e "${COLRED} ${i}${COLDEFAULT}" | ||
335 | done | ||
336 | echo | ||
337 | echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}" | ||
338 | echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}" | ||
339 | echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}" | ||
340 | echo | ||
341 | fi | ||
342 | fi | ||
343 | |||
344 | ## return output from src/install deps | ||
345 | [[ ${METHOD} = install ]] || \ | ||
346 | [[ ${METHOD} = srcinstall ]] || \ | ||
347 | [[ ${METHOD} = upgrade ]] || \ | ||
348 | [[ ${METHOD} = srcupgrade ]] && \ | ||
349 | echo "${ALLDEPS}" | ||
350 | |||
351 | # delete ${BUILDDIR}/virtuals if exists as not needed anymore | ||
352 | #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals |
Properties
Name | Value |
---|---|
svn:keywords | Id |