--- trunk/mage/usr/lib/mage/mage4.sh 2005/12/04 17:12:07 299 +++ trunk/mage/usr/lib/mage/mage4.sh 2013/08/14 07:25:43 2156 @@ -1,10 +1,11 @@ -#!/bin/sh +#!/bin/bash # Magellan Linux Installer (mage.sh) -# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.sh,v 1.11 2005-12-04 17:12:07 niro Exp $ +# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.sh,v 1.17 2008-06-16 09:29:57 niro Exp $ # default die function die() { + echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT} echo -e ${COLRED}"$@"${COLDEFAULT} exit 1 } @@ -14,37 +15,13 @@ source /etc/mage.rc.global || \ die "/etc/mage.rc.global missing" -[ -f /etc/mage.rc ] && source /etc/mage.rc || \ - die "Your /etc/mage.rc is missing. Aborting." +[ -f ${MAGERC} ] && source ${MAGERC} || \ + die "Your ${MAGERC} is missing. Aborting." [ -f ${MLIBDIR}/mage4.functions.sh ] && \ source ${MLIBDIR}/mage4.functions.sh || \ die "mage functions missing" -## only for tests -> normally in /etc/rc.d/init.d/functions -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 - # export default path export PATH="${PATH}:${MLIBDIR}" @@ -54,7 +31,7 @@ # sanity checks [ ! -e ${VIRTUALDB_FILE} ] && touch ${VIRTUALDB_FILE} -if [ ! -e ${VIRTUALDB_DEFAULTS} ] && [[ $1 != update ]] +if [ ! -e ${VIRTUALDB_DEFAULTS} ] && [[ $1 != update ]] && [[ $1 != update-tarball ]] then echo echo "Please choose an profile from the mage tree." @@ -82,7 +59,8 @@ echo " install - installs a package" echo " srcinstall - installs a package from source" echo " uninstall - removes a package" - echo " update - updates mage-tree" + echo " update - updates the mage-tree via rsync" + echo " update-tarball - updates the mage-tree via a tarball" echo " uppretend - pretend dependencies for a system upgrade" echo " upgrade - runs a complete system upgrade" echo " srcuppretend - pretend dependencies for a system upgrade from source" @@ -91,6 +69,7 @@ echo " clean - removes *all* downloaded packages" echo " unpack - unpacks *all* needed package for 'foo'" echo " download - downloads *all* needed packages for 'foo'" + echo " print-features - prints all enabled mage-features" echo " version - prints version info" echo " regen-mage-tree - regenerates the whole mage database (for devs only)" echo @@ -113,24 +92,23 @@ showversion echo -# before anything run mage_setup -mage_setup || die "error in mage_setup()" - # install method METHOD="$1" -# initial unversionized packagename, gets overridden later +# initial unversionized packagename, gets overridden later on MAGENAME="$2" -if [[ ${METHOD} != upgrade ]] && \ - [[ ${METHOD} != srcupgrade ]] && \ - [[ ${METHOD} != uppretend ]] && \ - [[ ${METHOD} != srcuppretend ]] && \ - [[ ${METHOD} != update ]] && \ - [[ ${METHOD} != clean ]] && \ - [[ ${METHOD} != version ]] && \ - [[ ${METHOD} != search ]] && \ - [[ ${METHOD} != regen-mage-tree ]] +if [[ ${METHOD} != upgrade ]] && + [[ ${METHOD} != srcupgrade ]] && + [[ ${METHOD} != uppretend ]] && + [[ ${METHOD} != srcuppretend ]] && + [[ ${METHOD} != update ]] && + [[ ${METHOD} != update-tarball ]] && + [[ ${METHOD} != clean ]] && + [[ ${METHOD} != version ]] && + [[ ${METHOD} != search ]] && + [[ ${METHOD} != regen-mage-tree ]] && + [[ ${METHOD} != print-features ]] then [[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1 fi @@ -142,6 +120,12 @@ BUILDDIR=${MROOT}/${BUILDDIR} fi +# before anything run mage_setup +mage_setup || die "error in mage_setup()" + +# load supported mage features +load_mage_features + case ${METHOD} in download) # first of all get the right pkg which going to be installed @@ -153,6 +137,9 @@ # source the highest magefile of this pkg PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) + # package is masked + [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." + # convert PKGNAME to PNAME/PVER/PBUILD # we're working *only* with these three vars from here on PNAME="$(pkgname2pname ${PKGNAME})" @@ -180,6 +167,9 @@ # source the highest magefile of this pkg PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) + # package is masked + [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." + # convert PKGNAME to PNAME/PVER/PBUILD # we're working *only* with these three vars from here on PNAME="$(pkgname2pname ${PKGNAME})" @@ -206,6 +196,9 @@ # source the highest magefile of this pkg PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) + # package is masked + [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." + # convert PKGNAME to PNAME/PVER/PBUILD # we're working *only* with these three vars from here on PNAME="$(pkgname2pname ${PKGNAME})" @@ -230,6 +223,8 @@ ;; install) + have_root_privileges || die "You must be root to run this operation." + # first of all get the right pkg which going to be installed PCAT="$(pname2pcat ${MAGENAME})" @@ -239,6 +234,9 @@ # source the highest magefile of this pkg PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) + # package is masked + [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." + # convert PKGNAME to PNAME/PVER/PBUILD # we're working *only* with these three vars from here on PNAME="$(pkgname2pname ${PKGNAME})" @@ -264,11 +262,12 @@ # first fetch all packages fetch_packages ${ALLDEPS} || die "fetching packages" md5sum_packages ${ALLDEPS} || die "md5 sum packages" - unpack_packages ${ALLDEPS} || die "unpacking packages" install_packages ${ALLDEPS} || die "installing packages" ;; srcinstall) + have_root_privileges || die "You must be root to run this operation." + # first of all get the right pkg which going to be installed PCAT="$(pname2pcat ${MAGENAME})" @@ -278,6 +277,9 @@ # source the highest magefile of this pkg PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) + # package is masked + [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." + # convert PKGNAME to PNAME/PVER/PBUILD # we're working *only* with these three vars from here on PNAME="$(pkgname2pname ${PKGNAME})" @@ -304,12 +306,14 @@ ;; uninstall) - ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})" - if [ -z "${ALLDEPS}" ] - then - die "No package installed named '${MAGENAME}'." - fi - uninstall_packages ${ALLDEPS} + have_root_privileges || die "You must be root to run this operation." + + ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})" + if [ -z "${ALLDEPS}" ] + then + die "No package installed named '${MAGENAME}'." + fi + uninstall_packages ${ALLDEPS} ;; uppretend|srcuppretend) @@ -322,6 +326,8 @@ ;; upgrade) + have_root_privileges || die "You must be root to run this operation." + # get all dependencies of *all* installed packages # fake pcat,pname,pver,pbuild ... ALLDEPS="$(${MLIBDIR}/depwalker.sh \ @@ -334,11 +340,12 @@ # first fetch all packages fetch_packages ${ALLDEPS} || die "fetching packages" md5sum_packages ${ALLDEPS} || die "md5 sum packages" - unpack_packages ${ALLDEPS} || die "unpacking packages" install_packages ${ALLDEPS} || die "installing packages" ;; srcupgrade) + have_root_privileges || die "You must be root to run this operation." + # get all dependencies of *all* installed packages # fake pcat,pname,pver,pbuild ... ALLDEPS="$(${MLIBDIR}/depwalker.sh \ @@ -356,6 +363,8 @@ ;; unpack) + have_root_privileges || die "You must be root to run this operation." + # first of all get the right pkg which going to be installed PCAT="$(pname2pcat ${MAGENAME})" @@ -365,6 +374,9 @@ # source the highest magefile of this pkg PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) + # package is masked + [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." + # convert PKGNAME to PNAME/PVER/PBUILD # we're working *only* with these three vars from here on PNAME="$(pkgname2pname ${PKGNAME})" @@ -384,10 +396,17 @@ ;; update) + have_root_privileges || die "You must be root to run this operation." syncmage ;; + update-tarball) + have_root_privileges || die "You must be root to run this operation." + syncmage_tarball + ;; + clean) + have_root_privileges || die "You must be root to run this operation." cleanpkg ;; @@ -397,6 +416,8 @@ ;; regen-mage-tree) + have_root_privileges || die "You must be root to run this operation." + if [ -z "${SMAGESCRIPTSDIR}" ] || [ ! -d "${SMAGESCRIPTSDIR}" ] then echo "SMAGESCRIPTSDIR not found. Check your mage.rc or check out smage repos." @@ -408,6 +429,10 @@ done ;; + print-features) + mprintfeatures + ;; + *) print_usage ;;