1
1
#! /bin/bash
2
2
set -eo pipefail
3
3
4
- [[ $ DEBUG == true ]] && set -x
4
+ [[ " ${ DEBUG} " == true ]] && set -x
5
5
6
6
check_database_connection () {
7
7
echo " Attempting to connect to database ..."
8
- case ${DB_DRIVER} in
8
+ case " ${DB_DRIVER} " in
9
9
mysql)
10
10
prog=" mysqladmin -h ${DB_HOST} -u ${DB_USERNAME} ${DB_PASSWORD: +-p$DB_PASSWORD } status"
11
11
;;
@@ -18,7 +18,7 @@ check_database_connection() {
18
18
while ! ${prog} > /dev/null 2>&1
19
19
do
20
20
timeout=$(( $timeout - 1 ))
21
- if [[ $timeout -eq 0 ]]; then
21
+ if [[ " $timeout " -eq 0 ]]; then
22
22
echo
23
23
echo " Could not connect to database server! Aborting..."
24
24
exit 1
@@ -31,9 +31,9 @@ check_database_connection() {
31
31
32
32
checkdbinitmysql () {
33
33
table=sessions
34
- if [ " $( mysql -N -s -h ${DB_HOST} -u ${DB_USERNAME} ${DB_PASSWORD: +-p$DB_PASSWORD } ${DB_DATABASE} -e \
34
+ if [[ " $( mysql -N -s -h ${DB_HOST} -u ${DB_USERNAME} ${DB_PASSWORD: +-p$DB_PASSWORD } ${DB_DATABASE} -e \
35
35
" select count(*) from information_schema.tables where \
36
- table_schema='${DB_DATABASE} ' and table_name='${DB_PREFIX}${table} ';" ) " -eq 1 ]; then
36
+ table_schema='${DB_DATABASE} ' and table_name='${DB_PREFIX}${table} ';" ) " -eq 1 ]] ; then
37
37
echo " Table ${DB_PREFIX}${table} exists! ..."
38
38
else
39
39
echo " Table ${DB_PREFIX}${table} does not exist! ..."
@@ -45,7 +45,7 @@ checkdbinitmysql() {
45
45
checkdbinitpsql () {
46
46
table=sessions
47
47
export PGPASSWORD=${DB_PASSWORD}
48
- if [ " $( psql -h ${DB_HOST} -U ${DB_USERNAME} -d ${DB_DATABASE} -c " SELECT to_regclass('${DB_PREFIX}${table} ');" | grep -c " ${DB_PREFIX}${table} " ) " -eq 1 ]; then
48
+ if [[ " $( psql -h ${DB_HOST} -U ${DB_USERNAME} -d ${DB_DATABASE} -c " SELECT to_regclass('${DB_PREFIX}${table} ');" | grep -c " ${DB_PREFIX}${table} " ) " -eq 1 ] ]; then
49
49
echo " Table ${DB_PREFIX}${table} exists! ..."
50
50
else
51
51
echo " Table ${DB_PREFIX}${table} does not exist! ..."
@@ -55,7 +55,7 @@ checkdbinitpsql() {
55
55
}
56
56
57
57
check_configured () {
58
- case ${DB_DRIVER} in
58
+ case " ${DB_DRIVER} " in
59
59
mysql)
60
60
checkdbinitmysql
61
61
;;
@@ -68,6 +68,7 @@ check_configured() {
68
68
initialize_system () {
69
69
echo " Initializing Cachet container ..."
70
70
71
+ APP_KEY=${APP_KEY:- null}
71
72
APP_ENV=${APP_ENV:- development}
72
73
APP_DEBUG=${APP_DEBUG:- true}
73
74
APP_URL=${APP_URL:- http:// localhost}
@@ -79,11 +80,11 @@ initialize_system() {
79
80
DB_USERNAME=${DB_USERNAME:- postgres}
80
81
DB_PASSWORD=${DB_PASSWORD:- postgres}
81
82
82
- if [ ${DB_DRIVER} = " pgsql" ]; then
83
+ if [[ " ${DB_DRIVER} " = " pgsql" ] ]; then
83
84
DB_PORT=${DB_PORT:- 5432}
84
85
fi
85
86
86
- if [ ${DB_DRIVER} = " mysql" ]; then
87
+ if [[ " ${DB_DRIVER} " = " mysql" ] ]; then
87
88
DB_PORT=${DB_PORT:- 3306}
88
89
fi
89
90
@@ -119,10 +120,15 @@ initialize_system() {
119
120
PHP_MAX_CHILDREN=${PHP_MAX_CHILDREN:- 5}
120
121
121
122
# configure env file
122
- keygen=" $( sudo php artisan key:generate) "
123
- echo ${keygen}
124
- appkey=$( echo ${keygen} | grep -oP ' (?<=\[).*(?=\])' )
125
- sed ' s,{{APP_KEY}},' ${appkey} ' ,g' -i /var/www/html/.env
123
+ if [[ " ${APP_KEY} " == null ]]; then
124
+ keygen=" $( sudo php artisan key:generate) "
125
+ echo " ${keygen} "
126
+ appkey=$( echo ${keygen} | grep -oP ' (?<=\[).*(?=\])' )
127
+ echo " Please set ${appkey} as your APP_KEY variable in the environment or docker-compose.yml and re-launch"
128
+ exit 1
129
+ fi
130
+
131
+ sed ' s,{{APP_KEY}},' ${APP_KEY} ' ,g' -i /var/www/html/.env
126
132
127
133
sed ' s,{{APP_ENV}},' " ${APP_ENV} " ' ,g' -i /var/www/html/.env
128
134
sed ' s,{{APP_DEBUG}},' " ${APP_DEBUG} " ' ,g' -i /var/www/html/.env
0 commit comments