-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·31 lines (23 loc) · 942 Bytes
/
setup.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
#!/bin/bash
# make sure that ALL databases are available
# exit on error
set -e
sed --in-place --expression "s|^|${DEPLOYMENT_NAME:+${DEPLOYMENT_NAME}-}|" \
--expression "s|^\(${DEPLOYMENT_NAME}-\)${DEPLOYMENT_NAME}-|\1|g" /root/.pgpass
for DATABASE_DUMP in $POSTGRES_SETUP; do
HOST=$(echo "$DATABASE_DUMP" | cut -d '/' -f 1)
echo "[INFO] check availability of host $HOST"
psql --host "${DEPLOYMENT_NAME:+${DEPLOYMENT_NAME}-}${HOST}-db" \
--username "postgres" --file "postgres/health-check.sql" postgres > /dev/null
done
echo "[INFO] all databases are available"
# setup databases
# do not abort on error
set +e
for DATABASE_DUMP in $POSTGRES_SETUP; do
HOST=$(echo "$DATABASE_DUMP" | cut -d '/' -f 1)
echo "[INFO] initialize host $HOST with $DATABASE_DUMP"
psql --host "${DEPLOYMENT_NAME:+${DEPLOYMENT_NAME}-}${HOST}-db" \
--username "postgres" --file "postgres/$DATABASE_DUMP" postgres
done
echo "finishSetup"