Magellan Linux

Annotation of /branches/mage-next/src/magequery.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 777 - (hide annotations) (download) (as text)
Sun Oct 5 10:33:04 2008 UTC (15 years, 6 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/magequery.sh
File MIME type: application/x-sh
File size: 3813 byte(s)
-added search-method for categories

1 niro 32 #!/bin/bash
2    
3     #query mage database for installed packages
4 niro 777 # $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 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 niro 777 echo " -c CAT shows all packages of given categorie"
14 niro 210 echo " -i shows an inventory of all installed packages"
15 niro 777 echo " -f PATH searches packages name in given path"
16 niro 32 echo
17     echo " Examples:"
18     echo
19     echo " $(basename $0 .sh) -n xorg -v 6.8.0 -b r1"
20     echo " searches for package xorg-6.8.0-r1"
21     echo
22     }
23    
24 niro 210 # default args:
25     GET_INVENTORY=false
26 niro 304 SEARCH_ONLY_PATH=false
27 niro 777 SEARCH_ONLY_CAT=false
28 niro 210
29 niro 777 while getopts "n:v:b:f:c:hi-" opt ; do
30 niro 32 case "${opt}" in
31     n)
32     S_PNAME="${OPTARG}"
33     ;;
34    
35     v)
36     S_PVER="${OPTARG}"
37     ;;
38    
39     b)
40     S_PBUILD="${OPTARG}"
41     ;;
42 niro 210 i)
43     GET_INVENTORY="true"
44     ;;
45 niro 304 f)
46     SEARCH_ONLY_PATH="true"
47     SEARCH_PATH="${OPTARG}"
48     ;;
49 niro 777 c)
50     SEARCH_ONLY_CAT="true"
51     SEARCH_CAT="${OPTARG}"
52     ;;
53 niro 32 h)
54     print_usage
55     exit 0
56     ;;
57    
58     -) break
59     ;;
60    
61     *)
62     print_usage
63     exit 1
64     ;;
65     esac
66     done
67     shift $(($OPTIND - 1))
68    
69 niro 304 source /etc/mage.rc.global
70 niro 229 source /etc/mage.rc
71 niro 32 RETVAL=1
72    
73 niro 304 if [[ ${SEARCH_ONLY_PATH} = true ]]
74     then
75     unset S_PACKAGES
76     unset i pkg
77 niro 332 for i in $(fgrep -rl "${SEARCH_PATH}" ${INSTALLDB})
78 niro 304 do
79 niro 332 # print categorie and pkgname
80     pkg="$(basename ${i%/*/*})/$(basename ${i%/*})"
81 niro 304 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 niro 777 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 niro 210 if [[ ${GET_INVENTORY} = true ]]
111     then
112 niro 228 for package in $(find ${MROOT}${INSTALLDB} -mindepth 2 -maxdepth 2 -type d -printf "%h,%f\n" | sort)
113 niro 210 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 niro 228 for i in ${MROOT}${INSTALLDB}/*/*
131 niro 32 do
132     INST_PNAME=no
133     INST_PVER=no
134     INST_PBUILD=no
135    
136     x=$(basename ${i})
137     PNAME=${x%-*-*}
138     PVER=$(echo ${x#${PNAME}-}| cut -d- -f1)
139     PBUILD=$(echo ${x#${PNAME}-}| cut -d- -f2)
140    
141     if [[ ${PNAME} == ${S_PNAME} ]]
142     then
143     INST_PNAME=yes
144    
145     if [ -n "${S_PVER}" ]
146     then
147     if [[ ${PVER} == ${S_PVER} ]]
148     then
149     INST_PVER=yes
150     fi
151    
152     if [ -n "${S_PBUILD}" ]
153     then
154     if [[ ${PBUILD} == ${S_PBUILD} ]]
155     then
156     INST_PBUILD=yes
157     fi
158     fi
159     fi
160    
161     # search for pname only
162     if [ -n "${S_PNAME}" -a -z "${S_PVER}" -a -z "${S_PBUILD}" ]
163     then
164     if [ "${INST_PNAME}" = yes ]
165     then
166     echo "${S_PNAME} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
167     RETVAL=0
168     break
169     fi
170     fi
171    
172     # search for pname and pver
173     if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -z "${S_PBUILD}" ]
174     then
175     if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes" ]
176     then
177     echo "${S_PNAME}-${S_PVER} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
178     RETVAL=0
179     break
180     fi
181     fi
182    
183     # search for pname, pver and pbuild
184     if [ -n "${S_PNAME}" -a -n "${S_PVER}" -a -n "${S_PBUILD}" ]
185     then
186     if [ "${INST_PNAME}" = "yes" -a "${INST_PVER}" = "yes" -a "${INST_PBUILD}" = "yes" ]
187     then
188     echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"
189     RETVAL=0
190     break
191     fi
192     fi
193     fi
194     done
195    
196     exit ${RETVAL}