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