11#! /bin/bash
22set -e
33
4+ echoerr () { echo " $@ " 1>&2 ; }
5+
46if [ ! -f ' /var/www/BookStack/.env' ]; then
5- cp /var/www/BookStack/.env.example /var/www/BookStack/.env
7+ if [ " $DB_HOST " ]; then
8+ cat > /var/www/BookStack/.env << EOF
9+ # Environment
10+ APP_ENV=production
11+ APP_DEBUG=false
12+ APP_KEY=SomeRandomString
13+
14+ # Database details
15+ DB_HOST=${DB_HOST:- localhost}
16+ DB_DATABASE=${DB_DATABASE:- bookstack}
17+ DB_USERNAME=${DB_USERNAME:- bookstack}
18+ DB_PASSWORD=${DB_PASSWORD:- password}
19+
20+ # Cache and session
21+ CACHE_DRIVER=file
22+ SESSION_DRIVER=file
23+ # If using Memcached, comment the above and uncomment these
24+ #CACHE_DRIVER=memcached
25+ #SESSION_DRIVER=memcached
26+ QUEUE_DRIVER=sync
27+
28+ # Memcached settings
29+ # If using a UNIX socket path for the host, set the port to 0
30+ # This follows the following format: HOST:PORT:WEIGHT
31+ # For multiple servers separate with a comma
32+ MEMCACHED_SERVERS=127.0.0.1:11211:100
33+
34+ # Storage
35+ STORAGE_TYPE=local
36+ # Amazon S3 Config
37+ STORAGE_S3_KEY=false
38+ STORAGE_S3_SECRET=false
39+ STORAGE_S3_REGION=false
40+ STORAGE_S3_BUCKET=false
41+ # Storage URL
42+ # Used to prefix image urls for when using custom domains/cdns
43+ STORAGE_URL=false
644
7- if [ " $MYSQL_PORT_3306_TCP " ]; then
8- sed -i " s/\(DB_HOST *= *\).*/\1mysql/" ' /var/www/BookStack/.env'
9- sed -i " s/\(DB_DATABASE *= *\).*/\1${MYSQL_ENV_MYSQL_DATABASE:- root} /" ' /var/www/BookStack/.env'
10- sed -i " s/\(DB_USERNAME *= *\).*/\1${MYSQL_ENV_MYSQL_USER:- $MYSQL_ENV_MYSQL_ROOT_PASSWORD } /" ' /var/www/BookStack/.env'
11- sed -i " s/\(DB_PASSWORD *= *\).*/\1${MYSQL_ENV_MYSQL_PASSWORD:- bookstack} /" ' /var/www/BookStack/.env'
45+ # General auth
46+ AUTH_METHOD=standard
1247
13- cd /var/www/BookStack/ && php artisan key:generate && php artisan migrate --force
48+ # Social Authentication information. Defaults as off.
49+ GITHUB_APP_ID=false
50+ GITHUB_APP_SECRET=false
51+ GOOGLE_APP_ID=false
52+ GOOGLE_APP_SECRET=false
53+ # URL used for social login redirects, NO TRAILING SLASH
54+ EOF
1455 else
1556 echo >&2 ' warning: missing MYSQL_PORT_3306_TCP environment variables'
1657 echo >&2 ' Did you forget to --link some_mysql_container:mysql ?'
1758 exit 1
1859 fi
1960fi
2061
21- apache2-foreground
62+ echoerr wait-for-db: waiting for ${DB_HOST} :3306
63+
64+ timeout 15 bash << EOT
65+ while ! (echo > /dev/tcp/${DB_HOST} /3306) >/dev/null 2>&1;
66+ do sleep 1;
67+ done;
68+ EOT
69+ RESULT=$?
70+
71+ if [ $RESULT -eq 0 ]; then
72+ # sleep another second for so that we don't get a "the database system is starting up" error
73+ sleep 1
74+ echoerr wait-for-db: done
75+ else
76+ echoerr wait-for-db: timeout out after 15 seconds waiting for ${DB_HOST} :3306
77+ fi
78+
79+ cd /var/www/BookStack/ && php artisan key:generate && php artisan migrate --force
80+
81+ exec apache2-foreground
0 commit comments