Annotation of /trunk/mage/usr/lib/mage/sql_functions.sh
Parent Directory | Revision Log
Revision 486 -
(hide annotations)
(download)
(as text)
Mon Apr 30 15:09:05 2007 UTC (17 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 29937 byte(s)
Mon Apr 30 15:09:05 2007 UTC (17 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 29937 byte(s)
added sql functions overlay
1 | niro | 486 | #!/bin/bash |
2 | |||
3 | die() | ||
4 | { | ||
5 | echo -e "Exited ${BASH_SOURCE} at line no ${BASH_LINENO}." | ||
6 | echo -e "$@" | ||
7 | exit 1 | ||
8 | } | ||
9 | |||
10 | sql() | ||
11 | { | ||
12 | local sqlcmd="$*" | ||
13 | [[ -z ${sqlcmd} ]] && die "no sqlcmd given." | ||
14 | |||
15 | sqlite3 -nullvalue 'NULL' -list -separator '|' "${DBFILE}" << EOF || die "error running '$@'" | ||
16 | ${sqlcmd}; | ||
17 | EOF | ||
18 | } | ||
19 | |||
20 | mage_setup() | ||
21 | { | ||
22 | [ ! -d ${MROOT}${INSTALLDB} ] && install -d ${MROOT}${INSTALLDB} | ||
23 | [ ! -d ${MROOT}${INSTALLDB}/records ] && install -d ${MROOT}${INSTALLDB}/records | ||
24 | # [ ! -f ${MROOT}${VIRTUALDB_FILE} ] && touch ${MROOT}${VIRTUALDB_FILE} | ||
25 | [ ! -d ${PKGDIR} ] && install -d ${PKGDIR} | ||
26 | [ ! -d ${BUILDDIR} ] && install -d ${BUILDDIR} | ||
27 | [ ! -d ${MAGEDIR} ] && install -d ${MAGEDIR} | ||
28 | |||
29 | return 0 | ||
30 | } | ||
31 | |||
32 | dep2pver() | ||
33 | { | ||
34 | local pver | ||
35 | |||
36 | pver="${1##*/}" | ||
37 | |||
38 | # cut version only if not virtual or it will cut the name | ||
39 | if [[ $(dep2pcat $1) != virtual ]] && \ | ||
40 | [[ $2 != virtual ]] | ||
41 | then | ||
42 | echo "${pver##*-}" | ||
43 | fi | ||
44 | } | ||
45 | |||
46 | |||
47 | |||
48 | |||
49 | |||
50 | ## atoi string | ||
51 | atoi() | ||
52 | { | ||
53 | local pver="$1" | ||
54 | local len | ||
55 | local value | ||
56 | local finalpver | ||
57 | |||
58 | # first run a basic char to int on argv | ||
59 | len=${#pver} | ||
60 | for ((x=0; x < len; x++)) | ||
61 | do | ||
62 | value="${pver:${x}:1}" | ||
63 | case ${value} in | ||
64 | a) value=".1.";; | ||
65 | b) value=".2.";; | ||
66 | c) value=".3.";; | ||
67 | d) value=".4.";; | ||
68 | e) value=".5.";; | ||
69 | f) value=".6.";; | ||
70 | g) value=".7.";; | ||
71 | h) value=".8.";; | ||
72 | i) value=".9.";; | ||
73 | j) value=".10.";; | ||
74 | k) value=".11.";; | ||
75 | l) value=".12.";; | ||
76 | m) value=".13.";; | ||
77 | n) value=".14.";; | ||
78 | o) value=".15.";; | ||
79 | p) value=".16.";; | ||
80 | q) value=".17.";; | ||
81 | r) value=".18.";; | ||
82 | s) value=".19.";; | ||
83 | t) value=".20.";; | ||
84 | u) value=".21.";; | ||
85 | v) value=".22.";; | ||
86 | w) value=".23.";; | ||
87 | x) value=".24.";; | ||
88 | y) value=".25.";; | ||
89 | z) value=".26.";; | ||
90 | _|-|\|) value=".0.";; | ||
91 | 0*) value="${value/0/.0.}";; | ||
92 | esac | ||
93 | |||
94 | # save new var | ||
95 | finalpver="${finalpver}${value}" | ||
96 | done | ||
97 | echo ${finalpver} | ||
98 | } | ||
99 | |||
100 | ## max_len string1 string2 | ||
101 | max_len() | ||
102 | { | ||
103 | local str1="$1" | ||
104 | local str2="$2" | ||
105 | local len1 | ||
106 | local len2 | ||
107 | |||
108 | # substitute spaces | ||
109 | str1=$(echo "${str1}" | sed "s:\ ::g") | ||
110 | str2=$(echo "${str2}" | sed "s:\ ::g") | ||
111 | |||
112 | # bash returns lenghts always +1 | ||
113 | len1=$(( ${#str1} -1 )) | ||
114 | len2=$(( ${#str2} -1 )) | ||
115 | |||
116 | if [[ ${len1} -ge ${len2} ]] | ||
117 | then | ||
118 | echo "${len1}" | ||
119 | else | ||
120 | echo "${len2}" | ||
121 | fi | ||
122 | } | ||
123 | |||
124 | # is_higher pver1 pver2 | ||
125 | is_higher() | ||
126 | { | ||
127 | local pver1="$1" | ||
128 | local pver2="$2" | ||
129 | local fpver | ||
130 | local fpver | ||
131 | local arr1 | ||
132 | local arr2 | ||
133 | local maxarrlen | ||
134 | local i | ||
135 | local x | ||
136 | |||
137 | # build to arrays with fixed pvers | ||
138 | fpver1=$(atoi ${pver1} | sed "s:\.:\ :g") | ||
139 | fpver2=$(atoi ${pver2} | sed "s:\.:\ :g") | ||
140 | |||
141 | maxarrlen=$(max_len "${fpver1}" "${fpver2}") | ||
142 | |||
143 | # fill array with values | ||
144 | declare -i x=0 | ||
145 | for i in ${fpver1} | ||
146 | do | ||
147 | arr1[${x}]="${i}" | ||
148 | ((x++)) | ||
149 | done | ||
150 | # now fill the rest with ZEROS | ||
151 | if [[ ${x} -lt ${maxarrlen} ]] | ||
152 | then | ||
153 | for (( i=x; i<maxarrlen;i++)) | ||
154 | do | ||
155 | arr1[${i}]="0" | ||
156 | done | ||
157 | fi | ||
158 | |||
159 | # fill array with values | ||
160 | declare -i x=0 | ||
161 | for i in ${fpver2} | ||
162 | do | ||
163 | arr2[${x}]="${i}" | ||
164 | ((x++)) | ||
165 | done | ||
166 | # now fill the rest with ZEROS | ||
167 | if [[ ${x} -lt ${maxarrlen} ]] | ||
168 | then | ||
169 | for (( i=x; i<maxarrlen;i++)) | ||
170 | do | ||
171 | arr2[${i}]="0" | ||
172 | done | ||
173 | fi | ||
174 | |||
175 | # now compare the to arrays | ||
176 | for ((i=0; i < ${maxarrlen}; i++)) | ||
177 | do | ||
178 | if [[ ${arr1[${i}]} -ne ${arr2[${i}]} ]] | ||
179 | then | ||
180 | if [[ ${arr1[${i}]} -gt ${arr2[${i}]} ]] | ||
181 | then | ||
182 | echo "${pver1}" | ||
183 | return | ||
184 | else | ||
185 | echo "${pver2}" | ||
186 | return | ||
187 | fi | ||
188 | fi | ||
189 | done | ||
190 | |||
191 | # both values are the same, so print the first | ||
192 | echo "${pver1}" | ||
193 | } | ||
194 | |||
195 | highest_pkg2() | ||
196 | { | ||
197 | local pname="$1" | ||
198 | local state="$2" | ||
199 | |||
200 | case ${state} in | ||
201 | stable) search="state='stable'" ;; | ||
202 | testing) search="state='stable' or state='testing'" ;; | ||
203 | unstable) search="state='stable' or state='testing' or state='unstable'" ;; | ||
204 | esac | ||
205 | |||
206 | for current in $(sql "select pver,pbuild from packages where pname='${pname}' and (${search})") | ||
207 | do | ||
208 | [[ x -eq 0 ]] && max="${current}" | ||
209 | max="$(is_higher ${current} ${max})" | ||
210 | ((x++)) | ||
211 | done | ||
212 | |||
213 | echo "${max}" | ||
214 | } | ||
215 | |||
216 | highest_pkg() { | ||
217 | local pname="$1" | ||
218 | local state="$2" | ||
219 | local search | ||
220 | local retval | ||
221 | |||
222 | case ${state} in | ||
223 | stable) search="state='stable'" ;; | ||
224 | testing) search="state='stable' or state='testing'" ;; | ||
225 | unstable) search="state='stable' or state='testing' or state='unstable'" ;; | ||
226 | esac | ||
227 | |||
228 | #retval=$(sql "select pver,pbuild from packages where pname='${pname}' and (${search}) order by pver desc,pbuild desc limit 1") | ||
229 | #echo "${pname}-$(echo ${retval} | cut -d'|' -f1)-r$(echo ${retval} | cut -d'|' -f2)" | ||
230 | |||
231 | retval=$(sql "select pver,pbuild from packages where pname='${pname}' and (${search}) order by pver desc,pbuild desc limit 1") | ||
232 | echo "${retval}" | ||
233 | } | ||
234 | |||
235 | all_depends() | ||
236 | { | ||
237 | local pname="$1" | ||
238 | local state="$2" | ||
239 | local highest | ||
240 | local retval | ||
241 | local pver | ||
242 | local pbuild | ||
243 | local i | ||
244 | |||
245 | highest=$(highest_pkg2 "${pname}" "${state}") | ||
246 | pver="${highest%|*}" | ||
247 | pbuild="${highest##*|}" | ||
248 | |||
249 | sql "select categories.pcat, | ||
250 | depends.pname, | ||
251 | depends.pver, | ||
252 | depends.pbuild | ||
253 | from depends | ||
254 | inner join packages | ||
255 | on depends.pkg_id=packages.id | ||
256 | and packages.pname='${pname}' | ||
257 | and packages.pver='${pver}' | ||
258 | and packages.pbuild='${pbuild}' | ||
259 | inner join categories | ||
260 | on depends.pcat_id=categories.id" | ||
261 | } | ||
262 | |||
263 | all_sdepends() | ||
264 | { | ||
265 | local pname="$1" | ||
266 | local state="$2" | ||
267 | local highest | ||
268 | local retval | ||
269 | local pver | ||
270 | local pbuild | ||
271 | local i | ||
272 | |||
273 | highest=$(highest_pkg2 "${pname}" "${state}") | ||
274 | pver="${highest%|*}" | ||
275 | pbuild="${highest##*|}" | ||
276 | |||
277 | sql "select categories.pcat, | ||
278 | sdepends.pname, | ||
279 | sdepends.pver, | ||
280 | sdepends.pbuild | ||
281 | from sdepends | ||
282 | inner join packages | ||
283 | on sdepends.pkg_id=packages.id | ||
284 | and packages.pname='${pname}' | ||
285 | and packages.pver='${pver}' | ||
286 | and packages.pbuild='${pbuild}' | ||
287 | inner join categories | ||
288 | on sdepends.pcat_id=categories.id" | ||
289 | } | ||
290 | |||
291 | ALLDEPS="" | ||
292 | #ALREADY_PROCESSED="" | ||
293 | resolv_pkgs() { | ||
294 | local method="$1" | ||
295 | local pname="$2" | ||
296 | local state="$3" | ||
297 | local depcat | ||
298 | local depname | ||
299 | local depver | ||
300 | local depbuild | ||
301 | local highest | ||
302 | local fullname | ||
303 | local searchcmd | ||
304 | local searchcmd2 | ||
305 | local pkgid | ||
306 | |||
307 | case ${method} in | ||
308 | --install) | ||
309 | searchcmd="all_depends ${pname} ${state}" | ||
310 | searchcmd2="" | ||
311 | ;; | ||
312 | --src-install) | ||
313 | searchcmd="all_depends ${pname} ${state}" | ||
314 | searchcmd2="all_sdepends ${pname} ${state}" | ||
315 | ;; | ||
316 | esac | ||
317 | |||
318 | [[ -z ${pname} ]] && return 1 | ||
319 | |||
320 | while read line | ||
321 | do | ||
322 | [[ -z ${line} ]] && continue | ||
323 | |||
324 | depcat="${line%%|*}" | ||
325 | depname="${line#*|}" | ||
326 | depname="${depname%%|*}" | ||
327 | |||
328 | # check processed pnames, to speed things up | ||
329 | # local i | ||
330 | # for i in ${ALREADY_PROCESSED} | ||
331 | # do | ||
332 | # [[ ${depname} = ${i} ]] && continue | ||
333 | # done | ||
334 | |||
335 | # hotfix | ||
336 | if [[ ${depcat} = virtual ]] | ||
337 | then | ||
338 | case ${depname} in | ||
339 | x11) | ||
340 | depcat=x11-base | ||
341 | depname=xorg | ||
342 | ;; | ||
343 | glibc) | ||
344 | depcat=sys-libs | ||
345 | depname=glibc-nptl | ||
346 | ;; | ||
347 | kernel) | ||
348 | depcat=sys-kernel | ||
349 | depname=kernel26-magellan | ||
350 | ;; | ||
351 | kernel-headers) | ||
352 | depcat=sys-kernel | ||
353 | depname=linux-libc-headers | ||
354 | ;; | ||
355 | kernel-sources) | ||
356 | depcat=sys-kernel | ||
357 | depname=kernel26-sources-magellan | ||
358 | ;; | ||
359 | java) | ||
360 | depcat=dev-java | ||
361 | depname=sun-jdk | ||
362 | ;; | ||
363 | mta) | ||
364 | depcat=net-mail | ||
365 | depname=ssmtp | ||
366 | ;; | ||
367 | editor) | ||
368 | depcat=app-editors | ||
369 | depname=nano | ||
370 | ;; | ||
371 | cron) | ||
372 | depcat=sys-apps | ||
373 | depname=fcron | ||
374 | ;; | ||
375 | syslog) | ||
376 | depcat=app-admin | ||
377 | depname=syslog-ng | ||
378 | ;; | ||
379 | alsa-drivers) | ||
380 | depcat=sys-kernel | ||
381 | depname=kernel26-magellan | ||
382 | ;; | ||
383 | nvidia-drivers) | ||
384 | depcat=sys-kernel | ||
385 | depname=kernel26-magellan | ||
386 | ;; | ||
387 | ati-drivers) | ||
388 | depcat=sys-kernel | ||
389 | depname=kernel26-magellan | ||
390 | ;; | ||
391 | opengl) | ||
392 | depcat=media-libs | ||
393 | depname=mesa | ||
394 | ;; | ||
395 | esac | ||
396 | fi | ||
397 | |||
398 | highest=$(highest_pkg2 ${depname} ${state}) | ||
399 | depver="${highest%|*}" | ||
400 | depbuild="${highest##*|}" | ||
401 | |||
402 | fullname="${depcat}/${depname}-${depver}-r${depbuild}" | ||
403 | |||
404 | #### check ob DFILE schon installiert ist #### | ||
405 | is_installed --pcat "${depcat}" --pname "${depname}" --pver "${depver}" --pbuild "${depbuild}" && continue | ||
406 | |||
407 | ## check ob schon in ALLDEPS enthalten dann mach weiter | ||
408 | if [[ -z $(echo ${ALLDEPS} | fgrep "${fullname}") ]] | ||
409 | then | ||
410 | resolv_pkgs "${method}" "${depname}" "${state}" | ||
411 | ALLDEPS="${ALLDEPS} ${fullname}" | ||
412 | fi | ||
413 | |||
414 | # list of all processed pnames, to speed things up | ||
415 | # ALREADY_PROCESSED="${ALREADY_PROCESSED} ${depname}" | ||
416 | |||
417 | # unset all vars | ||
418 | unset depname | ||
419 | unset depcat | ||
420 | unset depver | ||
421 | unset depbuild | ||
422 | unset fullname | ||
423 | unset shighest | ||
424 | done << EOF | ||
425 | $(${searchcmd}) | ||
426 | $(${searchcmd2}) | ||
427 | EOF | ||
428 | } | ||
429 | |||
430 | # start_depwanderer pname state | ||
431 | start_depwanderer() | ||
432 | { | ||
433 | local highest | ||
434 | local method="$1" | ||
435 | local pname="$2" | ||
436 | local pver | ||
437 | local pbuild | ||
438 | local pcat | ||
439 | local state="$3" | ||
440 | local x i | ||
441 | |||
442 | # get some suitable pkg info | ||
443 | highest=$(highest_pkg2 "${pname}" "${state}") | ||
444 | pver="${highest%|*}" | ||
445 | pbuild="${highest##*|}" | ||
446 | pcat=$(sql "select categories.pcat | ||
447 | from packages | ||
448 | inner join categories | ||
449 | on packages.pcat_id=categories.id | ||
450 | where packages.pname='${pname}' | ||
451 | and packages.pver='${pver}' | ||
452 | and packages.pbuild='${pbuild}'") | ||
453 | |||
454 | # already installed ?? | ||
455 | if is_installed --pcat "${pcat}" --pname "${pname}" --pver "${pver}" --pbuild "${pbuild}" | ||
456 | then | ||
457 | echo "Package ${pcat}/${pname}-${pver}-r${pbuild} already installed." | ||
458 | return 2 | ||
459 | fi | ||
460 | |||
461 | resolv_pkgs "${method}" "${pname}" "${state}" | ||
462 | declare -i x=1 | ||
463 | for i in ${ALLDEPS} | ||
464 | do | ||
465 | #echo "${x}: ${i}" | ||
466 | echo "${i}" | ||
467 | ((x++)) | ||
468 | done | ||
469 | |||
470 | # add the package itself to the dependencies | ||
471 | #echo "$((x++)): ${pcat}/${pname}-${pver}-r${pbuild}" | ||
472 | echo "${pcat}/${pname}-${pver}-r${pbuild}" | ||
473 | } | ||
474 | |||
475 | |||
476 | # fetch_packages /path/to/mage/file1 /path/to/mage/file2 | ||
477 | fetch_packages() | ||
478 | { | ||
479 | local list="$@" | ||
480 | local pkg | ||
481 | local mirr | ||
482 | local magefile | ||
483 | local md5file | ||
484 | local opt | ||
485 | local count_current | ||
486 | local count_total | ||
487 | local pname | ||
488 | local pver | ||
489 | local pbuild | ||
490 | |||
491 | [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}." | ||
492 | |||
493 | # get count of total packages | ||
494 | declare -i count_current=0 | ||
495 | declare -i count_total=0 | ||
496 | |||
497 | for i in ${list}; do (( count_total++ )); done | ||
498 | |||
499 | for magefile in ${list} | ||
500 | do | ||
501 | #pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" | ||
502 | |||
503 | pname="$(magename2pname ${magefile})" | ||
504 | pver="$(magename2pver ${magefile})" | ||
505 | pbuild="$(magename2pbuild ${magefile})" | ||
506 | pkg="${pname}-${pver}-${ARCH}-${pbuild}.${PKGSUFFIX}" | ||
507 | |||
508 | pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild/r/}'") | ||
509 | |||
510 | (( count_current++ )) | ||
511 | xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]" | ||
512 | |||
513 | # abort on virtual pkg | ||
514 | if [[ ${pkgtype} = virtual ]] | ||
515 | then | ||
516 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
517 | echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " | ||
518 | continue | ||
519 | fi | ||
520 | |||
521 | # abort on sources pkg | ||
522 | if [[ ${pkgtype} = sources ]] | ||
523 | then | ||
524 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
525 | echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " | ||
526 | continue | ||
527 | fi | ||
528 | |||
529 | # abort if already exist | ||
530 | if [ -f ${PKGDIR}/${pkg} ] | ||
531 | then | ||
532 | echo -ne " ${COLBLUE}***${COLDEFAULT}" | ||
533 | echo " fetch complete (${count_current}/${count_total}): ${pkg} ... " | ||
534 | continue | ||
535 | fi | ||
536 | |||
537 | for mirr in ${MIRRORS} | ||
538 | do | ||
539 | echo -ne " ${COLBLUE}***${COLDEFAULT}" | ||
540 | #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... " | ||
541 | echo -e " fetching (${count_current}/${count_total}): ${pkg} ... " | ||
542 | [[ ${VERBOSE} = off ]] && opt="--quiet" | ||
543 | wget \ | ||
544 | --passive-ftp \ | ||
545 | --tries 3 \ | ||
546 | --continue \ | ||
547 | --progress bar \ | ||
548 | --directory-prefix=${PKGDIR} \ | ||
549 | ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg} | ||
550 | if [[ $? = 0 ]] | ||
551 | then | ||
552 | break | ||
553 | else | ||
554 | continue | ||
555 | fi | ||
556 | done | ||
557 | |||
558 | if [ ! -f ${PKGDIR}/${pkg} ] | ||
559 | then | ||
560 | die "Could not download ${pkg}" | ||
561 | fi | ||
562 | done | ||
563 | |||
564 | # add a crlf for a better view | ||
565 | if [ ${count_total} -gt 1 ]; then echo; fi | ||
566 | } | ||
567 | |||
568 | mage_install() | ||
569 | { | ||
570 | # local all possible vars of a mage file | ||
571 | # to prevent bad issues | ||
572 | local PKGNAME | ||
573 | local STATE | ||
574 | local DESCRIPTION | ||
575 | local HOMEPAGE | ||
576 | local DEPEND | ||
577 | local SDEPEND | ||
578 | local PROVIDE | ||
579 | local PKGTYPE | ||
580 | local preinstall | ||
581 | local postinstall | ||
582 | local preremove | ||
583 | local postremove | ||
584 | |||
585 | local pcat | ||
586 | local pname | ||
587 | local pver | ||
588 | local pbuild | ||
589 | local count_total | ||
590 | local count_current | ||
591 | local magefile | ||
592 | local src_install | ||
593 | |||
594 | # very basic getops | ||
595 | for i in $* | ||
596 | do | ||
597 | case $1 in | ||
598 | --pcat|-c) shift; pcat="$1" ;; | ||
599 | --pname|-n) shift; pname="$1" ;; | ||
600 | --pver|-v) shift; pver="$1" ;; | ||
601 | --pbuild|-b) shift; pbuild="$1" ;; | ||
602 | --count-total) shift; count_total="$1" ;; | ||
603 | --count-current) shift; count_current="$1" ;; | ||
604 | --src-install|-s) shift; src_install=true ;; | ||
605 | esac | ||
606 | shift | ||
607 | done | ||
608 | |||
609 | # sanity checks; abort if not given | ||
610 | [ -z "${pcat}" ] && die "mage_install() \$pcat not given." | ||
611 | [ -z "${pname}" ] && die "mage_install() \$pname not given." | ||
612 | [ -z "${pver}" ] && die "mage_install() \$pver not given." | ||
613 | [ -z "${pbuild}" ] && die "mage_install() \$pbuild not given." | ||
614 | |||
615 | # check needed global vars | ||
616 | [ -z "${MAGEDIR}" ] && die "mage_install() \$MAGEDIR not set." | ||
617 | [ -z "${INSTALLDB}" ] && die "mage_install() \$INSTALLDB not set." | ||
618 | [ -z "${BUILDDIR}" ] && die "mage_install() \$BUILDDIR not set." | ||
619 | |||
620 | xtitle "[ (${count_current}/${count_total}) Installing ${pcat}/${pname}-${pver}-${pbuild} ]" | ||
621 | echo -ne "${COLBLUE} >>> ${COLDEFAULT}" | ||
622 | echo -n "installing (${count_current}/${count_total}): " | ||
623 | echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" | ||
624 | echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}" | ||
625 | |||
626 | # magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage" | ||
627 | # source ${magefile} | ||
628 | PKGNAME="${pname}-${pver}-${ARCH}-${pbuild}" | ||
629 | |||
630 | # abort on sources if no srcinstall | ||
631 | if [[ ${PKGTYPE} = sources ]] && [[ ${src_install} != true ]] | ||
632 | then | ||
633 | echo | ||
634 | echo -e "This Package is a Source Package." | ||
635 | echo | ||
636 | echo -e "Only 'srcinstall' works with this type of packages" | ||
637 | echo -en "If you have done a srcinstall before, " | ||
638 | echo -e "you will find the files in /usr/src." | ||
639 | echo | ||
640 | exit 1 | ||
641 | fi | ||
642 | |||
643 | ## preinstall scripts | ||
644 | if [ -n "$(typeset -f preinstall)" ] | ||
645 | then | ||
646 | echo -e " ${COLBLUE}***${COLDEFAULT} running preinstall ... " | ||
647 | preinstall | ||
648 | unset preinstall | ||
649 | fi | ||
650 | |||
651 | if [[ ${src_install} = true ]] | ||
652 | then | ||
653 | local smage2file | ||
654 | # check needed global vars | ||
655 | [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not set." | ||
656 | [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not set." | ||
657 | [ -z "${BINDIR}" ] && die "\$BINDIR not set." | ||
658 | |||
659 | # build the package first | ||
660 | if [[ ${MAGEDEBUG} = on ]] | ||
661 | then | ||
662 | echo M:${pname} | ||
663 | echo V:${pver} | ||
664 | echo B:${pbuild} | ||
665 | fi | ||
666 | |||
667 | smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2 | ||
668 | if [ -f "${smage2file}" ] | ||
669 | then | ||
670 | echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... " | ||
671 | smage2 ${smage2file} || die "compile failed" | ||
672 | else | ||
673 | echo | ||
674 | echo "$(basename ${SMAGEFILE}) not found." | ||
675 | echo "update your smage-tree and try it again." | ||
676 | echo | ||
677 | die | ||
678 | fi | ||
679 | fi | ||
680 | |||
681 | if [[ ${PKGTYPE} != virtual ]] && \ | ||
682 | [[ ${PKGTYPE} != sources ]] | ||
683 | then | ||
684 | echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... " | ||
685 | build_doinstall ${PKGNAME} | ||
686 | fi | ||
687 | |||
688 | ## postinstall scripts | ||
689 | if [ -n "$(typeset -f postinstall)" ] | ||
690 | then | ||
691 | echo -e " ${COLBLUE}***${COLDEFAULT} running postinstall ... " | ||
692 | postinstall | ||
693 | unset postinstall | ||
694 | fi | ||
695 | |||
696 | # install a database entry | ||
697 | install_database_entry \ | ||
698 | --pcat "${pcat}" \ | ||
699 | --pname "${pname}" \ | ||
700 | --pver "${pver}" \ | ||
701 | --pbuild "${pbuild}" \ | ||
702 | --pkgname "${PKGNAME}" \ | ||
703 | --pkgtype "${PKGTYPE}" \ | ||
704 | || die "error in mage_install() running install_database_entry()." | ||
705 | |||
706 | # remove the package dir now | ||
707 | if [ -d ${BUILDDIR}/${PKGNAME} ] | ||
708 | then | ||
709 | rm -rf ${BUILDDIR}/${PKGNAME} | ||
710 | fi | ||
711 | |||
712 | # rebuilds toplevel info node | ||
713 | if [[ ${MAGE_INFO_REBUILD} = true ]] | ||
714 | then | ||
715 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
716 | echo -n "rebuilding top-level info node ... " | ||
717 | ${MLIBDIR}/mkinfodir ${MROOT}/usr/share/info \ | ||
718 | > ${MROOT}/usr/share/info/dir && \ | ||
719 | echo "done." || echo "failure." | ||
720 | unset MAGE_INFO_REBUILD | ||
721 | fi | ||
722 | |||
723 | # rebuilds the enviroment with the content of /etc/env.d | ||
724 | if [[ ${MAGE_ENV_REBUILD} = true ]] | ||
725 | then | ||
726 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
727 | echo -n "rebuilding environment ... " | ||
728 | ${MLIBDIR}/env-rebuild.sh > /dev/null && \ | ||
729 | echo "done." || echo "failure." | ||
730 | unset MAGE_ENV_REBUILD | ||
731 | fi | ||
732 | |||
733 | xtitleclean | ||
734 | |||
735 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
736 | echo -n "package " | ||
737 | # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" | ||
738 | # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " | ||
739 | echo "successfully installed." | ||
740 | |||
741 | # unset these functions | ||
742 | unset -f preinstall | ||
743 | unset -f postinstall | ||
744 | unset -f preremove | ||
745 | unset -f postremove | ||
746 | } | ||
747 | |||
748 | md5sum_packages() | ||
749 | { | ||
750 | local list="$@" | ||
751 | local magefile | ||
752 | local pcat | ||
753 | local pname | ||
754 | local pkgname | ||
755 | local pkgfile | ||
756 | local pkgtype | ||
757 | local count_current | ||
758 | local count_total | ||
759 | local pver | ||
760 | local pbuild | ||
761 | |||
762 | # get count of total packages | ||
763 | declare -i count_current=0 | ||
764 | declare -i count_total=0 | ||
765 | |||
766 | for i in ${list}; do (( count_total++ )); done | ||
767 | |||
768 | for magefile in ${list} | ||
769 | do | ||
770 | pcat=${magefile%%/*} | ||
771 | pname=$(magename2pname ${magefile}) | ||
772 | pver=$(magename2pver ${magefile}) | ||
773 | pbuild=$(magename2pbuild ${magefile}) | ||
774 | |||
775 | pkgname="${pname}-${pver}-${ARCH}-${pbuild}" | ||
776 | #md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" | ||
777 | pkgfile="${pkgname}.${PKGSUFFIX}" | ||
778 | pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild/r/}'") | ||
779 | md5=$(sql "select packages_info.md5 from packages_info inner join packages on packages_info.pkg_id=packages.id where packages.pname='${pname}' and packages.pver='${pver}' and packages.pbuild='${pbuild/r/}' and arch='${ARCH}'") | ||
780 | #echo "DEBUG: ${md5}" | ||
781 | |||
782 | (( count_current++ )) | ||
783 | xtitle "[ (${count_current}/${count_total}) MD5SUM: ${pkgfile} ]" | ||
784 | |||
785 | # abort on virtual pkg | ||
786 | if [[ ${pkgtype} = virtual ]] | ||
787 | then | ||
788 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
789 | echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " | ||
790 | continue | ||
791 | fi | ||
792 | |||
793 | # abort on sources pkg | ||
794 | if [[ ${pkgtype} = sources ]] | ||
795 | then | ||
796 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
797 | echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " | ||
798 | continue | ||
799 | fi | ||
800 | |||
801 | # if [ -f "${md5file}" ] | ||
802 | # then | ||
803 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
804 | echo -ne "checking md5sum (${count_current}/${count_total}): " | ||
805 | #( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed" | ||
806 | ( cd ${PKGDIR}; md5sum --check << EOF ;)|| die "md5 for ${pkgfile} failed" | ||
807 | ${md5} ${pkgfile} | ||
808 | EOF | ||
809 | |||
810 | # else | ||
811 | # echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
812 | # echo -e "!! no md5sum file found for ${pkgfile} :(" | ||
813 | # fi | ||
814 | done | ||
815 | |||
816 | # add a crlf for a better view | ||
817 | if [ ${count_total} -gt 1 ]; then echo; fi | ||
818 | } | ||
819 | |||
820 | unpack_packages() | ||
821 | { | ||
822 | local list="$@" | ||
823 | local magefile | ||
824 | local pkg | ||
825 | local pkgtype | ||
826 | local count_current | ||
827 | local count_total | ||
828 | |||
829 | # get count of total packages | ||
830 | declare -i count_current=0 | ||
831 | declare -i count_total=0 | ||
832 | |||
833 | for i in ${list}; do (( count_total++ )); done | ||
834 | |||
835 | for magefile in ${list} | ||
836 | do | ||
837 | #pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" | ||
838 | #pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" | ||
839 | |||
840 | pname=$(magename2pname ${magefile}) | ||
841 | pver=$(magename2pver ${magefile}) | ||
842 | pbuild=$(magename2pbuild ${magefile}) | ||
843 | pkg="${pname}-${pver}-${ARCH}-${pbuild}.${PKGSUFFIX}" | ||
844 | pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild/r/}'") | ||
845 | |||
846 | (( count_current++ )) | ||
847 | xtitle "[ (${count_current}/${count_total}) Unpacking ${pkg} ]" | ||
848 | |||
849 | # abort on virtual pkg | ||
850 | if [[ ${pkgtype} = virtual ]] | ||
851 | then | ||
852 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
853 | echo " !unpack virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " | ||
854 | continue | ||
855 | fi | ||
856 | |||
857 | # abort on sources pkg | ||
858 | if [[ ${pkgtype} = sources ]] | ||
859 | then | ||
860 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
861 | echo " !unpack sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " | ||
862 | continue | ||
863 | fi | ||
864 | |||
865 | echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... " | ||
866 | tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}" | ||
867 | done | ||
868 | |||
869 | # add a crlf for a better view | ||
870 | if [ ${count_total} -gt 1 ]; then echo; fi | ||
871 | } | ||
872 | |||
873 | install_packages() | ||
874 | { | ||
875 | local list="$@" | ||
876 | local pkg | ||
877 | local pcat | ||
878 | local pname | ||
879 | local pver | ||
880 | local pbuild | ||
881 | local total_pkgs | ||
882 | local current_pkg | ||
883 | local src_install | ||
884 | local uninstall_list | ||
885 | |||
886 | # check for --src-install | ||
887 | if [[ $1 = --src-install ]] | ||
888 | then | ||
889 | # remove --src-install from list | ||
890 | list=${list/--src-install/} | ||
891 | # enable src-install | ||
892 | src_install="--src-install" | ||
893 | fi | ||
894 | |||
895 | # reset MAGE_PROTECT_COUNTER | ||
896 | declare -i MAGE_PROTECT_COUNTER=0 | ||
897 | export MAGE_PROTECT_COUNTER | ||
898 | |||
899 | # get count of total packages | ||
900 | declare -i total_pkgs=0 | ||
901 | declare -i current_pkg=0 | ||
902 | for i in ${list}; do (( total_pkgs++ )); done | ||
903 | |||
904 | echo | ||
905 | |||
906 | if [[ -n ${MROOT} ]] | ||
907 | then | ||
908 | echo -ne ${COLRED} | ||
909 | echo "!! installing in MROOT=${MROOT}" | ||
910 | echo -ne ${COLDEFAULT} | ||
911 | echo | ||
912 | fi | ||
913 | |||
914 | for pkg in ${list} | ||
915 | do | ||
916 | (( current_pkg++ )) | ||
917 | #pcat=$(magename2pcat ${pkg}) | ||
918 | pcat="${pkg%%/*}" | ||
919 | pname=$(magename2pname ${pkg}) | ||
920 | pver=$(magename2pver ${pkg}) | ||
921 | pbuild=$(magename2pbuild ${pkg}) | ||
922 | |||
923 | mage_install \ | ||
924 | --pcat ${pcat} \ | ||
925 | --pname ${pname} \ | ||
926 | --pver ${pver} \ | ||
927 | --pbuild ${pbuild} \ | ||
928 | --count-total ${total_pkgs} \ | ||
929 | --count-current ${current_pkg} \ | ||
930 | ${src_install} | ||
931 | |||
932 | # check for allready installed packages and remove them | ||
933 | # except the package we have installed | ||
934 | uninstall_list="$(get_uninstall_candidates \ | ||
935 | --pcat "${pcat}" \ | ||
936 | --pname "${pname}" \ | ||
937 | --protected ${pcat}/${pname}-${pver}-${pbuild})" | ||
938 | |||
939 | # uninstall all packges in uninstall_list if not empty | ||
940 | if [ -n "${uninstall_list}" ] | ||
941 | then | ||
942 | echo | ||
943 | uninstall_packages ${uninstall_list} \ | ||
944 | || die "install_packges() uninstalling not-needed." | ||
945 | fi | ||
946 | |||
947 | # crlf for better view in VERBOSE mode | ||
948 | #if [[ ${VERBOSE} = on ]]; then echo; fi | ||
949 | echo | ||
950 | done | ||
951 | |||
952 | #echo "DEBUG MAGE_PROTECT_COUNTER=${MAGE_PROTECT_COUNTER}" | ||
953 | show_etc_update_mesg | ||
954 | } | ||
955 | |||
956 | uninstall_packages() | ||
957 | { | ||
958 | local list="$@" | ||
959 | local pcat | ||
960 | local pname | ||
961 | local pver | ||
962 | local pbuild | ||
963 | local can_pcat | ||
964 | local can_pname | ||
965 | local can_ver_list | ||
966 | |||
967 | if [[ -n ${MROOT} ]] | ||
968 | then | ||
969 | echo -ne ${COLRED} | ||
970 | echo "!! uninstalling from MROOT=${MROOT}" | ||
971 | echo -ne ${COLDEFAULT} | ||
972 | echo | ||
973 | fi | ||
974 | |||
975 | # generate a candidates list | ||
976 | for pkg in ${list} | ||
977 | do | ||
978 | #pcat=$(dep2pcat ${pkg}) | ||
979 | pcat="${pkg%%/*}" | ||
980 | pname=$(magename2pname ${pkg}) | ||
981 | pver=$(magename2pver ${pkg}) | ||
982 | pbuild=$(magename2pbuild ${pkg}) | ||
983 | can_pcat="${pcat}" | ||
984 | can_pname="${pname}" | ||
985 | |||
986 | if [ -z "${can_ver_list}" ] | ||
987 | then | ||
988 | can_ver_list=" ${pver}-${pbuild}" | ||
989 | else | ||
990 | can_ver_list="${can_ver_list}, ${pver}-${pbuild}" | ||
991 | fi | ||
992 | done | ||
993 | |||
994 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
995 | echo "following candidate(s) will be removed:" | ||
996 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
997 | echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}" | ||
998 | echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}" | ||
999 | echo | ||
1000 | if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ] | ||
1001 | then | ||
1002 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
1003 | echo "( Press [CTRL+C] to abort )" | ||
1004 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
1005 | echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..." | ||
1006 | for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--)) | ||
1007 | do | ||
1008 | echo -ne "${COLRED} ${i}${COLDEFAULT}" | ||
1009 | sleep 1 | ||
1010 | done | ||
1011 | echo | ||
1012 | echo | ||
1013 | fi | ||
1014 | |||
1015 | for pkg in ${list} | ||
1016 | do | ||
1017 | pcat=$(dep2pcat ${pkg}) | ||
1018 | pname=$(magename2pname ${pkg}) | ||
1019 | pver=$(magename2pver ${pkg}) | ||
1020 | pbuild=$(magename2pbuild ${pkg}) | ||
1021 | |||
1022 | mage_uninstall \ | ||
1023 | --pcat ${pcat} \ | ||
1024 | --pname ${pname} \ | ||
1025 | --pver ${pver} \ | ||
1026 | --pbuild ${pbuild} \ | ||
1027 | --count-total ${total_pkgs} \ | ||
1028 | --count-current ${current_pkg} \ | ||
1029 | ${src_install} | ||
1030 | |||
1031 | # crlf for better view in VERBOSE mode | ||
1032 | #if [[ ${VERBOSE} = on ]]; then echo; fi | ||
1033 | echo | ||
1034 | done | ||
1035 | } | ||
1036 | |||
1037 | is_installed() | ||
1038 | { | ||
1039 | local DBFILE | ||
1040 | local pkgid | ||
1041 | local pcat | ||
1042 | local pname | ||
1043 | local pbuild | ||
1044 | local pver | ||
1045 | |||
1046 | # very basic getops | ||
1047 | for i in $* | ||
1048 | do | ||
1049 | case $1 in | ||
1050 | --pcat|-c) shift; pcat="$1" ;; | ||
1051 | --pname|-n) shift; pname="$1" ;; | ||
1052 | --pver|-v) shift; pver="$1" ;; | ||
1053 | --pbuild|-b) shift; pbuild="$1" ;; | ||
1054 | esac | ||
1055 | shift | ||
1056 | done | ||
1057 | |||
1058 | DBFILE="${MAGE_INSTALL_DB}" | ||
1059 | pkgid=$(sql "select id from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild}'") | ||
1060 | |||
1061 | [[ ! -z ${pkgid} ]] && return 0 | ||
1062 | return 1 | ||
1063 | } | ||
1064 | |||
1065 | reverse_depends() | ||
1066 | { | ||
1067 | local DBFILE | ||
1068 | local pname="$1" | ||
1069 | |||
1070 | DBFILE="${MAGE_INSTALL_DB}" | ||
1071 | sql "select categories.pcat, | ||
1072 | packages.pname, | ||
1073 | packages.pver, | ||
1074 | packages.pbuild | ||
1075 | from depends | ||
1076 | inner join packages on packages.id=depends.pkg_id | ||
1077 | inner join categories on categories.id=packages.pcat_id | ||
1078 | where depends.pname='${pname}'" | ||
1079 | } | ||
1080 | |||
1081 | reverse_sdepends() | ||
1082 | { | ||
1083 | local DBFILE | ||
1084 | local pname="$1" | ||
1085 | |||
1086 | DBFILE="${MAGE_INSTALL_DB}" | ||
1087 | sql "select categories.pcat, | ||
1088 | packages.pname, | ||
1089 | packages.pver, | ||
1090 | packages.pbuild | ||
1091 | from sdepends | ||
1092 | inner join packages on packages.id=sdepends.pkg_id | ||
1093 | inner join categories on categories.id=packages.pcat_id | ||
1094 | where sdepends.pname='${pname}'" | ||
1095 | } | ||
1096 | |||
1097 | create_database_layout() | ||
1098 | { | ||
1099 | sql "create table categories(id integer primary key, pcat text unique)" | ||
1100 | sql "create table packages(id integer primary key, | ||
1101 | pname text, | ||
1102 | pver text, | ||
1103 | pbuild text, | ||
1104 | pcat_id numeric, | ||
1105 | state text, | ||
1106 | provide text, | ||
1107 | pkgtype text | ||
1108 | )" | ||
1109 | sql "create table depends(id integer primary key, pkg_id numeric, relation text, pcat_id numeric, pname text, pver text, pbuild text)" | ||
1110 | sql "create table sdepends(id integer primary key, pkg_id numeric, relation text, pcat_id numeric, pname text, pver text, pbuild text)" | ||
1111 | sql "create table packages_info(id integer primary key, pkg_id numeric, arch text, md5 text, mtime numeric, homepage text, description text, size numeric)" | ||
1112 | #sql "create table packages_content(id integer primary key, pkginfo_id numeric, char text, dirs text, files text, pipes text, symlinks text)" | ||
1113 | sql "create table packages_content(id integer primary key, pkginfo_id numeric, char blob, dirs blob, files blob, pipes blob, symlinks blob)" | ||
1114 | } | ||
1115 | |||
1116 | install_database_entry() | ||
1117 | { | ||
1118 | local pcat | ||
1119 | local pname | ||
1120 | local pver | ||
1121 | local pbuild | ||
1122 | local pkgtype | ||
1123 | local pkgname | ||
1124 | local magefile | ||
1125 | local dbrecorddir | ||
1126 | local provide | ||
1127 | local homepage | ||
1128 | local description | ||
1129 | local pkgid | ||
1130 | local depends | ||
1131 | local sdepends | ||
1132 | local relation | ||
1133 | local depcatid | ||
1134 | local depname | ||
1135 | local depver | ||
1136 | local depbuild | ||
1137 | local mage_pkg_id | ||
1138 | local i | ||
1139 | local install_pkg_id | ||
1140 | local table | ||
1141 | |||
1142 | # very basic getops | ||
1143 | for i in $* | ||
1144 | do | ||
1145 | case $1 in | ||
1146 | --pcat|-c) shift; pcat="$1" ;; | ||
1147 | --pname|-n) shift; pname="$1" ;; | ||
1148 | --pver|-v) shift; pver="$1" ;; | ||
1149 | --pbuild|-b) shift; pbuild="$1" ;; | ||
1150 | --pkgname|-a) shift; pkgname="$1" ;; | ||
1151 | # --state|-s) shift; state="$1" ;; | ||
1152 | --pkgtype|-t) shift; pkgtype="$1" ;; | ||
1153 | esac | ||
1154 | shift | ||
1155 | done | ||
1156 | |||
1157 | # sanity checks; abort if not given | ||
1158 | [[ -z ${pcat} ]] && die "install_database_entry() \$pcat not given." | ||
1159 | [[ -z ${pname} ]] && die "install_database_entry() \$pname not given." | ||
1160 | [[ -z ${pver} ]] && die "install_database_entry() \$pver not given." | ||
1161 | [[ -z ${pbuild} ]] && die "install_database_entry() \$pbuild not given." | ||
1162 | [[ -z ${pkgname} ]] && die "install_database_entry() \$pkgname not given." | ||
1163 | # [[ -z ${state} ]] && die "install_database_entry() \$state not given." | ||
1164 | |||
1165 | # check needed global vars | ||
1166 | [[ -z ${MAGEDIR} ]] && die "install_database_entry() \$MAGEDIR not set." | ||
1167 | [[ -z ${INSTALLDB} ]] && die "install_database_entry() \$INSTALLDB not set." | ||
1168 | |||
1169 | # first of all convert pbuild to database format (remove the r) | ||
1170 | pbuild="${pbuild/r/}" | ||
1171 | |||
1172 | # check if | ||
1173 | # copy all things over over | ||
1174 | # mage.pkg_id | ||
1175 | DBFILE="${MAGE_PACKAGES_DB}" | ||
1176 | mage_pkg_id=$(sql "select id from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild}'") | ||
1177 | |||
1178 | DBFILE="${MAGE_INSTALL_DB}" | ||
1179 | # add pcat to installdb if missing | ||
1180 | if [[ -z $(sql "select id from categories where pcat='${pcat}'") ]] | ||
1181 | then | ||
1182 | sql "insert into categories (pcat) values ('${pcat}')" | ||
1183 | fi | ||
1184 | |||
1185 | # attach install database | ||
1186 | # install.categories.id != main.categories.id !!! | ||
1187 | # so get pcat from pcat_id via inner join. | ||
1188 | # then query install db which id pcat has and use this one | ||
1189 | # final phase copies the whole crap to the install db | ||
1190 | # use some more rows to copy the whole table | ||
1191 | sqlite3 ${MAGE_PACKAGES_DB} \ | ||
1192 | "attach database '${MAGE_INSTALL_DB}' as install; | ||
1193 | insert into install.packages | ||
1194 | (pcat_id, | ||
1195 | pname, | ||
1196 | pver, | ||
1197 | pbuild, | ||
1198 | state, | ||
1199 | provide, | ||
1200 | pkgtype) | ||
1201 | select mage_id, | ||
1202 | main.packages.pname, | ||
1203 | main.packages.pver, | ||
1204 | main.packages.pbuild, | ||
1205 | main.packages.state, | ||
1206 | main.packages.provide, | ||
1207 | main.packages.pkgtype | ||
1208 | from main.packages, | ||
1209 | (select id as mage_id | ||
1210 | from install.categories where pcat=( | ||
1211 | select pcat from main.packages | ||
1212 | inner join main.categories | ||
1213 | on main.categories.id=main.packages.pcat_id | ||
1214 | where main.packages.id='${mage_pkg_id}') | ||
1215 | ) | ||
1216 | where main.packages.id=${mage_pkg_id};" | ||
1217 | |||
1218 | # get install db pkg_id | ||
1219 | install_pkg_id=$(sql "select max(id) from packages") | ||
1220 | |||
1221 | # now copy dependencies | ||
1222 | # replace pkg with the one from insatll.db | ||
1223 | for table in depends sdepends | ||
1224 | do | ||
1225 | sqlite3 ${MAGE_PACKAGES_DB} \ | ||
1226 | "attach database '${MAGE_INSTALL_DB}' as install; | ||
1227 | insert into install.${table} | ||
1228 | (pkg_id, | ||
1229 | relation, | ||
1230 | pcat_id, | ||
1231 | pname, | ||
1232 | pver, | ||
1233 | pbuild) | ||
1234 | select '${install_pkg_id}', | ||
1235 | relation, | ||
1236 | pcat_id, | ||
1237 | pname, | ||
1238 | pver, | ||
1239 | pbuild | ||
1240 | from main.${table} where pkg_id='${mage_pkg_id}'" | ||
1241 | done | ||
1242 | |||
1243 | # and now the package infos | ||
1244 | sqlite3 ${MAGE_PACKAGES_DB} \ | ||
1245 | "attach database '${MAGE_INSTALL_DB}' as install; | ||
1246 | insert into install.packages_info | ||
1247 | (pkg_id, | ||
1248 | arch, | ||
1249 | md5, | ||
1250 | mtime, | ||
1251 | homepage, | ||
1252 | description, | ||
1253 | size) | ||
1254 | select '${install_pkg_id}', | ||
1255 | arch, | ||
1256 | md5, | ||
1257 | mtime, | ||
1258 | homepage, | ||
1259 | description, | ||
1260 | size | ||
1261 | from main.packages_info | ||
1262 | where pkg_id='${mage_pkg_id}' and arch='${ARCH}'" | ||
1263 | |||
1264 | # now install PKGTYPE specific files | ||
1265 | case ${pkgtype} in | ||
1266 | virtual) echo ;; | ||
1267 | sources) echo ;; | ||
1268 | *) | ||
1269 | # and finally the package_content | ||
1270 | # but we first need to know the pkg_info id | ||
1271 | # because of the arch dependency | ||
1272 | pkg_info_id=$(sql "select max(id) from packages_info") | ||
1273 | |||
1274 | sql "insert into packages_content | ||
1275 | (pkginfo_id, | ||
1276 | char, | ||
1277 | dirs, | ||
1278 | files, | ||
1279 | pipes, | ||
1280 | symlinks) | ||
1281 | values('${pkg_info_id}', | ||
1282 | 'records/${pkg_info_id}/char.bz2', | ||
1283 | 'records/${pkg_info_id}/dirs.bz2', | ||
1284 | 'records/${pkg_info_id}/files.bz2', | ||
1285 | 'records/${pkg_info_id}/pipes.bz2', | ||
1286 | 'records/${pkg_info_id}/symlinks.bz2')" | ||
1287 | # create compressed content files | ||
1288 | entrydir=${BUILDDIR}/${pname}-${pver}-${ARCH}-r${pbuild} | ||
1289 | local entryfile | ||
1290 | for entryfile in char dirs files pipes symlinks | ||
1291 | do | ||
1292 | install -d $(dirname ${MAGE_INSTALL_DB})/records/${pkg_info_id} | ||
1293 | cat ${entrydir}/.${entryfile} | bzip2 -9 >> $(dirname ${MAGE_INSTALL_DB})/records/${pkg_info_id}/${entryfile}.bz2 | ||
1294 | done | ||
1295 | ;; | ||
1296 | esac | ||
1297 | } |