--- trunk/mage/usr/lib/mage/mage4.functions.sh 2011/05/27 12:56:38 1293 +++ trunk/mage/usr/lib/mage/mage4.functions.sh 2011/12/27 10:43:40 1549 @@ -2,6 +2,29 @@ # 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 $ +COLRED="\033[1;6m\033[31m" +COLGREEN="\033[1;6m\033[32m" +COLYELLOW="\033[1;6m\033[33m" +COLBLUE="\033[1;6m\033[34m" +COLMAGENTA="\033[1;6m\033[35m" +COLWHITE="\033[1;6m\033[37m" +COLGRAY="\033[0;6m\033[37m" +COLBOLD="\033[1m" +COLDEFAULT="\033[0m" + +if [[ ${NOCOLORS} = true ]] +then + COLRED="" + COLGREEN="" + COLYELLOW="" + COLBLUE="" + COLMAGENTA="" + COLWHITE="" + COLGRAY="" + COLBOLD="" + COLDEFAULT="" +fi + mage_setup() { [ ! -d ${MROOT}${INSTALLDB} ] && \ @@ -15,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="$@" @@ -141,7 +208,6 @@ [ -z "${pathto}" ] && continue [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR: ${MROOT}${pathto}" - # monitors /etc/env.d -> env-rebuild [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true @@ -1261,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 @@ -1317,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 @@ -1365,7 +1519,7 @@ done # clean up backup files (foo~) - find ${MAGEDIR} -name *~ -exec rm '{}' ';' + find ${MAGEDIR} -name \*~ -exec rm '{}' ';' # check if a newer mage version is available is_newer_mage_version_available @@ -1492,7 +1646,7 @@ } -# cuts full pathnames or versioniezed names down to basename +# cuts full pathnames or versionized names down to basename choppkgname() { #we want this only if full name was used @@ -1575,7 +1729,7 @@ local magefile # do not list the content of a directory, only the name (-d) - for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/*) + for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null) do [[ -z ${magefile} ]] && continue # we exclude subdirs (for stuff like a md5sum dir) @@ -1588,28 +1742,6 @@ fi done -# do not so anything -# # stop here if HIGHEST_MAGEFILE is zero -# # this package must be unstable or old -# if [ -z "${HIGHEST_MAGEFILE}" ] -# then -# echo -# echo -n "All packages named " -# echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT} -# echo -n " are marked " -# echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT} -# echo "." -# echo "You need to declare USE_UNSTABLE=true to install this." -# echo -# echo "Example:" -# echo " USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}" -# echo -# echo "Be warned that these packages are not stable and may cause serious problems." -# echo "You should know what you are doing, so don't complain about any damage." -# echo -# return 1 -# fi - echo "${HIGHEST_MAGEFILE}" return 0 } @@ -2462,9 +2594,9 @@ if [[ -n ${MAGE_TARGETS} ]] then # basic svn compat - if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] + if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] then - for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2 + for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2 do smage2file="${i}" done @@ -2475,9 +2607,9 @@ elif [[ -n ${SPLIT_PACKAGE_BASE} ]] then # basic svn compat - if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] + if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] then - for i in ${SMAGESCRIPTSDIR}/trunk/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2 + for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2 do smage2file="${i}" done @@ -2487,9 +2619,9 @@ else # basic svn compat - if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] + if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] then - for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2 + for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2 do smage2file="${i}" done @@ -3089,11 +3221,11 @@ then # needs busybox support return 0 - else - # no busybox - return 1 fi fi + + # no busybox + return 1 } # busybox_filter_wget_options ${wget_opts} @@ -3128,3 +3260,17 @@ echo "${opts}" fi } + +have_root_privileges() +{ + local retval + + if [[ $(id -u) = 0 ]] + then + retval=0 + else + retval=1 + fi + + return ${retval} +}