33# Exit on non defined variables and on non zero exit codes
44set -eu
55
6+ # + ---------- + #
7+ # | -- VARS -- | #
8+ # + ---------- + #
9+
610SERVER_ADMIN=" ${SERVER_ADMIN:- you@ example.com} "
711HTTP_SERVER_NAME=" ${HTTP_SERVER_NAME:- localhost} "
812HTTPS_SERVER_NAME=" ${HTTPS_SERVER_NAME:- localhost} "
@@ -11,41 +15,100 @@ TZ="${TZ:-UTC}"
1115PHP_MEMORY_LIMIT=" ${PHP_MEMORY_LIMIT:- 256M} "
1216UPLOAD_MAX_FILESIZE=" ${UPLOAD_MAX_FILESIZE:- 8M} "
1317
14- echo ' Updating configurations'
18+ # If TRUE, outputs pre and post-change config files, if a /debug folder has also been mounted.
19+ # i.e. - '/opt/docker/configs/littlelink/debug:/debug:rw'
20+ # Useful for comparing (and fixing) changes, if necessary.
21+ DEBUG=" TRUE"
22+
23+ # Read Current LLC Version
24+ # When version.json has CR/LF, it fx up, so have to add tr to remove the line endings.
25+ v=" $( cat /htdocs/version.json | tr -d ' \r\n' ) "
26+
27+ # Calc length of whitespace we need, based on version length.
28+ vlen=" $(( 27 - ${# v} )) "
29+
30+ echo ' + ------------------------------------------------------------------ +'
31+ printf ' | LITTLELINK CUSTOM v%s%*s|\n' " ${v} " " $vlen " | tr ' ' " "
32+
33+ # + ---------------- + #
34+ # | -- HTTPD.CONF -- | #
35+ # + ---------------- + #
36+
37+ echo ' + ------------------------------------------------------------------ +'
38+ echo ' | Updating Configuration: Apache Base (/etc/apache2/httpd.conf) |'
39+
40+ # ALTER: Server Admin, Name, Document Root.
41+
42+ if [[ ${DEBUG} == " TRUE" && -d /debug ]]; then cp /etc/apache2/httpd.conf /debug/httpd.BEFORE.conf; fi
1543
16- # Change Server Admin, Name, Document Root
1744sed -i " s/ServerAdmin\ you@example.com/ServerAdmin\ ${SERVER_ADMIN} /" /etc/apache2/httpd.conf
18- sed -i " s/#ServerName\ localhost :80/ServerName\ ${HTTP_SERVER_NAME} /" /etc/apache2/httpd.conf
45+ sed -i " s/#ServerName\ www.example.com :80/ServerName\ ${HTTP_SERVER_NAME} /" /etc/apache2/httpd.conf
1946sed -i ' s#^DocumentRoot ".*#DocumentRoot "/htdocs"#g' /etc/apache2/httpd.conf
2047sed -i ' s#Directory "/var/www/localhost/htdocs"#Directory "/htdocs"#g' /etc/apache2/httpd.conf
2148sed -i ' s#AllowOverride None#AllowOverride All#' /etc/apache2/httpd.conf
2249
23- # Change TransferLog after ErrorLog
24- sed -i ' s#^ErrorLog .*#ErrorLog "/dev/stderr"\nTransferLog "/dev/stdout"#g' /etc/apache2/httpd.conf
25- sed -i ' s#CustomLog .* combined#CustomLog "/dev/stdout" combined#g' /etc/apache2/httpd.conf
26-
27- # SSL DocumentRoot and Log locations
28- sed -i ' s#^ErrorLog .*#ErrorLog "/dev/stderr"#g' /etc/apache2/conf.d/ssl.conf
29- sed -i ' s#^TransferLog .*#TransferLog "/dev/stdout"#g' /etc/apache2/conf.d/ssl.conf
30- sed -i ' s#^DocumentRoot ".*#DocumentRoot "/htdocs"#g' /etc/apache2/conf.d/ssl.conf
31- sed -i " s/ServerAdmin\ you@example.com/ServerAdmin\ ${SERVER_ADMIN} /" /etc/apache2/conf.d/ssl.conf
32- sed -i " s/ServerName\ localhost:443/ServerName\ ${HTTPS_SERVER_NAME} /" /etc/apache2/conf.d/ssl.conf
50+ # ALTER: TransferLog after ErrorLog.
51+ sed -i ' s#^ErrorLog .*#ErrorLog "logs/error.log"#g' /etc/apache2/httpd.conf
52+ sed -i ' s#LogFormat .* %t#LogFormat "[%{%a %b %d %H:%M:%S}t.%{usec_frac}t %{%Y}t] [httpd.conf] %h %l %u#g' /etc/apache2/httpd.conf
53+ sed -i ' s#CustomLog logs.* combined#BrowserMatchNoCase ^healthcheck nolog\n\n CustomLog "logs/access.log" combinedio env=!nolog\n#g' /etc/apache2/httpd.conf
3354
34- # Re-define LogLevel
55+ # ALTER: LogLevel.
3556sed -i " s#^LogLevel .*#LogLevel ${LOG_LEVEL} #g" /etc/apache2/httpd.conf
3657
3758# Enable commonly used apache modules
38- sed -i ' s/#LoadModule\ rewrite_module/LoadModule\ rewrite_module/' /etc/apache2/httpd.conf
3959sed -i ' s/#LoadModule\ deflate_module/LoadModule\ deflate_module/' /etc/apache2/httpd.conf
4060sed -i ' s/#LoadModule\ expires_module/LoadModule\ expires_module/' /etc/apache2/httpd.conf
61+ sed -i ' s/#LoadModule\ logio_module/LoadModule\ logio_module/' /etc/apache2/httpd.conf
62+ sed -i ' s/#LoadModule\ rewrite_module/LoadModule\ rewrite_module/' /etc/apache2/httpd.conf
63+
64+ if [[ ${DEBUG} == " TRUE" && -d /debug ]]; then cp /etc/apache2/httpd.conf /debug/httpd.AFTER.conf; fi
4165
42- # Modify php memory limit and timezone
66+ # + -------------- + #
67+ # | -- SSL.CONF -- | #
68+ # + -------------- + #
69+
70+ echo ' | Updating Configuration: Apache SSL (/etc/apache2/conf.d/ssl.conf) |'
71+
72+ # ALTER: SSL DocumentRoot and Log locations
73+
74+ if [[ ${DEBUG} == " TRUE" && -d /debug ]]; then cp /etc/apache2/conf.d/ssl.conf /debug/ssl.BEFORE.conf; fi
75+
76+ sed -i ' s#^ErrorLog .*#ErrorLog "logs/ssl-error.log"#g' /etc/apache2/conf.d/ssl.conf
77+ sed -i " s/^TransferLog .*/#TransferLog \" logs\/ssl-transfer.log\" \nLogLevel ${LOG_LEVEL} /g" /etc/apache2/conf.d/ssl.conf
78+ sed -i ' s#^DocumentRoot ".*#DocumentRoot "/htdocs"#g' /etc/apache2/conf.d/ssl.conf
79+ sed -i " s/ServerAdmin\ you@example.com/ServerAdmin\ ${SERVER_ADMIN} /" /etc/apache2/conf.d/ssl.conf
80+ sed -i " s/ServerName\ www.example.com:443/ServerName\ ${HTTPS_SERVER_NAME} /" /etc/apache2/conf.d/ssl.conf
81+
82+ sed -i ' s#CustomLog .*#LogFormat "[%{%a %b %d %H:%M:%S}t.%{usec_frac}t %{%Y}t] [ssl.conf] %h %l %u \\"%r\\" %>s %b \\"%{Referer}i\\" \\"%{User-Agent}i\\"" combined\n\nCustomLog "logs/ssl-access.log" combined#g' /etc/apache2/conf.d/ssl.conf
83+ sed -i ' /.*%{SSL_PROTOCOL}x.*/d' /etc/apache2/conf.d/ssl.conf
84+
85+ if [[ ${DEBUG} == " TRUE" && -d /debug ]]; then cp /etc/apache2/conf.d/ssl.conf /debug/ssl.AFTER.conf; fi
86+
87+ # + ------------- + #
88+ # | -- PHP.INI -- | #
89+ # + ------------- + #
90+
91+ echo ' | Updating Configuration: PHP (/etc/php8/php.ini) |'
92+
93+ if [[ ${DEBUG} == " TRUE" && -d /debug ]]; then cp /etc/php8/php.ini /debug/php.BEFORE.ini; fi
94+
95+ # ALTER: Modify php memory limit and timezone
4396sed -i " s/memory_limit = .*/memory_limit = ${PHP_MEMORY_LIMIT} /" /etc/php8/php.ini
4497sed -i " s/upload_max_filesize = .*/upload_max_filesize = ${UPLOAD_MAX_FILESIZE} /" /etc/php8/php.ini
4598sed -i " s#^;date.timezone =\$ #date.timezone = \" ${TZ} \" #" /etc/php8/php.ini
4699
47100echo " is_llc_docker = true" >> /etc/php8/php.ini
48101
49- echo ' Running Apache'
102+ if [[ ${DEBUG} == " TRUE" && -d /debug ]]; then cp /etc/php8/php.ini /debug/php.AFTER.ini; fi
103+
104+ # + ---------- + #
105+ # | -- MISC -- | #
106+ # + ---------- + #
107+
108+ echo ' | Updating Configuration: Complete |'
109+ echo ' | ------------------------------------------------------------------ |'
110+ echo ' | Running Apache |'
111+ echo ' + ------------------------------------------------------------------ +'
112+ echo
50113
51114httpd -D FOREGROUND
0 commit comments