-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathentrypoint.sh
76 lines (62 loc) · 3.15 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
#!/bin/bash
if [ ! -f /config/ownsettings.php ] && [ -f /var/www/spotweb/ownsettings.php ]; then
cp /var/www/spotweb/ownsettings.php /config/ownsettings.php
fi
touch /config/ownsettings.php && chown www-data:www-data /config/ownsettings.php
rm -f /var/www/spotweb/ownsettings.php
ln -s /config/ownsettings.php /var/www/spotweb/ownsettings.php
chown -R www-data:www-data /var/www/spotweb
if [[ -n "$SPOTWEB_DB_TYPE" && -n "$SPOTWEB_DB_HOST" && -n "$SPOTWEB_DB_NAME" && -n "$SPOTWEB_DB_USER" ]]; then
echo "Creating database configuration"
echo "<?php" > /config/dbsettings.inc.php
echo "\$dbsettings['engine'] = '$SPOTWEB_DB_TYPE';" >> /config/dbsettings.inc.php
echo "\$dbsettings['host'] = '$SPOTWEB_DB_HOST';" >> /config/dbsettings.inc.php
echo "\$dbsettings['dbname'] = '$SPOTWEB_DB_NAME';" >> /config/dbsettings.inc.php
echo "\$dbsettings['user'] = '$SPOTWEB_DB_USER';" >> /config/dbsettings.inc.php
if [[ -n "$SPOTWEB_DB_PASS" ]]; then
echo "\$dbsettings['pass'] = '$SPOTWEB_DB_PASS';" >> /config/dbsettings.inc.php
fi
fi
if [[ -n "$SPOTWEB_DB_PORT" ]]; then
echo "\$dbsettings['port'] = '$SPOTWEB_DB_PORT';" >> /config/dbsettings.inc.php
fi
if [ -f /config/dbsettings.inc.php ]; then
chown www-data:www-data /config/dbsettings.inc.php
rm /var/www/spotweb/dbsettings.inc.php
ln -s /config/dbsettings.inc.php /var/www/spotweb/dbsettings.inc.php
else
echo -e "\nWARNING: You have no database configuration file, either create /config/dbsettings.inc.php or restart this container with the correct environment variables to auto generate the config.\n"
fi
TZ=${TZ:-"Europe/Amsterdam"}
echo -e "Setting (PHP) time zone to ${TZ}\n"
sed -i "s#^;date.timezone =.*#date.timezone = ${TZ}#g" /etc/php/8.*/*/php.ini
if [[ -n "$SPOTWEB_CRON_RETRIEVE" || -n "$SPOTWEB_CRON_CACHE_CHECK" ]]; then
ln -sf /proc/$$/fd/1 /var/log/stdout
service cron start
if [[ -n "$SPOTWEB_CRON_RETRIEVE" ]]; then
echo "$SPOTWEB_CRON_RETRIEVE su -l www-data -s /usr/bin/php /var/www/spotweb/retrieve.php >/var/log/stdout 2>&1" > /etc/crontab
fi
if [[ -n "$SPOTWEB_CRON_CACHE_CHECK" ]]; then
echo "$SPOTWEB_CRON_CACHE_CHECK su -l www-data -s /usr/bin/php /var/www/spotweb/bin/check-cache.php >/var/log/stdout 2>&1" >> /etc/crontab
fi
crontab /etc/crontab
fi
# Run database update
/usr/bin/php /var/www/spotweb/bin/upgrade-db.php >/dev/null 2>&1
# Clean up apache pid (if there is one)
rm -rf /run/apache2/apache2.pid
# Enabling PHP mod rewrite, expires and deflate (they may be on already by default)
unset rt
/usr/sbin/a2enmod rewrite && rt=1
/usr/sbin/a2enmod expires && rt=1
/usr/sbin/a2enmod deflate && rt=1
# Change Apache port if needed from the default 80 to `WEBSERVER_PORT` (to run unprivileged or with a host network where no port mapping is available)
if [[ -n "$WEBSERVER_PORT" ]]; then
sed -i 's/^Listen 80$/Listen '"$WEBSERVER_PORT"'/' /etc/apache2/ports.conf
sed -i 's/VirtualHost \*:80>/VirtualHost \*:'"$WEBSERVER_PORT"'>/' /etc/apache2/sites-enabled/000-default.conf
fi
# Only restart if one of the enmod commands succeeded
if [[ -n $rt ]]; then
/etc/init.d/apache2 restart
fi
tail -F /var/log/apache2/* /dev/stdout /dev/stderr