Magellan Linux

Annotation of /tags/mage-0_4_29/usr/lib/mage/magequery.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1206 - (hide annotations) (download) (as text)
Fri Jan 28 20:33:29 2011 UTC (13 years, 3 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/magequery.sh
File MIME type: application/x-sh
File size: 3811 byte(s)
-fixed a typo and some cosmetics
1 niro 32 #!/bin/bash
2    
3     #query mage database for installed packages
4 niro 777 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/magequery.sh,v 1.13 2008-10-05 10:33:04 niro Exp $
5 niro 32
6     print_usage()
7     {
8     echo "$(basename $0 .sh) querys the mage database for installed packages."
9     echo
10     echo " -n NAME searches for name NAME"
11     echo " -v VER searches for version VER, needs -n"
12     echo " -b BUILD searches for build number BUILD, needs -n -v"
13 niro 777 echo " -c CAT shows all packages of given categorie"
14 niro 210 echo " -i shows an inventory of all installed packages"
15 niro 1206 echo " -f PATH searches package names in given path"
16 niro 32 echo
17     echo " Examples:"
18     echo
19     echo " $(basename $0 .sh) -n xorg -v 6.8.0 -b r1"
20     echo " searches for package xorg-6.8.0-r1"
21     echo
22     }
23    
24 niro 210 # default args:
25     GET_INVENTORY=false
26 niro 304 SEARCH_ONLY_PATH=false
27 niro 777 SEARCH_ONLY_CAT=false
28 niro 210
29 niro 1206 while getopts "n:v:b:f:c:hi-" opt
30     do
31 niro 32 case "${opt}" in
32     n)
33     S_PNAME="${OPTARG}"
34     ;;
35    
36     v)
37     S_PVER="${OPTARG}"
38     ;;
39    
40     b)
41     S_PBUILD="${OPTARG}"
42     ;;
43 niro 210 i)
44     GET_INVENTORY="true"
45     ;;
46 niro 304 f)
47     SEARCH_ONLY_PATH="true"
48     SEARCH_PATH="${OPTARG}"
49     ;;
50 niro 777 c)
51     SEARCH_ONLY_CAT="true"
52     SEARCH_CAT="${OPTARG}"
53     ;;
54 niro 32 h)
55     print_usage
56     exit 0
57     ;;
58    
59     -) break
60     ;;
61    
62     *)
63     print_usage
64     exit 1
65     ;;
66     esac
67     done
68     shift $(($OPTIND - 1))
69    
70 niro 304 source /etc/mage.rc.global
71 niro 229 source /etc/mage.rc
72 niro 32 RETVAL=1
73    
74 niro 304 if [[ ${SEARCH_ONLY_PATH} = true ]]
75     then
76     unset S_PACKAGES
77     unset i pkg
78 niro 332 for i in $(fgrep -rl "${SEARCH_PATH}" ${INSTALLDB})
79 niro 304 do
80 niro 332 # print categorie and pkgname
81     pkg="$(basename ${i%/*/*})/$(basename ${i%/*})"
82 niro 304 if [[ -z $(echo ${S_PACKAGES} | grep ${pkg}) ]]
83     then
84     S_PACKAGES="${S_PACKAGES} ${pkg}"
85     fi
86     done
87    
88     # show packages
89     for pkg in ${S_PACKAGES}
90     do
91     echo "${pkg}"
92     done
93    
94     exit 0
95     fi
96    
97 niro 777 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 niro 210 if [[ ${GET_INVENTORY} = true ]]
112     then
113 niro 228 for package in $(find ${MROOT}${INSTALLDB} -mindepth 2 -maxdepth 2 -type d -printf "%h,%f\n" | sort)
114 niro 210 do
115     pcat="$(basename $(echo ${package} | cut -d, -f1))"
116     pname="$(echo ${package} | cut -d, -f2)"
117     if [ -z "${invlist}" ]
118     then
119     invlist="${pcat}/${pname}"
120     else
121     invlist="${invlist}
122     ${pcat}/${pname}"
123     fi
124     done
125    
126     # now show the list
127     echo "${invlist}"
128     exit 0
129     fi
130    
131 niro 228 for i in ${MROOT}${INSTALLDB}/*/*
132 niro 32 do
133     INST_PNAME=no
134     INST_PVER=no
135     INST_PBUILD=no
136    
137     x=$(basename ${i})
138     PNAME=${x%-*-*}
139     PVER=$(echo ${x#${PNAME}-}| cut -d- -f1)
140     PBUILD=$(echo ${x#${PNAME}-}| cut -d- -f2)
141    
142     if [[ ${PNAME} == ${S_PNAME} ]]
143     then
144     INST_PNAME=yes
145    
146     if [ -n "${S_PVER}" ]
147     then
148     if [[ ${PVER} == ${S_PVER} ]]
149     then
150     INST_PVER=yes
151     fi
152    
153     if [ -n "${S_PBUILD}" ]
154     then
155     if [[ ${PBUILD} == ${S_PBUILD} ]]
156     then
157     INST_PBUILD=yes
158     fi
159     fi
160     fi
161    
162     # search for pname only
163     if [ -n "${S_PNAME}" -a -z "${S_PVER}" -a -z "${S_PBUILD}" ]
164     then
165     if [ "${INST_PNAME}" = yes ]
166     then
167     echo "${S_PNAME} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
168     RETVAL=0
169     break
170     fi
171     fi
172    
173     # search for pname and pver
174     if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -z "${S_PBUILD}" ]
175     then
176     if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes" ]
177     then
178     echo "${S_PNAME}-${S_PVER} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
179     RETVAL=0
180     break
181     fi
182     fi
183    
184     # search for pname, pver and pbuild
185     if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -n "${S_PBUILD}" ]
186     then
187     if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes" -a "${INST_PBUILD}" = "yes" ]
188     then
189     echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
190     RETVAL=0
191     break
192     fi
193     fi
194     fi
195     done
196    
197     exit ${RETVAL}