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 |
|
# always export C locale to fix utf-8 issues |
7 |
|
export LC_ALL=C |
8 |
|
|
9 |
print_usage() |
print_usage() |
10 |
{ |
{ |
15 |
echo " -b BUILD searches for build number BUILD, needs -n -v" |
echo " -b BUILD searches for build number BUILD, needs -n -v" |
16 |
echo " -c CAT shows all packages of given categorie" |
echo " -c CAT shows all packages of given categorie" |
17 |
echo " -i shows an inventory of all installed packages" |
echo " -i shows an inventory of all installed packages" |
18 |
echo " -f PATH searches packages name in given path" |
echo " -f PATH searches packages which own given file" |
19 |
|
echo " -e PATH searches the package which owns the exact given filename" |
20 |
echo |
echo |
21 |
echo " Examples:" |
echo " Examples:" |
22 |
echo |
echo |
29 |
GET_INVENTORY=false |
GET_INVENTORY=false |
30 |
SEARCH_ONLY_PATH=false |
SEARCH_ONLY_PATH=false |
31 |
SEARCH_ONLY_CAT=false |
SEARCH_ONLY_CAT=false |
32 |
|
SEARCH_EXACT_FILENAME=false |
33 |
|
|
34 |
|
# no params given, or is only an arg not ar param, exit |
35 |
|
if [[ $# -lt 1 ]] || [[ ${1:0:1} != - ]] |
36 |
|
then |
37 |
|
print_usage |
38 |
|
exit 1 |
39 |
|
fi |
40 |
|
|
41 |
while getopts "n:v:b:f:c:hi-" opt ; do |
# very basic getops |
42 |
case "${opt}" in |
for i in $* |
43 |
n) |
do |
44 |
S_PNAME="${OPTARG}" |
case $1 in |
45 |
;; |
-n) shift; S_PNAME="$1" ;; |
46 |
|
-v) shift; S_PVER="$1" ;; |
47 |
v) |
-b) shift; S_PBUILD="$1" ;; |
48 |
S_PVER="${OPTARG}" |
-i) GET_INVENTORY="true" ;; |
49 |
;; |
-f) SEARCH_ONLY_PATH="true"; shift; SEARCH_PATH="$1" ;; |
50 |
|
-e) SEARCH_ONLY_PATH="true"; SEARCH_EXACT_FILENAME="true"; shift; SEARCH_PATH="$1" ;; |
51 |
b) |
-c) SEARCH_ONLY_CAT="true"; shift; SEARCH_CAT="$1" ;; |
52 |
S_PBUILD="${OPTARG}" |
-h) print_usage; exit 0 ;; |
53 |
;; |
-*) print_usage; exit 1 ;; |
|
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 |
|
|
;; |
|
54 |
esac |
esac |
55 |
|
shift |
56 |
done |
done |
|
shift $(($OPTIND - 1)) |
|
57 |
|
|
58 |
source /etc/mage.rc.global |
source /etc/mage.rc.global |
59 |
source /etc/mage.rc |
source ${MAGERC} |
60 |
RETVAL=1 |
RETVAL=1 |
61 |
|
|
62 |
if [[ ${SEARCH_ONLY_PATH} = true ]] |
if [[ ${SEARCH_ONLY_PATH} = true ]] |
63 |
then |
then |
64 |
unset S_PACKAGES |
unset S_PACKAGES |
65 |
unset i pkg |
unset i pkg |
66 |
for i in $(fgrep -rl "${SEARCH_PATH}" ${INSTALLDB}) |
if [[ ${SEARCH_EXACT_FILENAME} = true ]] |
67 |
|
then |
68 |
|
# fix ++, which gets interpreted as a regex |
69 |
|
SEARCH_PATH="${SEARCH_PATH//+/\\+}" |
70 |
|
# fix [, which gets interpreted as a regex |
71 |
|
SEARCH_PATH="${SEARCH_PATH//[/\\[}" |
72 |
|
S_CANDIDATES=$(egrep -rl "^${SEARCH_PATH}§" ${INSTALLDB}) |
73 |
|
else |
74 |
|
S_CANDIDATES=$(fgrep -rl "${SEARCH_PATH}" ${INSTALLDB}) |
75 |
|
fi |
76 |
|
for i in ${S_CANDIDATES} |
77 |
do |
do |
78 |
|
# ignore magefiles! |
79 |
|
case ${i} in |
80 |
|
*.mage) continue ;; |
81 |
|
esac |
82 |
|
|
83 |
# print categorie and pkgname |
# print categorie and pkgname |
84 |
pkg="$(basename ${i%/*/*})/$(basename ${i%/*})" |
pkg="$(basename ${i%/*/*})/$(basename ${i%/*})" |
85 |
if [[ -z $(echo ${S_PACKAGES} | grep ${pkg}) ]] |
if [[ -z $(echo ${S_PACKAGES} | grep ${pkg}) ]] |
117 |
do |
do |
118 |
pcat="$(basename $(echo ${package} | cut -d, -f1))" |
pcat="$(basename $(echo ${package} | cut -d, -f1))" |
119 |
pname="$(echo ${package} | cut -d, -f2)" |
pname="$(echo ${package} | cut -d, -f2)" |
120 |
if [ -z "${invlist}" ] |
if [[ -z ${invlist} ]] |
121 |
then |
then |
122 |
invlist="${pcat}/${pname}" |
invlist="${pcat}/${pname}" |
123 |
else |
else |
139 |
|
|
140 |
x=$(basename ${i}) |
x=$(basename ${i}) |
141 |
PNAME=${x%-*-*} |
PNAME=${x%-*-*} |
142 |
PVER=$(echo ${x#${PNAME}-}| cut -d- -f1) |
PVER=$(echo ${x#${PNAME}-} | cut -d- -f1) |
143 |
PBUILD=$(echo ${x#${PNAME}-}| cut -d- -f2) |
PBUILD=$(echo ${x#${PNAME}-} | cut -d- -f2) |
144 |
|
|
145 |
if [[ ${PNAME} == ${S_PNAME} ]] |
if [[ ${PNAME} == ${S_PNAME} ]] |
146 |
then |
then |
147 |
INST_PNAME=yes |
INST_PNAME=yes |
148 |
|
|
149 |
if [ -n "${S_PVER}" ] |
if [[ -n ${S_PVER} ]] |
150 |
then |
then |
151 |
if [[ ${PVER} == ${S_PVER} ]] |
if [[ ${PVER} == ${S_PVER} ]] |
152 |
then |
then |
153 |
INST_PVER=yes |
INST_PVER=yes |
154 |
fi |
fi |
155 |
|
|
156 |
if [ -n "${S_PBUILD}" ] |
if [[ -n ${S_PBUILD} ]] |
157 |
then |
then |
158 |
if [[ ${PBUILD} == ${S_PBUILD} ]] |
if [[ ${PBUILD} == ${S_PBUILD} ]] |
159 |
then |
then |
163 |
fi |
fi |
164 |
|
|
165 |
# search for pname only |
# search for pname only |
166 |
if [ -n "${S_PNAME}" -a -z "${S_PVER}" -a -z "${S_PBUILD}" ] |
if [[ -n ${S_PNAME} ]] && [[ -z ${S_PVER} ]] && [[ -z ${S_PBUILD} ]] |
167 |
then |
then |
168 |
if [ "${INST_PNAME}" = yes ] |
if [[ ${INST_PNAME} = yes ]] |
169 |
then |
then |
170 |
echo "${S_PNAME} is installed [ ${PNAME}-${PVER}-${PBUILD} ]" |
echo "${S_PNAME} is installed [ ${PNAME}-${PVER}-${PBUILD} ]" |
171 |
RETVAL=0 |
RETVAL=0 |
174 |
fi |
fi |
175 |
|
|
176 |
# search for pname and pver |
# search for pname and pver |
177 |
if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -z "${S_PBUILD}" ] |
if [[ -n ${S_PNAME} ]] && [[ -n ${S_PVER} ]] && [[ -z ${S_PBUILD} ]] |
178 |
then |
then |
179 |
if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes" ] |
if [[ ${INST_PNAME} = yes ]] && [[ ${INST_PVER} = yes ]] |
180 |
then |
then |
181 |
echo "${S_PNAME}-${S_PVER} is installed [ ${PNAME}-${PVER}-${PBUILD} ]" |
echo "${S_PNAME}-${S_PVER} is installed [ ${PNAME}-${PVER}-${PBUILD} ]" |
182 |
RETVAL=0 |
RETVAL=0 |
185 |
fi |
fi |
186 |
|
|
187 |
# search for pname, pver and pbuild |
# search for pname, pver and pbuild |
188 |
if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -n "${S_PBUILD}" ] |
if [[ -n ${S_PNAME} ]] && [[ -n ${S_PVER} ]] && [[ -n ${S_PBUILD} ]] |
189 |
then |
then |
190 |
if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes" -a "${INST_PBUILD}" = "yes" ] |
if [[ ${INST_PNAME} = yes ]] && [[ ${INST_PVER} = yes ]] && [[ ${INST_PBUILD} = yes ]] |
191 |
then |
then |
192 |
echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${PNAME}-${PVER}-${PBUILD} ]" |
echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${PNAME}-${PVER}-${PBUILD} ]" |
193 |
RETVAL=0 |
RETVAL=0 |