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