--- trunk/mage/usr/lib/mage/depwalker.sh 2005/09/09 16:35:46 226 +++ trunk/mage/usr/lib/mage/depwalker.sh 2013/10/16 07:40:02 2221 @@ -1,7 +1,6 @@ #!/bin/bash - -#depwalker -# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/depwalker.sh,v 1.1 2005-09-09 16:35:27 niro Exp $ +# $Id$ +# dependeny walker # default die function die() @@ -10,37 +9,17 @@ exit 1 } -# # include all needed files -# [ -f ${MLIBDIR}/conf/mage.rc.global ] && \ -# source ${MLIBDIR}/conf/mage.rc.global || \ -# die "${MLIBDIR}/conf/mage.rc.global missing" -# -# [ -f /etc/mage.rc ] && source /etc/mage.rc || \ -# die "Your /etc/mage.rc is missing. Aborting." -# -# [ -f ${MLIBDIR}/mage.functions.sh ] && \ -# source ${MLIBDIR}/mage.functions.sh || \ -# die "mage functions missing" - -# for tests only -source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage.rc.global -source /etc/mage.rc -source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh - -# not serios if missing, only for colors -[ -f /etc/init.d/functions ] && source /etc/init.d/functions - -# disable colors if wanted -if [[ ${NOCOLORS} = true ]] -then - COLRED="" - COLGREEN="" - COLYELLOW="" - COLBLUE="" - COLMAGENTA="" - COLWHITE="" - COLDEFAULT="" -fi +# include all needed files +[ -f /etc/mage.rc.global ] && \ + source /etc/mage.rc.global || \ + die "/etc/mage.rc.global missing" + +[ -f ${MAGERC} ] && source ${MAGERC} || \ + die "Your ${MAGERC} is missing. Aborting." + +[ -f ${MLIBDIR}/mage4.functions.sh ] && \ + source ${MLIBDIR}/mage4.functions.sh || \ + die "mage functions missing" usage() { @@ -53,13 +32,19 @@ echo " -v --pver version number of the package" echo " -b --pbuild build number of the package" echo " -m --method which calc method should be used:" - echo " install srcinstall depend srcdepend" + echo " -d --debug enable debug mode" + echo " install, srcinstall, depend, srcdepend" + echo " upgrade, srcupgrade," + echo " install-build-prerequisites, pretend-build-prerequisites" echo - echo "method,name, version and build must be given !" + echo "method, name, version and build must be given !" echo exit 1 } +# always default debug=0 +DEBUG=0 + # very basic getops for i in $* do @@ -69,6 +54,7 @@ --pver|-v) shift; PVER="$1" ;; --pbuild|-b) shift; PBUILD="$1" ;; --method|-m) shift; METHOD="$1" ;; + --debug|-d) shift; DEBUG=1 ;; --help|-h) usage ;; esac shift @@ -90,9 +76,36 @@ ALLDEPS="" MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage" +# much faster than fgrep +checklist_alldeps() +{ + local i + local item="$1" + + for i in ${ALLDEPS} + do + [[ ${i} = ${item} ]] && return 1 + done + + return 0 +} + +checklist_processeddeps() +{ + local i + local item="$1" + + for i in ${PROCESSEDDEPS} + do + [[ ${i} = ${item} ]] && return 1 + done + + return 0 +} + ##################### -## rumwandern /path/to/mage/file/.mage -rumwandern() +## depwalking /path/to/mage/file/.mage +depwalking() { unset DEPEND unset SDEPEND @@ -108,14 +121,27 @@ local INSTALL_VIRTUAL local PNAME local PCAT + local PVER + local PBUILD DFILE="$1" source ${DFILE} + + # forced nodeps + if [[ ${NODEPS} = true ]] + then + DEPEND="" + SDEPEND="" + fi + MY_DEPEND="${DEPEND}" # for srcinstall & srcdepend only; SDEPEND also needed - if [[ ${METHOD} = srcinstall ]] || [[ ${METHOD} = srcpretend ]] + if [[ ${METHOD} = srcinstall ]] || \ + [[ ${METHOD} = srcpretend ]] || \ + [[ ${METHOD} = srcupgrade ]] || \ + [[ ${METHOD} = srcuppretend ]] then # only if SDEPEND is not zero if [ -n "${SDEPEND}" ] @@ -131,6 +157,28 @@ fi fi + if [[ ${METHOD} = install-build-prerequisites ]] || \ + [[ ${METHOD} = pretend-build-prerequisites ]] + then + # only one time + if [[ ${LOOP_COUNTER} -lt 1 ]] + then + # only if SDEPEND is not zero + if [ -n "${SDEPEND}" ] + then + # crlf is substantly needed !! + if [ -n "${MY_DEPEND}" ] + then + MY_DEPEND="${MY_DEPEND} + ${SDEPEND}" + else + MY_DEPEND="${SDEPEND}" + fi + fi + fi + LOOP_COUNTER=${LOOP_COUNTER}+1 + fi + unset DEPEND unset SDEPEND @@ -141,20 +189,50 @@ while read SYM DEPNAME do + if [[ ${DEBUG} = 1 ]] + then + echo "DEBUG: DEPNAME='${DEPNAME}'" >&2 + fi + + # exclude empty depnames + [[ -z ${DEPNAME} ]] && continue + + # exclude all already processed deps -without version + if ! checklist_processeddeps "${DEPNAME%-*}" + then + continue + fi + + # mark depfile as processed to prevent double runs -without version + # but do not add any virtuals to PROCESSEDDEPS or their resolved + # pkgnames will be ignored and they are missing on the dependecy-list + if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]] + then + PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}" + fi + HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") + if [[ -z ${HIGHEST_DEPFILE} ]] + then + INVALID_DEPS+=" ${DEPNAME}:${DFILE}" + continue + fi PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" PNAME="$(magename2pname ${HIGHEST_DEPFILE})" PVER="$(magename2pver ${HIGHEST_DEPFILE})" PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})" - ## check ob schon in ALLDEPS enthalten dann mach weiter - if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ] + ## dep already in ALLDEPS? then going on + + # usage of fgrep is extremly slow and consumes a lot of cpu power + #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ] + if checklist_alldeps "${HIGHEST_DEPFILE}" then - ### check ob DFILE schon installiert ist ### + ### check if the dependency is already installed ### if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] then - rumwandern ${HIGHEST_DEPFILE} + depwalking ${HIGHEST_DEPFILE} ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}" fi fi @@ -164,25 +242,78 @@ return 0 } +[[ ${METHOD} = pretend ]] || \ + [[ ${METHOD} = srcpretend ]] || \ + [[ ${METHOD} = uppretend ]] || \ + [[ ${METHOD} = srcuppretend ]] || \ + [[ ${METHOD} = pretend-build-prerequisites ]] && \ + echo -n "Calculating dependencies ... " -### abort if this package is already installed (retval 3) -# maybe later ? -#[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3 -[[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]] && \ - echo -n "Calculating dependencies ... " +if [[ ${METHOD} = upgrade ]] || \ + [[ ${METHOD} = srcupgrade ]] || \ + [[ ${METHOD} = uppretend ]] || \ + [[ ${METHOD} = srcuppretend ]] +then + INSTDEPS="$(${MLIBDIR}/magequery.sh -i)" + for dep in ${INSTDEPS} + do + PCAT="$(magename2pcat ${dep} installdb)" + PNAME="$(magename2pname ${dep})" + + # get the highest mage file from mage-db + MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" + + # if no install candidate was found, record this + # and process with the next one + if [[ -z ${MAGEFILE} ]] + then + NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}" + continue + fi -# get dependencies the package -rumwandern ${MAGEFILE} + # now get the pver&pbuild from the new file + PVER="$(magename2pver ${MAGEFILE})" + PBUILD="$(magename2pbuild ${MAGEFILE})" -[[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]] && echo "done" + # do not walk files which are installed + if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] + then + # get dependencies the package + depwalking ${MAGEFILE} + fi + done +else + LOOP_COUNTER=0 + # get all dependencies of the package + depwalking ${MAGEFILE} +fi + +if [[ ${METHOD} != install-build-prerequisites ]] && + [[ ${METHOD} != pretend-build-prerequisites ]] +then + # now add the package itself to the dependencies + # (if not exists already) + if checklist_alldeps "${MAGEFILE}" + then + ALLDEPS="${ALLDEPS} ${MAGEFILE}" + fi +fi +[[ ${METHOD} = pretend ]] || \ + [[ ${METHOD} = srcpretend ]] || \ + [[ ${METHOD} = uppretend ]] || \ + [[ ${METHOD} = srcuppretend ]] || \ + [[ ${METHOD} = pretend-build-prerequisites ]] && \ + echo "done" -# now add the package itself to the dependencies -ALLDEPS="${ALLDEPS} ${MAGEFILE}" ## show output of pretend -if [[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]] +if [[ ${METHOD} = pretend ]] || \ + [[ ${METHOD} = srcpretend ]] || \ + [[ ${METHOD} = uppretend ]] || \ + [[ ${METHOD} = srcuppretend ]] || \ + [[ ${METHOD} = pretend-build-prerequisites ]] then # this is a little bit faster declare -i x=0 @@ -199,7 +330,7 @@ PBUILD="$(magename2pbuild ${i})" if [ -z "${list}" ] then - list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" + list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" else list="${list} \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" @@ -209,10 +340,38 @@ echo "done" echo -e "${list}" echo + + if [[ ! -z ${INVALID_DEPS} ]] + then + echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}" + for i in ${INVALID_DEPS} + do + _dep="${i%%:*}" + _mage="${i##*:}" + echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}" + done + echo + fi + + if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]] + then + echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}" + for i in ${NO_UPGRADE_CANDIDATE} + do + echo -e "${COLRED} ${i}${COLDEFAULT}" + done + echo + echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}" + echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}" + echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}" + echo + fi fi ## return output from src/install deps -[[ ${METHOD} = install ]] || [[ ${METHOD} = srcinstall ]] && echo "${ALLDEPS}" - -# delete ${BUILDDIR}/virtuals if exists as not needed anymore -#[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals +[[ ${METHOD} = install ]] || \ + [[ ${METHOD} = srcinstall ]] || \ + [[ ${METHOD} = upgrade ]] || \ + [[ ${METHOD} = srcupgrade ]] || \ + [[ ${METHOD} = install-build-prerequisites ]] && \ + echo "${ALLDEPS}"