1 |
8699
|
aaronmk
|
#!/bin/bash -e
|
2 |
|
|
# links to locally-available resources
|
3 |
8893
|
aaronmk
|
. "$(dirname "${BASH_SOURCE[0]}")"/util.sh
|
4 |
9854
|
aaronmk
|
.rel db.sh
|
5 |
9860
|
aaronmk
|
.rel make.sh
|
6 |
9854
|
aaronmk
|
.rel sync.sh
|
7 |
8699
|
aaronmk
|
|
8 |
8705
|
aaronmk
|
if self_not_included; then
|
9 |
|
|
|
10 |
9331
|
aaronmk
|
root_dir="$(canon_rel_path "$(dirname "${BASH_SOURCE[0]}")"/../..)" || return
|
11 |
9787
|
aaronmk
|
|
12 |
9793
|
aaronmk
|
root_rel_path() { echo_func; base_dir="$root_dir" canon_rel_path "$1"; }
|
13 |
9787
|
aaronmk
|
|
14 |
8699
|
aaronmk
|
bin_dir="$root_dir"/bin
|
15 |
9331
|
aaronmk
|
bin_dir_abs="$(realpath "$bin_dir")" || return
|
16 |
8705
|
aaronmk
|
|
17 |
10048
|
aaronmk
|
: "${PATH_add=1}"
|
18 |
|
|
if test "$PATH_add"; then export PATH="$bin_dir_abs:$PATH"; fi
|
19 |
8708
|
aaronmk
|
|
20 |
8939
|
aaronmk
|
#### make
|
21 |
|
|
|
22 |
9074
|
aaronmk
|
root_make() { echo_func; make --directory="$root_dir" "$@"; }
|
23 |
8939
|
aaronmk
|
|
24 |
8890
|
aaronmk
|
#### connection vars
|
25 |
|
|
|
26 |
9630
|
aaronmk
|
: "${remote_ssh_server=vegbiendev.nceas.ucsb.edu}"
|
27 |
|
|
: "${remote_server=}"
|
28 |
8890
|
aaronmk
|
: "${local_server=localhost}"
|
29 |
|
|
: "${local_user=bien}"
|
30 |
|
|
: "${local_password="$(cat "$root_dir"/config/bien_password)"}"
|
31 |
9650
|
aaronmk
|
: "${local_pg_database=vegbien}"
|
32 |
9575
|
aaronmk
|
: "${root_user=root}"
|
33 |
|
|
: "${root_password=$local_password}"
|
34 |
8890
|
aaronmk
|
|
35 |
11350
|
aaronmk
|
#### ssh
|
36 |
|
|
|
37 |
|
|
require_remote()
|
38 |
|
|
{
|
39 |
|
|
echo_func
|
40 |
|
|
test "$(hostname -f)" = "$remote_ssh_server" \
|
41 |
|
|
|| die "must be run on $remote_ssh_server"
|
42 |
|
|
}
|
43 |
|
|
|
44 |
8890
|
aaronmk
|
#### databases
|
45 |
|
|
|
46 |
|
|
### MySQL
|
47 |
|
|
|
48 |
8891
|
aaronmk
|
: "${postgres_compat=1}"
|
49 |
|
|
|
50 |
9577
|
aaronmk
|
mysql_local() { echo_func; use_local_remote; mysql "$@"; }
|
51 |
|
|
|
52 |
9153
|
aaronmk
|
mysql_export_local() { echo_func; use_local_remote; mysql_export "$@"; }
|
53 |
|
|
|
54 |
9074
|
aaronmk
|
mysqldump_local() { echo_func; use_local_remote; mysqldump_diffable "$@"; }
|
55 |
8892
|
aaronmk
|
|
56 |
9576
|
aaronmk
|
mysql_root() { echo_func; use_local_remote; use_root; mysql "$@"; }
|
57 |
|
|
|
58 |
8890
|
aaronmk
|
### PostgreSQL
|
59 |
|
|
|
60 |
9650
|
aaronmk
|
func_override psql__db_sh
|
61 |
9074
|
aaronmk
|
psql() # usage: [file=...] [dir=...] self
|
62 |
8777
|
aaronmk
|
{
|
63 |
9235
|
aaronmk
|
echo_func; kw_params file dir
|
64 |
9645
|
aaronmk
|
if test "$file"; then local dir="${dir:-$(dirname "$file")}"; fi
|
65 |
8834
|
aaronmk
|
local dir="${dir:-$top_dir}"
|
66 |
11433
|
aaronmk
|
if isset public; then local schema="${schema:-$public}"; fi
|
67 |
9427
|
aaronmk
|
mk_schema_esc
|
68 |
|
|
mk_table_esc
|
69 |
11365
|
aaronmk
|
local is_root="`case "$USER" in *postgres) echo 1;; esac`"
|
70 |
11362
|
aaronmk
|
echo_vars is_root
|
71 |
8777
|
aaronmk
|
|
72 |
11362
|
aaronmk
|
if test ! "$is_root"; then use_local; fi
|
73 |
11352
|
aaronmk
|
(if test "$schema" -a "$table"; then cat <<EOF
|
74 |
8777
|
aaronmk
|
\cd $dir
|
75 |
9427
|
aaronmk
|
\set schema $schema_esc
|
76 |
|
|
\set table $table_esc
|
77 |
|
|
\set table_str '''$table_esc'''
|
78 |
9827
|
aaronmk
|
SET search_path TO $schema_esc;
|
79 |
8777
|
aaronmk
|
EOF
|
80 |
11352
|
aaronmk
|
fi
|
81 |
9645
|
aaronmk
|
cat${file:+ "$file"}
|
82 |
9650
|
aaronmk
|
)|psql__db_sh "$@"
|
83 |
8777
|
aaronmk
|
}
|
84 |
|
|
|
85 |
12800
|
aaronmk
|
public_schema_exists() { echo_func; schema=public clog++ pg_schema_exists; }
|
86 |
9046
|
aaronmk
|
|
87 |
10765
|
aaronmk
|
pg_dump_local() { echo_func; use_local; pg_dump "$@"; }
|
88 |
9801
|
aaronmk
|
|
89 |
10765
|
aaronmk
|
|
90 |
9801
|
aaronmk
|
#### sync
|
91 |
|
|
|
92 |
|
|
: "${sync_local_dir=$root_dir}"
|
93 |
10033
|
aaronmk
|
: "${sync_remote_subdir=bien/}"
|
94 |
|
|
: "${sync_remote_url=jupiter:/data/dev/aaronmk/$sync_remote_subdir}"
|
95 |
9801
|
aaronmk
|
|
96 |
9896
|
aaronmk
|
sync_upload() { echo_func; use_sync; upload --no-owner --no-group "$@"; }
|
97 |
9801
|
aaronmk
|
|
98 |
10247
|
aaronmk
|
|
99 |
|
|
#### data loading
|
100 |
|
|
|
101 |
|
|
# prevent automated tests when the public schema contains the live DB
|
102 |
|
|
if test "$(hostname -s)" = vegbiendev; then export can_test=; fi
|
103 |
|
|
|
104 |
8705
|
aaronmk
|
fi
|