1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/moodle_ynh.git synced 2024-09-03 19:46:23 +02:00

Add config file (#54)

* Update upgrade
This commit is contained in:
Éric Gaspar 2021-08-17 15:46:31 +02:00 committed by GitHub
parent 7b41378eaa
commit 7cefa74aa2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 1374 additions and 60 deletions

View file

@ -3,6 +3,8 @@
domain="domain.tld"
path="/path"
admin="john"
language="fr"
site_name="Moodle"
is_public=1
; Checks
pkg_linter=1
@ -12,14 +14,15 @@
setup_private=1
setup_public=1
upgrade=1
# 3.10.2~ynh1
upgrade=1 from_commit=499ac857a9e80bbf56c93e448086e84e09e97ac6
# 3.11.1~ynh1
upgrade=1 from_commit=b2abcd9cefa16e5c5e0e6963a92ebc961be12d1a
backup_restore=1
multi_instance=1
change_url=0
change_url=1
;;; Options
Email=
Notification=none
;;; Upgrade options
; commit=499ac857a9e80bbf56c93e448086e84e09e97ac6
name=3.10.2~ynh1
; commit=b2abcd9cefa16e5c5e0e6963a92ebc961be12d1a
name=3.11.1~ynh1

1157
conf/config-dist.php Normal file

File diff suppressed because it is too large Load diff

View file

@ -1 +1 @@
*/15 * * * * __USER__ /usr/bin/php__PHPVERSION__ -f __FINALPATH__/admin/cli/cron.php
*/15 * * * * __APP__ /usr/bin/php__PHPVERSION__ -f __FINALPATH__/admin/cli/cron.php

View file

@ -46,10 +46,30 @@
"type": "user",
"example": "johndoe"
},
{
"name": "site_name",
"type": "string",
"ask": {
"en": "Choose a name for the site you want to create",
"fr": "Choisissez un nom pour le site que vous voulez créer"
},
"default": "moodle",
"example": "moodle"
},
{
"name": "is_public",
"type": "boolean",
"default": true
},
{
"name": "language",
"type": "string",
"ask": {
"en": "Choose the application language",
"fr": "Choisissez la langue de l'application"
},
"choices": ["en", "fr"],
"default": "fr"
}
]
}

114
scripts/change_url Normal file
View file

@ -0,0 +1,114 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
old_domain=$YNH_APP_OLD_DOMAIN
old_path=$YNH_APP_OLD_PATH
new_domain=$YNH_APP_NEW_DOMAIN
new_path=$YNH_APP_NEW_PATH
app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
data_path=$(ynh_app_setting_get --app=$app --key=data_path)
language=$(ynh_app_setting_get --app=$app --key=language)
# Add settings here as needed by your application
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
#=================================================
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
change_domain=0
if [ "$old_domain" != "$new_domain" ]
then
change_domain=1
fi
change_path=0
if [ "$old_path" != "$new_path" ]
then
change_path=1
fi
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the NGINX config file
if [ $change_path -eq 1 ]
then
# Make a backup of the original NGINX config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for NGINX helper
domain="$old_domain"
path_url="$new_path"
# Create a dedicated NGINX config
ynh_add_nginx_config
fi
# Change the domain for NGINX
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1
domain=$new_domain
path_url=$new_path
ynh_replace_string --match_string="\$CFG->wwwroot = '.*'" --replace_string="\$CFG->wwwroot = 'https://${domain}${path_url%/}';" --target_file="$final_path/config.php"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --last

View file

@ -24,6 +24,8 @@ domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
language=$YNH_APP_ARG_LANGUAGE
site_name=$YNH_APP_ARG_SITE_NAME
email=$(ynh_user_get_info --username=$admin --key=mail)
password=$(ynh_string_random --length=30)
@ -48,6 +50,8 @@ ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=language --value=$language
ynh_app_setting_set --app=$app --key=site_name --value=$site_name
#=================================================
# STANDARD MODIFICATIONS
@ -89,10 +93,6 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
@ -127,9 +127,9 @@ chown -R $app:www-data "$data_path"
#=================================================
# SETUP APPLICATION
#=================================================
ynh_script_progression --message="Setting up the application..." --weight=190
ynh_script_progression --message="Setting up the application..." --weight=19
ynh_exec_as $app php${phpversion} "$final_path/admin/cli/install.php" --wwwroot="https://$domain${path_url%/}" --dataroot="$data_path" --dbtype='pgsql' --dbname="$db_name" --dbuser="$db_name" --dbpass="$db_pwd" --adminuser="$admin" --adminpass="$password" --adminemail="$email" --fullname="YunoHost" --shortname="YNH" --non-interactive --agree-license
php${phpversion} "$final_path/admin/cli/install.php" --wwwroot="https://${domain}${path_url%/}" --dataroot="$data_path" --dbtype='pgsql' --dbname="$db_name" --dbuser="$db_name" --dbpass="$db_pwd" --lang="$language" --adminuser="$admin" --adminpass="$password" --adminemail="$email" --fullname="$site_name" --shortname="$site_name" --non-interactive --agree-license
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config.php"
@ -152,7 +152,11 @@ ynh_psql_execute_as_root --database="$db_name" --sql="UPDATE public.mdl_config_p
# The admin is an ldap user
ynh_psql_execute_as_root --database="$db_name" --sql="UPDATE public.mdl_user SET auth='ldap' WHERE username='$admin';"
ynh_exec_as $app php$phpversion "$final_path/admin/cli/purge_caches.php"
php$phpversion "$final_path/admin/cli/purge_caches.php"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# ADD CRON JOB

