Magellan Linux

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

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

revision 43 by niro, Mon Jan 10 01:59:03 2005 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  # version: 0.3.6-r11  # $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"
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   case "${opt}" in  GET_INVENTORY=false
26   n)  SEARCH_ONLY_PATH=false
27   S_PNAME="${OPTARG}"  SEARCH_ONLY_CAT=false
28   ;;  
29    # no params given, or is only an arg not ar param, exit
30   v)  if [[ $# -lt 1 ]] || [[ ${1:0:1} != - ]]
31   S_PVER="${OPTARG}"  then
32   ;;   print_usage
33     exit 1
34   b)  fi
35   S_PBUILD="${OPTARG}"  
36   ;;  # very basic getops
37   h)  for i in $*
38   print_usage  do
39   exit 0   case $1 in
40   ;;   -n) shift; S_PNAME="$1" ;;
41     -v) shift; S_PVER="$1" ;;
42   -) break   -b) shift; S_PBUILD="$1" ;;
43   ;;   -i) GET_INVENTORY="true" ;;
44     -f) SEARCH_ONLY_PATH="true"; shift; SEARCH_PATH="$1" ;;
45   *)   -c) SEARCH_ONLY_CAT="true"; shift; SEARCH_CAT="$1" ;;
46   print_usage   -h) print_usage; exit 0 ;;
47   exit 1   -*) print_usage; exit 1 ;;
  ;;  
48   esac   esac
49     shift
50  done  done
 shift $(($OPTIND - 1))  
   
51    
52    source /etc/mage.rc.global
53  source /etc/mage.rc  source /etc/mage.rc
54  RETVAL=1  RETVAL=1
55    
56  for i in ${INSTALLDB}/*/*  if [[ ${SEARCH_ONLY_PATH} = true ]]
57    then
58     unset S_PACKAGES
59     unset i pkg
60     for i in $(fgrep -rl "${SEARCH_PATH}" ${INSTALLDB})
61     do
62     # ignore magefiles!
63     case ${i} in
64     *.mage) continue ;;
65     esac
66    
67     # print categorie and pkgname
68     pkg="$(basename ${i%/*/*})/$(basename ${i%/*})"
69     if [[ -z $(echo ${S_PACKAGES} | grep ${pkg}) ]]
70     then
71     S_PACKAGES="${S_PACKAGES} ${pkg}"
72     fi
73     done
74    
75     # show packages
76     for pkg in ${S_PACKAGES}
77     do
78     echo "${pkg}"
79     done
80    
81     exit 0
82    fi
83    
84    if [[ ${SEARCH_ONLY_CAT} = true ]]
85    then
86     # no packages of SEARCH_CAT are installed
87     [[ ! -d ${MROOT}${INSTALLDB}/${SEARCH_CAT} ]] && exit 1
88    
89     for i in ${INSTALLDB}/${SEARCH_CAT}/*
90     do
91     # print categorie and pkgname
92     echo "$(basename ${i%/*})/$(basename ${i})"
93     done
94    
95     exit 0
96    fi
97    
98    if [[ ${GET_INVENTORY} = true ]]
99    then
100     for package in $(find ${MROOT}${INSTALLDB} -mindepth 2 -maxdepth 2 -type d -printf "%h,%f\n" | sort)
101     do
102     pcat="$(basename $(echo ${package} | cut -d, -f1))"
103     pname="$(echo ${package} | cut -d, -f2)"
104     if [[ -z ${invlist} ]]
105     then
106     invlist="${pcat}/${pname}"
107     else
108     invlist="${invlist}
109    ${pcat}/${pname}"
110     fi
111     done
112    
113     # now show the list
114     echo "${invlist}"
115     exit 0
116    fi
117    
118    for i in ${MROOT}${INSTALLDB}/*/*
119  do  do
120   INST_PNAME=no   INST_PNAME=no
121   INST_PVER=no   INST_PVER=no
# Line 59  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 83  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 94  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 105  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.43  
changed lines
  Added in v.1290