-
Notifications
You must be signed in to change notification settings - Fork 73
/
yaptest-db-install.sh
executable file
·45 lines (36 loc) · 1.6 KB
/
yaptest-db-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh
if [ $# != 2 ]; then
echo "Usage: $0 yaptest_template.sql { osx | linux }"
exit 0;
fi
YAPTEST_TEMPLATE_SQL=$1
PLATFORM=$2
if [ "$PLATFORM" = "osx" ]; then
echo "Configuring for OSX"
YAPTEST_TEMPLATE_NAME=yaptest_template
EXISTING_DATABASE=template1
PSQL=psql81
export PATH=$PATH:/opt/local/bin:/opt/local/lib/postgresql80/bin # needed on mac for createuser, createdb and dropdb
which $PSQL
createuser -a -d postgres # needed to make sure the postgres user exists on mac - should exist elsewhere
else
echo "Configuring for Linux"
YAPTEST_TEMPLATE_NAME=yaptest_template
EXISTING_DATABASE=template1
PSQL=psql # change to psql8 on mac or symlink psql -> psql8
fi
echo "update pg_database set datistemplate = 'f', datallowconn = 't' where datname = '"$YAPTEST_TEMPLATE_NAME"';" | $PSQL $EXISTING_DATABASE
dropdb $YAPTEST_TEMPLATE_NAME
echo "DROP USER yaptest_user;" | $PSQL $EXISTING_DATABASE
createdb $YAPTEST_TEMPLATE_NAME
# In order to create databases we need to do things slightly
# differently on postgres 8.2+
PGVERSION82=`$PSQL -U postgres template1 -c 'SELECT version()' | grep 'PostgreSQL 8.[23456789]'`
if [ -z "$PGVERSION82" ]; then
echo "CREATE USER yaptest_user CREATEDB ;" | $PSQL $YAPTEST_TEMPLATE_NAME
else
echo "CREATE USER yaptest_user;" | $PSQL $YAPTEST_TEMPLATE_NAME
echo "UPDATE pg_shadow SET usecreatedb = 't' WHERE usename = 'yaptest_user';" | $PSQL $YAPTEST_TEMPLATE_NAME
fi
cat $YAPTEST_TEMPLATE_SQL | $PSQL $YAPTEST_TEMPLATE_NAME
echo "UPDATE pg_database SET datistemplate = 't', datallowconn = 't' WHERE datname = '"$YAPTEST_TEMPLATE_NAME"';" | $PSQL $YAPTEST_TEMPLATE_NAME