1
|
#!/bin/bash -e
|
2
|
# links to locally-available resources
|
3
|
. "$(dirname "${BASH_SOURCE[0]}")"/util.sh
|
4
|
|
5
|
if self_not_included; then
|
6
|
|
7
|
root_dir="$(dirname "${BASH_SOURCE[0]}")"/..
|
8
|
bin_dir="$root_dir"/bin
|
9
|
bin_dir_abs="$(realpath "$bin_dir")"
|
10
|
|
11
|
export PATH="$bin_dir_abs:$PATH"
|
12
|
|
13
|
#### make
|
14
|
|
15
|
root_make () { echo_func; extern make --directory="$root_dir" "$@"; }
|
16
|
|
17
|
#### connection vars
|
18
|
|
19
|
: "${remote_server=vegbiendev.nceas.ucsb.edu}"
|
20
|
: "${local_server=localhost}"
|
21
|
: "${local_user=bien}"
|
22
|
: "${local_password="$(cat "$root_dir"/config/bien_password)"}"
|
23
|
|
24
|
#### databases
|
25
|
|
26
|
### MySQL
|
27
|
|
28
|
: "${postgres_compat=1}"
|
29
|
|
30
|
mysql ()
|
31
|
{
|
32
|
echo_func
|
33
|
echo_run mysql_bien --database="$schema" --verbose "$@"
|
34
|
}
|
35
|
|
36
|
mysqldump_local ()
|
37
|
{
|
38
|
echo_func
|
39
|
use_local_remote; mysqldump_diffable "$@"
|
40
|
}
|
41
|
|
42
|
### PostgreSQL
|
43
|
|
44
|
psql () # usage: [file=...] [dir=...] self
|
45
|
{
|
46
|
echo_func
|
47
|
if test -n "$file"; then
|
48
|
set -- --file "$file" "$@"
|
49
|
local dir="${dir:-$(dirname "$file")}"
|
50
|
fi
|
51
|
local dir="${dir:-$top_dir}"
|
52
|
|
53
|
local psql_cmd="psql_$(if log_sql; then echo verbose; else echo script; fi)_vegbien"
|
54
|
(cat <<EOF
|
55
|
\cd $dir
|
56
|
\set schema "$schema"
|
57
|
\set table "$table"
|
58
|
\set table_str '''"$table"'''
|
59
|
SET search_path TO "$schema", util;
|
60
|
EOF
|
61
|
cat)|
|
62
|
env no_search_path=1 "$psql_cmd" --output /dev/fd/4 "$@" 4>&1 >&2
|
63
|
}
|
64
|
|
65
|
fi
|