--- trunk/mage/usr/lib/mage/mage4.functions.sh 2011/12/30 10:07:18 1599 +++ trunk/mage/usr/lib/mage/mage4.functions.sh 2012/10/12 12:59:32 1952 @@ -66,13 +66,14 @@ case ${method} in md5) cmd="md5sum" ;; sha256) cmd="sha256sum" ;; - *) die "mchecksum(): unkown method '${method}'" ;; + *) die "mchecksum(): unknown method '${method}'" ;; esac if [[ -d ${rundir} ]] then pushd ${rundir} &> /dev/null - ${cmd} -c ${file} &> /dev/null + # be verbose here + ${cmd} -c ${file} #&> /dev/null retval="$?" popd &> /dev/null else @@ -82,6 +83,25 @@ return "${retval}" } +mcheckemptydir() +{ + local dir="$1" + local retval=1 + + if [[ ! -d ${dir} ]] + then + echo "mcheckemptydir(): '${dir}' is not a directory!" + retval=3 + else + shopt -s nullglob dotglob + files=( ${dir}/* ) + (( ${#files[*]} )) || retval=0 + shopt -u nullglob dotglob + fi + + return ${retval} +} + unpack_packages() { local list="$@" @@ -151,8 +171,9 @@ mtime=$(stat -c %Y "${reference}") touch \ --no-create \ + --no-dereference \ --time=mtime \ - --reference "${reference}" \ + --reference="${reference}" \ "${pathto}" echo "${mtime}" @@ -394,13 +415,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 @@ -787,20 +808,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 @@ -1401,10 +1411,10 @@ real_uris="$(convertmirrors ${uri})" # verbose or not - mqueryfeature "!verbose" && wget_opts="--quiet" + mqueryfeature "!verbose" && wget_opts+=" --quiet" # filter wget options if busybox was found - wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})" + wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})" # create outputdir [[ ! -d ${outputdir} ]] && install -d "${outputdir}" @@ -1545,8 +1555,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} ..." @@ -1579,14 +1593,23 @@ else echo -ne "${COLBLUE} --- ${COLDEFAULT}" echo -n "checking md5sum... " - ( cd ${temp}; md5sum -c ${latest_md5} ) || die "md5 for ${latest_tarball} failed" + mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed" fi if [[ -d ${MAGEDIR} ]] then echo -ne "${COLBLUE} --- ${COLDEFAULT}" echo "cleaning old mage-tree ${MAGEDIR}..." - rm -rf ${MAGEDIR} + # honor mountpoints and empty dirs + if mountpoint -q ${MAGEDIR} + then + if ! mcheckemptydir ${MAGEDIR} + then + find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xarg --no-run-if-empty rm -r + fi + else + rm -rf ${MAGEDIR} + fi fi if need_busybox_support tar @@ -1645,20 +1668,23 @@ } -# cuts full pathnames or versionized names down to basename -choppkgname() -{ - #we want this only if full name was used - if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ] - then - #cuts ARCH and PBUILD - #ARCH comes from ${MAGERC} - MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g") +# unused? +# +# # cuts full pathnames or versionized names down to basename +# choppkgname() +# { +# #we want this only if full name was used +# if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ] +# then +# #cuts ARCH and PBUILD +# #ARCH comes from ${MAGERC} +# MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g") +# +# #cuts version number +# MAGENAME=$(basename ${MAGENAME%-*} .mage) +# fi +# } - #cuts version number - MAGENAME=$(basename ${MAGENAME%-*} .mage) - fi -} # get_categorie $PNAME, returns CATEGORIE # $1=pname @@ -1844,18 +1870,35 @@ local filename="${file##*/}" local count local output + local oldprotected local i + local x - declare -i count=0 + # hack; do not honor a global set IFS like '§' + local IFS + + 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 + + # dirty hack to convert 0001 -> 1; 0120 -> 120 etc + x="${#count}" + for (( i=0; i