--- trunk/mage/usr/lib/mage/mageupgrade.sh 2005/01/06 03:39:45 37 +++ trunk/mage/usr/lib/mage/mageupgrade.sh 2005/08/16 23:24:11 187 @@ -1,26 +1,74 @@ #!/bin/bash # mage upgrade -# version: 0.3.6-r9 +# $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} = fake ] || - [ ${x} = virtual ] || + if [ ${x} = virtual ] || [ ${x} = virtuals ] || [ ${x} = virtuals.old ] || [ ! -d ${directory} ] @@ -38,15 +86,16 @@ # check if there is any higher version in mage db - #needed packages may have ben renamed ?? + # needed packages may have been renamed ?? if [ -d ${MAGEDIR}/${PCAT}/${PNAME} ] then CATEGORIE=${PCAT} MAGENAME=${PNAME} get_highest_magefile &> /dev/null - #compare them + # 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} ]] @@ -57,7 +106,7 @@ fi fi - #unset some vars for shure + # unset some vars for sure unset x unset PNAME unset PVER @@ -71,16 +120,41 @@ unset package directory -echo -echo "I'm now ready to upgrade your system." -echo "Press any key to continue or [CTRL-C] to abort ..." -echo -read +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 + +# now run the update for package in ${UPGRADE_LIST} do - /sbin/mage install ${package} || exit 1 + 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." @@ -94,28 +168,42 @@ 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 + + # resource /etc/profile source /etc/profile done echo "The system upgrade is now complete." -echo -n "Would you like to see the list of ignored packages ? [ y/n ] " -read answer -if [[ ${answer} = y ]] + +if [ -n "${PLEASE_VALIDATE}" ] && [[ ${AUTOANSWER} = false ]] then - echo - for i in ${PLEASE_VALIDATE} - do - echo "avoided: ${i}" - done + 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