-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdocker-initdb.sh
executable file
·53 lines (45 loc) · 1014 Bytes
/
docker-initdb.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
#!/bin/sh
NAVETC=/etc/nav
DBCONF="$NAVETC/db.conf"
NOINITDB=${NOINITDB:-0}
DB=${PGDATABASE:-nav}
USER=${PGUSER:-nav}
HOST=${PGHOST:-postgres}
PORT=${PGPORT:-5432}
PASSWORD=${PGPASSWORD:-$(pwgen 12 1)}
log()
{
echo "$(date): $@"
}
cat > "$DBCONF" <<EOF
# autogenerated on container start
dbhost=$HOST
dbport=$PORT
db_nav=$DB
script_default=$USER
userpw_$USER=$PASSWORD
EOF
>&2 cat "$DBCONF"
if [ "${NOINITDB}" -eq 0 ]; then
export PGHOST="$HOST"
export PGUSER="$USER"
export PGDATABASE="$DB"
export PGPORT="$PORT"
export PGPASSWORD="$PASSWORD"
fi
until psql -l; do
log "Postgres is unavailable - sleeping"
sleep 1
done
if [ "${NOINITDB}" -eq 0 ] && ! (psql -l | grep -q "$DB"); then
if [ -f "/database.sql" ]; then
log "Initializing a new database schema from /database.sql"
navsyncdb -c -r /database.sql
else
log "Initializing a new database schema"
navsyncdb -c
fi
fi
log "Synchronizing database schema"
navsyncdb -o
log "Synchronization complete"