3 |
# query mage database for installed packages |
# query mage database for installed packages |
4 |
# $Id$ |
# $Id$ |
5 |
|
|
6 |
|
# always export C locale to fix utf-8 issues |
7 |
|
export LC_ALL=C |
8 |
|
|
9 |
print_usage() |
print_usage() |
10 |
{ |
{ |
11 |
echo "$(basename $0 .sh) querys the mage database for installed packages." |
echo "$(basename $0 .sh) querys the mage database for installed packages." |
15 |
echo " -b BUILD searches for build number BUILD, needs -n -v" |
echo " -b BUILD searches for build number BUILD, needs -n -v" |
16 |
echo " -c CAT shows all packages of given categorie" |
echo " -c CAT shows all packages of given categorie" |
17 |
echo " -i shows an inventory of all installed packages" |
echo " -i shows an inventory of all installed packages" |
18 |
echo " -f PATH searches package names in given path" |
echo " -f PATH searches packages which own given file" |
19 |
|
echo " -e PATH searches the package which owns the exact given filename" |
20 |
echo |
echo |
21 |
echo " Examples:" |
echo " Examples:" |
22 |
echo |
echo |
29 |
GET_INVENTORY=false |
GET_INVENTORY=false |
30 |
SEARCH_ONLY_PATH=false |
SEARCH_ONLY_PATH=false |
31 |
SEARCH_ONLY_CAT=false |
SEARCH_ONLY_CAT=false |
32 |
|
SEARCH_EXACT_FILENAME=false |
33 |
|
|
34 |
# no params given, or is only an arg not ar param, exit |
# no params given, or is only an arg not ar param, exit |
35 |
if [[ $# -lt 1 ]] || [[ ${1:0:1} != - ]] |
if [[ $# -lt 1 ]] || [[ ${1:0:1} != - ]] |
47 |
-b) shift; S_PBUILD="$1" ;; |
-b) shift; S_PBUILD="$1" ;; |
48 |
-i) GET_INVENTORY="true" ;; |
-i) GET_INVENTORY="true" ;; |
49 |
-f) SEARCH_ONLY_PATH="true"; shift; SEARCH_PATH="$1" ;; |
-f) SEARCH_ONLY_PATH="true"; shift; SEARCH_PATH="$1" ;; |
50 |
|
-e) SEARCH_ONLY_PATH="true"; SEARCH_EXACT_FILENAME="true"; shift; SEARCH_PATH="$1" ;; |
51 |
-c) SEARCH_ONLY_CAT="true"; shift; SEARCH_CAT="$1" ;; |
-c) SEARCH_ONLY_CAT="true"; shift; SEARCH_CAT="$1" ;; |
52 |
-h) print_usage; exit 0 ;; |
-h) print_usage; exit 0 ;; |
53 |
-*) print_usage; exit 1 ;; |
-*) print_usage; exit 1 ;; |
56 |
done |
done |
57 |
|
|
58 |
source /etc/mage.rc.global |
source /etc/mage.rc.global |
59 |
source /etc/mage.rc |
source ${MAGERC} |
60 |
RETVAL=1 |
RETVAL=1 |
61 |
|
|
62 |
if [[ ${SEARCH_ONLY_PATH} = true ]] |
if [[ ${SEARCH_ONLY_PATH} = true ]] |
63 |
then |
then |
64 |
unset S_PACKAGES |
unset S_PACKAGES |
65 |
unset i pkg |
unset i pkg |
66 |
for i in $(fgrep -rl "${SEARCH_PATH}" ${INSTALLDB}) |
if [[ ${SEARCH_EXACT_FILENAME} = true ]] |
67 |
|
then |
68 |
|
# fix ++, which gets interpreted as a regex |
69 |
|
SEARCH_PATH="${SEARCH_PATH//+/\\+}" |
70 |
|
# fix [, which gets interpreted as a regex |
71 |
|
SEARCH_PATH="${SEARCH_PATH//[/\\[}" |
72 |
|
S_CANDIDATES=$(egrep -rl "^${SEARCH_PATH}§" ${INSTALLDB}) |
73 |
|
else |
74 |
|
S_CANDIDATES=$(fgrep -rl "${SEARCH_PATH}" ${INSTALLDB}) |
75 |
|
fi |
76 |
|
for i in ${S_CANDIDATES} |
77 |
do |
do |
78 |
# ignore magefiles! |
# ignore magefiles! |
79 |
case ${i} in |
case ${i} in |