Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1112 by niro, Wed Jul 14 17:38:51 2010 UTC revision 1118 by niro, Thu Jul 22 07:19:48 2010 UTC
# Line 5  source /etc/mage.rc Line 5  source /etc/mage.rc
5    
6    
7  #### fixups ####  #### fixups ####
8  MLIBDIR=/home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage  MLIBDIR=/home/tjoke/svn/magellan-source/branches/mage-sql/usr/lib/mage
9  INSTALLDB=/var/db/mage  INSTALLDB=/var/db/mage
10  #################  #################
11    
# Line 29  ${sqlcmd}; Line 29  ${sqlcmd};
29  EOF  EOF
30  }  }
31    
32    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  create_database_layout()  create_database_layout()
177  {  {
178   sql "create table categories(id integer primary key, pcat text unique)"   sql "create table categories(id integer primary key, pcat text unique)"
# Line 65  create_database_layout() Line 209  create_database_layout()
209   script text)"   script text)"
210  }  }
211    
212  convert_smage_db()  smage2sqlite()
213  {  {
214   local i   local i
  local smagefile  
  local PCATEGORIE  
  local PNAME  
  local PVER  
  local PBUILD  
215   local pcatid   local pcatid
  local STATE  
216   local pkgid   local pkgid
217   local dep   local dep
  local PKGNAME  
  local DESCRIPTION  
  local HOMEPAGE  
  local DEPEND  
  local SDEPEND  
  local PROVIDE  
  local PKGTYPE  
  local preinstall  
  local postinstall  
  local preremove  
  local postremove  
218   local sym   local sym
219   local depname   local depname
220   local depver   local depver
# Line 97  convert_smage_db() Line 224  convert_smage_db()
224   local md5file   local md5file
225   local md5sum   local md5sum
226    
227   # create categories   pcatid=$(sql "select id from categories where pcat='${PCATEGORIE}'")
  cat ${SMAGESCRIPTSDIR}/.known_categories | while read pcat  
  do  
  case ${pcat} in  
  include|profiles) continue;;  
  esac  
228    
229   sql "insert into categories (pcat) values('${pcat}')"   sql "insert into packages(
230   done   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    
248   # create packages   pkgid=$(sql "select id from packages where pname='${PNAME}' and pver='${PVER}' and pbuild='${PBUILD}'")
249   for smagefile in $(find ${SMAGESCRIPTSDIR}/glibc-nptl -type f -name '*'.smage2 | sort)  
250     # depends
251     while read sym dep
252   do   do
253   case ${DEBUG} in   # ignore scripts atm -FIXME!!!
254   1|true) echo "converting ${smagefile}" ;;   case ${sym} in
255     \$\(*) continue ;;
256   esac   esac
257    
258   source ${smagefile}   [[ -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    
264   # substitute r from pbuild   if [[ -z ${depcatid} ]]
265   PBUILD="${PBUILD/r/}"   then
266     die "Error: '${PNAME}' -> depcat '${depcat}' has no depcatid, it does no exist in database!"
267     fi
268    
269   pcatid=$(sql "select id from categories where pcat='${PCATEGORIE}'")   sql "insert into depends(pkg_id,
270   sql "insert into packages(   relation,
271     pcat_id,
272   pname,   pname,
273   pver,   pver,
274   pbuild,   pbuild)
275   pcat_id,   values('${pkgid}',
276   state,   '${sym}',
277   provide,   '${depcatid}',
278   pkgtype   '${depname}',
279   )   '${depver}',
280   values(   '${depbuild}')"
281   '${PNAME}',   done << EOF
  '${PVER}',  
  '${PBUILD}',  
  '${pcatid}',  
  '${STATE}',  
  '${PROVIDE}',  
  '${PKGTYPE}'  
  )"  
   
  pkgid=$(sql "select id from packages where pname='${PNAME}' and pver='${PVER}' and pbuild='${PBUILD}'")  
  # depends  
  while read sym dep  
  do  
  [[ -z ${dep} ]] && continue  
  depcat="$(dep2pcat ${dep})"  
  depcatid=$(sql "select id from categories where pcat='${depcat}'")  
  depname="$(dep2pname ${dep})"  
  depver="$(dep2pver ${dep})"  
  sql "insert into depends(pkg_id,  
  relation,  
  pcat_id,  
  pname,  
  pver,  
  pbuild)  
  values('${pkgid}',  
  '${sym}',  
  '${depcatid}',  
  '${depname}',  
  '${depver}',  
  '${depbuild}')"  
  done << EOF  
