@@ -20,10 +20,20 @@ set -euo pipefail
2020rm -f /var/run/cron.pid 2> /dev/null || true
2121cron
2222
23+ # Initialize the mounted application directory from the image seed on first start.
24+ if [ ! -f /var/www/html/public/index.php ]; then
25+ echo " Initializing Moodle application directory..."
26+ mkdir -p /var/www/html
27+ cp -a /usr/src/moodle/. /var/www/html/
28+ chown -R www-data:www-data /var/www/html
29+ fi
30+
2331# Restore config.php from moodledata if it was persisted after a previous install
2432if [ -f " ${MOODLE_DATA} /.moodle_config.php" ] && [ ! -f /var/www/html/config.php ]; then
2533 echo " Restoring config.php from moodledata..."
2634 cp " ${MOODLE_DATA} /.moodle_config.php" /var/www/html/config.php
35+ chown www-data:www-data /var/www/html/config.php
36+ chmod 644 /var/www/html/config.php
2737fi
2838
2939# Wait for the database to be ready (max 120 seconds)
@@ -72,12 +82,14 @@ if [ ! -f /var/www/html/config.php ]; then
7282 # Persist config.php to moodledata so it survives container recreations
7383 cp /var/www/html/config.php " ${MOODLE_DATA} /.moodle_config.php"
7484 chown www-data:www-data /var/www/html/config.php
85+ chmod 644 /var/www/html/config.php
7586elif php /var/www/html/admin/cli/upgrade.php --is-pending --non-interactive 2> /dev/null | grep -q " pending\|Upgrade" ; then
7687 echo " Database upgrade pending, running upgrade..."
7788 php /var/www/html/admin/cli/upgrade.php --non-interactive
7889 echo " Moodle upgrade complete."
7990 cp /var/www/html/config.php " ${MOODLE_DATA} /.moodle_config.php"
8091 chown www-data:www-data /var/www/html/config.php
92+ chmod 644 /var/www/html/config.php
8193fi
8294
8395exec " $@ "
0 commit comments