#!/bin/bash # Magellan Linux Installer (mage.sh) # $Id$ # set default variables : ${MAGERC="@@SYSCONFDIR@@/mage.rc"} : ${MLIBDIR="@@MAGELIBDIR@@"} # first of all include common functions source ${MLIBDIR}/common.functions.sh || exit 1 source @@SYSCONFDIR@@/mage.rc.global || die "@@SYSCONFDIR@@/mage.rc.global missing." source ${MAGERC} || die "${MAGERC} missing." source ${MLIBDIR}/mage4.functions.sh || die "${MLIBDIR}/mage4.functions.sh missing." # export default path export PATH="${PATH}:${MLIBDIR}" # export the default C locale export LC_ALL=C # sanity checks [ ! -e ${VIRTUALDB_FILE} ] && touch ${VIRTUALDB_FILE} if [ ! -e ${VIRTUALDB_DEFAULTS} ] && [[ $1 != update ]] && [[ $1 != update-rsync ]] && [[ $1 != update-tarball ]] then echo echo "Please choose an profile from the mage tree." echo "ln -snf ${MAGEDIR}/profiles/profilename @@SYSCONFDIR@@/mage-profile" exit 1 fi # default messages print_usage() { #showversion #echo echo "Usage: $(basename $0) [option] pkgname ..." echo "Options:" echo " pretend - pretends dependencies of a package" echo " srcpretend - pretends dependencies of a package (build from source)" echo " install - installs a package" echo " srcinstall - installs a package from source" echo " uninstall - removes a package" echo " update - updates the mage-tree via default sync method" echo " update-rsync - 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" echo " srcupgrade - runs a complete system upgrade from source" echo " pretend-build-prerequisites - prints build prerequisites" echo " install-build-prerequisites - install build prerequisites" echo " run-preinstall - runs preinstall part of an installed package" echo " run-postinstall - runs postinstall part of an installed package" echo " search - searches mage-tree for a package" 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 echo "Environment variables::" # echo "NOINSTALL=yes $(basename $0) srcinstall PACKAGE" # echo "Builds a Package with its dependencies, but won't install anything." # echo echo "MAGE_DISTRIBUTION=unstable $(basename $0) [src]install PACKAGE" echo "Overrides stable packages; you can install packages that are marked unstable." echo echo "MAGE_DISTRIBUTION=testing $(basename $0) [src]install PACKAGE" echo "Overrides stable packages; you can install packages that are marked testing." echo echo "NOCOLORS=true $(basename $0) [src]install PACKAGE" echo "Disables all colors in the messages." echo } showversion echo # install method METHOD="$1" # initial unversionized packagename, gets overridden later on MAGENAME="$2" if [[ ${METHOD} != upgrade ]] && [[ ${METHOD} != srcupgrade ]] && [[ ${METHOD} != uppretend ]] && [[ ${METHOD} != srcuppretend ]] && [[ ${METHOD} != update ]] && [[ ${METHOD} != update-rsync ]] && [[ ${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 # set PKGDIR and BUILDDIR to MROOT if [[ -n ${MROOT} ]] then PKGDIR=${MROOT}/${PKGDIR} BUILDDIR=${MROOT}/${BUILDDIR} fi # before anything run mage_setup mage_setup || die "error in mage_setup()" # load supported mage features load_mage_features # query debug mode if mqueryfeature "debug" then depwalker_debug="--debug" else depwalker_debug="" fi case ${METHOD} in download) 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})" # package does not exists [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." # 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})" PVER="$(pkgname2pver ${PKGNAME})" PBUILD="$(pkgname2pbuild ${PKGNAME})" # get all dependencies of this package ALLDEPS="$(${MLIBDIR}/depwalker \ --method install \ --pcat ${PCAT} \ --pname ${PNAME} \ --pver ${PVER} \ --pbuild ${PBUILD} \ ${depwalker_debug})" fetch_packages ${ALLDEPS} || die "fetching packages" md5sum_packages ${ALLDEPS} || die "md5 sum packages" ;; srcdownload) 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})" # package does not exists [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." # 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})" PVER="$(pkgname2pver ${PKGNAME})" PBUILD="$(pkgname2pbuild ${PKGNAME})" # get all dependencies of this package ALLDEPS="$(${MLIBDIR}/depwalker \ --method srcinstall \ --pcat ${PCAT} \ --pname ${PNAME} \ --pver ${PVER} \ --pbuild ${PBUILD} \ ${depwalker_debug})" fetch_packages ${ALLDEPS} || die "fetching packages" ;; pretend|srcpretend|pretend-build-prerequisites) # first of all get the right pkg which going to be installed PCAT="$(pname2pcat ${MAGENAME})" # package does not exists [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." # 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})" PVER="$(pkgname2pver ${PKGNAME})" PBUILD="$(pkgname2pbuild ${PKGNAME})" # abort if already installed if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} then echo -en "Package " echo -en "${COLRED}${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" echo -e " already installed." exit 3 fi # get all dependencies of this package ${MLIBDIR}/depwalker \ --method ${METHOD} \ --pcat ${PCAT} \ --pname ${PNAME} \ --pver ${PVER} \ --pbuild ${PBUILD} \ ${depwalker_debug} ;; install|install-build-prerequisites) 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})" # package does not exists [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." # 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})" PVER="$(pkgname2pver ${PKGNAME})" PBUILD="$(pkgname2pbuild ${PKGNAME})" if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} then echo -en "Package " echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" echo -e " already installed." exit 3 fi # get all dependencies of this package ALLDEPS="$(${MLIBDIR}/depwalker \ --method ${METHOD} \ --pcat ${PCAT} \ --pname ${PNAME} \ --pver ${PVER} \ --pbuild ${PBUILD} \ ${depwalker_debug})" # first fetch all packages fetch_packages ${ALLDEPS} || die "fetching packages" md5sum_packages ${ALLDEPS} || die "md5 sum 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})" # package does not exists [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." # 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})" PVER="$(pkgname2pver ${PKGNAME})" PBUILD="$(pkgname2pbuild ${PKGNAME})" if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} then echo -en "Package " echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" echo -e " already installed." exit 3 fi # get all dependencies of this package ALLDEPS="$(${MLIBDIR}/depwalker \ --method ${METHOD} \ --pcat ${PCAT} \ --pname ${PNAME} \ --pver ${PVER} \ --pbuild ${PBUILD} \ ${depwalker_debug})" install_packages --src-install ${ALLDEPS} || die "src-installing packages" ;; uninstall) 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} ;; run-preinstall|run-postinstall) 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 rerun_pkgfunctions --method "${METHOD//run-}" ${ALLDEPS} ;; uppretend|srcuppretend) ${MLIBDIR}/depwalker \ --method ${METHOD} \ --pcat ${METHOD} \ --pname ${METHOD} \ --pver ${METHOD} \ --pbuild ${METHOD} \ ${depwalker_debug} ;; 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 \ --method ${METHOD} \ --pcat ${METHOD} \ --pname ${METHOD} \ --pver ${METHOD} \ --pbuild ${METHOD} \ ${depwalker_debug})" # first fetch all packages fetch_packages ${ALLDEPS} || die "fetching packages" md5sum_packages ${ALLDEPS} || die "md5 sum 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 \ --method ${METHOD} \ --pcat ${METHOD} \ --pname ${METHOD} \ --pver ${METHOD} \ --pbuild ${METHOD} \ ${depwalker_debug})" install_packages --src-install ${ALLDEPS} || die "src-installing packages" ;; search) pkgsearch "${MAGENAME}" ;; 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})" # package does not exists [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." # 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})" PVER="$(pkgname2pver ${PKGNAME})" PBUILD="$(pkgname2pbuild ${PKGNAME})" # get all dependencies of this package ALLDEPS="$(${MLIBDIR}/depwalker \ --method install \ --pcat ${PCAT} \ --pname ${PNAME} \ --pver ${PVER} \ --pbuild ${PBUILD} \ ${depwalker_debug})" fetch_packages ${ALLDEPS} || die "fetching packages" md5sum_packages ${ALLDEPS} || die "md5 sum packages" unpack_packages ${ALLDEPS} || die "unpacking packages" ;; update) have_root_privileges || die "You must be root to run this operation." # default to tarball [[ -z ${MAGE_UPDATE_METHOD} ]] && MAGE_UPDATE_METHOD="tarball" case ${MAGE_UPDATE_METHOD} in rsync) syncmage ;; tarball) syncmage_tarball ;; *) die "Unknown MAGE_UPDATE_METHOD defined." ;; esac ;; update-rsync) 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 ;; version) # showversion exit 0 ;; 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." exit 1 fi for i in $(find ${SMAGESCRIPTSDIR} -type f -name "*.smage2") do smage2 only-regen-tree "${i}" done ;; print-features) mprintfeatures ;; *) print_usage ;; esac