1
|
#!/bin/bash -e
|
2
|
# links to locally-available resources
|
3
|
. "$(dirname "${BASH_SOURCE[0]}")"/util.sh
|
4
|
. "$(dirname "${BASH_SOURCE[0]}")"/db.sh
|
5
|
|
6
|
if self_not_included; then
|
7
|
|
8
|
root_dir="$(canon_rel_path "$(dirname "${BASH_SOURCE[0]}")"/../..)" || return
|
9
|
bin_dir="$root_dir"/bin
|
10
|
bin_dir_abs="$(realpath "$bin_dir")" || return
|
11
|
|
12
|
export PATH="$bin_dir_abs:$PATH"
|
13
|
|
14
|
#### make
|
15
|
|
16
|
root_make() { echo_func; make --directory="$root_dir" "$@"; }
|
17
|
|
18
|
#### connection vars
|
19
|
|
20
|
: "${remote_server=vegbiendev.nceas.ucsb.edu}"
|
21
|
: "${local_server=localhost}"
|
22
|
: "${local_user=bien}"
|
23
|
: "${local_password="$(cat "$root_dir"/config/bien_password)"}"
|
24
|
: "${root_user=root}"
|
25
|
: "${root_password=$local_password}"
|
26
|
|
27
|
#### databases
|
28
|
|
29
|
### MySQL
|
30
|
|
31
|
: "${postgres_compat=1}"
|
32
|
|
33
|
mysql_export_local() { echo_func; use_local_remote; mysql_export "$@"; }
|
34
|
|
35
|
mysqldump_local() { echo_func; use_local_remote; mysqldump_diffable "$@"; }
|
36
|
|
37
|
### PostgreSQL
|
38
|
|
39
|
psql() # usage: [file=...] [dir=...] self
|
40
|
{
|
41
|
echo_func; kw_params file dir
|
42
|
if test "$file"; then
|
43
|
set -- --file "$file" "$@"
|
44
|
local dir="${dir:-$(dirname "$file")}"
|
45
|
fi
|
46
|
local dir="${dir:-$top_dir}"
|
47
|
mk_schema_esc
|
48
|
mk_table_esc
|
49
|
|
50
|
local psql_cmd="psql_$(if can_log; then echo verbose; else echo script; fi)_vegbien"
|
51
|
local redirs=("${redirs[@]}" '13>&1') # not 11 because it gives a
|
52
|
# "/dev/fd/11: Bad file descriptor" error when 11 is set with exec
|
53
|
# right before the command instead of on the subshell it's executed in
|
54
|
(cat <<EOF
|
55
|
\cd $dir
|
56
|
\set schema $schema_esc
|
57
|
\set table $table_esc
|
58
|
\set table_str '''$table_esc'''
|
59
|
SET search_path TO $schema_esc, util;
|
60
|
EOF
|
61
|
cat)|cmd_log_fd=1 \
|
62
|
env no_search_path=1 "$psql_cmd" --output /dev/fd/13 "$@"
|
63
|
# --output is for query *results*, not echoed statements
|
64
|
}
|
65
|
|
66
|
public_schema_exists() { psql_script_vegbien </dev/null 2>/dev/null; }
|
67
|
|
68
|
fi
|