--- branches/mage-sql/usr/lib/mage/sql_functions.sh 2010/07/17 10:48:23 1115 +++ branches/mage-sql/usr/lib/mage/sql_functions.sh 2010/07/22 07:47:49 1121 @@ -43,6 +43,53 @@ fi } +# returns pname from fullname +# fullname2pver [fullname] -> PCAT/PNAME-PVER-PBUILD +fullname2pname() +{ + local i pname + + i="${1#*/}" + pname="${i%-*-*}" + echo "${pname}" +} + +# returns pver from fullname +# fullname2pver [fullname] -> PCAT/PNAME-PVER-PBUILD +fullname2pver() +{ + local i pver + + i="${1#*/}" + i="${i/$(fullname2pname $1)-/}" + pver="${i%-*}" + echo "${pver}" +} + +# returns pbuild from fullname +# fullname2pbuild [fullname] -> PCAT/PNAME-PVER-PBUILD +fullname2pbuild() +{ + local i pbuild + + i="$1" + pbuild="${i##*-}" + echo "${pbuild}" +} + +# returns pcat from magename +# fullname2pcat [fullname] -> PCAT/PNAME-PVER-PBUILD +fullname2pcat() +{ + local i pcat + + i="${1%/*}" + # get basename + pcat="${i##*/}" + echo "${pcat}" +} + + ## atoi string atoi() { @@ -157,9 +204,11 @@ # now compare the to arrays for ((i=0; i < ${maxarrlen}; i++)) do - if [[ ${fpver1[${i}]} -ne ${fpver2[${i}]} ]] + #if [[ ${fpver1[${i}]} -ne ${fpver2[${i}]} ]] + if [[ ${fpver1[${i}]} != ${fpver2[${i}]} ]] then - if [[ ${fpver1[${i}]} -gt ${fpver2[${i}]} ]] + #if [[ ${fpver1[${i}]} -gt ${fpver2[${i}]} ]] + if [[ ${fpver1[${i}]} > ${fpver2[${i}]} ]] then echo "${pver1}" return @@ -199,16 +248,8 @@ all_depends() { local pname="$1" - local state="$2" - local highest - local retval - local pver - local pbuild - local i - - highest=$(highest_pkg "${pname}" "${state}") - pver="${highest%|*}" - pbuild="${highest##*|}" + local pver="$2" + local pbuild="$3" sql "select categories.pcat, depends.pname, @@ -227,16 +268,8 @@ all_sdepends() { local pname="$1" - local state="$2" - local highest - local retval - local pver - local pbuild - local i - - highest=$(highest_pkg "${pname}" "${state}") - pver="${highest%|*}" - pbuild="${highest##*|}" + local pver="$2" + local pbuild="$3" sql "select categories.pcat, sdepends.pname, @@ -263,10 +296,10 @@ # fetch_packages /path/to/mage/file1 /path/to/mage/file2 fetch_packages() { - local list="$@" + local list=( $@ ) local pkg local mirr - local magefile + local item local md5file local opt local count_current @@ -275,21 +308,19 @@ local pver local pbuild - [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}." + [[ -z ${MIRRORS} ]] && die "You have no mirrors defined. Please edit your ${MAGERC}." # get count of total packages declare -i count_current=0 declare -i count_total=0 - for i in ${list}; do (( count_total++ )); done + count_total="${#list[*]}" - for magefile in ${list} + for item in ${list[*]} do - #pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" - - pname="$(magename2pname ${magefile})" - pver="$(magename2pver ${magefile})" - pbuild="$(magename2pbuild ${magefile})" + pname="$(fullname2pname ${item})" + pver="$(fullname2pver ${item})" + pbuild="$(fullname2pbuild ${item})" pkg="${pname}-${pver}-${ARCH}-${pbuild}.${PKGSUFFIX}" pkgtype=$(sql "select pkgtype from packages where pname='${pname}' and pver='${pver}' and pbuild='${pbuild}'") @@ -352,6 +383,124 @@ if [ ${count_total} -gt 1 ]; then echo; fi } +md5sum_packages() +{ + local list=( $@ ) + local item + 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 + + count_total="${#list[*]}" + + for item in ${list[*]} + do + pcat=${item%%/*} + pname=$(fullname2pname ${item}) + pver=$(fullname2pver ${item}) + pbuild=$(fullname2pbuild ${item}) + + pkgname="${pname}-${pver}-${ARCH}-${pbuild}" + 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}'") + + (( 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 [[ ! -z ${md5} ]] + then + echo -ne "${COLBLUE} *** ${COLDEFAULT}" + echo -ne "checking md5sum (${count_current}/${count_total}): " + ( 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 item + 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 + + count_total="${#list[*]}" + + for item in ${list[*]} + do + pname=$(fullname2pname ${item}) + pver=$(fullname2pver ${item}) + pbuild=$(fullname2pbuild ${item}) + 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 +} + mage_install() { # local all possible vars of a mage file @@ -438,6 +587,7 @@ if [[ ${src_install} = true ]] then local smage2file + local repository # check needed global vars [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not set." [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not set." @@ -450,8 +600,13 @@ echo V:${pver} echo B:${pbuild} fi - - smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2 + repository=$(sql "select repositories.name from repositories + inner join packages + on packages.repo_id=repositories.id + where packages.pname='${pname}' + and packages.pver='${pver}' + and packages.pbuild='${pbuild}';") + smage2file=${SMAGESCRIPTSDIR}/${repository}/${pname}/${pname}-${pver}-${pbuild}.smage2 if [ -f "${smage2file}" ] then echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... " @@ -532,131 +687,6 @@ unset -f postremove } -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 -} - install_packages() { local list="$@"