forked from crazy-max/docker-matomo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
144 lines (121 loc) · 3.96 KB
/
entrypoint.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/sh
function runas_nginx() {
su - nginx -s /bin/sh -c "$1"
}
TZ=${TZ:-UTC}
MEMORY_LIMIT=${MEMORY_LIMIT:-256M}
UPLOAD_MAX_SIZE=${UPLOAD_MAX_SIZE:-16M}
OPCACHE_MEM_SIZE=${OPCACHE_MEM_SIZE:-128}
REAL_IP_FROM=${REAL_IP_FROM:-0.0.0.0/32}
REAL_IP_HEADER=${REAL_IP_HEADER:-X-Forwarded-For}
LOG_LEVEL=${LOG_LEVEL:-WARN}
SIDECAR_CRON=${SIDECAR_CRON:-0}
SSMTP_PORT=${SSMTP_PORT:-25}
SSMTP_HOSTNAME=${SSMTP_HOSTNAME:-$(hostname -f)}
SSMTP_TLS=${SSMTP_TLS:-NO}
# Timezone
echo "Setting timezone to ${TZ}..."
ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime
echo ${TZ} > /etc/timezone
# PHP
echo "Setting PHP-FPM configuration..."
sed -e "s/@MEMORY_LIMIT@/$MEMORY_LIMIT/g" \
-e "s/@UPLOAD_MAX_SIZE@/$UPLOAD_MAX_SIZE/g" \
/tpls/etc/php7/php-fpm.d/www.conf > /etc/php7/php-fpm.d/www.conf
# OpCache
echo "Setting OpCache configuration..."
sed -e "s/@OPCACHE_MEM_SIZE@/$OPCACHE_MEM_SIZE/g" \
/tpls/etc/php7/conf.d/opcache.ini > /etc/php7/conf.d/opcache.ini
# Nginx
echo "Setting Nginx configuration..."
sed -e "s#@UPLOAD_MAX_SIZE@#$UPLOAD_MAX_SIZE#g" \
-e "s#@REAL_IP_FROM@#$REAL_IP_FROM#g" \
-e "s#@REAL_IP_HEADER@#$REAL_IP_HEADER#g" \
/tpls/etc/nginx/nginx.conf > /etc/nginx/nginx.conf
# SSMTP
echo "Setting SSMTP configuration..."
if [ -z "$SSMTP_HOST" ] ; then
echo "WARNING: SSMTP_HOST must be defined if you want to send emails"
else
cat > /etc/ssmtp/ssmtp.conf <<EOL
mailhub=${SSMTP_HOST}:${SSMTP_PORT}
hostname=${SSMTP_HOSTNAME}
FromLineOverride=YES
AuthUser=${SSMTP_USER}
AuthPass=${SSMTP_PASSWORD}
UseTLS=${SSMTP_TLS}
UseSTARTTLS=${SSMTP_TLS}
EOL
fi
unset SSMTP_HOST
unset SSMTP_USER
unset SSMTP_PASSWORD
# Init Matomo
echo "Initializing Matomo files / folders..."
mkdir -p /data/config /data/misc /data/plugins /data/session /data/tmp /etc/supervisord /var/log/supervisord
# Copy global config
cp -Rf /var/www/config /data/
# Check plugins
echo "Checking Matomo plugins..."
plugins=$(ls -l /data/plugins | egrep '^d' | awk '{print $9}')
for plugin in ${plugins}; do
if [ -d /var/www/plugins/${plugin} ]; then
rm -rf /var/www/plugins/${plugin}
fi
echo " - Adding ${plugin}"
ln -sf /data/plugins/${plugin} /var/www/plugins/${plugin}
done
# Check user folder
echo "Checking Matomo user-misc folder..."
if [ ! -d /data/misc/user ]; then
if [[ ! -L /var/www/misc/user && -d /var/www/misc/user ]]; then
mv -f /var/www/misc/user /data/misc/
fi
ln -sf /data/misc/user /var/www/misc/user
fi
# Fix perms
echo "Fixing permissions..."
chown -R nginx. /data
# Sidecar cron container ?
if [ "$SIDECAR_CRON" = "1" ]; then
echo ">>"
echo ">> Sidecar cron container detected for Matomo"
echo ">>"
# Init
rm /etc/supervisord/nginx.conf /etc/supervisord/php.conf
rm -rf ${CRONTAB_PATH}
mkdir -m 0644 -p ${CRONTAB_PATH}
touch ${CRONTAB_PATH}/nginx
# GeoIP
if [ ! -z "$CRON_GEOIP" ]; then
echo "Creating GeoIP cron task with the following period fields : $CRON_GEOIP"
echo "${CRON_GEOIP} /usr/local/bin/update_geoip" >> ${CRONTAB_PATH}/nginx
else
echo "CRON_GEOIP env var empty..."
fi
# Archive
if [ ! -z "$CRON_ARCHIVE" ]; then
echo "Creating Matomo archive cron task with the following period fields : $CRON_ARCHIVE"
echo "${CRON_ARCHIVE} /usr/local/bin/matomo_archive" >> ${CRONTAB_PATH}/nginx
else
echo "CRON_ARCHIVE env var empty..."
fi
# Fix perms
echo "Fixing permissions..."
chmod -R 0644 ${CRONTAB_PATH}
else
rm /etc/supervisord/cron.conf
# Check if already installed
if [ -f /data/config/config.ini.php ]; then
echo "Setting Matomo log level to $LOG_LEVEL..."
runas_nginx "php /var/www/console config:set --section='log' --key='log_level' --value='$LOG_LEVEL'"
echo "Upgrading and setting Matomo configuration..."
runas_nginx "php /var/www/console core:update --yes --no-interaction"
runas_nginx "php /var/www/console config:set --section='General' --key='minimum_memory_limit' --value='-1'"
else
echo ">>"
echo ">> Open your browser to install Matomo through the wizard"
echo ">>"
fi
fi
exec "$@"