1
|
#!/bin/bash -e
|
2
|
# links to locally-available resources
|
3
|
. "$(dirname "${BASH_SOURCE[0]}")"/util.sh
|
4
|
.rel db.sh
|
5
|
.rel make.sh
|
6
|
.rel sync.sh
|
7
|
|
8
|
if self_not_included; then
|
9
|
|
10
|
root_dir="$(canon_rel_path "$(dirname "${BASH_SOURCE[0]}")"/../..)" || return
|
11
|
|
12
|
root_rel_path() { echo_func; base_dir="$root_dir" canon_rel_path "$1"; }
|
13
|
|
14
|
bin_dir="$root_dir"/bin
|
15
|
bin_dir_abs="$(realpath "$bin_dir")" || return
|
16
|
|
17
|
export PATH="$bin_dir_abs:$PATH"
|
18
|
|
19
|
#### make
|
20
|
|
21
|
root_make() { echo_func; make --directory="$root_dir" "$@"; }
|
22
|
|
23
|
#### connection vars
|
24
|
|
25
|
: "${remote_ssh_server=vegbiendev.nceas.ucsb.edu}"
|
26
|
: "${remote_server=}"
|
27
|
: "${local_server=localhost}"
|
28
|
: "${local_user=bien}"
|
29
|
: "${local_password="$(cat "$root_dir"/config/bien_password)"}"
|
30
|
: "${local_pg_database=vegbien}"
|
31
|
: "${root_user=root}"
|
32
|
: "${root_password=$local_password}"
|
33
|
|
34
|
#### databases
|
35
|
|
36
|
### MySQL
|
37
|
|
38
|
: "${postgres_compat=1}"
|
39
|
|
40
|
mysql_local() { echo_func; use_local_remote; mysql "$@"; }
|
41
|
|
42
|
mysql_export_local() { echo_func; use_local_remote; mysql_export "$@"; }
|
43
|
|
44
|
mysqldump_local() { echo_func; use_local_remote; mysqldump_diffable "$@"; }
|
45
|
|
46
|
mysql_root() { echo_func; use_local_remote; use_root; mysql "$@"; }
|
47
|
|
48
|
### PostgreSQL
|
49
|
|
50
|
func_override psql__db_sh
|
51
|
psql() # usage: [file=...] [dir=...] self
|
52
|
{
|
53
|
echo_func; kw_params file dir
|
54
|
if test "$file"; then local dir="${dir:-$(dirname "$file")}"; fi
|
55
|
local dir="${dir:-$top_dir}"
|
56
|
mk_schema_esc
|
57
|
mk_table_esc
|
58
|
|
59
|
use_local
|
60
|
(cat <<EOF
|
61
|
\cd $dir
|
62
|
\set schema $schema_esc
|
63
|
\set table $table_esc
|
64
|
\set table_str '''$table_esc'''
|
65
|
SET search_path TO $schema_esc;
|
66
|
EOF
|
67
|
cat${file:+ "$file"}
|
68
|
)|psql__db_sh "$@"
|
69
|
}
|
70
|
|
71
|
public_schema_exists() { psql_script_vegbien </dev/null 2>/dev/null; }
|
72
|
|
73
|
|
74
|
#### sync
|
75
|
|
76
|
: "${sync_local_dir=$root_dir}"
|
77
|
: "${sync_remote_url=jupiter:/data/dev/aaronmk/bien}"
|
78
|
|
79
|
sync_upload() { echo_func; use_sync; upload "$@"; }
|
80
|
|
81
|
sync_download() { echo_func; use_sync; upload "$@"; }
|
82
|
|
83
|
fi
|