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_ssh_server=vegbiendev.nceas.ucsb.edu}"
|
21
|
: "${remote_server=}"
|
22
|
: "${local_server=localhost}"
|
23
|
: "${local_user=bien}"
|
24
|
: "${local_password="$(cat "$root_dir"/config/bien_password)"}"
|
25
|
: "${local_pg_database=vegbien}"
|
26
|
: "${root_user=root}"
|
27
|
: "${root_password=$local_password}"
|
28
|
|
29
|
#### databases
|
30
|
|
31
|
### MySQL
|
32
|
|
33
|
: "${postgres_compat=1}"
|
34
|
|
35
|
mysql_local() { echo_func; use_local_remote; mysql "$@"; }
|
36
|
|
37
|
mysql_export_local() { echo_func; use_local_remote; mysql_export "$@"; }
|
38
|
|
39
|
mysqldump_local() { echo_func; use_local_remote; mysqldump_diffable "$@"; }
|
40
|
|
41
|
mysql_root() { echo_func; use_local_remote; use_root; mysql "$@"; }
|
42
|
|
43
|
### PostgreSQL
|
44
|
|
45
|
func_override psql__db_sh
|
46
|
psql() # usage: [file=...] [dir=...] self
|
47
|
{
|
48
|
echo_func; kw_params file dir
|
49
|
if test "$file"; then local dir="${dir:-$(dirname "$file")}"; fi
|
50
|
local dir="${dir:-$top_dir}"
|
51
|
mk_schema_esc
|
52
|
mk_table_esc
|
53
|
|
54
|
use_local
|
55
|
(cat <<EOF
|
56
|
\cd $dir
|
57
|
\set schema $schema_esc
|
58
|
\set table $table_esc
|
59
|
\set table_str '''$table_esc'''
|
60
|
SET search_path TO $schema_esc, util;
|
61
|
EOF
|
62
|
cat${file:+ "$file"}
|
63
|
)|psql__db_sh "$@"
|
64
|
}
|
65
|
|
66
|
public_schema_exists() { psql_script_vegbien </dev/null 2>/dev/null; }
|
67
|
|
68
|
fi
|