#!/bin/bash # mage upgrade # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mageupgrade.sh,v 1.10 2005-08-16 23:24:11 niro Exp $ # some default vars : ${MLIBDIR=/usr/lib/mage} : ${DEBUG=false} : ${AUTOANSWER=false} : ${SRCINSTALL=false} : ${AUTOCLEAN=false} : ${NO_CALC=false} source /etc/mage.rc source ${MLIBDIR}/mage3.functions.sh source /etc/init.d/functions unset UPGRADE_LIST unset PLEASE_VALIDATE usage() { echo echo "Usage: $(basename $0) [command] ..." echo echo " --help shows this help" echo " --no-calc do not show deps, running straight forward" echo " --autoclean clean all downloaded files automatically" echo " --autoanswer answer all questions automatically" echo " --src-install install from sources rather from binary packages" echo " --debug show debug messages" echo exit 1 } # get options for opt in $@ do case ${opt} in --no-calc) NO_CALC=true ;; --autoclean) AUTOCLEAN=true ;; --autoanswer) AUTOANSWER=true ;; --src-install) SRCINSTALL=true ;; --debug) DEBUG=true ;; --help) usage ;; *) usage ;; esac done echo "Fetching list of all installed packages ..." # get list for directory in ${INSTALLDB}/* do # supress virtuals and fake packages or files x=$(basename ${directory}) if [ ${x} = virtual ] || [ ${x} = virtuals ] || [ ${x} = virtuals.old ] || [ ! -d ${directory} ] then continue fi for package in ${directory}/* do x=$(basename ${package}) PNAME=${x%-*-*} PVER=$(echo ${x#${PNAME}-}| cut -d- -f1) PBUILD=$(echo ${x#${PNAME}-}| cut -d- -f2) PCAT=$(basename $(dirname ${package})) # check if there is any higher version in mage db # needed packages may have been renamed ?? if [ -d ${MAGEDIR}/${PCAT}/${PNAME} ] then CATEGORIE=${PCAT} MAGENAME=${PNAME} get_highest_magefile &> /dev/null # compare them if [[ $(basename ${HIGHEST_MAGEFILE} .mage) > ${PNAME}-${PVER}-${PBUILD} ]] then UPGRADE_LIST="${UPGRADE_LIST} ${PNAME}" SHOW_LIST="${SHOW_LIST}:${PCAT}/${PNAME},[${PVER}-${PBUILD} -> $(basename ${HIGHEST_MAGEFILE#${HIGHEST_MAGEFILE%-*-*}-} .mage)]" else # put them only on PLEASE_VALIDATE if they are not the same package if [[ $(basename ${HIGHEST_MAGEFILE} .mage) != ${PNAME}-${PVER}-${PBUILD} ]] then echo "Not added: ${PNAME}-${PVER}-${PBUILD} is newer than $(basename ${HIGHEST_MAGEFILE} .mage)." PLEASE_VALIDATE="${PLEASE_VALIDATE} ${PNAME}-${PVER}-${PBUILD}" fi fi fi # unset some vars for sure unset x unset PNAME unset PVER unset PBUILD unset PCAT unset CATEGORIE unset MAGENAME unset HIGHEST_MAGEFILE done done unset package directory if [[ ${NO_CALC} = false ]] && [[ ${AUTOANSWER} = false ]] then # show the list echo echo "Packages selected for upgrade:" OLDIFS="${IFS}" IFS=: for package in ${SHOW_LIST} do # nice output :) echo -en \\033[10G echo -en ${COLGREEN}"$(echo ${package} | cut -d',' -f1)"${COLDEFAULT} echo -en \\033[40G echo -e ${COLBLUE}"$(echo ${package} | cut -d',' -f2)"${COLDEFAULT} done IFS="${OLDIFS}" echo echo "I'm now ready to upgrade your system." echo "Press any key to continue or [CTRL-C] to abort ..." echo read fi # now run the update for package in ${UPGRADE_LIST} do if [[ ${SRCINSTALL} = false ]] then /sbin/mage install ${package} || exit 1 else /sbin/mage srcinstall ${package} || exit 1 fi if [[ ${DEBUG} = true ]] then echo "Installation of ${package} completed." echo "Press any key to continue ..." read fi if [[ ${AUTOANSWER} = true ]] then yes | MAGE_UNINSTALL_TIMEOUT=0 /sbin/mage uninstall ${package} || exit 1 else MAGE_UNINSTALL_TIMEOUT=0 /sbin/mage uninstall ${package} || exit 1 fi if [[ ${AUTOCLEAN} = true ]] then /sbin/mage clean || exit 1 if [[ ${SRCINSTALL} = true ]] && \ [ -d ${SOURCEDIR}/${package} ] then rm -f ${SOURCEDIR}/${package} || exit 1 fi fi if [[ ${DEBUG} = true ]] then echo "Uninstallation of ${package} completed." echo "Press any key to continue ..." read fi # resource /etc/profile source /etc/profile done echo "The system upgrade is now complete." if [ -n "${PLEASE_VALIDATE}" ] && [[ ${AUTOANSWER} = false ]] then echo -n "Would you like to see the list of ignored packages ? [ y/n ] " read answer if [[ ${answer} = y ]] then echo for i in ${PLEASE_VALIDATE} do echo "avoided: ${i}" done fi fi echo echo "Please remember to run etc-update to update your config files." echo "You should also source /etc/profile or re-login to your shell." echo