Magellan Linux

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

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

revision 1289 by niro, Thu May 12 21:28:23 2011 UTC revision 1290 by niro, Thu May 12 22:20:59 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.13 2008-10-05 10:33:04 niro Exp $  # $Id$
5    
6  print_usage()  print_usage()
7  {  {
# Line 26  GET_INVENTORY=false Line 26  GET_INVENTORY=false
26  SEARCH_ONLY_PATH=false  SEARCH_ONLY_PATH=false
27  SEARCH_ONLY_CAT=false  SEARCH_ONLY_CAT=false
28    
29  while getopts "n:v:b:f:c:hi-" opt  # no params given, or is only an arg not ar param, exit
30    if [[ $# -lt 1 ]] || [[ ${1:0:1} != - ]]
31    then
32     print_usage
33     exit 1
34    fi
35    
36    # very basic getops
37    for i in $*
38  do  do
39   case "${opt}" in   case $1 in
40   n)   -n) shift; S_PNAME="$1" ;;
41   S_PNAME="${OPTARG}"   -v) shift; S_PVER="$1" ;;
42   ;;   -b) shift; S_PBUILD="$1" ;;
43     -i) GET_INVENTORY="true" ;;
44   v)   -f) SEARCH_ONLY_PATH="true"; shift; SEARCH_PATH="$1" ;;
45   S_PVER="${OPTARG}"   -c) SEARCH_ONLY_CAT="true"; shift; SEARCH_CAT="$1" ;;
46   ;;   -h) print_usage; exit 0 ;;
47     -*) print_usage; exit 1 ;;
  b)  
  S_PBUILD="${OPTARG}"  
  ;;  
  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  
  ;;  
   
  -) break  
  ;;  
   
  *)  
  print_usage  
  exit 1  
  ;;  
48   esac   esac
49     shift
50  done  done
 shift $(($OPTIND - 1))  
51    
52  source /etc/mage.rc.global  source /etc/mage.rc.global
53  source /etc/mage.rc  source /etc/mage.rc
# Line 119  then Line 101  then
101   do   do
102   pcat="$(basename $(echo ${package} | cut -d, -f1))"   pcat="$(basename $(echo ${package} | cut -d, -f1))"
103   pname="$(echo ${package} | cut -d, -f2)"   pname="$(echo ${package} | cut -d, -f2)"
104   if [ -z "${invlist}" ]   if [[ -z ${invlist} ]]
105   then   then
106   invlist="${pcat}/${pname}"   invlist="${pcat}/${pname}"
107   else   else
# Line 141  do Line 123  do
123    
124   x=$(basename ${i})   x=$(basename ${i})
125   PNAME=${x%-*-*}   PNAME=${x%-*-*}
126   PVER=$(echo ${x#${PNAME}-}| cut -d- -f1)   PVER=$(echo ${x#${PNAME}-} | cut -d- -f1)
127   PBUILD=$(echo ${x#${PNAME}-}| cut -d- -f2)   PBUILD=$(echo ${x#${PNAME}-} | cut -d- -f2)
128    
129   if [[ ${PNAME} == ${S_PNAME} ]]   if [[ ${PNAME} == ${S_PNAME} ]]
130   then   then
131   INST_PNAME=yes   INST_PNAME=yes
132    
133   if [ -n "${S_PVER}" ]   if [[ -n ${S_PVER} ]]
134   then   then
135   if [[ ${PVER} == ${S_PVER} ]]   if [[ ${PVER} == ${S_PVER} ]]
136   then   then
137   INST_PVER=yes   INST_PVER=yes
138   fi   fi
139    
140   if [ -n "${S_PBUILD}" ]   if [[ -n ${S_PBUILD} ]]
141   then   then
142   if [[ ${PBUILD} == ${S_PBUILD} ]]   if [[ ${PBUILD} == ${S_PBUILD} ]]
143   then   then
# Line 165  do Line 147  do
147   fi   fi
148    
149   # search for pname only   # search for pname only
150   if [ -n "${S_PNAME}" -a -z "${S_PVER}" -a -z "${S_PBUILD}" ]   if [[ -n ${S_PNAME} ]] && [[ -z ${S_PVER} ]] && [[ -z ${S_PBUILD} ]]
151   then   then
152   if [ "${INST_PNAME}" = yes ]   if [[ ${INST_PNAME} = yes ]]
153   then   then
154   echo "${S_PNAME} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
155   RETVAL=0   RETVAL=0
# Line 176  do Line 158  do
158   fi   fi
159    
160   # search for pname and pver   # search for pname and pver
161   if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -z "${S_PBUILD}" ]   if [[ -n ${S_PNAME} ]] && [[ -n ${S_PVER} ]] && [[ -z ${S_PBUILD} ]]
162   then   then
163   if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes" ]   if [[ ${INST_PNAME} = yes ]] && [[ ${INST_PVER} = yes ]]
164   then   then
165   echo "${S_PNAME}-${S_PVER} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME}-${S_PVER} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
166   RETVAL=0   RETVAL=0
# Line 187  do Line 169  do
169   fi   fi
170    
171   # search for pname, pver and pbuild   # search for pname, pver and pbuild
172   if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -n "${S_PBUILD}" ]   if [[ -n ${S_PNAME} ]] && [[ -n ${S_PVER} ]] && [[ -n ${S_PBUILD} ]]
173   then   then
174   if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes"  -a "${INST_PBUILD}" = "yes" ]   if [[ ${INST_PNAME} = yes ]] && [[ ${INST_PVER} = yes ]] && [[ ${INST_PBUILD} = yes ]]
175   then   then
176   echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
177   RETVAL=0   RETVAL=0

Legend:
Removed from v.1289  
changed lines
  Added in v.1290