Magellan Linux

Diff of /trunk/mage/usr/lib/mage/magequery.sh

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

revision 229 by niro, Fri Sep 9 16:51:51 2005 UTC revision 1206 by niro, Fri Jan 28 20:33:29 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.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 $
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 /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     # print categorie and pkgname
81     pkg="$(basename ${i%/*/*})/$(basename ${i%/*})"
82     if [[ -z $(echo ${S_PACKAGES} | grep ${pkg}) ]]
83     then
84     S_PACKAGES="${S_PACKAGES} ${pkg}"
85     fi
86     done
87    
88     # show packages
89     for pkg in ${S_PACKAGES}
90     do
91     echo "${pkg}"
92     done
93    
94     exit 0
95    fi
96    
97    if [[ ${SEARCH_ONLY_CAT} = true ]]
98    then
99     # no packages of SEARCH_CAT are installed
100     [[ ! -d ${MROOT}${INSTALLDB}/${SEARCH_CAT} ]] && exit 1
101    
102     for i in ${INSTALLDB}/${SEARCH_CAT}/*
103     do
104     # print categorie and pkgname
105     echo "$(basename ${i%/*})/$(basename ${i})"
106     done
107    
108     exit 0
109    fi
110    
111  if [[ ${GET_INVENTORY} = true ]]  if [[ ${GET_INVENTORY} = true ]]
112  then  then
113   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.229  
changed lines
  Added in v.1206