Revision 11559
Added by Paul Sarando about 11 years ago
geoscrub.sh | ||
---|---|---|
17 | 17 |
DB_HOST_OPT="" |
18 | 18 |
SCRIPT_DIR="$(dirname $0)" |
19 | 19 |
|
20 |
function usage { |
|
21 |
echo "Usage: $0 [OPTIONS]" >&2 |
|
22 |
echo "Valid Options:" >&2 |
|
23 |
echo "-d, --dbname=DBNAME database name psql commands will connect to" >&2 |
|
24 |
echo "-h, --host=HOSTNAME database server host or socket directory" >&2 |
|
25 |
echo "-U, --username=USERNAME database user name" >&2 |
|
26 |
exit 1; |
|
27 |
} |
|
28 |
|
|
29 |
while [[ $# -gt 0 ]]; do |
|
30 |
case "$1" in |
|
31 |
-\? | --help) |
|
32 |
usage |
|
33 |
;; |
|
34 |
-h) |
|
35 |
if [[ -z $2 ]]; then |
|
36 |
echo "Option $1 requires an argument." >&2 |
|
37 |
usage |
|
38 |
fi |
|
39 |
DB_HOST_OPT="-h $2" |
|
40 |
shift 2 |
|
41 |
;; |
|
42 |
--host=*) |
|
43 |
DB_HOST_OPT="-h ${1#*=}" |
|
44 |
shift |
|
45 |
;; |
|
46 |
-U) |
|
47 |
if [[ -z $2 ]]; then |
|
48 |
echo "Option $1 requires an argument." >&2 |
|
49 |
usage |
|
50 |
fi |
|
51 |
DB_USER="$2" |
|
52 |
shift 2 |
|
53 |
;; |
|
54 |
--username=*) |
|
55 |
DB_USER="${1#*=}" |
|
56 |
shift |
|
57 |
;; |
|
58 |
-d) |
|
59 |
if [[ -z $2 ]]; then |
|
60 |
echo "Option $1 requires an argument." >&2 |
|
61 |
usage |
|
62 |
fi |
|
63 |
DB_NAME="$2" |
|
64 |
shift 2 |
|
65 |
;; |
|
66 |
--dbname=*) |
|
67 |
DB_NAME="${1#*=}" |
|
68 |
shift |
|
69 |
;; |
|
70 |
*) |
|
71 |
echo "Invalid option: $1" >&2 |
|
72 |
usage |
|
73 |
;; |
|
74 |
esac |
|
75 |
done |
|
76 |
|
|
20 | 77 |
function run_sql_script { |
21 | 78 |
local SCRIPT=$1 |
22 | 79 |
|
... | ... | |
27 | 84 |
fi |
28 | 85 |
} |
29 | 86 |
|
30 |
"${SCRIPT_DIR}"/load-geoscrub-input.sh |
|
87 |
"${SCRIPT_DIR}"/load-geoscrub-input.sh -U "$DB_USER" $DB_HOST_OPT -d "$DB_NAME"
|
|
31 | 88 |
if [[ $? != 0 ]]; then |
32 | 89 |
echo "Could not load ${DB_NAME} database with geonames.org data." |
33 | 90 |
exit 1 |
Also available in: Unified diff
Added cmd-line options to biengeo bash scripts.
All biengeo bash scripts now accept command line options to specify psql
user, host, and database values.
These options are the same as those defined by the psql command.
If an invalid option is given to a script, a usage message is printed
and the script quits.
For example:
setup.sh -U bien -h localhost -d geoscrub_test