forked from afterlogic/docker-aurora-files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-lamp.sh
112 lines (88 loc) · 3.14 KB
/
run-lamp.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
function exportBoolean {
if [ "${!1}" = "**Boolean**" ]; then
export ${1}=''
else
export ${1}='Yes.'
fi
}
function runMariaDB() {
/usr/bin/mysqld_safe --timezone=${DATE_TIMEZONE}&
RET=1
while [[ RET -eq 1 ]]; do
sleep 5
RET=$(/etc/init.d/mysql status | grep stopped | wc -l);
done
}
function countFilesInDir() {
find $1 -maxdepth 1 -not -path '*/.*' -not -path $1 2>/dev/null | wc -l
}
function mergeConfig() {
jq -s '.[0] * .[1]' $1 $2 > /tmp/tempConfig.json && mv -f /tmp/tempConfig.json $1
}
function applyUserConfigOverrides() {
configOverridesDir=$1
echo "=> Applying user config overrides"
aurorafilesSettingsDirPath=/var/www/html/data/settings
mainConfigFile=$configOverridesDir/config.json
if [[ -f $mainConfigFile ]]; then
echo "=> Processing $mainConfigFile"
mergeConfig $aurorafilesSettingsDirPath/config.json $mainConfigFile
fi
if [[ $(countFilesInDir $configOverridesDir/modules) -gt 0 ]]; then
echo "=> Applying modules configs"
for moduleConfig in $configOverridesDir/modules/*; do
echo "=> Processing $moduleConfig"
configFilePath="${moduleConfig##$configOverridesDir/}"
mergeConfig $aurorafilesSettingsDirPath/$configFilePath $configOverridesDir/$configFilePath
done
fi
}
exportBoolean LOG_STDOUT
exportBoolean LOG_STDERR
if [ $LOG_STDERR ]; then
/bin/ln -sf /dev/stderr /var/log/apache2/error.log
else
LOG_STDERR='No.'
fi
if [ $ALLOW_OVERRIDE == 'All' ]; then
/bin/sed -i 's/AllowOverride\ None/AllowOverride\ All/g' /etc/apache2/apache2.conf
fi
if [ $LOG_LEVEL != 'warn' ]; then
/bin/sed -i "s/LogLevel\ warn/LogLevel\ ${LOG_LEVEL}/g" /etc/apache2/apache2.conf
fi
# enable php short tags:
/bin/sed -i "s/short_open_tag\ \=\ Off/short_open_tag\ \=\ On/g" /etc/php/7.4/apache2/php.ini
# stdout server info:
if [ $LOG_STDOUT ]; then
/bin/ln -sf /dev/stdout /var/log/apache2/access.log
fi
# Set PHP timezone
/bin/sed -i "s/\;date\.timezone\ \=/date\.timezone\ \=\ ${DATE_TIMEZONE}/" /etc/php/7.4/apache2/php.ini
# Initialize databases if none
if [[ ! -d /var/lib/mysql/afterlogic ]]; then
echo "=> Creating database..."
mysql_install_db > /dev/null 2>&1
runMariaDB
mysql -uroot -e "CREATE DATABASE afterlogic"
mysql -uroot -e "CREATE USER 'rootuser'@'localhost' IDENTIFIED BY 'dockerbundle'"
mysql -uroot -e "GRANT USAGE ON * . * TO 'rootuser'@'localhost' IDENTIFIED BY 'dockerbundle';"
mysql -uroot -e "GRANT SELECT,ALTER,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,REFERENCES ON \`afterlogic\` . * TO 'rootuser'@'localhost';FLUSH PRIVILEGES;"
mysql -uroot -e "SET PASSWORD FOR 'rootuser'@'localhost' = PASSWORD( 'dockerbundle' ); FLUSH PRIVILEGES;"
echo "=> Database created!"
php /var/www/html/afterlogic.php
chown -R www-data:www-data /var/www/html/data
chmod -R 0777 /var/www/html/data
else
echo "=> Using an existing database"
runMariaDB
fi
if [[ $(countFilesInDir /opt/afterlogic/data/settings) -gt 0 ]]; then
applyUserConfigOverrides /opt/afterlogic/data/settings
fi
# Run Apache:
if [ $LOG_LEVEL == 'debug' ]; then
/usr/sbin/apachectl -DFOREGROUND -k start -e debug
else
&>/dev/null /usr/sbin/apachectl -DFOREGROUND -k start
fi