Project

General

Profile

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
. "$(dirname "${BASH_SOURCE[0]}")"/sync.sh
6

    
7
if self_not_included; then
8

    
9
root_dir="$(canon_rel_path "$(dirname "${BASH_SOURCE[0]}")"/../..)" || return
10

    
11
root_rel_path() { echo_func; base_dir="$root_dir" canon_rel_path "$1"; }
12

    
13
bin_dir="$root_dir"/bin
14
bin_dir_abs="$(realpath "$bin_dir")" || return
15

    
16
export PATH="$bin_dir_abs:$PATH"
17

    
18
#### make
19

    
20
root_make() { echo_func; make --directory="$root_dir" "$@"; }
21

    
22
#### connection vars
23

    
24
: "${remote_ssh_server=vegbiendev.nceas.ucsb.edu}"
25
: "${remote_server=}"
26
: "${local_server=localhost}"
27
: "${local_user=bien}"
28
: "${local_password="$(cat "$root_dir"/config/bien_password)"}"
29
: "${local_pg_database=vegbien}"
30
: "${root_user=root}"
31
: "${root_password=$local_password}"
32

    
33
#### databases
34

    
35
### MySQL
36

    
37
: "${postgres_compat=1}"
38

    
39
mysql_local() { echo_func; use_local_remote; mysql "$@"; }
40

    
41
mysql_export_local() { echo_func; use_local_remote; mysql_export "$@"; }
42

    
43
mysqldump_local() { echo_func; use_local_remote; mysqldump_diffable "$@"; }
44

    
45
mysql_root() { echo_func; use_local_remote; use_root; mysql "$@"; }
46

    
47
### PostgreSQL
48

    
49
func_override psql__db_sh
50
psql() # usage: [file=...] [dir=...] self
51
{
52
	echo_func; kw_params file dir
53
	if test "$file"; then local dir="${dir:-$(dirname "$file")}"; fi
54
	local dir="${dir:-$top_dir}"
55
	mk_schema_esc
56
	mk_table_esc
57
	
58
	use_local
59
	(cat <<EOF
60
\cd $dir
61
\set schema $schema_esc
62
\set table $table_esc
63
\set table_str '''$table_esc'''
64
SET search_path TO $schema_esc, util;
65
EOF
66
	cat${file:+ "$file"}
67
	)|psql__db_sh "$@"
68
}
69

    
70
public_schema_exists() { psql_script_vegbien </dev/null 2>/dev/null; }
71

    
72

    
73
#### sync
74

    
75
: "${sync_local_dir=$root_dir}"
76
: "${sync_remote_url=jupiter:/data/dev/aaronmk/bien}"
77

    
78
sync_upload() { echo_func; use_sync; upload "$@"; }
79

    
80
sync_download() { echo_func; use_sync; upload "$@"; }
81

    
82
fi
(5-5/9)