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.7 2005-06-01 15:48:31 niro Exp $ |
# $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 |
|
|
6 |
print_usage() |
print_usage() |
7 |
{ |
{ |
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 name in given path" |
16 |
echo |
echo |
17 |
echo " Examples:" |
echo " Examples:" |
18 |
echo |
echo |
21 |
echo |
echo |
22 |
} |
} |
23 |
|
|
24 |
while getopts "n:v:b:h-" opt ; do |
# default args: |
25 |
|
GET_INVENTORY=false |
26 |
|
SEARCH_ONLY_PATH=false |
27 |
|
SEARCH_ONLY_CAT=false |
28 |
|
|
29 |
|
while getopts "n:v:b:f:c:hi-" opt ; do |
30 |
case "${opt}" in |
case "${opt}" in |
31 |
n) |
n) |
32 |
S_PNAME="${OPTARG}" |
S_PNAME="${OPTARG}" |
39 |
b) |
b) |
40 |
S_PBUILD="${OPTARG}" |
S_PBUILD="${OPTARG}" |
41 |
;; |
;; |
42 |
|
i) |
43 |
|
GET_INVENTORY="true" |
44 |
|
;; |
45 |
|
f) |
46 |
|
SEARCH_ONLY_PATH="true" |
47 |
|
SEARCH_PATH="${OPTARG}" |
48 |
|
;; |
49 |
|
c) |
50 |
|
SEARCH_ONLY_CAT="true" |
51 |
|
SEARCH_CAT="${OPTARG}" |
52 |
|
;; |
53 |
h) |
h) |
54 |
print_usage |
print_usage |
55 |
exit 0 |
exit 0 |
66 |
done |
done |
67 |
shift $(($OPTIND - 1)) |
shift $(($OPTIND - 1)) |
68 |
|
|
69 |
|
source /etc/mage.rc.global |
70 |
source /etc/mage.rc |
source /etc/mage.rc |
71 |
RETVAL=1 |
RETVAL=1 |
72 |
|
|
73 |
for i in ${INSTALLDB}/*/* |
if [[ ${SEARCH_ONLY_PATH} = true ]] |
74 |
|
then |
75 |
|
unset S_PACKAGES |
76 |
|
unset i pkg |
77 |
|
for i in $(fgrep -rl "${SEARCH_PATH}" ${INSTALLDB}) |
78 |
|
do |
79 |
|
# print categorie and pkgname |
80 |
|
pkg="$(basename ${i%/*/*})/$(basename ${i%/*})" |
81 |
|
if [[ -z $(echo ${S_PACKAGES} | grep ${pkg}) ]] |
82 |
|
then |
83 |
|
S_PACKAGES="${S_PACKAGES} ${pkg}" |
84 |
|
fi |
85 |
|
done |
86 |
|
|
87 |
|
# show packages |
88 |
|
for pkg in ${S_PACKAGES} |
89 |
|
do |
90 |
|
echo "${pkg}" |
91 |
|
done |
92 |
|
|
93 |
|
exit 0 |
94 |
|
fi |
95 |
|
|
96 |
|
if [[ ${SEARCH_ONLY_CAT} = true ]] |
97 |
|
then |
98 |
|
# no packages of SEARCH_CAT are installed |
99 |
|
[[ ! -d ${MROOT}${INSTALLDB}/${SEARCH_CAT} ]] && exit 1 |
100 |
|
|
101 |
|
for i in ${INSTALLDB}/${SEARCH_CAT}/* |
102 |
|
do |
103 |
|
# print categorie and pkgname |
104 |
|
echo "$(basename ${i%/*})/$(basename ${i})" |
105 |
|
done |
106 |
|
|
107 |
|
exit 0 |
108 |
|
fi |
109 |
|
|
110 |
|
if [[ ${GET_INVENTORY} = true ]] |
111 |
|
then |
112 |
|
for package in $(find ${MROOT}${INSTALLDB} -mindepth 2 -maxdepth 2 -type d -printf "%h,%f\n" | sort) |
113 |
|
do |
114 |
|
pcat="$(basename $(echo ${package} | cut -d, -f1))" |
115 |
|
pname="$(echo ${package} | cut -d, -f2)" |
116 |
|
if [ -z "${invlist}" ] |
117 |
|
then |
118 |
|
invlist="${pcat}/${pname}" |
119 |
|
else |
120 |
|
invlist="${invlist} |
121 |
|
${pcat}/${pname}" |
122 |
|
fi |
123 |
|
done |
124 |
|
|
125 |
|
# now show the list |
126 |
|
echo "${invlist}" |
127 |
|
exit 0 |
128 |
|
fi |
129 |
|
|
130 |
|
for i in ${MROOT}${INSTALLDB}/*/* |
131 |
do |
do |
132 |
INST_PNAME=no |
INST_PNAME=no |
133 |
INST_PVER=no |
INST_PVER=no |