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.10 2005-09-09 16:51:51 niro Exp $ |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/magequery.sh,v 1.11 2005-12-26 23:12:44 niro Exp $ |
5 |
|
|
6 |
print_usage() |
print_usage() |
7 |
{ |
{ |
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 " -i shows an inventory of all installed packages" |
echo " -i shows an inventory of all installed packages" |
14 |
|
echo " -f searches packages name in given path" |
15 |
echo |
echo |
16 |
echo " Examples:" |
echo " Examples:" |
17 |
echo |
echo |
22 |
|
|
23 |
# default args: |
# default args: |
24 |
GET_INVENTORY=false |
GET_INVENTORY=false |
25 |
|
SEARCH_ONLY_PATH=false |
26 |
|
|
27 |
while getopts "n:v:b:hi-" opt ; do |
while getopts "n:v:b:f:hi-" opt ; do |
28 |
case "${opt}" in |
case "${opt}" in |
29 |
n) |
n) |
30 |
S_PNAME="${OPTARG}" |
S_PNAME="${OPTARG}" |
40 |
i) |
i) |
41 |
GET_INVENTORY="true" |
GET_INVENTORY="true" |
42 |
;; |
;; |
43 |
|
f) |
44 |
|
SEARCH_ONLY_PATH="true" |
45 |
|
SEARCH_PATH="${OPTARG}" |
46 |
|
;; |
47 |
h) |
h) |
48 |
print_usage |
print_usage |
49 |
exit 0 |
exit 0 |
60 |
done |
done |
61 |
shift $(($OPTIND - 1)) |
shift $(($OPTIND - 1)) |
62 |
|
|
63 |
|
source /etc/mage.rc.global |
64 |
source /etc/mage.rc |
source /etc/mage.rc |
65 |
RETVAL=1 |
RETVAL=1 |
66 |
|
|
67 |
|
if [[ ${SEARCH_ONLY_PATH} = true ]] |
68 |
|
then |
69 |
|
unset S_PACKAGES |
70 |
|
unset i pkg |
71 |
|
for i in $(grep -irl "${SEARCH_PATH}" ${INSTALLDB}) |
72 |
|
do |
73 |
|
pkg="$(basename $(dirname ${i}))" |
74 |
|
if [[ -z $(echo ${S_PACKAGES} | grep ${pkg}) ]] |
75 |
|
then |
76 |
|
S_PACKAGES="${S_PACKAGES} ${pkg}" |
77 |
|
fi |
78 |
|
done |
79 |
|
|
80 |
|
# show packages |
81 |
|
for pkg in ${S_PACKAGES} |
82 |
|
do |
83 |
|
echo "${pkg}" |
84 |
|
done |
85 |
|
|
86 |
|
exit 0 |
87 |
|
fi |
88 |
|
|
89 |
if [[ ${GET_INVENTORY} = true ]] |
if [[ ${GET_INVENTORY} = true ]] |
90 |
then |
then |
91 |
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) |