Magellan Linux

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

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

revision 57 by niro, Tue Feb 15 00:37:07 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  # version: 0.3.6-r12  # $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"
15     echo "    -f PATH   searches package names in given path"
16   echo   echo
17   echo " Examples:"   echo " Examples:"
18   echo   echo
# Line 18  print_usage() Line 21  print_usage()
21   echo   echo
22  }  }
23    
24  while getopts "n:v:b:h-" opt ; do  # default args:
25    GET_INVENTORY=false
26    SEARCH_ONLY_PATH=false
27    SEARCH_ONLY_CAT=false
28    
29    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 31  while getopts "n:v:b:h-" opt ; do Line 40  while getopts "n:v:b:h-" opt ; do
40   b)   b)
41   S_PBUILD="${OPTARG}"   S_PBUILD="${OPTARG}"
42   ;;   ;;
43     i)
44     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 47  while getopts "n:v:b:h-" opt ; do Line 67  while getopts "n:v:b:h-" 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  for i in ${INSTALLDB}/*/*  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 ]]
112    then
113     for package in $(find ${MROOT}${INSTALLDB} -mindepth 2 -maxdepth 2 -type d -printf "%h,%f\n" | sort)
114     do
115     pcat="$(basename $(echo ${package} | cut -d, -f1))"
116     pname="$(echo ${package} | cut -d, -f2)"
117     if [ -z "${invlist}" ]
118     then
119     invlist="${pcat}/${pname}"
120     else
121     invlist="${invlist}
122    ${pcat}/${pname}"
123     fi
124     done
125    
126     # now show the list
127     echo "${invlist}"
128     exit 0
129    fi
130    
131    for i in ${MROOT}${INSTALLDB}/*/*
132  do  do
133   INST_PNAME=no   INST_PNAME=no
134   INST_PVER=no   INST_PVER=no

Legend:
Removed from v.57  
changed lines
  Added in v.1206