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