Magellan Linux

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

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

revision 210 by niro, Sun Aug 28 19:17:48 2005 UTC revision 1509 by niro, Tue Aug 30 14:17:45 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.8 2005-08-28 19:17:48 niro Exp $  # $Id$
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 packages which own given file"
16     echo "    -e PATH   searches the package which owns the exact given filename"
17   echo   echo
18   echo " Examples:"   echo " Examples:"
19   echo   echo
# Line 21  print_usage() Line 24  print_usage()
24    
25  # default args:  # default args:
26  GET_INVENTORY=false  GET_INVENTORY=false
27    SEARCH_ONLY_PATH=false
28    SEARCH_ONLY_CAT=false
29    SEARCH_EXACT_FILENAME=false
30    
31  while getopts "n:v:b:hi-" opt ; do  # no params given, or is only an arg not ar param, exit
32   case "${opt}" in  if [[ $# -lt 1 ]] || [[ ${1:0:1} != - ]]
33   n)  then
34   S_PNAME="${OPTARG}"   print_usage
35   ;;   exit 1
36    fi
37   v)  
38   S_PVER="${OPTARG}"  # very basic getops
39   ;;  for i in $*
40    do
41   b)   case $1 in
42   S_PBUILD="${OPTARG}"   -n) shift; S_PNAME="$1" ;;
43   ;;   -v) shift; S_PVER="$1" ;;
44   i)   -b) shift; S_PBUILD="$1" ;;
45   GET_INVENTORY="true"   -i) GET_INVENTORY="true" ;;
46   ;;   -f) SEARCH_ONLY_PATH="true"; shift; SEARCH_PATH="$1" ;;
47   h)   -e) SEARCH_ONLY_PATH="true"; SEARCH_EXACT_FILENAME="true"; shift; SEARCH_PATH="$1" ;;
48   print_usage   -c) SEARCH_ONLY_CAT="true"; shift; SEARCH_CAT="$1" ;;
49   exit 0   -h) print_usage; exit 0 ;;
50   ;;   -*) print_usage; exit 1 ;;
   
  -) break  
  ;;  
   
  *)  
  print_usage  
  exit 1  
  ;;  
51   esac   esac
52     shift
53  done  done
 shift $(($OPTIND - 1))  
   