View file

@ -120,6 +120,8 @@ ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./d
ynh_script_progression --message="Restoring the cron file..." --weight=3
ynh_restore_file --origin_path="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app"
#=================================================
# GENERIC FINALIZATION

View file

@ -22,6 +22,9 @@ admin=$(ynh_app_setting_get --app=$app --key=admin)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
data_path=$(ynh_app_setting_get --app=$app --key=data_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
language=$(ynh_app_setting_get --app=$app --key=language)
site_name=$(ynh_app_setting_get --app=$app --key=site_name)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#=================================================
# CHECK VERSION
@ -29,6 +32,20 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name)
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up Moodle before upgrading (may take a while)..." --weight=10
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
@ -39,6 +56,18 @@ if [ -z "$admin" ]; then
ynh_die --message="This app can't be upgraded from a very old version of the package. Please remove and reinstall Moodle"
fi
# If the language is not defined
if [ -z "$language" ]; then
language="fr"
ynh_app_setting_set --app=$app --key=language --value=$language
fi
# If the site_name is not defined
if [ -z "$site_name" ]; then
site_name="YunoHost"
ynh_app_setting_set --app=$app --key=site_name --value=$site_name
fi
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
@ -46,20 +75,6 @@ if ynh_legacy_permissions_exists; then
ynh_app_setting_delete --app=$app --key=is_public
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up Moodle before upgrading (may take a while)..." --weight=30
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CREATE DEDICATED USER
#=================================================
@ -74,32 +89,41 @@ ynh_system_user_create --username=$app --home_dir="$final_path"
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# if [ "$upgrade_type" == "UPGRADE_APP" ]
# then
# ynh_script_progression --message="Upgrading source files..." --weight=6
# # Create a temporary directory
# tmpdir="$(mktemp -d)"
# # Backup the config file in the temp dir
# cp -a "$final_path/config.php" "$tmpdir/config.php"
# # Remove the app directory securely
# ynh_secure_remove --file="$final_path"
# # Download, check integrity, uncompress and patch the source from app.src
# ynh_setup_source --dest_dir="$final_path"
# # Copy the admin saved settings from tmp directory to final path
# cp -a "$tmpdir/config.php" "$final_path/config.php"
# # Remove the tmp directory securely
# ynh_secure_remove --file="$tmpdir"
# fi
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=6
# Create a temporary directory
tmpdir="$(mktemp -d)"
# Backup the config file in the temp dir
cp -a "$final_path/config.php" "$tmpdir/config.php"
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
#ynh_secure_remove --file="$final_path"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
# Copy the admin saved settings from tmp directory to final path
cp -a "$tmpdir/config.php" "$final_path/config.php"
# Remove the tmp directory securely
ynh_secure_remove --file="$tmpdir"
ynh_setup_source --dest_dir="$final_path" --keep="$final_path/config.php"
php${phpversion} $final_path/admin/cli/upgrade.php
fi
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# NGINX CONFIGURATION
@ -125,18 +149,6 @@ ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1
ynh_add_fpm_config --package="$extra_php_dependencies"
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#=================================================
# UPGRADING THE APPLICATION
#=================================================
# ynh_script_progression --message="Upgrading the application..." --weight=1
# ynh_backup_if_checksum_is_different --file="$final_path/config.php"
# ynh_exec_as $app php${phpversion} "$final_path/admin/cli/upgrade.php" --non-interactive
# # Recalculate and store the checksum of the file for the next upgrade.
# ynh_store_file_checksum --file="$final_path/config.php"
#=================================================
# ACTIVATE LDAP SUPPORT
#=================================================
@ -155,7 +167,11 @@ ynh_psql_execute_as_root --database="$db_name" --sql="UPDATE public.mdl_config_p
# The admin is an ldap user
ynh_psql_execute_as_root --database="$db_name" --sql="UPDATE public.mdl_user SET auth='ldap' WHERE username='$admin';"
ynh_exec_as $app php${phpversion} "$final_path/admin/cli/purge_caches.php"
php${phpversion} "$final_path/admin/cli/purge_caches.php"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# ADD CRON JOB
@ -166,8 +182,6 @@ ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app"
chown -R $app:www-data "$final_path"
#=================================================
# RELOAD NGINX
#=================================================