--- trunk/mage/usr/lib/mage/mage4.functions.sh 2012/01/13 23:20:39 1654 +++ trunk/mage/usr/lib/mage/mage4.functions.sh 2014/01/06 12:53:31 2364 @@ -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,8 +74,24 @@ if [[ -d ${rundir} ]] then pushd ${rundir} &> /dev/null - ${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 @@ -101,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 @@ -119,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 @@ -170,8 +198,9 @@ mtime=$(stat -c %Y "${reference}") touch \ --no-create \ + --no-dereference \ --time=mtime \ - --reference "${reference}" \ + --reference="${reference}" \ "${pathto}" echo "${mtime}" @@ -413,13 +442,13 @@ ln -snf "${link}" "${MROOT}${pathto}" -# # fix mtime and db -# fix_descriptor ${pkgname}/.symlinks \ -# "${pathto}" \ -# "${posix}" \ -# "${link}" \ -# "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ -# "${MROOT}${pathto}")" + # fix mtime and db + fix_descriptor ${pkgname}/.symlinks \ + "${pathto}" \ + "${posix}" \ + "${link}" \ + "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ + "${MROOT}${pathto}")" done < ${BUILDDIR}/${pkgname}/.symlinks @@ -806,20 +835,9 @@ mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)" - # if $pathto is a symlink than compare linked binary - if [ -L "${MROOT}${pathto}" ] - then - # readlink -f resolves full path of linked file - x="$(readlink -f "${MROOT}${pathto}")" - - # abort if target does not exists - # we keep safe here, theoretically the link can removed - [ ! -e "${x}" ] && return 1 - - x=$(stat -c %Y "${x}") - else - x=$(stat -c %Y "${MROOT}${pathto}") - fi + # no extra handlink for symlinks anymore as fix_mtime + # uses --no-dereference, compare directly + x=$(stat -c %Y "${MROOT}${pathto}") [[ ${mtime} = ${x} ]] && return 0 @@ -1385,7 +1403,7 @@ output+="${mirror}${addon}/${uri/${scheme}/}" done else - output="${uri}" + output="${uri}" fi echo "${output}" @@ -1452,7 +1470,10 @@ { local i local list="$@" - local pkg + local pkgname + local pkgfile + local pcat + local pname local mirr local magefile local md5file @@ -1460,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}." @@ -1474,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 @@ -1492,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 @@ -1564,8 +1606,12 @@ for mirr in ${MIRRORS} do - # path without distribution - mymirr="${mirr%/*}" + # path without distribution + # (only for stable|testing|unstable and not DISTROTAG) + case ${mirr##*/} in + stable|testing|unstable) mymirr="${mirr%/*}";; + *) mymirr="${mirr}";; + esac echo -ne "${COLBLUE} --- ${COLDEFAULT}" echo "fetching latest md5 from ${mymirr} ..." @@ -1610,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} @@ -1768,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 @@ -1875,18 +1921,36 @@ local filename="${file##*/}" local count local output + local oldprotected local i + local x + + # hack; do not honor a global set IFS like '§' + local IFS - declare -i count=0 + count=0 # check if there are already protected files - for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" | + for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" | sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" | sort -t'%' -k3 -k2 | cut -f1 -d'%') do - count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::") + count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')" + done + + # convert 0001 -> 1; 0120 -> 120 etc + # use bash internal base functions to this task + x="$((10#${count}))" + for (( i=0; i