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
export PATH="$bin_dir_abs:$PATH"
18

    
19
#### make
20

    
21
func_override make__make_sh
22
make()
23
{
24
	echo_func
25
	if ((verbosity == 1)); then local verbosity=; fi # use default
26
	make__make_sh "$@"
27
}
28

    
29
root_make() { echo_func; make --directory="$root_dir" "$@"; }
30

    
31
#### connection vars
32

    
33
: "${remote_ssh_server=vegbiendev.nceas.ucsb.edu}"
34
: "${remote_server=}"
35
: "${local_server=localhost}"
36
: "${local_user=bien}"
37
: "${local_password="$(cat "$root_dir"/config/bien_password)"}"
38
: "${local_pg_database=vegbien}"
39
: "${root_user=root}"
40
: "${root_password=$local_password}"
41

    
42
#### databases
43

    
44
### MySQL
45

    
46
: "${postgres_compat=1}"
47

    
48
mysql_local() { echo_func; use_local_remote; mysql "$@"; }
49

    
50
mysql_export_local() { echo_func; use_local_remote; mysql_export "$@"; }
51

    
52
mysqldump_local() { echo_func; use_local_remote; mysqldump_diffable "$@"; }
53

    
54
mysql_root() { echo_func; use_local_remote; use_root; mysql "$@"; }
55

    
56
### PostgreSQL
57

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

    
79
public_schema_exists() { psql_script_vegbien </dev/null 2>/dev/null; }
80

    
81

    
82
#### sync
83

    
84
: "${sync_local_dir=$root_dir}"
85
: "${sync_remote_url=jupiter:/data/dev/aaronmk/bien}"
86

    
87
sync_upload() { echo_func; use_sync; upload "$@"; }
88

    
89
sync_download() { echo_func; use_sync; upload "$@"; }
90

    
91
fi
(5-5/9)