--- trunk/mage/usr/lib/mage/magequery.sh 2005/09/09 16:51:51 229 +++ trunk/mage/usr/lib/mage/magequery.sh 2011/05/12 21:28:23 1288 @@ -1,7 +1,7 @@ #!/bin/bash #query mage database for installed packages -# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/magequery.sh,v 1.10 2005-09-09 16:51:51 niro Exp $ +# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/magequery.sh,v 1.13 2008-10-05 10:33:04 niro Exp $ print_usage() { @@ -10,7 +10,9 @@ echo " -n NAME searches for name NAME" echo " -v VER searches for version VER, needs -n" echo " -b BUILD searches for build number BUILD, needs -n -v" + echo " -c CAT shows all packages of given categorie" echo " -i shows an inventory of all installed packages" + echo " -f PATH searches package names in given path" echo echo " Examples:" echo @@ -21,8 +23,11 @@ # default args: GET_INVENTORY=false +SEARCH_ONLY_PATH=false +SEARCH_ONLY_CAT=false -while getopts "n:v:b:hi-" opt ; do +while getopts "n:v:b:f:c:hi-" opt +do case "${opt}" in n) S_PNAME="${OPTARG}" @@ -38,6 +43,14 @@ i) GET_INVENTORY="true" ;; + f) + SEARCH_ONLY_PATH="true" + SEARCH_PATH="${OPTARG}" + ;; + c) + SEARCH_ONLY_CAT="true" + SEARCH_CAT="${OPTARG}" + ;; h) print_usage exit 0 @@ -54,10 +67,52 @@ done shift $(($OPTIND - 1)) - +source /etc/mage.rc.global source /etc/mage.rc RETVAL=1 +if [[ ${SEARCH_ONLY_PATH} = true ]] +then + unset S_PACKAGES + unset i pkg + for i in $(fgrep -rl "${SEARCH_PATH}" ${INSTALLDB}) + do + # ignore magefiles! + case ${i} in + *.mage) continue ;; + esac + + # print categorie and pkgname + pkg="$(basename ${i%/*/*})/$(basename ${i%/*})" + if [[ -z $(echo ${S_PACKAGES} | grep ${pkg}) ]] + then + S_PACKAGES="${S_PACKAGES} ${pkg}" + fi + done + + # show packages + for pkg in ${S_PACKAGES} + do + echo "${pkg}" + done + + exit 0 +fi + +if [[ ${SEARCH_ONLY_CAT} = true ]] +then + # no packages of SEARCH_CAT are installed + [[ ! -d ${MROOT}${INSTALLDB}/${SEARCH_CAT} ]] && exit 1 + + for i in ${INSTALLDB}/${SEARCH_CAT}/* + do + # print categorie and pkgname + echo "$(basename ${i%/*})/$(basename ${i})" + done + + exit 0 +fi + if [[ ${GET_INVENTORY} = true ]] then for package in $(find ${MROOT}${INSTALLDB} -mindepth 2 -maxdepth 2 -type d -printf "%h,%f\n" | sort)