11#! /bin/bash
22set -e
33
4- DB_PORT=${DB_PORT:- 3306}
5-
64echoerr () { echo " $@ " 1>&2 ; }
75
6+ # Split out host and port from DB_HOST env variable
7+ IFS=" :" read -r DB_HOST_NAME DB_PORT <<< " $DB_HOST"
8+ DB_PORT=${DB_PORT:- 3306}
9+
810if [ ! -f ' /var/www/BookStack/.env' ]; then
911 if [[ " ${DB_HOST} " ]]; then
1012 cat > /var/www/BookStack/.env << EOF
@@ -19,7 +21,6 @@ if [ ! -f '/var/www/BookStack/.env' ]; then
1921
2022 # Database details
2123 DB_HOST=${DB_HOST:- localhost}
22- DB_PORT=${DB_PORT:- 3306}
2324 DB_DATABASE=${DB_DATABASE:- bookstack}
2425 DB_USERNAME=${DB_USERNAME:- bookstack}
2526 DB_PASSWORD=${DB_PASSWORD:- password}
@@ -79,15 +80,15 @@ if [ ! -f '/var/www/BookStack/.env' ]; then
7980 # URL used for social login redirects, NO TRAILING SLASH
8081EOF
8182 else
82- echo >&2 ' error: missing DB_PORT or DB_HOST environment variables '
83+ echo >&2 ' error: missing DB_HOST environment variable '
8384 exit 1
8485 fi
8586fi
8687
87- echoerr wait-for-db: waiting for ${DB_HOST } :${DB_PORT}
88+ echoerr wait-for-db: waiting for ${DB_HOST_NAME } :${DB_PORT}
8889
8990timeout 15 bash << EOT
90- while ! (echo > /dev/tcp/${DB_HOST } /${DB_PORT} ) >/dev/null 2>&1;
91+ while ! (echo > /dev/tcp/${DB_HOST_NAME } /${DB_PORT} ) >/dev/null 2>&1;
9192 do sleep 1;
9293done;
9394EOT
@@ -98,7 +99,7 @@ if [ $RESULT -eq 0 ]; then
9899 sleep 1
99100 echoerr wait-for-db: done
100101else
101- echoerr wait-for-db: timeout out after 15 seconds waiting for ${DB_HOST } :${DB_PORT}
102+ echoerr wait-for-db: timeout out after 15 seconds waiting for ${DB_HOST_NAME } :${DB_PORT}
102103fi
103104
104105cd /var/www/BookStack/ && php artisan key:generate && php artisan migrate --force
0 commit comments