Magellan Linux

Diff of /branches/mage-next/src/magequery.in

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 228 by niro, Fri Sep 9 16:51:17 2005 UTC revision 1288 by niro, Thu May 12 21:28:23 2011 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2    
3  #query mage database for installed packages  #query mage database for installed packages
4  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/magequery.sh,v 1.9 2005-09-09 16:51:17 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 $
5    
6  print_usage()  print_usage()
7  {  {
# Line 10  print_usage() Line 10  print_usage()
10   echo "    -n NAME   searches for name NAME"   echo "    -n NAME   searches for name NAME"
11   echo "    -v VER    searches for version VER, needs -n"   echo "    -v VER    searches for version VER, needs -n"
12   echo "    -b BUILD  searches for build number BUILD, needs -n -v"   echo "    -b BUILD  searches for build number BUILD, needs -n -v"
13     echo "    -c CAT    shows all packages of given categorie"
14   echo "    -i        shows an inventory of all installed packages"   echo "    -i        shows an inventory of all installed packages"
15     echo "    -f PATH   searches package names in given path"
16   echo   echo
17   echo " Examples:"   echo " Examples:"
18   echo   echo
# Line 21  print_usage() Line 23  print_usage()
23    
24  # default args:  # default args:
25  GET_INVENTORY=false  GET_INVENTORY=false
26    SEARCH_ONLY_PATH=false
27    SEARCH_ONLY_CAT=false
28    
29  while getopts "n:v:b:hi-" opt ; do  while getopts "n:v:b:f:c:hi-" opt
30    do
31   case "${opt}" in   case "${opt}" in
32   n)   n)
33   S_PNAME="${OPTARG}"   S_PNAME="${OPTARG}"
# Line 38  while getopts "n:v:b:hi-" opt ; do Line 43  while getopts "n:v:b:hi-" opt ; do
43   i)   i)
44   GET_INVENTORY="true"   GET_INVENTORY="true"
45   ;;   ;;
46     f)
47     SEARCH_ONLY_PATH="true"
48     SEARCH_PATH="${OPTARG}"
49     ;;
50     c)
51     SEARCH_ONLY_CAT="true"
52     SEARCH_CAT="${OPTARG}"
53     ;;
54   h)   h)
55   print_usage   print_usage
56   exit 0   exit 0
# Line 54  while getopts "n:v:b:hi-" opt ; do Line 67  while getopts "n:v:b:hi-" opt ; do
67  done  done
68  shift $(($OPTIND - 1))  shift $(($OPTIND - 1))
69    
70    source /etc/mage.rc.global
71  source ${MROOT}/etc/mage.rc  source /etc/mage.rc
72  RETVAL=1  RETVAL=1
73    
74    if [[ ${SEARCH_ONLY_PATH} = true ]]
75    then
76     unset S_PACKAGES
77     unset i pkg
78     for i in $(fgrep -rl "${SEARCH_PATH}" ${INSTALLDB})
79     do
80     # ignore magefiles!
81     case ${i} in
82     *.mage) continue ;;
83     esac
84    
85     # print categorie and pkgname
86     pkg="$(basename ${i%/*/*})/$(basename ${i%/*})"
87     if [[ -z $(echo ${S_PACKAGES} | grep ${pkg}) ]]
88     then
89     S_PACKAGES="${S_PACKAGES} ${pkg}"
90     fi
91     done
92    
93     # show packages
94     for pkg in ${S_PACKAGES}
95     do
96     echo "${pkg}"
97     done
98    
99     exit 0
100    fi
101    
102    if [[ ${SEARCH_ONLY_CAT} = true ]]
103    then
104     # no packages of SEARCH_CAT are installed
105     [[ ! -d ${MROOT}${INSTALLDB}/${SEARCH_CAT} ]] && exit 1
106    
107     for i in ${INSTALLDB}/${SEARCH_CAT}/*
108     do
109     # print categorie and pkgname
110     echo "$(basename ${i%/*})/$(basename ${i})"
111     done
112    
113     exit 0
114    fi
115    
116  if [[ ${GET_INVENTORY} = true ]]  if [[ ${GET_INVENTORY} = true ]]
117  then  then
118   for package in $(find ${MROOT}${INSTALLDB} -mindepth 2 -maxdepth 2 -type d -printf "%h,%f\n" | sort)   for package in $(find ${MROOT}${INSTALLDB} -mindepth 2 -maxdepth 2 -type d -printf "%h,%f\n" | sort)

Legend:
Removed from v.228  
changed lines
  Added in v.1288