install_moodle.sh 4.03 KB
Newer Older
1
2
3
4
5
6
7
#!/bin/bash

# Import environment variables from .env
set -a
. .env
set +a

8
9
10
11
12
13
14
15
16
17
18
19
20
# Ensure correct ownership and permissions before installation
docker-compose exec moodle chown -R www-data:www-data ${MOODLE_BASE_DIR}
docker-compose exec moodle chmod -R 755 ${MOODLE_BASE_DIR}

# Ensure necessary directories in moodledata exist
docker-compose exec moodle mkdir -p ${MOODLE_BASE_DIR_DATA}
docker-compose exec moodle mkdir -p ${MOODLE_BASE_DIR_DATA}/localcache
docker-compose exec moodle mkdir -p ${MOODLE_BASE_DIR_DATA}/sessions
docker-compose exec moodle mkdir -p ${MOODLE_BASE_DIR_DATA}/temp
docker-compose exec moodle mkdir -p ${MOODLE_BASE_DIR_DATA}/trashdir
docker-compose exec moodle chown -R www-data:www-data ${MOODLE_BASE_DIR_DATA}
docker-compose exec moodle chmod -R 775 ${MOODLE_BASE_DIR_DATA}

21
# Install Moodle
22
sleep 5
23
24
docker-compose exec moodle php ${MOODLE_BASE_DIR}/admin/cli/install.php \
                               --wwwroot="${MOODLE_WWWROOT}" \
25
                               --phpunit_dataroot="${MOODLE_WWWROOT}" \
26
27
28
29
30
31
32
33
34
35
36
37
                               --dataroot="${MOODLE_BASE_DIR_DATA}" \
                               --dbtype="mariadb" \
                               --dbname="${MOODLE_DATABASE_NAME}" \
                               --dbuser="${MOODLE_DATABASE_USER}" \
                               --dbpass="${MOODLE_DATABASE_PASSWORD}" \
                               --dbhost="${MOODLE_DATABASE_HOST}" \
                               --adminpass="${MOODLE_DATABASE_ROOT_PASSWORD}" \
                               --fullname="${MOODLE_FULLNAME}" \
                               --shortname="${MOODLE_SHORTNAME}" \
                               --agree-license \
                               --non-interactive

38
# Check if database backup exists and restore it if it does
39
 BACKUP_FILE="moodle/moodle_backup.sql"
40
41
42
43
 if [ -f "$BACKUP_FILE" ]; then
 #    docker-compose exec mariadb apt-get update && apt-get install -y mysql-client && rm -rf /var/lib/apt/lists/*
     docker-compose exec mariadb bash -c "apt-get update && apt-get install -y mysql-client && rm -rf /var/lib/apt/lists/*"
     echo "Database backup found. Restoring..."
44
     docker-compose exec -T mariadb mysql -u ${MOODLE_DATABASE_USER} -p${MOODLE_DATABASE_PASSWORD} ${MOODLE_DATABASE_NAME} < moodle/moodle_backup.sql
45
46
47
48
49
     echo "Database restored from backup."
 else
     echo "No database backup found. Skipping restore."
 fi

50
51
52
53
54
55
# Locale setting inside the Docker container
docker-compose exec -u root moodle bash -c "apt-get update && apt-get install -y locales && \
    echo 'en_AU.UTF-8 UTF-8' >> /etc/locale.gen && \
    locale-gen && \
    update-locale"

56
# Composer installation to run phpunit tests
Artem Baranovskyi's avatar
Artem Baranovskyi committed
57
58
59
 docker-compose exec moodle php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
 docker-compose exec moodle php composer-setup.php --install-dir=/usr/local/bin --filename=composer
 docker-compose exec moodle php -r "unlink('composer-setup.php');"
60
 docker-compose exec moodle bash -c "cd /app && /usr/local/bin/composer install --no-interaction --no-plugins --no-scripts --no-dev --prefer-dist && /usr/local/bin/composer dump-autoload"
Artem Baranovskyi's avatar
Artem Baranovskyi committed
61

62
63
# Next, configure PHPUnit for Moodle:
 docker-compose exec moodle php admin/tool/phpunit/cli/init.php
64

65
66
67
68
69
70
71
72
 # Ensure correct ownership and permissions after installation
 docker-compose exec moodle chown -R www-data:www-data ${MOODLE_BASE_DIR}
 docker-compose exec moodle chmod -R 755 ${MOODLE_BASE_DIR}

 # Set correct access rules for the plugin
 docker-compose exec moodle chown -R www-data:www-data ${MOODLE_BASE_DIR}/local/asystgrade
 docker-compose exec moodle chmod -R 775 ${MOODLE_BASE_DIR}/local/asystgrade
 sudo chown -R $(whoami):$(whoami) ./asystgrade
73
74

# Create the run_sag script file
75
docker-compose exec flask bash -c 'cat <<EOF > /usr/local/bin/run_sag
76
77
#!/bin/bash
. /opt/myenv/bin/activate
78
79
80
#cd ${MOODLE_BASE_DIR}/asyst/Source/Skript/german
cd /app/asyst/Source/Skript/german
/opt/myenv/bin/python3 /app/api.py
81
82
EOF'

83
84

# Make the script executable & run it
85
86
docker-compose exec flask chmod +x /usr/local/bin/run_sag
docker-compose exec flask /usr/local/bin/run_sag