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 9013 aaronmk
root_dir="$(dirname "${BASH_SOURCE[0]}")"/../..
9 8699 aaronmk
bin_dir="$root_dir"/bin
10 8924 aaronmk
bin_dir_abs="$(realpath "$bin_dir")"
11 8705 aaronmk
12 8925 aaronmk
export PATH="$bin_dir_abs:$PATH"
13 8708 aaronmk
14 8939 aaronmk
#### make
15
16 8958 aaronmk
root_make () { echo_func; make --directory="$root_dir" "$@"; }
17 8939 aaronmk
18 8890 aaronmk
#### connection vars
19
20
: "${remote_server=vegbiendev.nceas.ucsb.edu}"
21
: "${local_server=localhost}"
22
: "${local_user=bien}"
23
: "${local_password="$(cat "$root_dir"/config/bien_password)"}"
24
25
#### databases
26
27
### MySQL
28
29 8891 aaronmk
: "${postgres_compat=1}"
30
31 8959 aaronmk
mysqldump_local () { echo_func; use_local_remote; mysqldump_diffable "$@"; }
32 8892 aaronmk
33 8890 aaronmk
### PostgreSQL
34
35 8833 aaronmk
psql () # usage: [file=...] [dir=...] self
36 8777 aaronmk
{
37 8881 aaronmk
	echo_func
38 8777 aaronmk
	if test -n "$file"; then
39
		set -- --file "$file" "$@"
40 8834 aaronmk
		local dir="${dir:-$(dirname "$file")}"
41 8777 aaronmk
	fi
42 8834 aaronmk
	local dir="${dir:-$top_dir}"
43 8777 aaronmk
44 8790 aaronmk
	local psql_cmd="psql_$(if log_sql; then echo verbose; else echo script; fi)_vegbien"
45 8777 aaronmk
	(cat <<EOF
46
\cd $dir
47
\set schema "$schema"
48
\set table "$table"
49
\set table_str '''"$table"'''
50
SET search_path TO "$schema", util;
51
EOF
52
	cat)|
53 8937 aaronmk
	env no_search_path=1 "$psql_cmd" --output /dev/fd/4 "$@" 4>&1 >&2
54 8777 aaronmk
}
55
56 8705 aaronmk
fi