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 1113 by niro, Wed Jul 14 17:38:51 2010 UTC revision 1114 by niro, Sat Jul 17 10:45:30 2010 UTC
# Line 43  dep2pver() Line 43  dep2pver()
43   fi   fi
44  }  }
45    
   
   
   
   
46  ## atoi string  ## atoi string
47  atoi()  atoi()
48  {  {
# Line 88  atoi() Line 84  atoi()
84   y) value=".25.";;   y) value=".25.";;
85   z) value=".26.";;   z) value=".26.";;
86   _|-|\|) value=".0.";;   _|-|\|) value=".0.";;
  0*) value="${value/0/.0.}";;  
87   esac   esac
88    
89   # save new var   # save new var
# Line 121  max_len() Line 116  max_len()
116   fi   fi
117  }  }
118    
 # is_higher pver1 pver2  
119  is_higher()  is_higher()
120  {  {
121   local pver1="$1"   local pver1="$1"
# Line 135  is_higher() Line 129  is_higher()
129   local x   local x
130    
131   # build to arrays with fixed pvers   # build to arrays with fixed pvers
132   fpver1=$(atoi ${pver1} | sed "s:\.:\ :g")   fpver1=($(atoi ${pver1} | sed "s:\.:\ :g"))
133   fpver2=$(atoi ${pver2} | sed "s:\.:\ :g")   fpver2=($(atoi ${pver2} | sed "s:\.:\ :g"))
134    
135   maxarrlen=$(max_len "${fpver1}" "${fpver2}")   maxarrlen=$(max_len "${fpver1[*]}" "${fpver2[*]}")
136    
  # fill array with values  
  declare -i x=0  
  for i in ${fpver1}  
  do  
  arr1[${x}]="${i}"  
  ((x++))  
  done  
137   # now fill the rest with ZEROS   # now fill the rest with ZEROS
138     x=${#fpver1[*]}
139   if [[ ${x} -lt ${maxarrlen} ]]   if [[ ${x} -lt ${maxarrlen} ]]
140   then   then
141   for (( i=x; i<maxarrlen;i++))   for (( i=x; i<maxarrlen;i++))
142   do   do
143   arr1[${i}]="0"   fpver1[${i}]="0"
144   done   done
145   fi   fi
146    
  # fill array with values  
  declare -i x=0  
  for i in ${fpver2}  
  do  
  arr2[${x}]="${i}"  
  ((x++))  
  done  
147   # now fill the rest with ZEROS   # now fill the rest with ZEROS
148     x=${#fpver2[*]}
149   if [[ ${x} -lt ${maxarrlen} ]]   if [[ ${x} -lt ${maxarrlen} ]]
150   then   then
151   for (( i=x; i<maxarrlen;i++))   for (( i=x; i<maxarrlen;i++))
152   do   do
153   arr2[${i}]="0"   fpver2[${i}]="0"
154   done   done
155   fi   fi
156    
157   # now compare the to arrays   # now compare the to arrays
158   for ((i=0; i < ${maxarrlen}; i++))   for ((i=0; i < ${maxarrlen}; i++))
159   do   do
160   if [[ ${arr1[${i}]} -ne ${arr2[${i}]} ]]   if [[ ${fpver1[${i}]} -ne ${fpver2[${i}]} ]]
161   then   then
162   if [[ ${arr1[${i}]} -gt ${arr2[${i}]} ]]   if [[ ${fpver1[${i}]} -gt ${fpver2[${i}]} ]]
163   then   then
164   echo "${pver1}"   echo "${pver1}"
165   return   return
# Line 192  is_higher() Line 174  is_higher()
174   echo "${pver1}"   echo "${pver1}"
175  }  }
176    
177  highest_pkg2()  highest_pkg()
178  {  {
179   local pname="$1"   local pname="$1"
180   local state="$2"   local state="$2"
181     local retval
182    
183   case ${state} in   case ${state} in
184   stable) search="state='stable'" ;;   stable) search="state='stable'" ;;
# Line 213  highest_pkg2() Line 196  highest_pkg2()
196   echo "${max}"   echo "${max}"
197  }  }
198    
 highest_pkg() {  
  local pname="$1"  
  local state="$2"  
  local search  
  local retval  
   
  case ${state} in  
  stable) search="state='stable'" ;;  
  testing) search="state='stable' or state='testing'" ;;  
  unstable) search="state='stable' or state='testing' or state='unstable'" ;;  
  esac  
   
  #retval=$(sql "select pver,pbuild from packages where pname='${pname}' and (${search}) order by pver desc,pbuild desc limit 1")  
  #echo "${pname}-$(echo ${retval} | cut -d'|' -f1)-r$(echo ${retval} | cut -d'|' -f2)"  
   
  retval=$(sql "select pver,pbuild from packages where pname='${pname}' and (${search}) order by pver desc,pbuild desc limit 1")  
  echo "${retval}"  
 }  
   
