Project

General

Profile

1
#!/bin/bash -e
2
# links to locally-available resources
3
. "$(dirname "${BASH_SOURCE[0]}")"/util.run
4

    
5
if self_not_included; then
6

    
7
root_dir="$(dirname "${BASH_SOURCE[0]}")"/../..
8
bin_dir="$root_dir"/bin
9

    
10
export PATH="$bin_dir:$PATH"
11

    
12
#### connection vars
13

    
14
: "${remote_server=vegbiendev.nceas.ucsb.edu}"
15
: "${local_server=localhost}"
16
: "${local_user=bien}"
17
: "${local_password="$(cat "$root_dir"/config/bien_password)"}"
18

    
19
#### databases
20

    
21
### MySQL
22

    
23
: "${postgres_compat=1}"
24

    
25
mysql ()
26
{
27
	echo_func
28
	echo_run mysql_bien --database="$schema" --verbose "$@"
29
}
30

    
31
### PostgreSQL
32

    
33
psql () # usage: [file=...] [dir=...] self
34
{
35
	echo_func
36
	if test -n "$file"; then
37
		set -- --file "$file" "$@"
38
		local dir="${dir:-$(dirname "$file")}"
39
	fi
40
	local dir="${dir:-$top_dir}"
41
	
42
	local psql_cmd="psql_$(if log_sql; then echo verbose; else echo script; fi)_vegbien"
43
	(cat <<EOF
44
\cd $dir
45
\set schema "$schema"
46
\set table "$table"
47
\set table_str '''"$table"'''
48
SET search_path TO "$schema", util;
49
EOF
50
	cat)|
51
	env no_search_path=1 "$psql_cmd" --output /dev/fd/3 "$@" 3>&1 >&2
52
}
53

    
54
fi
(2-2/4)