Magellan Linux

Annotation of /branches/mage-sql/usr/lib/mage/convert_databases_smage.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1118 - (hide annotations) (download) (as text)
Thu Jul 22 07:19:48 2010 UTC (13 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 21482 byte(s)
-disabled content recording  atm
-upsert categories while creating installdb
-create routines script in pcat/pname-pver-pbuild instead of pkgid for easy database joins
-create empty post|pre|install|remove routines if do_script is defined but no routine to supress script errors

1 niro 489 #!/bin/bash
2    
3     source /etc/mage.rc.global
4     source /etc/mage.rc
5    
6    
7     #### fixups ####
8 niro 1113 MLIBDIR=/home/tjoke/svn/magellan-source/branches/mage-sql/usr/lib/mage
9 niro 489 INSTALLDB=/var/db/mage
10     #################
11    
12     source ${MLIBDIR}/mage4.functions.sh
13     source ${MLIBDIR}/sql_functions.sh
14    
15     die()
16     {
17     echo -e "Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."
18     echo -e "$@"
19     exit 1
20     }
21    
22     sql()
23     {
24     local sqlcmd="$*"
25     [[ -z ${sqlcmd} ]] && die "no sqlcmd given."
26    
27     sqlite3 -nullvalue 'NULL' -list -separator '|' ${DBFILE} << EOF || die "error running '$@'"
28     ${sqlcmd};
29     EOF
30     }
31    
32 niro 1113 split_save_variables()
33     {
34     export SAVED_PNAME="${PNAME}"
35     export SAVED_PVER="${PVER}"
36     export SAVED_PBUILD="${PBUILD}"
37     export SAVED_PCATEGORIE="${PCATEGORIE}"
38     export SAVED_DESCRIPTION="${DESCRIPTION}"
39     export SAVED_HOMEPAGE="${HOMEPAGE}"
40     export SAVED_SPECIAL_VARS="${SPECIAL_VARS}"
41     export SAVED_STATE="${STATE}"
42     export SAVED_PKGTYPE="${PKGTYPE}"
43     export SAVED_INHERITS="${INHERITS}"
44     export SAVED_DEPEND="${DEPEND}"
45     export SAVED_SDEPEND="${SDEPEND}"
46     export SAVED_PROVIDE="${PROVIDE}"
47     export SAVED_NOPKGBUILD="${NOPKGBUILD}"
48    
49     # bindir too
50     export SAVED_BINDIR="${BINDIR}"
51    
52     # export the SPLIT_PACKAGE_BASE
53     export SPLIT_PACKAGE_BASE="${SAVED_PNAME}"
54    
55     # functions
56     if [[ ! -z $(typeset -f preinstall) ]]
57     then
58     # rename the old one
59     local saved_preinstall
60     saved_preinstall=SAVED_$(typeset -f preinstall)
61     eval "${saved_preinstall}"
62     export -f SAVED_preinstall
63     fi
64    
65     if [[ ! -z $(typeset -f postinstall) ]]
66     then
67     # rename the old one
68     local saved_postinstall
69     saved_postinstall=SAVED_$(typeset -f postinstall)
70     eval "${saved_postinstall}"
71     export -f SAVED_postinstall
72     fi
73    
74     if [[ ! -z $(typeset -f preremove) ]]
75     then
76     # rename the old one
77     local saved_preremove
78     saved_preremove=SAVED_$(typeset -f preremove)
79     eval "${saved_preremove}"
80     export -f SAVED_preremove
81     fi
82    
83     if [[ ! -z $(typeset -f postremove) ]]
84     then
85     # rename the old one
86     local saved_postremove
87     saved_postremove=SAVED_$(typeset -f postremove)
88     eval "${saved_postremove}"
89     export -f SAVED_postremove
90     fi
91     }
92    
93     split_restore_variables()
94     {
95     export PNAME="${SAVED_PNAME}"
96     export PVER="${SAVED_PVER}"
97     export PBUILD="${SAVED_PBUILD}"
98     export PCATEGORIE="${SAVED_PCATEGORIE}"
99     export DESCRIPTION="${SAVED_DESCRIPTION}"
100     export HOMEPAGE="${SAVED_HOMEPAGE}"
101     export SPECIAL_VARS="${SAVED_SPECIAL_VARS}"
102     export STATE="${SAVED_STATE}"
103     export PKGTYPE="${SAVED_PKGTYPE}"
104     export INHERITS="${SAVED_INHERITS}"
105     export DEPEND="${SAVED_DEPEND}"
106     export SDEPEND="${SAVED_SDEPEND}"
107     export PROVIDE="${SAVED_PROVIDE}"
108     export NOPKGBUILD="${SAVED_NOPKGBUILD}"
109    
110     # bindir too
111     export BINDIR="${SAVED_BINDIR}"
112    
113     # functions
114     if [[ ! -z $(typeset -f SAVED_preinstall) ]]
115     then
116     # rename the old one
117     local saved_preinstall
118     saved_preinstall=$(typeset -f SAVED_preinstall)
119     eval "${saved_preinstall/SAVED_/}"
120     export -f preinstall
121     fi
122    
123     if [[ ! -z $(typeset -f SAVED_postinstall) ]]
124     then
125     # rename the old one
126     local saved_postinstall
127     saved_postinstall=$(typeset -f SAVED_postinstall)
128     eval "${saved_postinstall/SAVED_/}"
129     export -f postinstall
130     fi
131    
132     if [[ ! -z $(typeset -f SAVED_preremove) ]]
133     then
134     # rename the old one
135     local saved_preremove
136     saved_preremove=$(typeset -f SAVED_preremove)
137     eval "${saved_preremove/SAVED_/}"
138     export -f preremove
139     fi
140    
141     if [[ ! -z $(typeset -f SAVED_postremove) ]]
142     then
143     # rename the old one
144     local saved_postremove
145     saved_postremove=$(typeset -f SAVED_postremove)
146     eval "${saved_postremove/SAVED_/}"
147     export -f postremove
148     fi
149     }
150    
151     split_unset_variables()
152     {
153     # unset saved vars; not needed anymore
154     unset SAVED_PNAME
155     unset SAVED_PVER
156     unset SAVED_PBUILD
157     unset SAVED_PCATEGORIE
158     unset SAVED_DESCRIPTION
159     unset SAVED_HOMEPAGE
160     unset SAVED_SPECIAL_VARS
161     unset SAVED_STATE
162     unset SAVED_PKGTYPE
163     unset SAVED_INHERITS
164     unset SAVED_DEPEND
165     unset SAVED_SDEPEND
166     unset SAVED_PROVIDE
167     unset SAVED_BINDIR
168     unset SAVED_NOPKGBUILD
169     unset SPLIT_PACKAGE_BASE
170     unset -f SAVED_preinstall
171     unset -f SAVED_postinstall
172     unset -f SAVED_preremove
173     unset -f SAVED_postremove
174     }
175    
176 niro 489 create_database_layout()
177     {
178     sql "create table categories(id integer primary key, pcat text unique)"
179     sql "create table packages(id integer primary key,
180     pname text,
181     pver text,
182     pbuild text,
183     pcat_id numeric,
184     state text,
185     provide text,
186     pkgtype text
187     )"
188     sql "create table depends(id integer primary key, pkg_id numeric, relation text, pcat_id numeric, pname text, pver text, pbuild text)"
189     sql "create table sdepends(id integer primary key, pkg_id numeric, relation text, pcat_id numeric, pname text, pver text, pbuild text)"
190     sql "create table packages_info(id integer primary key, pkg_id numeric, arch text, md5 text, mtime numeric, homepage text, description text, size numeric)"
191     #sql "create table packages_content(id integer primary key, pkginfo_id numeric, char text, dirs text, files text, pipes text, symlinks text)"
192     sql "create table packages_content(id integer primary key, pkginfo_id numeric, char blob, dirs blob, files blob, pipes blob, symlinks blob)"
193     # sql "create table packages_routines(id integer primary key,
194     # pkg_id numeric,
195     # mincludes text,
196     # preinstall text,
197     # postinstall text,
198     # preremove text,
199     # postremove text,
200     # extra_functions text,
201     # extra_vars text)"
202     sql "create table packages_routines(id integer primary key,
203     pkg_id numeric,
204     mincludes text,
205     preinstall numeric,
206     postinstall numeric,
207     preremove numeric,
208     postremove numeric,
209     script text)"
210     }
211    
212 niro 1113 smage2sqlite()
213 niro 489 {
214     local i
215     local pcatid
216     local pkgid
217     local dep
218     local sym
219     local depname
220     local depver
221     local depbuild
222     local depcat
223     local depcatid
224     local md5file
225     local md5sum
226    
227 niro 1113 pcatid=$(sql "select id from categories where pcat='${PCATEGORIE}'")
228 niro 489
229 niro 1113 sql "insert into packages(
230     pname,
231     pver,
232     pbuild,
233     pcat_id,
234     state,
235     provide,
236     pkgtype
237     )
238     values(
239     '${PNAME}',
240     '${PVER}',
241     '${PBUILD}',
242     '${pcatid}',
243     '${STATE}',
244     '${PROVIDE}',
245     '${PKGTYPE}'
246     )"
247 niro 489
248 niro 1113 pkgid=$(sql "select id from packages where pname='${PNAME}' and pver='${PVER}' and pbuild='${PBUILD}'")
249    
250     # depends
251     while read sym dep
252 niro 489 do
253 niro 1113 # ignore scripts atm -FIXME!!!
254     case ${sym} in
255     \$\(*) continue ;;
256 niro 489 esac
257    
258 niro 1113 [[ -z ${dep} ]] && continue
259     depcat="$(dep2pcat ${dep})"
260     depcatid=$(sql "select id from categories where pcat='${depcat}'")
261     depname="$(dep2pname ${dep})"
262     depver="$(dep2pver ${dep})"
263 niro 489
264 niro 1113 if [[ -z ${depcatid} ]]
265     then
266     die "Error: '${PNAME}' -> depcat '${depcat}' has no depcatid, it does no exist in database!"
267     fi
268 niro 489
269 niro 1113 sql "insert into depends(pkg_id,
270     relation,
271     pcat_id,
272 niro 489 pname,
273     pver,
274 niro 1113 pbuild)
275     values('${pkgid}',
276     '${sym}',
277     '${depcatid}',
278     '${depname}',
279     '${depver}',
280     '${depbuild}')"
281     done << EOF
282 niro 489 ${DEPEND}
283     EOF
284 niro 1113 # sdepends
285     while read sym dep
286     do
287     [[ -z ${dep} ]] && continue
288     depcat="$(dep2pcat ${dep})"
289     depcatid=$(sql "select id from categories where pcat='${depcat}'")
290     depname="$(dep2pname ${dep})"
291     depver="$(dep2pver ${dep})"
292     sql "insert into sdepends(pkg_id,
293     relation,
294     pcat_id,
295     pname,
296     pver,
297     pbuild)
298     values('${pkgid}',
299     '${sym}',
300     '${depcatid}',
301     '${depname}',
302     '${depver}',
303     '${depbuild}')"
304     done << EOF
305 niro 489 ${SDEPEND}
306     EOF
307    
308 niro 1113 for arch in i686 x86_64
309     do
310     md5file="${MAGEDIR}/${PCATEGORIE}/${PNAME}/md5/${PNAME}-${PVER}-${arch}-r${PBUILD}.md5"
311     [[ -f ${md5file} ]] && md5sum="$(cat ${md5file} | cut -d' ' -f1)"
312 niro 489
313 niro 1113 # fix descriptions
314     DESCRIPTION="$(echo ${DESCRIPTION} | sed s:\':\'\':g)"
315 niro 489
316 niro 1113 sql "insert into packages_info(pkg_id, arch, md5, description, homepage)
317     values('${pkgid}','${arch}','${md5sum}','${DESCRIPTION}','${HOMEPAGE}')"
318     done
319 niro 489
320 niro 1113 # using $INHERITS directly
321     #mincludes="$(grep -r 'minclude ' ${magefile} | cut -d: -f2 | sed s:minclude\ ::)"
322 niro 489
323 niro 1113 # # #
324     # # # install routines & includes
325     # # #
326     # # # needs special magic: the last line of typeset has no ';'
327     # # # but to eval the function we must append it
328     # # # so this sed deletes the last line of the typeset output
329     # # # and replaces it with an ;} and a newline between
330     # # #
331     # # # but we will not add this fun when no postinstall etc are given
332     # # # -> [[ -n $(typeset -f postinstall ]] &&
333     # # #
334     # # # also the character ' is a problem while importing to sql
335     # # # because we use ' as escape char. so we replace it with ''
336     # # #
337     # # # $([[ -n $(typeset -f postinstall) ]] && echo -e "$(typeset -f postinstall | sed s:\':\'\':g | sed '$d');\n}")
338     # # #
339     # # sql "insert into packages_routines(pkg_id,
340     # # mincludes,
341     # # postinstall,
342     # # preinstall,
343     # # preremove,
344     # # postremove)
345     # # values('${pkgid}',
346     # # '${mincludes}',
347     # # '$([[ -n $(typeset -f postinstall) ]] && echo -e "$(typeset -f postinstall | sed s:\':\'\':g | sed '$d');\n}")',
348     # # '$([[ -n $(typeset -f preinstall) ]] && echo -e "$(typeset -f preinstall | sed s:\':\'\':g | sed '$d');\n}")',
349     # # '$([[ -n $(typeset -f preremove) ]] && echo -e "$(typeset -f preremove | sed s:\':\'\':g | sed '$d');\n}")',
350     # # '$([[ -n $(typeset -f postremove) ]] && echo -e "$(typeset -f postremove | sed s:\':\'\':g | sed '$d');\n}")')"
351 niro 489
352 niro 1113 local do_preinst=0
353     local do_postinst=0
354     local do_prerm=0
355     local do_postrm=0
356     local do_script=0
357     local script=""
358 niro 489
359 niro 1118 # # [[ -n $(typeset -f preinstall) ]] && do_preinst=1 && do_script=1
360     # # [[ -n $(typeset -f postinstall) ]] && do_postinst=1 && do_script=1
361     # # [[ -n $(typeset -f preremove) ]] && do_prerm=1 && do_script=1
362     # # [[ -n $(typeset -f postremove) ]] && do_postrm=1 && do_script=1
363     # #
364     # # [[ ${do_script} = 1 ]] && script="$(basename ${DBFILE} .sql).routines/${pkgid}/routines.sh"
365    
366 niro 1113 [[ -n $(typeset -f preinstall) ]] && do_preinst=1 && do_script=1
367     [[ -n $(typeset -f postinstall) ]] && do_postinst=1 && do_script=1
368     [[ -n $(typeset -f preremove) ]] && do_prerm=1 && do_script=1
369     [[ -n $(typeset -f postremove) ]] && do_postrm=1 && do_script=1
370 niro 489
371 niro 1118 [[ ${do_script} = 1 ]] && script="$(basename ${DBFILE} .sql).data/${PCATEGORIE}/${PNAME}-${PVER}-${PBUILD}/routines.sh"
372 niro 489
373 niro 1113 sql "insert into packages_routines(pkg_id,
374     mincludes,
375     postinstall,
376     preinstall,
377     preremove,
378     postremove,
379     script)
380     values('${pkgid}',
381     '${INHERITS}',
382     '${do_postinst}',
383     '${do_pretinst}',
384     '${do_prerm}',
385     '${do_postrm}',
386     '${script}')"
387 niro 489
388 niro 1118 # # # create it only if do_script=1
389     # # if [[ ${do_script} = 1 ]]
390     # # then
391     # # # create a routines script
392     # # local routines=$(dirname ${DBFILE})/${script}
393     # # install -d $(dirname ${routines})
394     # #
395     # # echo '#!/bin/sh' > ${routines}
396     # # echo "# routines.sh script for ${pkgid}, ${PNAME}-${PVER}-${PBUILD}" >> ${routines}
397     # # echo >> ${routines}
398     # #
399     # #
400     # # # special functions and variables
401     # # if [[ -n ${SPECIAL_VARS} ]]
402     # # then
403     # # local i
404     # # for i in ${SPECIAL_VARS}
405     # # do
406     # # # being tricky here :)
407     # # echo "${i}=\"$(eval echo \$${i})\"" >> ${routines}
408     # # done
409     # # echo >> ${routines}
410     # # fi
411     # #
412     # # # add special functions
413     # # if [[ -n ${SPECIAL_FUNCTIONS} ]]
414     # # then
415     # # local i
416     # # for i in ${SPECIAL_FUNCTIONS}
417     # # do
418     # # # add to mage (quotes needed !)
419     # # typeset -f "${i}" >> ${routines}
420     # # echo >> ${routines}
421     # # # unset to be safe (quotes needed !)
422     # # unset "${i}"
423     # # done
424     # # echo >> ${routines}
425     # # fi
426     # #
427     # # # postinstall and co
428     # # for i in preinstall postinstall preremove postremove
429     # # do
430     # # if [[ -n $(typeset -f "${i}") ]]
431     # # then
432     # # typeset -f "${i}" >> ${routines}
433     # # echo >> ${routines}
434     # # fi
435     # # done
436     # #
437     # # # create start logic
438     # # echo >> ${routines}
439     # # echo 'case $1 in' >> ${routines}
440     # # echo ' preinstall) preinstall ;;' >> ${routines}
441     # # echo ' postinstall) postinstall ;;' >> ${routines}
442     # # echo ' preremove) preremove ;;' >> ${routines}
443     # # echo ' postremove) postremove ;;' >> ${routines}
444     # # echo 'esac' >> ${routines}
445     # # echo >> ${routines}
446     # # fi
447    
448 niro 489 # create it only if do_script=1
449     if [[ ${do_script} = 1 ]]
450     then
451 niro 1113 # create a routines script
452     local routines=$(dirname ${DBFILE})/${script}
453     install -d $(dirname ${routines})
454 niro 489
455 niro 1113 echo '#!/bin/sh' > ${routines}
456 niro 1118 echo "# routines.sh script for ${PCATEGORIE}/${PNAME}-${PVER}-${PBUILD}" >> ${routines}
457 niro 1113 echo >> ${routines}
458 niro 489
459    
460 niro 1113 # special functions and variables
461     if [[ -n ${SPECIAL_VARS} ]]
462     then
463     local i
464     for i in ${SPECIAL_VARS}
465     do
466     # being tricky here :)
467     echo "${i}=\"$(eval echo \$${i})\"" >> ${routines}
468     done
469     echo >> ${routines}
470     fi
471    
472     # add special functions
473     if [[ -n ${SPECIAL_FUNCTIONS} ]]
474     then
475     local i
476     for i in ${SPECIAL_FUNCTIONS}
477     do
478     # add to mage (quotes needed !)
479     typeset -f "${i}" >> ${routines}
480     echo >> ${routines}
481     # unset to be safe (quotes needed !)
482     unset "${i}"
483     done
484     echo >> ${routines}
485     fi
486    
487     # postinstall and co
488     for i in preinstall postinstall preremove postremove
489     do
490     if [[ -n $(typeset -f "${i}") ]]
491 niro 489 then
492 niro 1113 typeset -f "${i}" >> ${routines}
493     echo >> ${routines}
494 niro 1118 else
495     echo "${i} () { return 0; }" >> ${routines}
496 niro 489 fi
497 niro 1113 done
498 niro 489
499 niro 1113 # create start logic
500     echo >> ${routines}
501     echo 'case $1 in' >> ${routines}
502     echo ' preinstall) preinstall ;;' >> ${routines}
503     echo ' postinstall) postinstall ;;' >> ${routines}
504     echo ' preremove) preremove ;;' >> ${routines}
505     echo ' postremove) postremove ;;' >> ${routines}
506     echo 'esac' >> ${routines}
507     echo >> ${routines}
508     fi
509    
510     unset PCATEGORIE
511     unset PNAME
512     unset PVER
513     unset PBUILD
514     unset STATE
515     unset DESCRIPTION
516     unset HOMEPAGE
517     unset PKGTYPE
518     unset PKGNAME
519     unset DEPEND
520     unset SDEPEND
521     unset PROVIDE
522     unset SPECIAL_VARS
523     unset SPECIAL_FUNCTIONS
524     unset INHERITS
525     unset SPLIT_PACKAGES
526    
527     # unset these functions
528     unset -f preinstall
529     unset -f postinstall
530     unset -f preremove
531     unset -f postremove
532     }
533    
534     categories2sqlite()
535     {
536     local file="$1"
537    
538     if [[ ! -f ${file} ]]
539     then
540     echo "${file} does not exist, ignoring..."
541     return 0
542     fi
543    
544     echo "using categories from ${file}..."
545     # create categories
546     cat ${file} | while read pcat
547     do
548     case ${pcat} in
549     include|profiles) continue;;
550     \#*|"") continue ;;
551     esac
552    
553     # "upsert"
554     if [[ -z $(sql "select pcat from categories where pcat='${pcat}'") ]]
555 niro 489 then
556 niro 1113 sql "insert into categories (pcat) values('${pcat}')"
557 niro 489 fi
558 niro 1113 done
559     }
560 niro 489
561 niro 1113 convert_smage_db()
562     {
563     local smagefile
564 niro 489
565 niro 1113 local PCATEGORIE
566     local PNAME
567     local PVER
568     local PBUILD
569     local STATE
570     local PKGNAME
571     local DESCRIPTION
572     local HOMEPAGE
573     local DEPEND
574     local SDEPEND
575     local PROVIDE
576     local PKGTYPE
577     local SPLIT_PACKAGES
578     local preinstall
579     local postinstall
580     local preremove
581     local postremove
582 niro 489
583 niro 1113 # create categories - global
584     categories2sqlite "${SMAGESCRIPTSDIR}/.known_categories"
585 niro 489
586 niro 1113 # create categories - repo specific
587     categories2sqlite "${SMAGESCRIPTSDIR}/${REPO}/.known_categories"
588    
589     # create packages
590     for smagefile in $(find ${SMAGESCRIPTSDIR}/${REPO} -type f -name \*.smage2 | sort)
591     do
592     case ${DEBUG} in
593     1|true) echo "converting ${smagefile}" ;;
594     esac
595    
596     source ${smagefile}
597    
598     # build several subpackages
599     if [[ -n ${SPLIT_PACKAGES} ]]
600     then
601     split_save_variables
602     for subpackage in ${SPLIT_PACKAGES}
603     do
604     echo "Running for subpackage '${subpackage}'..."
605    
606     # get the right variables for the split
607     export PNAME="${subpackage}"
608     split_info_${subpackage}
609    
610     smage2sqlite
611    
612     # restore smage environment
613     split_restore_variables
614     done
615     # unset all saved smage variables
616     split_unset_variables
617     else
618     smage2sqlite
619     fi
620    
621 niro 489 unset PCATEGORIE
622     unset PNAME
623     unset PVER
624     unset PBUILD
625     unset STATE
626     unset DESCRIPTION
627     unset HOMEPAGE
628     unset PKGTYPE
629     unset PKGNAME
630     unset DEPEND
631     unset SDEPEND
632     unset PROVIDE
633     unset SPECIAL_VARS
634     unset SPECIAL_FUNCTIONS
635     unset INHERITS
636 niro 1113 unset SPLIT_PACKAGES
637 niro 489
638     # unset these functions
639     unset -f preinstall
640     unset -f postinstall
641     unset -f preremove
642     unset -f postremove
643     done
644     }
645    
646     convert_install_db()
647     {
648     local i
649     local magefile
650     local pcat
651     local pname
652     local pver
653     local pbuild
654     local pcatid
655     local state
656     local preinstall
657     local postinstall
658     local preremove
659     local postremove
660     local pkgid
661     local dep
662     local PKGNAME
663     local STATE
664     local DESCRIPTION
665     local HOMEPAGE
666     local DEPEND
667     local SDEPEND
668     local PROVIDE
669     local PKGTYPE
670     local preinstall
671     local postinstall
672     local preremove
673     local postremove
674     local sym
675     local depname
676     local depver
677     local depbuild
678     local depcat
679     local depcatid
680     local md5file
681     local md5sum
682     local pkginfoid
683     local entrydir
684    
685 niro 1113 # first of all add virtual categorie
686     sql "insert into categories(pcat) values('virtual')"
687    
688 niro 489 # create categories
689     for i in virtual ${INSTALLDB}/*
690     do
691     pcat="$(basename ${i})"
692     case ${pcat} in
693     include|profiles) continue;;
694     esac
695    
696 niro 1118 # "upsert"
697     if [[ -z $(sql "select pcat from categories where pcat='${pcat}'") ]]
698     then
699     sql "insert into categories (pcat) values('${pcat}')"
700     fi
701 niro 489 done
702    
703     # create packages
704     for magefile in $(find ${INSTALLDB} -type f -name *.mage| sort)
705     do
706     case ${DEBUG} in
707     1|true) echo "converting ${magefile}" ;;
708     esac
709    
710     pcat="$(magename2pcat ${magefile})"
711     pname="$(magename2pname ${magefile})"
712     pver="$(magename2pver ${magefile})"
713     pbuild="$(magename2pbuild ${magefile})"
714    
715     source ${magefile}
716    
717     pcatid=$(sql "select id from categories where pcat='${pcat}'")
718     sql "insert into packages(
719     pname,
720     pver,
721     pbuild,
722     pcat_id,
723     state,
724     provide,
725     pkgtype
726     )
727     values(
728     '${pname}',
729     '${pver}',
730     '${pbuild}',
731     '${pcatid}',
732     '${STATE}',
733     '${PROVIDE}',
734     '${PKGTYPE}'
735     )"
736    
737     pkgid=$(sql "select id from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild}'")
738     # depends
739     while read sym dep
740     do
741     [[ -z ${dep} ]] && continue
742     depcat="$(dep2pcat ${dep})"
743     depcatid=$(sql "select id from categories where pcat='${depcat}'")
744     depname="$(dep2pname ${dep})"
745     depver="$(dep2pver ${dep})"
746     sql "insert into depends(pkg_id,
747     relation,
748     pcat_id,
749     pname,
750     pver,
751     pbuild)
752     values('${pkgid}',
753     '${sym}',
754     '${depcatid}',
755     '${depname}',
756     '${depver}',
757     '${depbuild}')"
758     done << EOF
759     ${DEPEND}
760     EOF
761     # sdepends
762     while read sym dep
763     do
764     [[ -z ${dep} ]] && continue
765     depcat="$(dep2pcat ${dep})"
766     depcatid=$(sql "select id from categories where pcat='${depcat}'")
767     depname="$(dep2pname ${dep})"
768     depver="$(dep2pver ${dep})"
769     sql "insert into sdepends(pkg_id,
770     relation,
771     pcat_id,
772     pname,
773     pver,
774     pbuild)
775     values('${pkgid}',
776     '${sym}',
777     '${depcatid}',
778     '${depname}',
779     '${depver}',
780     '${depbuild}')"
781     done << EOF
782     ${SDEPEND}
783     EOF
784    
785     DESCRIPTION="$(echo ${DESCRIPTION} | sed s:\':\'\':g)"
786     sql "insert into packages_info(pkg_id, arch, md5, description, homepage)
787     values('${pkgid}','${ARCH}','${md5sum}','${DESCRIPTION}','${HOMEPAGE}')"
788    
789    
790     # install routines & includes
791     sql "insert into packages_routines(pkg_id,
792     mincludes,
793     postinstall,
794     preinstall,
795     preremove,
796     postremove)
797     values('${pkgid}',
798     '${mincludes}',
799     '$(typeset -f postinstall | sed s:\':\'\':g)',
800     '$(typeset -f preinstall | sed s:\':\'\':g)',
801     '$(typeset -f preremove | sed s:\':\'\':g)',
802     '$(typeset -f postremove | sed s:\':\'\':g)')"
803    
804 niro 1118 # # #### ####
805     # # # record contents #
806     # # #### ####
807     # # pkginfoid=$(sql "select id from packages_info where pkg_id='${pkgid}' and arch='${ARCH}'")
808     # # entrydir="$(dirname ${magefile})"
809     # # sql "insert into packages_content(pkginfo_id,
810     # # char,
811     # # dirs,
812     # # files,
813     # # pipes,
814     # # symlinks)
815     # # values('${pkginfoid}',
816     # # '$(basename ${DBFILE} .sql).records/${pkginfoid}/char.bz2',
817     # # '$(basename ${DBFILE} .sql).records/${pkginfoid}/dirs.bz2',
818     # # '$(basename ${DBFILE} .sql).records/${pkginfoid}/files.bz2',
819     # # '$(basename ${DBFILE} .sql).records/${pkginfoid}/pipes.bz2',
820     # # '$(basename ${DBFILE} .sql).records/${pkginfoid}/symlinks.bz2')"
821     # # # create compressed content files
822     # # local entryfile
823     # # for entryfile in char dirs files pipes symlinks
824     # # do
825     # # install -d $(dirname ${DBFILE})/$(basename ${DBFILE} .sql).records/${pkginfoid}
826     # # cat ${entrydir}/.${entryfile} | bzip2 -9 >> $(dirname ${DBFILE})/$(basename ${DBFILE} .sql).records/${pkginfoid}/${entryfile}.bz2
827     # # done
828 niro 489
829     unset PKGNAME
830     unset DEPEND
831     unset SDEPEND
832     unset PROVIDE
833     unset SPECIAL_VARS
834     unset SPECIAL_FUNCTIONS
835    
836     # unset these functions
837     unset -f preinstall
838     unset -f postinstall
839     unset -f preremove
840     unset -f postremove
841     done
842     }
843    
844     convert_virtual_defaults()
845     {
846     local virtual
847     local package
848     local vcat
849     local vname
850     local pcat
851     local pname
852    
853     sql "create table virtual_defaults(id integer primary key, vcat text,vname text, pcat text, pname text)"
854    
855     while read virtual package
856     do
857     vcat="$(dirname ${virtual})"
858     vname="$(basename ${virtual})"
859     pcat="$(dirname ${package})"
860     pname="$(basename ${package})"
861    
862     sql "insert into virtual_defaults(vcat,vname,pcat,pname) values('${vcat}','${vname}','${pcat}','${pname}')"
863     done < /etc/mage-profile/virtuals.defaults
864     }
865    
866     METHOD="$1"
867     DBFILE="$2"
868 niro 1113 REPO="$3"
869 niro 489
870     [[ -z ${METHOD} ]] && die "No method given. Use --install, --packages or --virtual for your appropiate task"
871     [[ -z ${DBFILE} ]] && die "No database given."
872 niro 1113 [[ -z ${REPO} ]] && die "No repository given."
873 niro 489
874     case $1 in
875     --install|-i)
876     create_database_layout
877     convert_install_db
878     ;;
879     --packages|-p)
880 niro 1113 convert_virtual_defaults
881 niro 489 create_database_layout
882     convert_smage_db
883     ;;
884 niro 1113 # --virtuals|-v)
885     # convert_virtual_defaults
886     # ;;
887 niro 489 *) die "Unkown method." ;;
888     esac

Properties

Name Value
svn:executable *