282  ${DEPEND}  ${DEPEND}
283  EOF  EOF
284   # sdepends   # sdepends
285   while read sym dep   while read sym dep
286   do   do
287   [[ -z ${dep} ]] && continue   [[ -z ${dep} ]] && continue
288   depcat="$(dep2pcat ${dep})"   depcat="$(dep2pcat ${dep})"
289   depcatid=$(sql "select id from categories where pcat='${depcat}'")   depcatid=$(sql "select id from categories where pcat='${depcat}'")
290   depname="$(dep2pname ${dep})"   depname="$(dep2pname ${dep})"
291   depver="$(dep2pver ${dep})"   depver="$(dep2pver ${dep})"
292   sql "insert into sdepends(pkg_id,   sql "insert into sdepends(pkg_id,
293   relation,   relation,
294   pcat_id,   pcat_id,
295   pname,   pname,
296   pver,   pver,
297   pbuild)   pbuild)
298   values('${pkgid}',   values('${pkgid}',
299   '${sym}',   '${sym}',
300   '${depcatid}',   '${depcatid}',
301   '${depname}',   '${depname}',
302   '${depver}',   '${depver}',
303   '${depbuild}')"   '${depbuild}')"
304   done << EOF   done << EOF
305  ${SDEPEND}  ${SDEPEND}
306  EOF  EOF
307    
308   for arch in i686 x86_64   for arch in i686 x86_64
309   do   do
310   md5file="${MAGEDIR}/${PCATEGORIE}/${PNAME}/md5/${PNAME}-${PVER}-${arch}-r${PBUILD}.md5"   md5file="${MAGEDIR}/${PCATEGORIE}/${PNAME}/md5/${PNAME}-${PVER}-${arch}-r${PBUILD}.md5"
311   [[ -f ${md5file} ]] && md5sum="$(cat ${md5file} | cut -d' ' -f1)"   [[ -f ${md5file} ]] && md5sum="$(cat ${md5file} | cut -d' ' -f1)"
   
  # fix descriptions  
  DESCRIPTION="$(echo ${DESCRIPTION} | sed s:\':\'\':g)"  
   
  sql "insert into packages_info(pkg_id, arch, md5, description, homepage)  
  values('${pkgid}','${arch}','${md5sum}','${DESCRIPTION}','${HOMEPAGE}')"  
  done  
312    
313   # using $INHERITS directly   # fix descriptions
314   #mincludes="$(grep -r 'minclude ' ${magefile} | cut -d: -f2 | sed s:minclude\ ::)"   DESCRIPTION="$(echo ${DESCRIPTION} | sed s:\':\'\':g)"
315    
316  # # #   sql "insert into packages_info(pkg_id, arch, md5, description, homepage)
317  # # # install routines & includes   values('${pkgid}','${arch}','${md5sum}','${DESCRIPTION}','${HOMEPAGE}')"
318  # # #   done
 # # # needs special magic: the last line of typeset has no ';'  
 # # # but to eval the function we must append it  
 # # # so this sed deletes the last line of the typeset output  
 # # # and replaces it with an ;} and a newline between  
 # # #  
 # # # but we will not add this fun when no postinstall etc are given  
 # # # -> [[ -n $(typeset -f postinstall ]] &&  
 # # #  
 # # # also the character ' is a problem while importing to sql  
 # # # because we use ' as escape char. so we replace it with ''  
 # # #  
 # # # $([[ -n $(typeset -f postinstall) ]] && echo -e "$(typeset -f postinstall | sed s:\':\'\':g | sed '$d');\n}")  
 # # #  
 # # sql "insert into packages_routines(pkg_id,  
 # # mincludes,  
 # # postinstall,  
 # # preinstall,  
 # # preremove,  
 # # postremove)  
 # # values('${pkgid}',  
 # # '${mincludes}',  
 # # '$([[ -n $(typeset -f postinstall) ]] && echo -e "$(typeset -f postinstall | sed s:\':\'\':g | sed '$d');\n}")',  
 # # '$([[ -n $(typeset -f preinstall) ]] && echo -e "$(typeset -f preinstall | sed s:\':\'\':g | sed '$d');\n}")',  
 # # '$([[ -n $(typeset -f preremove) ]] && echo -e "$(typeset -f preremove | sed s:\':\'\':g | sed '$d');\n}")',  
 # # '$([[ -n $(typeset -f postremove) ]] && echo -e "$(typeset -f postremove | sed s:\':\'\':g | sed '$d');\n}")')"  
   
  local do_preinst=0  
  local do_postinst=0  
  local do_prerm=0  
  local do_postrm=0  
  local do_script=0  
  local script=""  
   
  [[ -n $(typeset -f preinstall) ]] && do_preinst=1 && do_script=1  
  [[ -n $(typeset -f postinstall) ]] && do_postinst=1 && do_script=1  
  [[ -n $(typeset -f preremove) ]] && do_prerm=1 && do_script=1  
  [[ -n $(typeset -f postremove) ]] && do_postrm=1 && do_script=1  
319    
320   [[ ${do_script} = 1 ]] && script="$(basename ${DBFILE} .sql).routines/${pkgid}/routines.sh"   # using $INHERITS directly
321     #mincludes="$(grep -r 'minclude ' ${magefile} | cut -d: -f2 | sed s:minclude\ ::)"
322    
323   sql "insert into packages_routines(pkg_id,  # # #
324   mincludes,  # # # install routines & includes
325   postinstall,  # # #
326   preinstall,  # # # needs special magic: the last line of typeset has no ';'
327   preremove,  # # # but to eval the function we must append it
328   postremove,  # # # so this sed deletes the last line of the typeset output
329   script)  # # # and replaces it with an ;} and a newline between
330   values('${pkgid}',  # # #
331   '${INHERITS}',  # # # but we will not add this fun when no postinstall etc are given
332   '${do_postinst}',  # # # -> [[ -n $(typeset -f postinstall ]] &&
333   '${do_pretinst}',  # # #
334   '${do_prerm}',  # # # also the character ' is a problem while importing to sql
335   '${do_postrm}',  # # # because we use ' as escape char. so we replace it with ''
336   '${script}')"  # # #
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    
352     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    
359    # # [[ -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     [[ -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    
371     [[ ${do_script} = 1 ]] && script="$(basename ${DBFILE} .sql).data/${PCATEGORIE}/${PNAME}-${PVER}-${PBUILD}/routines.sh"
372    
373     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    
388    # # # 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  # create it only if do_script=1  # create it only if do_script=1
449  if [[ ${do_script} = 1 ]]  if [[ ${do_script} = 1 ]]
450  then  then
451   # create a routines script   # create a routines script
452   local routines=$(dirname ${DBFILE})/${script}   local routines=$(dirname ${DBFILE})/${script}
453   install -d $(dirname ${routines})   install -d $(dirname ${routines})
454    
455     echo '#!/bin/sh' > ${routines}
456     echo "# routines.sh script for ${PCATEGORIE}/${PNAME}-${PVER}-${PBUILD}" >> ${routines}
457     echo >> ${routines}
458    
459    
460   echo "#!/bin/sh" > ${routines}   # special functions and variables
461   echo "# routines.sh script for #${pkgid}, ${PNAME}-${PVER}-${PBUILD}" >> ${routines}   if [[ -n ${SPECIAL_VARS} ]]
462   echo >> ${routines}   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   # special functions and variables   # postinstall and co
488   if [[ -n ${SPECIAL_VARS} ]]   for i in preinstall postinstall preremove postremove
489     do
490     if [[ -n $(typeset -f "${i}") ]]
491   then   then
492   local i   typeset -f "${i}" >> ${routines}
493   for i in ${SPECIAL_VARS}   echo >> ${routines}
494   do   else
495   # being tricky here :)   echo "${i} () { return 0; }" >> ${routines}
  echo "${i}=\"$(eval echo \$${i})\"" >> ${routines}  
  done  
  echo  >> ${routines}  
