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
mysql ()
24
{
25
	echo_func
26
	echo_run mysql_bien --database="$schema" --verbose "$@"
27
}
28

    
29
### PostgreSQL
30

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

    
52
fi
(2-2/4)