~ubuntu-branches/ubuntu/jaunty/beagle/jaunty-security

« back to all changes in this revision

Viewing changes to tools/blocate

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-05-04 00:31:32 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20080504003132-2tkm5o8moo5952ri
Tags: 0.3.7-2ubuntu1
 * Merge from Debian unstable. (LP: #225746) Remaining Ubuntu changes:
  - debian/control:
    + Rename ice{weasel,dove}-beagle to {mozilla,thunderbird}-beagle and
      and update the dependencies accordingly.
    + Change Maintainer to Ubuntu Mono Team.
  - debian/rules:
    + Install the mozilla-beagle and thunderbird-beagle extensions.
  - ice{dove,weasel}.dirs:
    + Renamed to {mozilla,thunderbird}-beagle.dirs.
    + Fixed paths to point to usr/lib/{firefox,thunderbird}

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#
 
3
# blocate
 
4
 
5
# Copyright (C) 2008 Nirbheek Chauhan <nirbheek.chauhan@gmail.com>
 
6
#
 
7
 
 
8
#
 
9
# Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
# of this software and associated documentation files (the "Software"), to deal
 
11
# in the Software without restriction, including without limitation the rights
 
12
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
# copies of the Software, and to permit persons to whom the Software is
 
14
# furnished to do so, subject to the following conditions:
 
15
#
 
16
# The above copyright notice and this permission notice shall be included in all
 
17
# copies or substantial portions of the Software.
 
18
#
 
19
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
25
# SOFTWARE.
 
26
#
 
27
 
 
28
 
 
29
# Get the config directory
 
30
if [ -n "${BEAGLE_HOME}" ]; then
 
31
        CONFDIR="${BEAGLE_HOME}/.beagle/config"
 
32
elif [ -n "${BEAGLE_STORAGE}" ]; then
 
33
        CONFDIR="${BEAGLE_STORAGE}/config"
 
34
elif [ -n "${BEAGLE_CONF_DIR}" ]; then
 
35
        CONFDIR="${BEAGLE_CONF_DIR}"
 
36
else
 
37
        CONFDIR="/etc/beagle"
 
38
fi
 
39
 
 
40
CONFFILE="${CONFDIR}/blocate.conf"
 
41
 
 
42
if ! [ -e "${CONFFILE}" ]; then
 
43
        echo "Error: config file \"${CONFFILE}\" does not exist"
 
44
        exit 1
 
45
fi
 
46
 
 
47
# Read config settings
 
48
source "${CONFFILE}"
 
49
 
 
50
print_help() {
 
51
        # Use here-documents for great justice.
 
52
        cat <<-DELIM
 
53
                blocate: Special locate powered by Beagle
 
54
                Web page: http://www.beagle-project.org/
 
55
                Usage: blocate [OPTIONS] <query string>
 
56
 
 
57
                Options:
 
58
                  -d, --database NAME       query backend given by NAME instead of default
 
59
                  -d, --database PATH       query backend given by PATH instead of default
 
60
                                            Both of the above options can be repeated.
 
61
                                            If they are specified then the default backends are ignored.
 
62
                                            Default backends are specified in ~/.beagle/config/blocate.conf or /etc/beagle/blocate.conf
 
63
        DELIM
 
64
}
 
65
 
 
66
# While we still have arguments..
 
67
while [ -n "${1}" ]; do
 
68
        # Take one in; shift
 
69
        arg=${1}; shift
 
70
        if [[ "${arg}" == "-h" || "${arg}" == "--help" ]]; then
 
71
                print_help
 
72
                exit
 
73
        elif [[ "${arg}" == "-d" || "${arg}" == "--database" ]]; then 
 
74
                # Take in it's value; shift
 
75
                argvalue=${1}; shift
 
76
                # Ignore config file
 
77
                ignore_config="true"
 
78
                if [[ "${argvalue}" =~ "/" ]]; then
 
79
                        # If the dir is not an absolute path
 
80
                        if [ -n "${argvalue%%/*}" ]; then
 
81
                                echo "Error: \"${argvalue}\" - relative paths not allowed"
 
82
                                exit 1
 
83
                        else
 
84
                                # If absolute path and DNE
 
85
                                if ! [ -d "${argvalue}" ]; then
 
86
                                        echo "Error: directory \"${argvalue}\" does not exist"
 
87
                                        exit 1
 
88
                                fi
 
89
                        fi
 
90
                        arg="--add-static-backend ${argvalue}"
 
91
                else
 
92
                        arg="--backend ${argvalue}"
 
93
                fi
 
94
        fi
 
95
        OPTS=("${OPTS[@]}" "${arg}")
 
96
done
 
97
 
 
98
# If you give -d, --database as args, the entire config is ignored
 
99
if [ "$ignore_config" != "true" ]; then
 
100
        for i in ${STATIC_INDEXES}; do
 
101
                OPTS=("${OPTS[@]}" "--add-static-backend" "${i}")
 
102
        done
 
103
        for i in ${BACKENDS}; do
 
104
                OPTS=("${OPTS[@]}" "--backend" "${i}")
 
105
        done
 
106
fi
 
107
 
 
108
# We add "--backend none" else it'll query all backends if there are no --backend params
 
109
beagle-static-query ${OPTS[@]} --backend none
 
110