--- trunk/mage/usr/lib/mage/mage4.functions.sh 2012/03/12 23:21:52 1781 +++ branches/mage-next/src/mage4.functions.sh 2014/01/29 12:12:22 2560 @@ -1,6 +1,6 @@ #!/bin/bash # Magellan Linux Installer Functions (mage.functions.sh) -# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.38 2008-10-05 10:32:24 niro Exp $ +# $Id$ COLRED="\033[1;6m\033[31m" COLGREEN="\033[1;6m\033[32m" @@ -46,6 +46,8 @@ local method local cmd local retval + local sum + local dest # very basic getops for i in $* @@ -72,9 +74,24 @@ if [[ -d ${rundir} ]] then pushd ${rundir} &> /dev/null - # be verbose here - ${cmd} -c ${file} #&> /dev/null - retval="$?" + + # all file must be non-zero + retval=0 + while read sum dest + do + if [ ! -s ${dest} ] + then + echo "${dest}: file is empty ;(" + retval=127 + fi + done < ${file} + if [[ ${retval} != 127 ]] + then + # be verbose here + ${cmd} -c ${file} #&> /dev/null + retval="$?" + fi + popd &> /dev/null else retval=1 @@ -102,12 +119,52 @@ return ${retval} } +unpack_package() +{ + local magefile="$1" + local pkgname + local pkgfile + local pkgtype + local tar_opts + + pkgname="$(get_value_from_magefile PKGNAME ${magefile})" + pkgfile="${pkgname}.${PKGSUFFIX}" + pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" + + xtitle "[ Unpacking ${pkg} ]" + + # abort on virtual pkg + if [[ ${pkgtype} = virtual ]] + then + echo -ne " ${COLBLUE}---${COLDEFAULT}" + echo " !unpack virtual ${pkgname} ... " + continue + fi + + # abort on sources pkg + if [[ ${pkgtype} = sources ]] + then + echo -ne " ${COLBLUE}---${COLDEFAULT}" + echo " !unpack sources ${pkgname} ... " + continue + fi + + # busybox? + if need_busybox_support tar + then + tar_opts="xjf" + else + tar_opts="xjmf" + fi + + echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkgfile} ... " + tar ${tar_opts} ${PKGDIR}/${pkgfile} -C ${BUILDDIR} || die "Unpacking package ${pkgfile}" +} + unpack_packages() { local list="$@" local magefile - local pkg - local pkgtype local count_current local count_total local tar_opts @@ -120,38 +177,8 @@ for magefile in ${list} do - pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" - pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" - + unpack_package "${magefile}" (( 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 - - # busybox? - if need_busybox_support tar - then - tar_opts="xjf" - else - tar_opts="xjmf" - fi - - echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... " - tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}" done # add a crlf for a better view @@ -1376,7 +1403,7 @@ output+="${mirror}${addon}/${uri/${scheme}/}" done else - output="${uri}" + output="${uri}" fi echo "${output}" @@ -1443,7 +1470,10 @@ { local i local list="$@" - local pkg + local pkgname + local pkgfile + local pcat + local pname local mirr local magefile local md5file @@ -1451,6 +1481,7 @@ local count_current local count_total local wget_opts + local fetching [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}." @@ -1465,17 +1496,22 @@ for magefile in ${list} do - pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" + pkgname="$(get_value_from_magefile PKGNAME ${magefile})" + pkgfile="${pkgname}.${PKGSUFFIX}" pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" + pcat=$(magename2pcat ${magefile}) + pname=$(magename2pname ${magefile}) + md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" + (( count_current++ )) - xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]" + xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]" # abort on virtual pkg if [[ ${pkgtype} = virtual ]] then echo -ne " ${COLBLUE}---${COLDEFAULT}" - echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " + echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... " continue fi @@ -1483,24 +1519,39 @@ if [[ ${pkgtype} = sources ]] then echo -ne " ${COLBLUE}---${COLDEFAULT}" - echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " + echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... " continue fi - # abort if already exist - if [ -f ${PKGDIR}/${pkg} ] + # check if FETCHING is required + if [ ! -f "${md5file}" ] + then + fetching=true + else + if mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 &> /dev/null + then + # md5's ok, no fetching required + fetching=false + else + fetching=true + fi + fi + + if [[ ${fetching} = false ]] then echo -ne " ${COLBLUE}***${COLDEFAULT}" - echo " fetch complete (${count_current}/${count_total}): ${pkg} ... " + echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... " continue + else + echo -ne " ${COLBLUE}***${COLDEFAULT}" + echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... " + mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}" fi - echo -ne " ${COLBLUE}***${COLDEFAULT}" - echo -e " fetching (${count_current}/${count_total}): ${pkg} ... " - mdownload --uri "package://${pkg}" --dir "${PKGDIR}" || die "Could not download ${pkg}" - if [ ! -f ${PKGDIR}/${pkg} ] + # sanity check, not really needed but to be sure + if [ ! -f ${PKGDIR}/${pkgfile} ] then - die "Package '${pkg}' after download not found in '${PKGDIR}'" + die "Package '${pkgfile}' after download not found in '${PKGDIR}'" fi done @@ -1605,7 +1656,7 @@ then if ! mcheckemptydir ${MAGEDIR} then - find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xarg --no-run-if-empty rm -r + find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r fi else rm -rf ${MAGEDIR} @@ -1763,7 +1814,7 @@ then HIGHEST_MAGEFILE=${magefile} #for debug only - mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" + mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2 fi done @@ -1887,8 +1938,9 @@ count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')" done - # dirty hack to convert 0001 -> 1; 0120 -> 120 etc - x="${#count}" + # convert 0001 -> 1; 0120 -> 120 etc + # use bash internal base functions to this task + x="$((10#${count}))" for (( i=0; i