--- trunk/mage/usr/lib/mage/mage4.functions.sh 2011/05/12 21:29:31 1289 +++ trunk/mage/usr/lib/mage/mage4.functions.sh 2012/01/13 13:07:38 1626 @@ -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(): unknown 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="$@" @@ -139,8 +206,7 @@ while read pathto posix user group do [ -z "${pathto}" ] && continue - [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR: ${MROOT}${pathto}" - + mqueryfeature "verbose" && echo -e "\t>>> DIR: ${MROOT}${pathto}" # monitors /etc/env.d -> env-rebuild [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true @@ -216,7 +282,7 @@ case ${retval} in # file is not protected - (over)write it 0|3) - [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}" install -m "${posix}" -o "${user}" -g "${group}" \ ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \ "${MROOT}${pathto}" @@ -234,7 +300,7 @@ # file is protected, write backup file 2) - if [[ ${VERBOSE} = on ]] + if mqueryfeature "verbose" then echo -en "${COLRED}" echo -n "! prot " @@ -265,7 +331,7 @@ # file is protected but ignored, delete the update/do nothing 4) - if [[ ${VERBOSE} = on ]] + if mqueryfeature "verbose" then echo -en "${COLRED}" echo -n "! ignr " @@ -324,7 +390,7 @@ while read pathto posix link mtime do [ -z "${pathto}" ] && continue - [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}" ln -snf "${link}" "${MROOT}${pathto}" @@ -374,7 +440,7 @@ while read pathto posix major minor user group do [ -z "${pathto}" ] && continue - [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}" mknod -m "${posix}" "${MROOT}${pathto}" # make it optional atm !! @@ -418,7 +484,7 @@ while read pathto posix major minor user group do [ -z "${pathto}" ] && continue - [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}" mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}" @@ -462,7 +528,7 @@ while read pathto posix user group do [ -z "${pathto}" ] && continue - [[ ${VERBOSE} = on ]] && echo -e "\t>>> FIFO: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}" mkfifo -m "${posix}" "${MROOT}${pathto}" chown "${user}:${group}" "${MROOT}${pathto}" @@ -796,7 +862,7 @@ [ -z "${pathto}" ] && continue if [ ! -L "${MROOT}${pathto}" ] then - [[ ${VERBOSE} = on ]] && \ + mqueryfeature "verbose" && \ echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}" continue fi @@ -808,12 +874,12 @@ # 1=keep me # case ${retval} in 0) - [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}" rm "${MROOT}${pathto}" ;; 1) - [[ ${VERBOSE} = on ]] && \ + mqueryfeature "verbose" && \ echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}" ;; esac @@ -880,7 +946,7 @@ if [ ! -e "${MROOT}${pathto}" ] then - [[ ${VERBOSE} = on ]] && \ + mqueryfeature "verbose" && \ echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}" continue fi @@ -906,13 +972,13 @@ case ${retval} in # file is not protected - delete it 0|3) - [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}" rm "${MROOT}${pathto}" ;; # file is protected, do not delete 2) - if [[ ${VERBOSE} = on ]] + if mqueryfeature "verbose" then echo -en "${COLRED}" echo -n "! prot " @@ -923,7 +989,7 @@ # file is protected but ignored, delete the update/do nothing 4) - if [[ ${VERBOSE} = on ]] + if mqueryfeature "verbose" then echo -en "${COLRED}" echo -n "! ignr " @@ -935,7 +1001,7 @@ esac ;; 1) - [[ ${VERBOSE} = on ]] && \ + mqueryfeature "verbose" && \ echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}" ;; esac @@ -997,7 +1063,7 @@ do [ -z "${pathto}" ] && continue - [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}" rm "${MROOT}${pathto}" done < ${MROOT}${INSTALLDB}/${pfull}/.pipes @@ -1057,7 +1123,7 @@ do [ -z "${pathto}" ] && continue - [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}" rm "${MROOT}${pathto}" done < ${MROOT}${INSTALLDB}/${pfull}/.char @@ -1119,7 +1185,7 @@ do [ -z "${pathto}" ] && continue - [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}" rm "${MROOT}${pathto}" done < ${MROOT}${INSTALLDB}/${pfull}/.fifo @@ -1180,7 +1246,7 @@ if [ ! -d "${MROOT}${pathto}" ] then - [[ ${VERBOSE} = on ]] && \ + mqueryfeature "verbose" && \ echo -e "${COLRED}! exist${COLDEFAULT} === DIR: ${MROOT}${pathto}" continue fi @@ -1188,7 +1254,7 @@ # exclude .keep directories if [ -f "${MROOT}${pathto}/.keep" ] then - [[ ${VERBOSE} = on ]] && \ + mqueryfeature "verbose" && \ echo -e "${COLRED}! .keep${COLDEFAULT} === DIR: ${MROOT}${pathto}" continue fi @@ -1201,9 +1267,9 @@ if rmdir "${MROOT}${pathto}" &> /dev/null then - [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t<<< DIR: ${MROOT}${pathto}" else - [[ ${VERBOSE} = on ]] && \ + mqueryfeature "verbose" && \ echo -e "${COLRED}! empty${COLDEFAULT} === DIR: ${MROOT}${pathto}" fi done @@ -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 + mqueryfeature "!verbose" && 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,12 @@ 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 +1518,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 @@ -1379,6 +1532,7 @@ local mirr mymirr local opt local tar_opts + local wget_opts # try to get the md5 marked as latest on the server latest_md5="mage-latest.md5" @@ -1386,6 +1540,9 @@ # try to get the tarball marked as latest on the server latest_tarball="mage-latest.tar.bz2" + # filter wget command if busybox was found + wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})" + for mirr in ${MIRRORS} do # path without distribution @@ -1393,16 +1550,16 @@ echo -ne "${COLBLUE} --- ${COLDEFAULT}" echo "fetching latest md5 from ${mymirr} ..." - [[ ${VERBOSE} = off ]] && opt="--quiet" + mqueryfeature "!verbose" && opt="--quiet" wget \ - ${WGET_FETCH_OPTIONS} \ + ${wget_opts} \ --directory-prefix=${temp} \ ${opt} ${mymirr}/rsync/tarballs/${latest_md5} echo -ne "${COLBLUE} --- ${COLDEFAULT}" echo "fetching latest tarball from ${mymirr} ..." wget \ - ${WGET_FETCH_OPTIONS} \ + ${wget_opts} \ --directory-prefix=${temp} \ ${opt} ${mymirr}/rsync/tarballs/${latest_tarball} if [[ $? = 0 ]] @@ -1488,7 +1645,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 @@ -1571,7 +1728,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) @@ -1580,32 +1737,10 @@ then HIGHEST_MAGEFILE=${magefile} #for debug only - [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" + mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" 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 } @@ -2010,11 +2145,11 @@ then for i in $* do - [[ ${MAGEDEBUG} = on ]] && \ + mqueryfeature "debug" && \ echo "--- Including ${MAGEDIR}/include/${i}.minc" source ${MAGEDIR}/include/${i}.minc done - [[ ${MAGEDEBUG} = on ]] && echo + mqueryfeature "debug" && echo fi } @@ -2458,9 +2593,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 @@ -2471,9 +2606,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 @@ -2483,9 +2618,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 @@ -3000,7 +3135,7 @@ eval "${functions}() { ${include}_${functions} ; }" # debug - [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}" + mqueryfeature "debug" && typeset -f "${functions}" shift done @@ -3085,11 +3220,11 @@ then # needs busybox support return 0 - else - # no busybox - return 1 fi fi + + # no busybox + return 1 } # busybox_filter_wget_options ${wget_opts} @@ -3124,3 +3259,135 @@ echo "${opts}" fi } + +have_root_privileges() +{ + local retval + + if [[ $(id -u) = 0 ]] + then + retval=0 + else + retval=1 + fi + + return ${retval} +} + +known_mage_feature() +{ + local feature="$1" + local retval + + case "${feature}" in + autosvc|!autosvc) retval=0 ;; + buildlog|!buildlog) retval=0 ;; + ccache|!ccache) retval=0 ;; + check|!check) retval=0 ;; + compressdoc|!compressdoc) retval=0 ;; + distcc|!distcc) retval=0 ;; + kernelsrcunpack|!kernelsrcunpack) retval=0 ;; + libtool|!libtool) retval=0 ;; + linuxsymlink|!linuxsymlink) retval=0 ;; + pkgbuild|!pkgbuild) retval=0 ;; + purge|!purge) retval=0 ;; + qalint|!qalint) retval=0 ;; + regentree|!regentree) retval=0 ;; + resume|!resume) retval=0 ;; + stepbystep|!stepbystep) retval=0 ;; + srcpkgbuild|!srcpkgbuild) retval=0 ;; + srcpkgtarball|!srcpkgtarball) retval=0 ;; + strip|!strip) retval=0 ;; + *) retval=1 ;; + esac + + return "${retval}" +} + +load_mage_features() +{ + for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]} + do + FVERBOSE=off msetfeature ${i} + done +} + +msetfeature() +{ + local feature + local count + local i + local found + + for feature in $@ + do + found=0 + count="${#MAGE_FEATURES_CURRENT[*]}" + + if ! known_mage_feature "${feature}" + then + [[ ${FVERBOSE} = off ]] || echo "unknown feature ${feature}, ignoring it" + return 3 + fi + + for ((i=0; i