Magellan Linux

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

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

revision 1115 by niro, Sat Jul 17 10:48:23 2010 UTC revision 1121 by niro, Thu Jul 22 07:47:49 2010 UTC
# Line 43  dep2pver() Line 43  dep2pver()
43   fi   fi
44  }  }
45    
46    # returns pname from fullname
47    # fullname2pver [fullname] -> PCAT/PNAME-PVER-PBUILD
48    fullname2pname()
49    {
50     local i pname
51    
52     i="${1#*/}"
53     pname="${i%-*-*}"
54     echo "${pname}"
55    }
56    
57    # returns pver from fullname
58    # fullname2pver [fullname] -> PCAT/PNAME-PVER-PBUILD
59    fullname2pver()
60    {
61     local i pver
62    
63     i="${1#*/}"
64     i="${i/$(fullname2pname $1)-/}"
65     pver="${i%-*}"
66     echo "${pver}"
67    }
68    
69    # returns pbuild from fullname
70    # fullname2pbuild [fullname] -> PCAT/PNAME-PVER-PBUILD
71    fullname2pbuild()
72    {
73     local i pbuild
74    
75     i="$1"
76     pbuild="${i##*-}"
77     echo "${pbuild}"
78    }
79    
80    # returns pcat from magename
81    # fullname2pcat [fullname] -> PCAT/PNAME-PVER-PBUILD
82    fullname2pcat()
83    {
84     local i pcat
85    
86     i="${1%/*}"
87     # get basename
88     pcat="${i##*/}"
89     echo "${pcat}"
90    }
91    
92    
93  ## atoi string  ## atoi string
94  atoi()  atoi()
95  {  {
# Line 157  is_higher() Line 204  is_higher()
204   # now compare the to arrays   # now compare the to arrays
205   for ((i=0; i < ${maxarrlen}; i++))   for ((i=0; i < ${maxarrlen}; i++))
206   do   do
207   if [[ ${fpver1[${i}]} -ne ${fpver2[${i}]} ]]   #if [[ ${fpver1[${i}]} -ne ${fpver2[${i}]} ]]
208     if [[ ${fpver1[${i}]} != ${fpver2[${i}]} ]]
209   then   then
210   if [[ ${fpver1[${i}]} -gt ${fpver2[${i}]} ]]   #if [[ ${fpver1[${i}]} -gt ${fpver2[${i}]} ]]
211     if [[ ${fpver1[${i}]} > ${fpver2[${i}]} ]]
212   then   then
213   echo "${pver1}"   echo "${pver1}"
214   return   return
# Line 199  highest_pkg() Line 248  highest_pkg()
248  all_depends()  all_depends()
249  {  {
250   local pname="$1"   local pname="$1"
251   local state="$2"   local pver="$2"
252   local highest   local pbuild="$3"
  local retval  
  local pver  
  local pbuild  
  local i  
   
  highest=$(highest_pkg "${pname}" "${state}")  
  pver="${highest%|*}"  
  pbuild="${highest##*|}"  
253    
254   sql "select categories.pcat,   sql "select categories.pcat,
255   depends.pname,   depends.pname,
# Line 227  all_depends() Line 268  all_depends()
268  all_sdepends()  all_sdepends()
269  {  {
270   local pname="$1"   local pname="$1"
271   local state="$2"   local pver="$2"
272   local highest   local pbuild="$3"
  local retval  
  local pver  
  local pbuild  
  local i  
   
  highest=$(highest_pkg "${pname}" "${state}")  
  pver="${highest%|*}"  
  pbuild="${highest##*|}"  
273    
274   sql "select categories.pcat,   sql "select categories.pcat,
275   sdepends.pname,   sdepends.pname,
# Line 263  default_virtualname_to_pkgname() Line 296  default_virtualname_to_pkgname()
296  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
297  fetch_packages()  fetch_packages()
298  {  {
299   local list="$@"   local list=( $@ )
300   local pkg   local pkg
301   local mirr   local mirr
302   local magefile   local item
303   local md5file   local md5file
304   local opt   local opt
305   local count_current   local count_current
# Line 275  fetch_packages() Line 308  fetch_packages()
308   local pver   local pver
309   local pbuild   local pbuild
310    
311   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [[ -z ${MIRRORS} ]] && die "You have no mirrors defined. Please edit your ${MAGERC}."
312    
313   # get count of total packages   # get count of total packages
314   declare -i count_current=0   declare -i count_current=0
315   declare -i count_total=0   declare -i count_total=0
316    
317   for i in ${list}; do (( count_total++ )); done   count_total="${#list[*]}"
318    
319   for magefile in ${list}   for item in ${list[*]}
320   do   do
321   #pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pname="$(fullname2pname ${item})"
322     pver="$(fullname2pver ${item})"
323   pname="$(magename2pname ${magefile})"   pbuild="$(fullname2pbuild ${item})"
  pver="$(magename2pver ${magefile})"  
  pbuild="$(magename2pbuild ${magefile})"  
324   pkg="${pname}-${pver}-${ARCH}-${pbuild}.${PKGSUFFIX}"   pkg="${pname}-${pver}-${ARCH}-${pbuild}.${PKGSUFFIX}"
325    
326   pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild}'")   pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild}'")
# Line 352  fetch_packages() Line 383  fetch_packages()
383   if [ ${count_total} -gt 1 ]; then echo; fi   if [ ${count_total} -gt 1 ]; then echo; fi
384  }  }
385    
386    md5sum_packages()
387    {
388     local list=( $@ )
389     local item
390     local pcat
391     local pname
392     local pkgname
393     local pkgfile
394     local pkgtype
395     local count_current
396     local count_total
397     local pver
398     local pbuild
399    
400     # get count of total packages
401     declare -i count_current=0
402     declare -i count_total=0
403    
404     count_total="${#list[*]}"
405    
406     for item in ${list[*]}
407     do
408     pcat=${item%%/*}
409     pname=$(fullname2pname ${item})
410     pver=$(fullname2pver ${item})
411     pbuild=$(fullname2pbuild ${item})
412    
413     pkgname="${pname}-${pver}-${ARCH}-${pbuild}"
414     pkgfile="${pkgname}.${PKGSUFFIX}"
415     pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild}'")
416     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}' and arch='${ARCH}'")
417    
418     (( count_current++ ))
419     xtitle "[ (${count_current}/${count_total}) MD5SUM: ${pkgfile} ]"
420    
421     # abort on virtual pkg
422     if [[ ${pkgtype} = virtual ]]
423     then
424     echo -ne " ${COLBLUE}---${COLDEFAULT}"
425     echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "
426     continue
427     fi
428    
429     # abort on sources pkg
430     if [[ ${pkgtype} = sources ]]
431     then
432     echo -ne " ${COLBLUE}---${COLDEFAULT}"
433     echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "
434     continue
435     fi
436    
437     if [[ ! -z ${md5} ]]
438     then
439     echo -ne "${COLBLUE} *** ${COLDEFAULT}"
440     echo -ne "checking md5sum (${count_current}/${count_total}): "
441     ( cd ${PKGDIR}; md5sum --check << EOF ;)|| die "md5 for ${pkgfile} failed"
442    ${md5}  ${pkgfile}
443    EOF
444     else
445     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
446     echo -e "!! no md5sum file found for ${pkgfile} :("
447     fi
448     done
449    
450     # add a crlf for a better view
451     if [ ${count_total} -gt 1 ]; then echo; fi
452    }
453    
454    unpack_packages()
455    {
456     local list=( $@ )
457     local item
458     local pkg
459     local pkgtype
460     local count_current
461     local count_total
462    
463     # get count of total packages
464     declare -i count_current=0
465     declare -i count_total=0
466    
467     count_total="${#list[*]}"
468    
469     for item in ${list[*]}
470     do
471     pname=$(fullname2pname ${item})
472     pver=$(fullname2pver ${item})
473     pbuild=$(fullname2pbuild ${item})
474     pkg="${pname}-${pver}-${ARCH}-${pbuild}.${PKGSUFFIX}"
475     pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild}'")
476    
477     (( count_current++ ))
478     xtitle "[ (${count_current}/${count_total}) Unpacking ${pkg} ]"
479    
480     # abort on virtual pkg
481     if [[ ${pkgtype} = virtual ]]
482     then
483     echo -ne " ${COLBLUE}---${COLDEFAULT}"
484     echo " !unpack virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "
485     continue
486     fi
487    
488     # abort on sources pkg
489     if [[ ${pkgtype} = sources ]]
490     then
491     echo -ne " ${COLBLUE}---${COLDEFAULT}"
492     echo " !unpack sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "
493     continue
494     fi
495    
496     echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "
497     tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"
498     done
499    
500     # add a crlf for a better view
501     if [ ${count_total} -gt 1 ]; then echo; fi
502    }
503    
504  mage_install()  mage_install()
505  {  {
506   # local all possible vars of a mage file   # local all possible vars of a mage file
# Line 438  mage_install() Line 587  mage_install()
587   if [[ ${src_install} = true ]]   if [[ ${src_install} = true ]]
588   then   then
589   local smage2file   local smage2file
590     local repository
591   # check needed global vars   # check needed global vars
592   [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not set."   [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not set."
593   [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not set."   [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not set."
# Line 450  mage_install() Line 600  mage_install()
600   echo V:${pver}   echo V:${pver}
601   echo B:${pbuild}   echo B:${pbuild}
602   fi   fi
603     repository=$(sql "select repositories.name from repositories
604   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   inner join packages
605     on packages.repo_id=repositories.id
606     where packages.pname='${pname}'
607     and packages.pver='${pver}'
608     and packages.pbuild='${pbuild}';")
609     smage2file=${SMAGESCRIPTSDIR}/${repository}/${pname}/${pname}-${pver}-${pbuild}.smage2
610   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
611   then   then
612   echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "   echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
# Line 532  mage_install() Line 687  mage_install()
687   unset -f postremove   unset -f postremove
688  }  }
689    
 md5sum_packages()  
 {  
  local list="$@"  
  local magefile  
  local pcat  
  local pname  
  local pkgname  
  local pkgfile  
  local pkgtype  
  local count_current  
  local count_total  
  local pver  
  local pbuild  
   
  # get count of total packages  
  declare -i count_current=0  
  declare -i count_total=0  
   
  for i in ${list}; do (( count_total++ )); done  
   
  for magefile in ${list}  
  do  
  pcat=${magefile%%/*}  
  pname=$(magename2pname ${magefile})  
  pver=$(magename2pver ${magefile})  
  pbuild=$(magename2pbuild ${magefile})  
   
  pkgname="${pname}-${pver}-${ARCH}-${pbuild}"  
  #md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"  
  pkgfile="${pkgname}.${PKGSUFFIX}"  
  pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild}'")  
  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}' and arch='${ARCH}'")  
  #echo "DEBUG: ${md5}"  
   
  (( count_current++ ))  
  xtitle "[ (${count_current}/${count_total}) MD5SUM: ${pkgfile} ]"  
   
  # abort on virtual pkg  
  if [[ ${pkgtype} = virtual ]]  
  then  
  echo -ne " ${COLBLUE}---${COLDEFAULT}"  
  echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "  
  continue  
  fi  
   
  # abort on sources pkg  
  if [[ ${pkgtype} = sources ]]  
  then  
  echo -ne " ${COLBLUE}---${COLDEFAULT}"  
  echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "  
  continue  
  fi  
   
 # if [ -f "${md5file}" ]  
 # then  
  echo -ne "${COLBLUE} *** ${COLDEFAULT}"  
  echo -ne "checking md5sum (${count_current}/${count_total}): "  
  #( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"  
  ( cd ${PKGDIR}; md5sum --check << EOF ;)|| die "md5 for ${pkgfile} failed"  
 ${md5}  ${pkgfile}  
 EOF  
   
 # else  
 # echo -ne "${COLBLUE} --- ${COLDEFAULT}"  
 # echo -e "!! no md5sum file found for ${pkgfile} :("  
 # fi  
  done  
   
  # add a crlf for a better view  
  if [ ${count_total} -gt 1 ]; then echo; fi  
 }  
   
 unpack_packages()  
 {  
  local list="$@"  
  local magefile  
  local pkg  
  local pkgtype  
  local count_current  
  local count_total  
   
  # get count of total packages  
  declare -i count_current=0  
  declare -i count_total=0  
   
  for i in ${list}; do (( count_total++ )); done  
   
  for magefile in ${list}  
  do  
  #pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"  
  #pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"  
   
  pname=$(magename2pname ${magefile})  
  pver=$(magename2pver ${magefile})  
  pbuild=$(magename2pbuild ${magefile})  
  pkg="${pname}-${pver}-${ARCH}-${pbuild}.${PKGSUFFIX}"  
  pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild}'")  
   
  (( count_current++ ))  
  xtitle "[ (${count_current}/${count_total}) Unpacking ${pkg} ]"  
   
  # abort on virtual pkg  
  if [[ ${pkgtype} = virtual ]]  
  then  
  echo -ne " ${COLBLUE}---${COLDEFAULT}"  
  echo " !unpack virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "  
  continue  
  fi  
   
  # abort on sources pkg  
  if [[ ${pkgtype} = sources ]]  
  then  
  echo -ne " ${COLBLUE}---${COLDEFAULT}"  
  echo " !unpack sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "  
  continue  
  fi  
   
  echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "  
  tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"  
  done  
   
  # add a crlf for a better view  
  if [ ${count_total} -gt 1 ]; then echo; fi  
 }  
   
690  install_packages()  install_packages()
691  {  {
692   local list="$@"   local list="$@"

Legend:
Removed from v.1115  
changed lines
  Added in v.1121