#!/bin/bash #depwalker # $Id$ # default die function die() { echo ${COLRED}"$@"${COLDEFAULT} exit 1 } # 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." #### fixups #### MLIBDIR="/home/tjoke/svn/magellan-source/branches/mage-sql/usr/lib/mage" INSTALLDB="/var/db/mage" #DBFILE="${MLIBDIR}/mage.db" DBFILE="${MLIBDIR}/main.db" MAGE_INSTALL_DB="${MLIBDIR}/install.db" ################# [ -f ${MLIBDIR}/mage4.functions.sh ] && \ source ${MLIBDIR}/mage4.functions.sh || \ die "mage functions missing" [ -f ${MLIBDIR}/sql_functions.sh ] && \ source ${MLIBDIR}/sql_functions.sh || \ die "sql functions missing" # not serious if missing, only needed 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 usage() { echo echo "Usage: $(basename $0) [command] [arg] ..." echo echo " -h --help shows this help" echo " -c --pcat categorie of the package" echo " -n --pname name of the package" 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 " upgrade, srcupgrade" echo echo "method, name, version and build must be given !" echo exit 1 } # very basic getops for i in $* do case $1 in --pcat|-c) shift; PCAT="$1" ;; --pname|-n) shift; PNAME="$1" ;; --pver|-v) shift; PVER="$1" ;; --pbuild|-b) shift; PBUILD="$1" ;; --method|-m) shift; METHOD="$1" ;; --help|-h) usage ;; esac shift done # sanity checks; abort if not given [ -z "${PCAT}" ] && usage [ -z "${PNAME}" ] && usage [ -z "${PVER}" ] && usage [ -z "${PBUILD}" ] && usage [ -z "${METHOD}" ] && usage # check needed global vars [ -z "${MAGEDIR}" ] && die "\$MAGEDIR not set." [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set." [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set." # other needed vars 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 } all_depends() { local pname="$1" local pver="$2" local pbuild="$3" sql "select categories.pcat, depends.pname, depends.pver, depends.pbuild from depends inner join packages on depends.pkg_id=packages.id and packages.pname='${pname}' and packages.pver='${pver}' and packages.pbuild='${pbuild}' inner join categories on depends.pcat_id=categories.id" } all_sdepends() { local pname="$1" local pver="$2" local pbuild="$3" sql "select categories.pcat, sdepends.pname, sdepends.pver, sdepends.pbuild from sdepends inner join packages on sdepends.pkg_id=packages.id and packages.pname='${pname}' and packages.pver='${pver}' and packages.pbuild='${pbuild}' inner join categories on sdepends.pcat_id=categories.id" } ##################### ## rumwandern /path/to/mage/file/.mage rumwandern() { unset DEPEND unset SDEPEND unset MY_DEPEND local DFILE local SYM local DEPNAME local HIGHEST_DEPFILE local MY_DEPEND local REAL_PGKNAME local VIRTUAL_NAME local INSTALL_VIRTUAL local PNAME local PCAT local PVER local PBUILD local pname="$1" local pver="$2" local pbuild="$3" local state="${MAGE_DISTRIBUTION}" local retval local fullname # forced nodeps if [[ ${NODEPS} = true ]] then DEPEND="" SDEPEND="" fi MY_DEPEND="$(all_depends ${pname} ${pver} ${pbuild})" # for srcinstall & srcdepend only; SDEPEND also needed if [[ ${METHOD} = srcinstall ]] || \ [[ ${METHOD} = srcpretend ]] || \ [[ ${METHOD} = srcupgrade ]] || \ [[ ${METHOD} = srcuppretend ]] then MY_DEPEND="${MY_DEPEND} $(all_sdepends ${pname} ${pver} ${pbuild})" fi unset DEPEND unset SDEPEND if [ -z "${MY_DEPEND}" ] then return 1 fi for line in ${MY_DEPEND} do depcat="${line%%|*}" depname="${line#*|}" depname="${depname%%|*}" # exclude empty depnames [[ -z ${depname} ]] && continue # exclude all already processed deps 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 if [[ ${depcat} = virtual ]] then retval=$(default_virtualname_to_pkgname "${depcat}" "${depname}") depcat=${retval%%|*} depname=${retval##*|} fi highest=$(highest_pkg ${depname} ${state}) depver="${highest%|*}" depbuild="${highest##*|}" fullname="${depcat}/${depname}-${depver}-${depbuild}" ## check ob schon in ALLDEPS enthalten dann mach weiter if checklist_alldeps "${fullname}" then ## check ob DFILE schon installiert ist if ! is_installed --pcat "${depcat}" --pname "${depname}" --pver "${depver}" --pbuild "${depbuild}" then rumwandern "${depname}" "${depver}" "${depbuild}" ALLDEPS="${ALLDEPS} ${fullname}" fi fi done return 0 } ### abort if this package is already installed (retval 3) # maybe later ? #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3 # # [[ ${METHOD} = pretend ]] || \ # # [[ ${METHOD} = srcpretend ]] || \ # # [[ ${METHOD} = uppretend ]] || \ # # [[ ${METHOD} = srcuppretend ]] && \ # # 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 # # # # # now get the pver&pbuild from the new file # # PVER="$(magename2pver ${MAGEFILE})" # # PBUILD="$(magename2pbuild ${MAGEFILE})" # # # # # do not wander files which are installed # # if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] # # then # # # get dependencies the package # # rumwandern ${MAGEFILE} # # # # # now add the package itself to the dependencies # # # (if not exists already) # # #if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ] # # if checklist_alldeps "${MAGEFILE}" # # then # # ALLDEPS="${ALLDEPS} ${MAGEFILE}" # # fi # # fi # # done # # else # # # get dependencies the package # # rumwandern ${MAGEFILE} # # # # # now add the package itself to the dependencies # # ALLDEPS="${ALLDEPS} ${MAGEFILE}" # # fi # # # # [[ ${METHOD} = pretend ]] || \ # # [[ ${METHOD} = srcpretend ]] || \ # # [[ ${METHOD} = uppretend ]] || \ # # [[ ${METHOD} = srcuppretend ]] && \ # # echo "done" # # # # # # ## show output of pretend # # if [[ ${METHOD} = pretend ]] || \ # # [[ ${METHOD} = srcpretend ]] || \ # # [[ ${METHOD} = uppretend ]] || \ # # [[ ${METHOD} = srcuppretend ]] # # then # # # this is a little bit faster # # declare -i x=0 # # echo -n "Building dependencies list ... " # # for i in ${ALLDEPS} # # do # # (( x++ )) # # k="$x" # # [ ${x} -le 9 ] && k="0${k}" # # #[ ${x} -le 99 ] && k="0${k}" # # PCAT="$(magename2pcat ${i})" # # PNAME="$(magename2pname ${i})" # # PVER="$(magename2pver ${i})" # # PBUILD="$(magename2pbuild ${i})" # # if [ -z "${list}" ] # # then # # list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" # # else # # list="${list} # # \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" # # fi # # unset PCAT PNAME PVER PBUILD # # done # # echo "done" # # echo -e "${list}" # # echo # # # # 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 ]] || \ # # [[ ${METHOD} = upgrade ]] || \ # # [[ ${METHOD} = srcupgrade ]] && \ # # echo "${ALLDEPS}" # # # # # delete ${BUILDDIR}/virtuals if exists as not needed anymore # # #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals #all_depends "${PNAME}" "${PVER}" "${PBUILD}" #all_depends "${PNAME}" "${MAGE_DISTRIBUTION}" #retval=$(default_virtualname_to_pkgname "virtual" "opengl") #depcat=${retval%%|*} #depname=${retval##*|} #echo "depcat='${depcat}'" #echo "depname='${depname}'" rumwandern "${PNAME}" "${PVER}" "${PBUILD}" # add the package itself ALLDEPS="${ALLDEPS} ${PCAT}/${PNAME}-${PVER}-${PBUILD}" declare -i x=0 for i in ${ALLDEPS} do (( x++ )) k="$x" [ ${x} -le 9 ] && k="0${k}" #[ ${x} -le 99 ] && k="0${k}" echo -e "\t[${k}] ${i}" done echo