Project

General

Profile

1 8699 aaronmk
#!/bin/bash -e
2
# links to locally-available resources
3 8893 aaronmk
. "$(dirname "${BASH_SOURCE[0]}")"/util.sh
4 9014 aaronmk
. "$(dirname "${BASH_SOURCE[0]}")"/db.sh
5 8699 aaronmk
6 8705 aaronmk
if self_not_included; then
7
8 9331 aaronmk
root_dir="$(canon_rel_path "$(dirname "${BASH_SOURCE[0]}")"/../..)" || return
9 9787 aaronmk
10
root_rel_path() { log++; base_dir="$root_dir" path="$1" rel_path; }
11
12 8699 aaronmk
bin_dir="$root_dir"/bin
13 9331 aaronmk
bin_dir_abs="$(realpath "$bin_dir")" || return
14 8705 aaronmk
15 8925 aaronmk
export PATH="$bin_dir_abs:$PATH"
16 8708 aaronmk
17 8939 aaronmk
#### make
18
19 9074 aaronmk
root_make() { echo_func; make --directory="$root_dir" "$@"; }
20 8939 aaronmk
21 8890 aaronmk
#### connection vars
22
23 9630 aaronmk
: "${remote_ssh_server=vegbiendev.nceas.ucsb.edu}"
24
: "${remote_server=}"
25 8890 aaronmk
: "${local_server=localhost}"
26
: "${local_user=bien}"
27
: "${local_password="$(cat "$root_dir"/config/bien_password)"}"
28 9650 aaronmk
: "${local_pg_database=vegbien}"
29 9575 aaronmk
: "${root_user=root}"
30
: "${root_password=$local_password}"
31 8890 aaronmk
32
#### databases
33
34
### MySQL
35
36 8891 aaronmk
: "${postgres_compat=1}"
37
38 9577 aaronmk
mysql_local() { echo_func; use_local_remote; mysql "$@"; }
39
40 9153 aaronmk
mysql_export_local() { echo_func; use_local_remote; mysql_export "$@"; }
41
42 9074 aaronmk
mysqldump_local() { echo_func; use_local_remote; mysqldump_diffable "$@"; }
43 8892 aaronmk
44 9576 aaronmk
mysql_root() { echo_func; use_local_remote; use_root; mysql "$@"; }
45
46 8890 aaronmk
### PostgreSQL
47
48 9650 aaronmk
func_override psql__db_sh
49 9074 aaronmk
psql() # usage: [file=...] [dir=...] self
50 8777 aaronmk
{
51 9235 aaronmk
	echo_func; kw_params file dir
52 9645 aaronmk
	if test "$file"; then local dir="${dir:-$(dirname "$file")}"; fi
53 8834 aaronmk
	local dir="${dir:-$top_dir}"
54 9427 aaronmk
	mk_schema_esc
55
	mk_table_esc
56 8777 aaronmk
57 9650 aaronmk
	use_local
58 8777 aaronmk
	(cat <<EOF
59
\cd $dir
60 9427 aaronmk
\set schema $schema_esc
61
\set table $table_esc
62
\set table_str '''$table_esc'''
63
SET search_path TO $schema_esc, util;
64 8777 aaronmk
EOF
65 9645 aaronmk
	cat${file:+ "$file"}
66 9650 aaronmk
	)|psql__db_sh "$@"
67 8777 aaronmk
}
68
69 9074 aaronmk
public_schema_exists() { psql_script_vegbien </dev/null 2>/dev/null; }
70 9046 aaronmk
71 8705 aaronmk
fi