--- trunk/mage/usr/lib/mage/mage4.functions.sh 2012/01/10 15:47:08 1620 +++ trunk/mage/usr/lib/mage/mage4.functions.sh 2013/10/25 07:28:23 2271 @@ -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 $* @@ -66,14 +68,30 @@ 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 - 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 @@ -82,12 +100,71 @@ 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_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 @@ -100,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 @@ -151,8 +198,9 @@ mtime=$(stat -c %Y "${reference}") touch \ --no-create \ + --no-dereference \ --time=mtime \ - --reference "${reference}" \ + --reference="${reference}" \ "${pathto}" echo "${mtime}" @@ -394,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 @@ -787,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 @@ -1366,7 +1403,7 @@ output+="${mirror}${addon}/${uri/${scheme}/}" done else - output="${uri}" + output="${uri}" fi echo "${output}" @@ -1401,10 +1438,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}" @@ -1433,7 +1470,8 @@ { local i local list="$@" - local pkg + local pkgname + local pkgfile local mirr local magefile local md5file @@ -1455,17 +1493,18 @@ 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})" (( 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 @@ -1473,24 +1512,24 @@ 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} ] + if [ -f ${PKGDIR}/${pkgfile} ] then echo -ne " ${COLBLUE}***${COLDEFAULT}" - echo " fetch complete (${count_current}/${count_total}): ${pkg} ... " + echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... " continue 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} ] + echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... " + mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}" + 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 @@ -1545,8 +1584,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 +1622,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 | xargs --no-run-if-empty rm -r + fi + else + rm -rf ${MAGEDIR} + fi fi if need_busybox_support tar @@ -1645,20 +1697,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 @@ -1737,7 +1792,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 @@ -1844,18 +1899,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