199  all_depends()  all_depends()
200  {  {
201   local pname="$1"   local pname="$1"
# Line 242  all_depends() Line 206  all_depends()
206   local pbuild   local pbuild
207   local i   local i
208    
209   highest=$(highest_pkg2 "${pname}" "${state}")   highest=$(highest_pkg "${pname}" "${state}")
210   pver="${highest%|*}"   pver="${highest%|*}"
211   pbuild="${highest##*|}"   pbuild="${highest##*|}"
212    
# Line 270  all_sdepends() Line 234  all_sdepends()
234   local pbuild   local pbuild
235   local i   local i
236    
237   highest=$(highest_pkg2 "${pname}" "${state}")   highest=$(highest_pkg "${pname}" "${state}")
238   pver="${highest%|*}"   pver="${highest%|*}"
239   pbuild="${highest##*|}"   pbuild="${highest##*|}"
240    
# Line 288  all_sdepends() Line 252  all_sdepends()
252   on sdepends.pcat_id=categories.id"   on sdepends.pcat_id=categories.id"
253  }  }
254    
255    default_virtualname_to_pkgname()
256    {
257     local vcat="$1"
258     local vname="$2"
259    
260     sql "select pcat,pname from virtual_defaults where vcat='${vcat}' and vname='${vname}'"
261    }
262    
263  ALLDEPS=""  ALLDEPS=""
264  #ALREADY_PROCESSED=""  #ALREADY_PROCESSED=""
265  resolv_pkgs() {  resolv_pkgs()
266    {
267   local method="$1"   local method="$1"
268   local pname="$2"   local pname="$2"
269   local state="$3"   local state="$3"
# Line 303  resolv_pkgs() { Line 276  resolv_pkgs() {
276   local searchcmd   local searchcmd
277   local searchcmd2   local searchcmd2
278   local pkgid   local pkgid
279     #local ALL_DEPS
280    
281   case ${method} in   case ${method} in
282   --install)   --install)
# Line 317  resolv_pkgs() { Line 291  resolv_pkgs() {
291    
292   [[ -z ${pname} ]] && return 1   [[ -z ${pname} ]] && return 1
293    
294   while read line   echo
295     echo "processing pname=${pname}"
296     echo "before ALL_DEPS=${ALL_DEPS[*]}"
297     read
298    
299     ALL_DEPS+=($(${searchcmd}))
300     ALL_DEPS+=($(${searchcmd2}))
301    
302     echo "after ALL_DEPS=${ALL_DEPS[*]}"
303     read
304    
305     for line in ${ALL_DEPS[${i}]}
306   do   do
307    # for (( i=0; i<count; i++))
308    # do
309    # echo "i=${i}"
310    # read
311    
312     line="${ALL_DEPS[${i}]}"
313    # while read line
314    # do
315   [[ -z ${line} ]] && continue   [[ -z ${line} ]] && continue
316    
317   depcat="${line%%|*}"   depcat="${line%%|*}"
# Line 395  resolv_pkgs() { Line 388  resolv_pkgs() {
388   esac   esac
389   fi   fi
390    
391   highest=$(highest_pkg2 ${depname} ${state})   highest=$(highest_pkg ${depname} ${state})
392   depver="${highest%|*}"   depver="${highest%|*}"
393   depbuild="${highest##*|}"   depbuild="${highest##*|}"
394    
395   fullname="${depcat}/${depname}-${depver}-r${depbuild}"   fullname="${depcat}/${depname}-${depver}-${depbuild}"
396    
397     echo "DEBUG: depcat='${depcat}'"
398     echo "DEBUG: depname='${depname}'"
399     echo "DEBUG: fullname='${fullname}'"
400    
401   #### check ob DFILE schon installiert ist ####   #### check ob DFILE schon installiert ist ####
402   is_installed --pcat "${depcat}" --pname "${depname}" --pver "${depver}" --pbuild "${depbuild}" && continue   is_installed --pcat "${depcat}" --pname "${depname}" --pver "${depver}" --pbuild "${depbuild}" && continue
# Line 407  resolv_pkgs() { Line 404  resolv_pkgs() {
404   ## check ob schon in ALLDEPS enthalten dann mach weiter   ## check ob schon in ALLDEPS enthalten dann mach weiter
405   if [[ -z $(echo ${ALLDEPS} | fgrep "${fullname}") ]]   if [[ -z $(echo ${ALLDEPS} | fgrep "${fullname}") ]]
406   then   then
407     echo "DEBUG: next loop! -> ${depname}"
408   resolv_pkgs "${method}" "${depname}" "${state}"   resolv_pkgs "${method}" "${depname}" "${state}"
409   ALLDEPS="${ALLDEPS} ${fullname}"   ALLDEPS="${ALLDEPS} ${fullname}"
410   fi   fi
# Line 421  resolv_pkgs() { Line 419  resolv_pkgs() {
419   unset depbuild   unset depbuild
420   unset fullname   unset fullname
421   unset shighest   unset shighest
422   done << EOF  # done << EOF
423  $(${searchcmd})  #$(${searchcmd})
424  $(${searchcmd2})  #$(${searchcmd2})
425  EOF  #EOF
426    # done
427     done
428  }  }
429    
430  # start_depwanderer pname state  # start_depwanderer pname state
# Line 440  start_depwanderer() Line 440  start_depwanderer()
440   local x i   local x i
441    
442   # get some suitable pkg info   # get some suitable pkg info
443   highest=$(highest_pkg2 "${pname}" "${state}")   highest=$(highest_pkg "${pname}" "${state}")
444   pver="${highest%|*}"   pver="${highest%|*}"
445   pbuild="${highest##*|}"   pbuild="${highest##*|}"
446   pcat=$(sql "select categories.pcat   pcat=$(sql "select categories.pcat
# Line 454  start_depwanderer() Line 454  start_depwanderer()
454   # already installed ??   # already installed ??
455   if is_installed --pcat "${pcat}" --pname "${pname}" --pver "${pver}" --pbuild "${pbuild}"   if is_installed --pcat "${pcat}" --pname "${pname}" --pver "${pver}" --pbuild "${pbuild}"
456   then   then
457   echo "Package ${pcat}/${pname}-${pver}-r${pbuild} already installed."   echo "Package ${pcat}/${pname}-${pver}-${pbuild} already installed."
458   return 2   return 2
459   fi   fi
460    
# Line 468  start_depwanderer() Line 468  start_depwanderer()
468   done   done
469    
470   # add the package itself to the dependencies   # add the package itself to the dependencies
471   #echo "$((x++)): ${pcat}/${pname}-${pver}-r${pbuild}"   #echo "$((x++)): ${pcat}/${pname}-${pver}-${pbuild}"
472   echo "${pcat}/${pname}-${pver}-r${pbuild}"   echo "${pcat}/${pname}-${pver}-${pbuild}"
473  }  }
474    
475    
# Line 505  fetch_packages() Line 505  fetch_packages()
505   pbuild="$(magename2pbuild ${magefile})"   pbuild="$(magename2pbuild ${magefile})"
506   pkg="${pname}-${pver}-${ARCH}-${pbuild}.${PKGSUFFIX}"   pkg="${pname}-${pver}-${ARCH}-${pbuild}.${PKGSUFFIX}"
507    
508   pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild/r/}'")   pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild}'")
509    
510   (( count_current++ ))   (( count_current++ ))
511   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"
# Line 775  md5sum_packages() Line 775  md5sum_packages()
775   pkgname="${pname}-${pver}-${ARCH}-${pbuild}"   pkgname="${pname}-${pver}-${ARCH}-${pbuild}"
776   #md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   #md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
777   pkgfile="${pkgname}.${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
778   pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild/r/}'")   pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild}'")
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}'")   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}'")
780   #echo "DEBUG: ${md5}"   #echo "DEBUG: ${md5}"
781    
782   (( count_current++ ))   (( count_current++ ))
# Line 841  unpack_packages() Line 841  unpack_packages()
841   pver=$(magename2pver ${magefile})   pver=$(magename2pver ${magefile})
842   pbuild=$(magename2pbuild ${magefile})   pbuild=$(magename2pbuild ${magefile})
843   pkg="${pname}-${pver}-${ARCH}-${pbuild}.${PKGSUFFIX}"   pkg="${pname}-${pver}-${ARCH}-${pbuild}.${PKGSUFFIX}"
844   pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild/r/}'")   pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild}'")
845    
846   (( count_current++ ))   (( count_current++ ))
847   xtitle "[ (${count_current}/${count_total}) Unpacking ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Unpacking ${pkg} ]"
# Line 1167  install_database_entry() Line 1167  install_database_entry()
1167   [[ -z ${INSTALLDB} ]] && die "install_database_entry() \$INSTALLDB not set."   [[ -z ${INSTALLDB} ]] && die "install_database_entry() \$INSTALLDB not set."
1168    
1169   # first of all convert pbuild to database format (remove the r)   # first of all convert pbuild to database format (remove the r)
1170   pbuild="${pbuild/r/}"   pbuild="${pbuild}"
1171    
1172   # check if   # check if
1173   # copy all things over over   # copy all things over over
# Line 1285  install_database_entry() Line 1285  install_database_entry()
1285   'records/${pkg_info_id}/pipes.bz2',   'records/${pkg_info_id}/pipes.bz2',
1286   'records/${pkg_info_id}/symlinks.bz2')"   'records/${pkg_info_id}/symlinks.bz2')"
1287   # create compressed content files   # create compressed content files
1288   entrydir=${BUILDDIR}/${pname}-${pver}-${ARCH}-r${pbuild}   entrydir=${BUILDDIR}/${pname}-${pver}-${ARCH}-${pbuild}
1289   local entryfile   local entryfile
1290   for entryfile in char dirs files pipes symlinks   for entryfile in char dirs files pipes symlinks
1291   do   do

Legend:
Removed from v.1113  
changed lines
  Added in v.1114