54    
55    source /etc/mage.rc.global
56  source /etc/mage.rc  source /etc/mage.rc
57  RETVAL=1  RETVAL=1
58    
59    if [[ ${SEARCH_ONLY_PATH} = true ]]
60    then
61     unset S_PACKAGES
62     unset i pkg
63     if [[ ${SEARCH_EXACT_FILENAME} = true ]]
64     then
65     # fix ++, which gets interpreted as a regex
66     SEARCH_PATH="${SEARCH_PATH//+/\\+}"
67     S_CANDIDATES=$(egrep -rl "^${SEARCH_PATH}§" ${INSTALLDB})
68     else
69     S_CANDIDATES=$(fgrep -rl "${SEARCH_PATH}" ${INSTALLDB})
70     fi
71     for i in ${S_CANDIDATES}
72     do
73     # ignore magefiles!
74     case ${i} in
75     *.mage) continue ;;
76     esac
77    
78     # print categorie and pkgname
79     pkg="$(basename ${i%/*/*})/$(basename ${i%/*})"
80     if [[ -z $(echo ${S_PACKAGES} | grep ${pkg}) ]]
81     then
82     S_PACKAGES="${S_PACKAGES} ${pkg}"
83     fi
84     done
85    
86     # show packages
87     for pkg in ${S_PACKAGES}
88     do
89     echo "${pkg}"
90     done
91    
92     exit 0
93    fi
94    
95    if [[ ${SEARCH_ONLY_CAT} = true ]]
96    then
97     # no packages of SEARCH_CAT are installed
98     [[ ! -d ${MROOT}${INSTALLDB}/${SEARCH_CAT} ]] && exit 1
99    
100     for i in ${INSTALLDB}/${SEARCH_CAT}/*
101     do
102     # print categorie and pkgname
103     echo "$(basename ${i%/*})/$(basename ${i})"
104     done
105    
106     exit 0
107    fi
108    
109  if [[ ${GET_INVENTORY} = true ]]  if [[ ${GET_INVENTORY} = true ]]
110  then  then
111   for package in $(find ${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)
112   do   do
113   pcat="$(basename $(echo ${package} | cut -d, -f1))"   pcat="$(basename $(echo ${package} | cut -d, -f1))"
114   pname="$(echo ${package} | cut -d, -f2)"   pname="$(echo ${package} | cut -d, -f2)"
115   if [ -z "${invlist}" ]   if [[ -z ${invlist} ]]
116   then   then
117   invlist="${pcat}/${pname}"   invlist="${pcat}/${pname}"
118   else   else
# Line 78  ${pcat}/${pname}" Line 126  ${pcat}/${pname}"
126   exit 0   exit 0
127  fi  fi
128    
129  for i in ${INSTALLDB}/*/*  for i in ${MROOT}${INSTALLDB}/*/*
130  do  do
131   INST_PNAME=no   INST_PNAME=no
132   INST_PVER=no   INST_PVER=no
# Line 86  do Line 134  do
134    
135   x=$(basename ${i})   x=$(basename ${i})
136   PNAME=${x%-*-*}   PNAME=${x%-*-*}
137   PVER=$(echo ${x#${PNAME}-}| cut -d- -f1)   PVER=$(echo ${x#${PNAME}-} | cut -d- -f1)
138   PBUILD=$(echo ${x#${PNAME}-}| cut -d- -f2)   PBUILD=$(echo ${x#${PNAME}-} | cut -d- -f2)
139    
140   if [[ ${PNAME} == ${S_PNAME} ]]   if [[ ${PNAME} == ${S_PNAME} ]]
141   then   then
142   INST_PNAME=yes   INST_PNAME=yes
143    
144   if [ -n "${S_PVER}" ]   if [[ -n ${S_PVER} ]]
145   then   then
146   if [[ ${PVER} == ${S_PVER} ]]   if [[ ${PVER} == ${S_PVER} ]]
147   then   then
148   INST_PVER=yes   INST_PVER=yes
149   fi   fi
150    
151   if [ -n "${S_PBUILD}" ]   if [[ -n ${S_PBUILD} ]]
152   then   then
153   if [[ ${PBUILD} == ${S_PBUILD} ]]   if [[ ${PBUILD} == ${S_PBUILD} ]]
154   then   then
# Line 110  do Line 158  do
158   fi   fi
159    
160   # search for pname only   # search for pname only
161   if [ -n "${S_PNAME}" -a -z "${S_PVER}" -a -z "${S_PBUILD}" ]   if [[ -n ${S_PNAME} ]] && [[ -z ${S_PVER} ]] && [[ -z ${S_PBUILD} ]]
162   then   then
163   if [ "${INST_PNAME}" = yes ]   if [[ ${INST_PNAME} = yes ]]
164   then   then
165   echo "${S_PNAME} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
166   RETVAL=0   RETVAL=0
# Line 121  do Line 169  do
169   fi   fi
170    
171   # search for pname and pver   # search for pname and pver
172   if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -z "${S_PBUILD}" ]   if [[ -n ${S_PNAME} ]] && [[ -n ${S_PVER} ]] && [[ -z ${S_PBUILD} ]]
173   then   then
174   if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes" ]   if [[ ${INST_PNAME} = yes ]] && [[ ${INST_PVER} = yes ]]
175   then   then
176   echo "${S_PNAME}-${S_PVER} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME}-${S_PVER} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
177   RETVAL=0   RETVAL=0
# Line 132  do Line 180  do
180   fi   fi
181    
182   # search for pname, pver and pbuild   # search for pname, pver and pbuild
183   if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -n "${S_PBUILD}" ]   if [[ -n ${S_PNAME} ]] && [[ -n ${S_PVER} ]] && [[ -n ${S_PBUILD} ]]
184   then   then
185   if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes"  -a "${INST_PBUILD}" = "yes" ]   if [[ ${INST_PNAME} = yes ]] && [[ ${INST_PVER} = yes ]] && [[ ${INST_PBUILD} = yes ]]
186   then   then
187   echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
188   RETVAL=0   RETVAL=0

Legend:
Removed from v.210  
changed lines
  Added in v.1509