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

    
6
if self_not_included; then
7

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

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

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

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

    
17
#### make
18

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

    
21
#### connection vars
22

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

    
32
#### databases
33

    
34
### MySQL
35

    
36
: "${postgres_compat=1}"
37

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

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

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

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

    
46
### PostgreSQL
47

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

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

    
71
fi
(5-5/8)