Project

General

Profile

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
: "${PATH_add=1}"
18
if test "$PATH_add"; then export PATH="$bin_dir_abs:$PATH"; fi
19

    
20
#### make
21

    
22
root_make() { echo_func; make --directory="$root_dir" "$@"; }
23

    
24
#### connection vars
25

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

    
35
#### 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
#### databases
45

    
46
### MySQL
47

    
48
: "${postgres_compat=1}"
49

    
50
mysql_local() { echo_func; use_local_remote; mysql "$@"; }
51

    
52
mysql_export_local() { echo_func; use_local_remote; mysql_export "$@"; }
53

    
54
mysqldump_local() { echo_func; use_local_remote; mysqldump_diffable "$@"; }
55

    
56
mysql_root() { echo_func; use_local_remote; use_root; mysql "$@"; }
57

    
58
### PostgreSQL
59

    
60
func_override psql__db_sh
61
psql() # usage: [file=...] [dir=...] self
62
{
63
	echo_func; kw_params file dir
64
	if test "$file"; then local dir="${dir:-$(dirname "$file")}"; fi
65
	local dir="${dir:-$top_dir}"
66
	mk_schema_esc
67
	mk_table_esc
68
	
69
	use_local
70
	(if test "$schema" -a "$table"; then cat <<EOF
71
\cd $dir
72
\set schema $schema_esc
73
\set table $table_esc
74
\set table_str '''$table_esc'''
75
SET search_path TO $schema_esc;
76
EOF
77
	fi
78
	cat${file:+ "$file"}
79
	)|psql__db_sh "$@"
80
}
81

    
82
public_schema_exists() { psql_script_vegbien </dev/null 2>/dev/null; }
83

    
84
pg_dump_local() { echo_func; use_local; pg_dump "$@"; }
85

    
86

    
87
#### sync
88

    
89
: "${sync_local_dir=$root_dir}"
90
: "${sync_remote_subdir=bien/}"
91
: "${sync_remote_url=jupiter:/data/dev/aaronmk/$sync_remote_subdir}"
92

    
93
sync_upload() { echo_func; use_sync; upload --no-owner --no-group "$@"; }
94

    
95

    
96
#### data loading
97

    
98
# prevent automated tests when the public schema contains the live DB
99
if test "$(hostname -s)" = vegbiendev; then export can_test=; fi
100

    
101
fi
(6-6/11)