--- trunk/mage/usr/lib/mage/mage4.functions.sh 2011/12/27 10:00:34 1548 +++ trunk/mage/usr/lib/mage/mage4.functions.sh 2011/12/27 10:43:40 1549 @@ -38,6 +38,50 @@ return 0 } +mchecksum() +{ + local i + local rundir + local file + local method + local cmd + local retval + + # very basic getops + for i in $* + do + case $1 in + --rundir|-r) shift; rundir="$1" ;; + --file|-f) shift; file="$1" ;; + --method|-m) shift; method="$1" ;; + esac + shift + done + + # sanity checks + [[ -z ${rundir} ]] && die "mchecksum(): rundir missing" + [[ -z ${file} ]] && die "mchecksum(): file missing" + [[ -z ${method} ]] && die "mchecksum(): method missing" + + case ${method} in + md5) cmd="md5sum" ;; + sha256) cmd="sha256sum" ;; + *) die "mchecksum(): unkown method '${method}'" ;; + esac + + if [[ -d ${rundir} ]] + then + pushd ${rundir} &> /dev/null + ${cmd} -c ${file} &> /dev/null + retval="$?" + popd &> /dev/null + else + retval=1 + fi + + return "${retval}" +} + unpack_packages() { local list="$@" @@ -1283,9 +1327,111 @@ done } +# convertmirrors [uri] +convertmirrors() +{ + local uri="$1" + local scheme + local mirror + local mirrors + local addon + local real_uri + local output + + # needs + [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!" + [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!" + [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!" + [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!" + [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!" + + # check known uri schemes + case ${uri} in + http://*|https://*|ftp://*|ftps://*) mirrors="" ;; + mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;; + package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;; + gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;; + sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;; + gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;; + kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;; + *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;; + esac + + if [[ ! -z ${mirrors} ]] + then + for mirror in ${mirrors} + do + # add a whitespace to the output + [[ -z ${output} ]] || output+=" " + output+="${mirror}${addon}/${uri/${scheme}/}" + done + else + output="${uri}" + fi + + echo "${output}" +} + +mdownload() +{ + local i + local uri + local real_uris + local mirror + local outputfile + local outputdir + local retval + local wget_opts + + # very basic getops + for i in $* + do + case $1 in + --uri|-u) shift; uri="$1" ;; + --dir|-d) shift; outputdir="$1" ;; + esac + shift + done + + # sanity checks; abort if not given + [[ -z ${uri} ]] && die "mdownload(): no uri given!" + [[ -z ${outputdir} ]] && die "mdownload(): no dir given!" + + # convert mirrored uris to the real ones + real_uris="$(convertmirrors ${uri})" + + # verbose or not + [[ ${VERBOSE} = off ]] && wget_opts="--quiet" + + # filter wget options if busybox was found + wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})" + + # create outputdir + [[ ! -d ${outputdir} ]] && install -d "${outputdir}" + + for mirror in ${real_uris} + do + # get the name of the output file + outputfile="${mirror##*/}" + + wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}" + retval="$?" + if [[ ${retval} = 0 ]] + then + break + else + continue + fi + done + + # return wget retval + return "${retval}" +} + # fetch_packages /path/to/mage/file1 /path/to/mage/file2 fetch_packages() { + local i local list="$@" local pkg local mirr @@ -1339,27 +1485,13 @@ continue fi - for mirr in ${MIRRORS} - do - echo -ne " ${COLBLUE}***${COLDEFAULT}" - #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... " - echo -e " fetching (${count_current}/${count_total}): ${pkg} ... " - [[ ${VERBOSE} = off ]] && opt="--quiet" - wget \ - ${wget_opts} \ - --directory-prefix=${PKGDIR} \ - ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg} - if [[ $? = 0 ]] - then - break - else - continue - fi - done + 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} ] then - die "Could not download ${pkg}" + die "Package '${pkg}' after download not found in '${PKGDIR}'" fi done