-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathdocker-entrypoint2.sh
More file actions
executable file
·111 lines (84 loc) · 2.71 KB
/
docker-entrypoint2.sh
File metadata and controls
executable file
·111 lines (84 loc) · 2.71 KB
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
#!/bin/bash
set -euo pipefail
# Remove exec from original entrypoint so we can continue here
sed -i -e 's/exec/\# exec/g' /usr/local/bin/docker-entrypoint.sh
# Normal setup
/bin/bash /usr/local/bin/docker-entrypoint.sh "$1"
# Generate vars for wp-config.php injection
echo "Generating PHP Defines from ENV..."
DEFINES=$(awk -v pat="$CONFIG_VAR_FLAG" 'END {
print "// Generated by docker-entrypoint2.sh:";
for (name in ENVIRON) {
if ( name ~ pat ) {
print "define(\"" substr(name, length(pat)+1) "\", \"" ENVIRON[name] "\");"
}
}
print " "
}' < /dev/null)
echo "$DEFINES"
echo "Adding Defines to wp-config.php..."
# Remove previously-injected vars
sed '/\/\/ENTRYPOINT_START/,/\/\/ENTRYPOINT_END/d' wp-config.php > wp-config.tmp
# Add current vars
awk '/^\/\*.*stop editing.*\*\/$/ && c == 0 { c = 1; system("cat") } { print }' wp-config.tmp > wp-config.php <<EOF
//ENTRYPOINT_START
$DEFINES
if (isset(\$_SERVER['HTTP_X_FORWARDED_PROTO']) && \$_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
\$_SERVER['HTTPS'] = 'on';
}
//ENTRYPOINT_END
EOF
rm wp-config.tmp
# First-run configuration
if [ ! -f /var/www/firstrun ]; then
echo "Executing first-run setup..."
# Install HyperDB Config
if [ "$ENABLE_HYPERDB" == "true" ]; then
echo "Installing HyperDB WPDB Drop-in"
cp /var/www/config/hyperdb/db-config.php /var/www/html/
cp /var/www/config/hyperdb/db.php /var/www/html/wp-content/
fi
# Install $WP_PLUGINS
echo "Installing WordPress Plugins: $WP_PLUGINS"
for PLUGIN in $WP_PLUGINS; do
echo "## Installing $PLUGIN"
if [ ! -e "wp-content/plugins/$PLUGIN" ]; then
if ( wget "https://downloads.wordpress.org/plugin/$PLUGIN.zip" ); then
unzip "$PLUGIN.zip" -q -d /var/www/html/wp-content/plugins/
rm "$PLUGIN.zip"
else
echo "## WARN: wget failed for https://downloads.wordpress.org/plugin/$PLUGIN.zip"
fi
else
echo "### $PLUGIN already installed, skipping."
fi
done
CRON_CMD="${CRON_CMD:-}"
if [ -n "$CRON_CMD" ]; then
echo "Installing Cron command: $CRON_CMD"
#write out current crontab
crontab -l > /tmp/mycron
echo "$CRON_CMD" >> /tmp/mycron
#install new cron file
crontab /tmp/mycron
echo "Cron CMD installed."
rm /tmp/mycron
fi
# Print firstrun date/time to file
date > /var/www/firstrun
else
echo "First run already completed, skipping configuration."
fi
# Set up Nginx Helper log directory
mkdir -p wp-content/uploads/nginx-helper
# Set usergroup for all modified files
chown -R www-data:www-data /var/www/html/
if [ "$ENABLE_CRON" == "true" ]; then
echo "Starting Cron daemon..."
if pgrep -x "crond" > /dev/null; then
echo "Running"
else
/usr/sbin/crond
fi
fi
exec "$@"