Magellan Linux

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

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

revision 304 by niro, Mon Dec 26 23:12:44 2005 UTC revision 1540 by niro, Tue Dec 20 12:50:13 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.11 2005-12-26 23:12:44 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        searches packages name in given path"   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 23  print_usage() Line 25  print_usage()
25  # default args:  # default args:
26  GET_INVENTORY=false  GET_INVENTORY=false
27  SEARCH_ONLY_PATH=false  SEARCH_ONLY_PATH=false
28    SEARCH_ONLY_CAT=false
29    SEARCH_EXACT_FILENAME=false
30    
31  while getopts "n:v:b:f: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   f)   -e) SEARCH_ONLY_PATH="true"; SEARCH_EXACT_FILENAME="true"; shift; SEARCH_PATH="$1" ;;
48   SEARCH_ONLY_PATH="true"   -c) SEARCH_ONLY_CAT="true"; shift; SEARCH_CAT="$1" ;;
49   SEARCH_PATH="${OPTARG}"   -h) print_usage; exit 0 ;;
50   ;;   -*) print_usage; exit 1 ;;
  h)  
  print_usage  
  exit 0  
  ;;  
   
  -) break  
  ;;  
   
  *)  
  print_usage  
  exit 1  
  ;;  
51   esac   esac
52     shift
53  done  done
 shift $(($OPTIND - 1))  
54    
55  source /etc/mage.rc.global  source /etc/mage.rc.global
56  source /etc/mage.rc  source /etc/mage.rc
# Line 68  if [[ ${SEARCH_ONLY_PATH} = true ]] Line 60  if [[ ${SEARCH_ONLY_PATH} = true ]]
60  then  then
61   unset S_PACKAGES   unset S_PACKAGES
62   unset i pkg   unset i pkg
63   for i in $(grep -irl "${SEARCH_PATH}" ${INSTALLDB})   if [[ ${SEARCH_EXACT_FILENAME} = true ]]
64     then
65     # fix ++, which gets interpreted as a regex
66     SEARCH_PATH="${SEARCH_PATH//+/\\+}"
67     # fix [, which gets interpreted as a regex
68     SEARCH_PATH="${SEARCH_PATH//[/\\[}"
69     S_CANDIDATES=$(egrep -rl "^${SEARCH_PATH}§" ${INSTALLDB})
70     else
71     S_CANDIDATES=$(fgrep -rl "${SEARCH_PATH}" ${INSTALLDB})
72     fi
73     for i in ${S_CANDIDATES}
74   do   do
75   pkg="$(basename $(dirname ${i}))"   # ignore magefiles!
76     case ${i} in
77     *.mage) continue ;;
78     esac
79    
80     # print categorie and pkgname
81     pkg="$(basename ${i%/*/*})/$(basename ${i%/*})"
82   if [[ -z $(echo ${S_PACKAGES} | grep ${pkg}) ]]   if [[ -z $(echo ${S_PACKAGES} | grep ${pkg}) ]]
83   then   then
84   S_PACKAGES="${S_PACKAGES} ${pkg}"   S_PACKAGES="${S_PACKAGES} ${pkg}"
# Line 86  then Line 94  then
94   exit 0   exit 0
95  fi  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 ]]  if [[ ${GET_INVENTORY} = true ]]
112  then  then
113   for package in $(find ${MROOT}${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)
114   do   do
115   pcat="$(basename $(echo ${package} | cut -d, -f1))"   pcat="$(basename $(echo ${package} | cut -d, -f1))"
116   pname="$(echo ${package} | cut -d, -f2)"   pname="$(echo ${package} | cut -d, -f2)"
117   if [ -z "${invlist}" ]   if [[ -z ${invlist} ]]
118   then   then
119   invlist="${pcat}/${pname}"   invlist="${pcat}/${pname}"
120   else   else
# Line 114  do Line 136  do
136    
137   x=$(basename ${i})   x=$(basename ${i})
138   PNAME=${x%-*-*}   PNAME=${x%-*-*}
139   PVER=$(echo ${x#${PNAME}-}| cut -d- -f1)   PVER=$(echo ${x#${PNAME}-} | cut -d- -f1)
140   PBUILD=$(echo ${x#${PNAME}-}| cut -d- -f2)   PBUILD=$(echo ${x#${PNAME}-} | cut -d- -f2)
141    
142   if [[ ${PNAME} == ${S_PNAME} ]]   if [[ ${PNAME} == ${S_PNAME} ]]
143   then   then
144   INST_PNAME=yes   INST_PNAME=yes
145    
146   if [ -n "${S_PVER}" ]   if [[ -n ${S_PVER} ]]
147   then   then
148   if [[ ${PVER} == ${S_PVER} ]]   if [[ ${PVER} == ${S_PVER} ]]
149   then   then
150   INST_PVER=yes   INST_PVER=yes
151   fi   fi
152    
153   if [ -n "${S_PBUILD}" ]   if [[ -n ${S_PBUILD} ]]
154   then   then
155   if [[ ${PBUILD} == ${S_PBUILD} ]]   if [[ ${PBUILD} == ${S_PBUILD} ]]
156   then   then
# Line 138  do Line 160  do
160   fi   fi
161    
162   # search for pname only   # search for pname only
163   if [ -n "${S_PNAME}" -a -z "${S_PVER}" -a -z "${S_PBUILD}" ]   if [[ -n ${S_PNAME} ]] && [[ -z ${S_PVER} ]] && [[ -z ${S_PBUILD} ]]
164   then   then
165   if [ "${INST_PNAME}" = yes ]   if [[ ${INST_PNAME} = yes ]]
166   then   then
167   echo "${S_PNAME} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
168   RETVAL=0   RETVAL=0
# Line 149  do Line 171  do
171   fi   fi
172    
173   # search for pname and pver   # search for pname and pver
174   if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -z "${S_PBUILD}" ]   if [[ -n ${S_PNAME} ]] && [[ -n ${S_PVER} ]] && [[ -z ${S_PBUILD} ]]
175   then   then
176   if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes" ]   if [[ ${INST_PNAME} = yes ]] && [[ ${INST_PVER} = yes ]]
177   then   then
178   echo "${S_PNAME}-${S_PVER} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME}-${S_PVER} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
179   RETVAL=0   RETVAL=0
# Line 160  do Line 182  do
182   fi   fi
183    
184   # search for pname, pver and pbuild   # search for pname, pver and pbuild
185   if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -n "${S_PBUILD}" ]   if [[ -n ${S_PNAME} ]] && [[ -n ${S_PVER} ]] && [[ -n ${S_PBUILD} ]]
186   then   then
187   if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes"  -a "${INST_PBUILD}" = "yes" ]   if [[ ${INST_PNAME} = yes ]] && [[ ${INST_PVER} = yes ]] && [[ ${INST_PBUILD} = yes ]]
188   then   then
189   echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
190   RETVAL=0   RETVAL=0

Legend:
Removed from v.304  
changed lines
  Added in v.1540