Annotation of /branches/mage-next/src/magequery.in
Parent Directory | Revision Log
Revision 78 -
(hide annotations)
(download)
(as text)
Wed Jun 1 15:48:52 2005 UTC (19 years, 4 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/magequery.sh
File MIME type: application/x-sh
File size: 2247 byte(s)
Wed Jun 1 15:48:52 2005 UTC (19 years, 4 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/magequery.sh
File MIME type: application/x-sh
File size: 2247 byte(s)
changed version tagging only
1 | niro | 32 | #!/bin/bash |
2 | |||
3 | #query mage database for installed packages | ||
4 | niro | 78 | # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/magequery.sh,v 1.7 2005-06-01 15:48:31 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 | echo | ||
14 | echo " Examples:" | ||
15 | echo | ||
16 | echo " $(basename $0 .sh) -n xorg -v 6.8.0 -b r1" | ||
17 | echo " searches for package xorg-6.8.0-r1" | ||
18 | echo | ||
19 | } | ||
20 | |||
21 | while getopts "n:v:b:h-" opt ; do | ||
22 | case "${opt}" in | ||
23 | n) | ||
24 | S_PNAME="${OPTARG}" | ||
25 | ;; | ||
26 | |||
27 | v) | ||
28 | S_PVER="${OPTARG}" | ||
29 | ;; | ||
30 | |||
31 | b) | ||
32 | S_PBUILD="${OPTARG}" | ||
33 | ;; | ||
34 | h) | ||
35 | print_usage | ||
36 | exit 0 | ||
37 | ;; | ||
38 | |||
39 | -) break | ||
40 | ;; | ||
41 | |||
42 | *) | ||
43 | print_usage | ||
44 | exit 1 | ||
45 | ;; | ||
46 | esac | ||
47 | done | ||
48 | shift $(($OPTIND - 1)) | ||
49 | |||
50 | |||
51 | source /etc/mage.rc | ||
52 | RETVAL=1 | ||
53 | |||
54 | for i in ${INSTALLDB}/*/* | ||
55 | do | ||
56 | INST_PNAME=no | ||
57 | INST_PVER=no | ||
58 | INST_PBUILD=no | ||
59 | |||
60 | x=$(basename ${i}) | ||
61 | PNAME=${x%-*-*} | ||
62 | PVER=$(echo ${x#${PNAME}-}| cut -d- -f1) | ||
63 | PBUILD=$(echo ${x#${PNAME}-}| cut -d- -f2) | ||
64 | |||
65 | if [[ ${PNAME} == ${S_PNAME} ]] | ||
66 | then | ||
67 | INST_PNAME=yes | ||
68 | |||
69 | if [ -n "${S_PVER}" ] | ||
70 | then | ||
71 | if [[ ${PVER} == ${S_PVER} ]] | ||
72 | then | ||
73 | INST_PVER=yes | ||
74 | fi | ||
75 | |||
76 | if [ -n "${S_PBUILD}" ] | ||
77 | then | ||
78 | if [[ ${PBUILD} == ${S_PBUILD} ]] | ||
79 | then | ||
80 | INST_PBUILD=yes | ||
81 | fi | ||
82 | fi | ||
83 | fi | ||
84 | |||
85 | # search for pname only | ||
86 | if [ -n "${S_PNAME}" -a -z "${S_PVER}" -a -z "${S_PBUILD}" ] | ||
87 | then | ||
88 | if [ "${INST_PNAME}" = yes ] | ||
89 | then | ||
90 | echo "${S_PNAME} is installed [ ${PNAME}-${PVER}-${PBUILD} ]" | ||
91 | RETVAL=0 | ||
92 | break | ||
93 | fi | ||
94 | fi | ||
95 | |||
96 | # search for pname and pver | ||
97 | if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -z "${S_PBUILD}" ] | ||
98 | then | ||
99 | if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes" ] | ||
100 | then | ||
101 | echo "${S_PNAME}-${S_PVER} is installed [ ${PNAME}-${PVER}-${PBUILD} ]" | ||
102 | RETVAL=0 | ||
103 | break | ||
104 | fi | ||
105 | fi | ||
106 | |||
107 | # search for pname, pver and pbuild | ||
108 | if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -n "${S_PBUILD}" ] | ||
109 | then | ||
110 | if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes" -a "${INST_PBUILD}" = "yes" ] | ||
111 | then | ||
112 | echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${PNAME}-${PVER}-${PBUILD} ]" | ||
113 | RETVAL=0 | ||
114 | break | ||
115 | fi | ||
116 | fi | ||
117 | fi | ||
118 | done | ||
119 | |||
120 | exit ${RETVAL} |