496   fi   fi
497     done
498    
499     # 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   # add special functions   # "upsert"
554   if [[ -n ${SPECIAL_FUNCTIONS} ]]   if [[ -z $(sql "select pcat from categories where pcat='${pcat}'") ]]
555   then   then
556   local i   sql "insert into categories (pcat) values('${pcat}')"
  for i in ${SPECIAL_FUNCTIONS}  
  do  
  # add to mage (quotes needed !)  
  typeset -f "${i}" >> ${routines}  
  echo >> ${routines}  
  # unset to be safe (quotes needed !)  
  unset "${i}"  
  done  
  echo  >> ${routines}  
557   fi   fi
558     done
559    }
560    
561   # postinstall and co  convert_smage_db()
562   for i in preinstall postinstall preremove postremove  {
563   do   local smagefile
  if [[ -n $(typeset -f "${i}") ]]  
  then  
  typeset -f "${i}" >> ${routines}  
  echo >> ${routines}  
  fi  
  done  
564    
565   # create start logic   local PCATEGORIE
566   echo >> ${routines}   local PNAME
567   echo 'case $1 in' >> ${routines}   local PVER
568   echo ' preinstall) preinstall ;;' >> ${routines}   local PBUILD
569   echo ' postinstall) postinstall ;;' >> ${routines}   local STATE
570   echo ' preremove) preremove ;;' >> ${routines}   local PKGNAME
571   echo ' postremove) postremove ;;' >> ${routines}   local DESCRIPTION
572   echo 'esac' >> ${routines}   local HOMEPAGE
573   echo >> ${routines}   local DEPEND
574  fi   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    
583     # create categories - global
584     categories2sqlite "${SMAGESCRIPTSDIR}/.known_categories"
585    
586     # 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   unset PCATEGORIE   unset PCATEGORIE
622   unset PNAME   unset PNAME
# Line 336  fi Line 633  fi
633   unset SPECIAL_VARS   unset SPECIAL_VARS
634   unset SPECIAL_FUNCTIONS   unset SPECIAL_FUNCTIONS
635   unset INHERITS   unset INHERITS
636     unset SPLIT_PACKAGES
637    
638   # unset these functions   # unset these functions
639   unset -f preinstall   unset -f preinstall
# Line 384  convert_install_db() Line 682  convert_install_db()
682   local pkginfoid   local pkginfoid
683   local entrydir   local entrydir
684    
685     # first of all add virtual categorie
686     sql "insert into categories(pcat) values('virtual')"
687    
688   # create categories   # create categories
689   for i in virtual ${INSTALLDB}/*   for i in virtual ${INSTALLDB}/*
690   do   do
# Line 392  convert_install_db() Line 693  convert_install_db()
693   include|profiles) continue;;   include|profiles) continue;;
694   esac   esac
695    
696   sql "insert into categories (pcat) values('${pcat}')"   # "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   done   done
702    
703   # create packages   # create packages
# Line 406  convert_install_db() Line 711  convert_install_db()
711   pname="$(magename2pname ${magefile})"   pname="$(magename2pname ${magefile})"
712   pver="$(magename2pver ${magefile})"   pver="$(magename2pver ${magefile})"
713   pbuild="$(magename2pbuild ${magefile})"   pbuild="$(magename2pbuild ${magefile})"
  # substitute r from pbuild  
  pbuild="${pbuild/r/}"  
714    
715   source ${magefile}   source ${magefile}
716    
# Line 498  EOF Line 801  EOF
801   '$(typeset -f preremove | sed s:\':\'\':g)',   '$(typeset -f preremove | sed s:\':\'\':g)',
802   '$(typeset -f postremove | sed s:\':\'\':g)')"   '$(typeset -f postremove | sed s:\':\'\':g)')"
803    
804   ####           ####  # # ####           ####
805   # record contents #  # # # record contents #
806   ####           ####  # # ####           ####
807   pkginfoid=$(sql "select id from packages_info where pkg_id='${pkgid}' and arch='${ARCH}'")  # # pkginfoid=$(sql "select id from packages_info where pkg_id='${pkgid}' and arch='${ARCH}'")
808   entrydir="$(dirname ${magefile})"  # # entrydir="$(dirname ${magefile})"
809   sql "insert into packages_content(pkginfo_id,  # # sql "insert into packages_content(pkginfo_id,
810   char,  # # char,
811   dirs,  # # dirs,
812   files,  # # files,
813   pipes,  # # pipes,
814   symlinks)  # # symlinks)
815   values('${pkginfoid}',  # # values('${pkginfoid}',
816   '$(basename ${DBFILE} .sql).records/${pkginfoid}/char.bz2',  # # '$(basename ${DBFILE} .sql).records/${pkginfoid}/char.bz2',
817   '$(basename ${DBFILE} .sql).records/${pkginfoid}/dirs.bz2',  # # '$(basename ${DBFILE} .sql).records/${pkginfoid}/dirs.bz2',
818   '$(basename ${DBFILE} .sql).records/${pkginfoid}/files.bz2',  # # '$(basename ${DBFILE} .sql).records/${pkginfoid}/files.bz2',
819   '$(basename ${DBFILE} .sql).records/${pkginfoid}/pipes.bz2',  # # '$(basename ${DBFILE} .sql).records/${pkginfoid}/pipes.bz2',
820   '$(basename ${DBFILE} .sql).records/${pkginfoid}/symlinks.bz2')"  # # '$(basename ${DBFILE} .sql).records/${pkginfoid}/symlinks.bz2')"
821   # create compressed content files  # # # create compressed content files
822   local entryfile  # # local entryfile
823   for entryfile in char dirs files pipes symlinks  # # for entryfile in char dirs files pipes symlinks
824   do  # # do
825   install -d $(dirname ${DBFILE})/$(basename ${DBFILE} .sql).records/${pkginfoid}  # # install -d $(dirname ${DBFILE})/$(basename ${DBFILE} .sql).records/${pkginfoid}
826   cat ${entrydir}/.${entryfile} | bzip2 -9 >> $(dirname ${DBFILE})/$(basename ${DBFILE} .sql).records/${pkginfoid}/${entryfile}.bz2  # # cat ${entrydir}/.${entryfile} | bzip2 -9 >> $(dirname ${DBFILE})/$(basename ${DBFILE} .sql).records/${pkginfoid}/${entryfile}.bz2
827   done  # # done
828    
829   unset PKGNAME   unset PKGNAME
830   unset DEPEND   unset DEPEND
# Line 562  convert_virtual_defaults() Line 865  convert_virtual_defaults()
865    
866  METHOD="$1"  METHOD="$1"
867  DBFILE="$2"  DBFILE="$2"
868    REPO="$3"
869    
870  [[ -z ${METHOD} ]] && die "No method given. Use --install, --packages or --virtual for your appropiate task"  [[ -z ${METHOD} ]] && die "No method given. Use --install, --packages or --virtual for your appropiate task"
871  [[ -z ${DBFILE} ]] && die "No database given."  [[ -z ${DBFILE} ]] && die "No database given."
872    [[ -z ${REPO} ]] && die "No repository given."
873    
874  case $1 in  case $1 in
875   --install|-i)   --install|-i)
# Line 572  case $1 in Line 877  case $1 in
877   convert_install_db   convert_install_db
878   ;;   ;;
879   --packages|-p)   --packages|-p)
880     convert_virtual_defaults
881   create_database_layout   create_database_layout
882   convert_smage_db   convert_smage_db
883   ;;   ;;
884   --virtuals|-v)  # --virtuals|-v)
885   convert_virtual_defaults  # convert_virtual_defaults
886   ;;  # ;;
887   *) die "Unkown method." ;;   *) die "Unkown method." ;;
888  esac  esac

Legend:
Removed from v.1112  
changed lines
  Added in v.1118