Magellan Linux

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

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

revision 33 by niro, Thu Jan 6 02:57:12 2005 UTC revision 1503 by niro, Tue Aug 30 12:19:11 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-r9  # $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 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 18  print_usage() Line 22  print_usage()
22   echo   echo
23  }  }
24    
25  while getopts "n:v:b:h-" opt ; do  # default args:
26   case "${opt}" in  GET_INVENTORY=false
27   n)  SEARCH_ONLY_PATH=false
28   S_PNAME="${OPTARG}"  SEARCH_ONLY_CAT=false
29   ;;  SEARCH_EXACT_FILENAME=false
30    
31   v)  # no params given, or is only an arg not ar param, exit
32   S_PVER="${OPTARG}"  if [[ $# -lt 1 ]] || [[ ${1:0:1} != - ]]
33   ;;  then
34     print_usage
35   b)   exit 1
36   S_PBUILD="${OPTARG}"  fi
37   ;;  
38   h)  # very basic getops
39   print_usage  for i in $*
40   exit 0  do
41   ;;   case $1 in
42     -n) shift; S_PNAME="$1" ;;
43   -) break   -v) shift; S_PVER="$1" ;;
44   ;;   -b) shift; S_PBUILD="$1" ;;
45     -i) GET_INVENTORY="true" ;;
46   *)   -f) SEARCH_ONLY_PATH="true"; shift; SEARCH_PATH="$1" ;;
47   print_usage   -e) SEARCH_ONLY_PATH="true"; SEARCH_EXACT_FILENAME="true"; shift; SEARCH_PATH="$1" ;;
48   exit 1   -c) SEARCH_ONLY_CAT="true"; shift; SEARCH_CAT="$1" ;;
49   ;;   -h) print_usage; exit 0 ;;
50     -*) 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  for i in ${INSTALLDB}/*/*  if [[ ${SEARCH_ONLY_PATH} = true ]]
60    then
61     unset S_PACKAGES
62     unset i pkg
63     if [[ ${SEARCH_EXACT_FILENAME} = true ]]
64     then
65     S_CANDIDATES=$(egrep -rl "${SEARCH_PATH}ยง" ${INSTALLDB})
66     else
67     S_CANDIDATES=$(fgrep -rl "${SEARCH_PATH}" ${INSTALLDB})
68     fi
69     for i in ${S_CANDIDATES}
70     do
71     # ignore magefiles!
72     case ${i} in
73     *.mage) continue ;;
74     esac
75    
76     # print categorie and pkgname
77     pkg="$(basename ${i%/*/*})/$(basename ${i%/*})"
78     if [[ -z $(echo ${S_PACKAGES} | grep ${pkg}) ]]
79     then
80     S_PACKAGES="${S_PACKAGES} ${pkg}"
81     fi
82     done
83    
84     # show packages
85     for pkg in ${S_PACKAGES}
86     do
87     echo "${pkg}"
88     done
89    
90     exit 0
91    fi
92    
93    if [[ ${SEARCH_ONLY_CAT} = true ]]
94    then
95     # no packages of SEARCH_CAT are installed
96     [[ ! -d ${MROOT}${INSTALLDB}/${SEARCH_CAT} ]] && exit 1
97    
98     for i in ${INSTALLDB}/${SEARCH_CAT}/*
99     do
100     # print categorie and pkgname
101     echo "$(basename ${i%/*})/$(basename ${i})"
102     done
103    
104     exit 0
105    fi
106    
107    if [[ ${GET_INVENTORY} = true ]]
108    then
109     for package in $(find ${MROOT}${INSTALLDB} -mindepth 2 -maxdepth 2 -type d -printf "%h,%f\n" | sort)
110     do
111     pcat="$(basename $(echo ${package} | cut -d, -f1))"
112     pname="$(echo ${package} | cut -d, -f2)"
113     if [[ -z ${invlist} ]]
114     then
115     invlist="${pcat}/${pname}"
116     else
117     invlist="${invlist}
118    ${pcat}/${pname}"
119     fi
120     done
121    
122     # now show the list
123     echo "${invlist}"
124     exit 0
125    fi
126    
127    for i in ${MROOT}${INSTALLDB}/*/*
128  do  do
129   INST_PNAME=no   INST_PNAME=no
130   INST_PVER=no   INST_PVER=no
# Line 59  do Line 132  do
132    
133   x=$(basename ${i})   x=$(basename ${i})
134   PNAME=${x%-*-*}   PNAME=${x%-*-*}
135   PVER=$(echo ${x#${PNAME}-}| cut -d- -f1)   PVER=$(echo ${x#${PNAME}-} | cut -d- -f1)
136   PBUILD=$(echo ${x#${PNAME}-}| cut -d- -f2)   PBUILD=$(echo ${x#${PNAME}-} | cut -d- -f2)
137    
138   if [[ ${PNAME} == ${S_PNAME} ]]   if [[ ${PNAME} == ${S_PNAME} ]]
139   then   then
140   INST_PNAME=yes   INST_PNAME=yes
141    
142   if [ -n "${S_PVER}" ]   if [[ -n ${S_PVER} ]]
143   then   then
144   if [[ ${PVER} == ${S_PVER} ]]   if [[ ${PVER} == ${S_PVER} ]]
145   then   then
146   INST_PVER=yes   INST_PVER=yes
147   fi   fi
148    
149   if [ -n "${S_PBUILD}" ]   if [[ -n ${S_PBUILD} ]]
150   then   then
151   if [[ ${PBUILD} == ${S_PBUILD} ]]   if [[ ${PBUILD} == ${S_PBUILD} ]]
152   then   then
# Line 83  do Line 156  do
156   fi   fi
157    
158   # search for pname only   # search for pname only
159   if [ -n "${S_PNAME}" -a -z "${S_PVER}" -a -z "${S_PBUILD}" ]   if [[ -n ${S_PNAME} ]] && [[ -z ${S_PVER} ]] && [[ -z ${S_PBUILD} ]]
160   then   then
161   if [ "${INST_PNAME}" = yes ]   if [[ ${INST_PNAME} = yes ]]
162   then   then
163   echo "${S_PNAME} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
164   RETVAL=0   RETVAL=0
# Line 94  do Line 167  do
167   fi   fi
168    
169   # search for pname and pver   # search for pname and pver
170   if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -z "${S_PBUILD}" ]   if [[ -n ${S_PNAME} ]] && [[ -n ${S_PVER} ]] && [[ -z ${S_PBUILD} ]]
171   then   then
172   if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes" ]   if [[ ${INST_PNAME} = yes ]] && [[ ${INST_PVER} = yes ]]
173   then   then
174   echo "${S_PNAME}-${S_PVER} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME}-${S_PVER} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
175   RETVAL=0   RETVAL=0
# Line 105  do Line 178  do
178   fi   fi
179    
180   # search for pname, pver and pbuild   # search for pname, pver and pbuild
181   if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -n "${S_PBUILD}" ]   if [[ -n ${S_PNAME} ]] && [[ -n ${S_PVER} ]] && [[ -n ${S_PBUILD} ]]
182   then   then
183   if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes"  -a "${INST_PBUILD}" = "yes" ]   if [[ ${INST_PNAME} = yes ]] && [[ ${INST_PVER} = yes ]] && [[ ${INST_PBUILD} = yes ]]
184   then   then
185   echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
186   RETVAL=0   RETVAL=0

Legend:
Removed from v.33  
changed lines
  Added in v.1503