-
Notifications
You must be signed in to change notification settings - Fork 12
/
run-a-little-postgres.sh
executable file
·93 lines (68 loc) · 1.21 KB
/
run-a-little-postgres.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# default options
destroy_existing=0
# local variables
initialized=0
function helptext {
cat <<EOH
Available Options:
-x
destroy the existing pgdata directory and start afresh
-h
shows this help text
EOH
exit
}
while getopts "xh" opt; do
case $opt in
x)
destroy_existing=1
;;
\?)
helptext
;;
h)
helptext
;;
esac
done
set -xe
export PATH="/usr/local/Cellar/postgresql/10.5/bin/:$PATH"
export PGDATA="$PWD/pgdata"
export PGHOST="$PGDATA/sockets"
export PGDATABASE="postgres"
export PGUSER="$USER"
if [ $destroy_existing -eq 1 ]; then
rm -rf $PGDATA
fi
if [ ! -d "$PGDATA" ]; then
pg_ctl init
mkdir -p "$PGDATA/sockets"
cat >> "$PGDATA/postgresql.conf" << EOF
unix_socket_directories = 'sockets'
listen_addresses = ''
EOF
initialized=1
fi
pg_ctl start
function cleanup {
set -x
pg_ctl stop
}
trap 'cleanup' SIGINT
if [ $initialized -eq 1 ]; then
createdb postgres_test
fi
cat > pgconfig.sh <<EOF
export PGHOST=$PGHOST
export PGDATABASE=$PGDATABASE
export PGUSER=$PGUSER
EOF
set +x
echo
echo \`source pgconfig.sh\` to get useful environment variables set up in other shells.
echo
while true; do
echo "a little postgres running... (ctrl-c to stop)"
sleep 60
done