diff --git a/README.md b/README.md index def1915..de8cac1 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Moodle app for YunoHost -[![Integration level](https://dash.yunohost.org/integration/moodle.svg)](https://dash.yunohost.org/appci/app/moodle) -[![Install moodle with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=moodle) +[![Integration level](https://dash.yunohost.org/integration/moodle.svg)](https://dash.yunohost.org/appci/app/moodle) ![](https://ci-apps.yunohost.org/ci/badges/moodle.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/moodle.maintain.svg) +[![Install Moodle with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=moodle) -> *This package allow you to install moodle quickly and simply on a YunoHost server. -If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* +> *This package allows you to install Moodle quickly and simply on a YunoHost server. +If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* ## Overview Moodle https://moodle.org is a learning platform designed to provide educators, administrators and learners with a single robust, secure and integrated system to create personalised learning environments. @@ -31,17 +31,17 @@ How to configure this app: by an admin panel. ## YunoHost specific features -#### Multi-users support +#### Multi-user support Are LDAP and HTTP auth supported? *Yes* Can the app be used by multiple users? *Yes* #### Supported architectures -* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/moodle%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/moodle/) +* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/moodle%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/moodle/) * ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/moodle%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/moodle/) -**More information on the documentation page:** +**More info on the documentation page:** https://yunohost.org/packaging_apps ## Links @@ -53,11 +53,10 @@ https://yunohost.org/packaging_apps --- -Developers info +Developer info ---------------- -**Only if you want to use a testing branch for coding, instead of merging directly into master.** -Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/moodle_ynh/tree/testing). +Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/moodle_ynh/tree/testing). To try the testing branch, please proceed like that. ``` diff --git a/check_process b/check_process index 82ac697..f57fbdf 100644 --- a/check_process +++ b/check_process @@ -12,6 +12,8 @@ setup_private=1 setup_public=1 upgrade=1 + # 3.8.2~ynh2 + upgrade=1 from_commit=3bdecdeabdcaaf1fdfade6e5b7dcfa30704c665c backup_restore=1 multi_instance=1 port_already_use=0 @@ -22,3 +24,6 @@ ;;; Options Email= Notification=none +;;; Upgrade options + ; commit=3bdecdeabdcaaf1fdfade6e5b7dcfa30704c665c + name=3.8.2~ynh2 diff --git a/conf/cron b/conf/cron index 95790c9..c07ace5 100644 --- a/conf/cron +++ b/conf/cron @@ -1 +1 @@ -*/15 * * * * __APP__ /usr/bin/php__YNH_PHP_VERSION__ -f __FINAL_PATH__/admin/cli/cron.php +*/15 * * * * __APP__ /usr/bin/php__PHPVERSION__ -f __FINAL_PATH__/admin/cli/cron.php diff --git a/conf/nginx.conf b/conf/nginx.conf index 062cca2..4a8cbd0 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -16,7 +16,7 @@ location __PATH__/ { try_files $uri $uri/ index.php; location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php/php__YNH_PHP_VERSION__-fpm-__NAME__.sock; + fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock; fastcgi_index index.php; include fastcgi_params; diff --git a/issue_template.md b/issue_template.md new file mode 100644 index 0000000..d82d230 --- /dev/null +++ b/issue_template.md @@ -0,0 +1,46 @@ +--- +name: Bug report +about: Create a report to help us debug, it would be nice to fill the template as much as you can to help us, help you and help us all. + +--- + +**How to post a meaningful bug report** +1. *Read this whole template first.* +2. *Determine if you are on the right place:* + - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change url...), you are on the right place!* + - *Otherwise, the issue may be due to Moodle itself. Refer to its documentation or repository for help.* + - *If you have a doubt, post here, we will figure it out together.* +3. *Delete the italic comments as you write over them below, and remove this guide.* +--- + +**Describe the bug** +*A clear and concise description of what the bug is.* + +**Versions** +- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...* +- YunoHost version: x.x.x +- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...* +- Are you in a special context or did you perform some particular tweaking on your YunoHost instance ?: *no / yes* + - If yes, please explain: +- Using, or trying to install package version/branch: +- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`* + +**To Reproduce** +*Steps to reproduce the behavior.* +- *If you performed a command from the CLI, the command itself is enough. For example:* + ```sh + sudo yunohost app install moodle + ``` +- *If you used the webadmin, please perform the equivalent command from the CLI first.* +- *If the error occurs in your browser, explain what you did:* + 1. *Go to '...'* + 2. *Click on '....'* + 3. *Scroll down to '....'* + 4. *See error* + +**Expected behavior** +*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.* + +**Logs** +*After a failed command, YunoHost makes the log available to you, but also to others, thanks to `yunohost log display [log name] --share`. The actual command, with the correct log name, is displayed at the end of the failed attempt in the CLI. Execute it and copy here the share link it outputs.* +*If applicable and useful, add screenshots to help explain your problem.* diff --git a/manifest.json b/manifest.json index 8569dcd..abc42e0 100644 --- a/manifest.json +++ b/manifest.json @@ -18,7 +18,8 @@ }, "multi_instance": true, "services": [ - "nginx" + "nginx", + "php7.0-fpm" ], "arguments": { "install" : [ diff --git a/pull_request_template.md b/pull_request_template.md new file mode 100644 index 0000000..d2922c1 --- /dev/null +++ b/pull_request_template.md @@ -0,0 +1,18 @@ +## Problem +- *Description of why you made this PR* + +## Solution +- *And how do you fix that problem* + +## PR Status +- [ ] Code finished. +- [ ] Tested with Package_check. +- [ ] Fix or enhancement tested. +- [ ] Upgrade from last version tested. +- [ ] Can be reviewed and tested. + +## Package_check results +--- +*If you have access to [App Continuous Integration for packagers](https://yunohost.org/#/packaging_apps_ci) you can provide a link to the package_check results like below, replacing '-NUM-' in this link by the PR number and USERNAME by your username on the ci-apps-dev. Or you provide a screenshot or a pastebin of the results* + +[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/moodle_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/moodle_ynh%20PR-NUM-%20(USERNAME)/) diff --git a/scripts/_common.sh b/scripts/_common.sh index 631df84..0a05c81 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,10 +5,16 @@ #================================================= # dependencies used by the app -YNH_PHP_VERSION="7.3" -extra_pkg_dependencies="php$YNH_PHP_VERSION-common php$YNH_PHP_VERSION-mbstring php$YNH_PHP_VERSION-curl php$YNH_PHP_VERSION-xmlrpc php$YNH_PHP_VERSION-soap php$YNH_PHP_VERSION-zip php$YNH_PHP_VERSION-gd php$YNH_PHP_VERSION-xml php$YNH_PHP_VERSION-intl php$YNH_PHP_VERSION-json php$YNH_PHP_VERSION-pgsql php$YNH_PHP_VERSION-ldap" pkg_dependencies="postgresql" +YNH_PHP_VERSION="7.3" + +extra_php_dependencies="php$YNH_PHP_VERSION-common php$YNH_PHP_VERSION-mbstring php$YNH_PHP_VERSION-curl php$YNH_PHP_VERSION-xmlrpc php$YNH_PHP_VERSION-soap php$YNH_PHP_VERSION-zip php$YNH_PHP_VERSION-gd php$YNH_PHP_VERSION-xml php$YNH_PHP_VERSION-intl php$YNH_PHP_VERSION-json php$YNH_PHP_VERSION-pgsql php$YNH_PHP_VERSION-ldap" + +#================================================= +# PERSONAL HELPERS +#================================================= + #================================================= # EXPERIMENTAL HELPERS #================================================= @@ -24,4 +30,8 @@ exec_as() { else sudo -u "$USER" "$@" fi -} \ No newline at end of file +} + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/backup b/scripts/backup index f2873e9..77616ce 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,9 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= +#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh -source ../settings/scripts/ynh_add_extra_apt_repos -source ../settings/scripts/ynh_install_php source /usr/share/yunohost/helpers #================================================= @@ -21,7 +20,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -29,13 +28,16 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) data_path=$(ynh_app_setting_get --app=$app --key=data_path) domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= -# STANDARD BACKUP STEPS +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." + #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_script_progression --message="Backing up the main app directory..." ynh_backup --src_path="$final_path" @@ -44,35 +46,32 @@ ynh_backup --src_path="$data_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Backing up nginx web server configuration..." ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Backing up php-fpm configuration..." -ynh_backup --src_path="/etc/php/$YNH_PHP_VERSION/fpm/pool.d/$app.conf" - -#================================================= -# BACKUP THE POSTGRESQL DATABASE -#================================================= -ynh_script_progression --message="Backing up the PostgreSQL database..." - -ynh_psql_dump_db --database="$db_name" > db.sql +ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= # SPECIFIC BACKUP #================================================= -# BACKUP A CRON FILE +# BACKUP VARIOUS FILES #================================================= -ynh_script_progression --message="Backing up the cron file..." ynh_backup --src_path="/etc/cron.d/$app" +#================================================= +# BACKUP THE POSTGRESQL DATABASE +#================================================= +ynh_print_info --message="Backing up the PostgreSQL database..." + +ynh_psql_dump_db --database="$db_name" > db.sql + #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 51129c9..7d2f159 100644 --- a/scripts/install +++ b/scripts/install @@ -7,8 +7,6 @@ #================================================= source _common.sh -source ynh_add_extra_apt_repos -source ynh_install_php source /usr/share/yunohost/helpers #================================================= @@ -26,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 +email=$(ynh_user_get_info $admin mail) +password=$(ynh_string_random --length=30) app=$YNH_APP_INSTANCE_NAME @@ -57,15 +57,9 @@ ynh_app_setting_set --app=$app --key=is_public --value=$is_public #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=60 +ynh_script_progression --message="Installing dependencies..." -if [ "$(lsb_release --codename --short)" = "stretch" ]; then - ynh_install_app_dependencies $pkg_dependencies - ynh_install_php --phpversion="$YNH_PHP_VERSION" --package="$extra_pkg_dependencies" -else - pkg_dependencies="$pkg_dependencies $extra_pkg_dependencies" - ynh_install_app_dependencies $pkg_dependencies -fi +ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE POSTGRESQL DATABASE @@ -75,8 +69,9 @@ ynh_script_progression --message="Creating a PostgreSQL database..." --weight=4 ynh_psql_test_if_first_run db_name=$(ynh_sanitize_dbid --db_name=$app) +db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name -ynh_psql_setup_db --db_user=$db_name --db_name=$db_name +ynh_psql_setup_db --db_user=$db_user --db_name=$db_name db_pwd=$(ynh_app_setting_get $app psqlpwd) @@ -95,7 +90,7 @@ ynh_setup_source --dest_dir="$final_path" ynh_script_progression --message="Configuring nginx web server..." --weight=2 # Create a dedicated nginx config -ynh_add_nginx_config YNH_PHP_VERSION +ynh_add_nginx_config #================================================= # CREATE DEDICATED USER @@ -111,7 +106,8 @@ ynh_system_user_create --username=$app ynh_script_progression --message="Configuring php-fpm..." --weight=1 # Create a dedicated php-fpm config -ynh_add_fpm_config --phpversion="$YNH_PHP_VERSION" +ynh_add_fpm_config --package="$extra_php_dependencies" +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # SPECIFIC SETUP @@ -127,12 +123,9 @@ chown -R "$app": "$final_path" #================================================= # SETUP APPLICATION #================================================= -ynh_script_progression --message="Configuring the application..." --weight=190 +ynh_script_progression --message="Setuping the application..." --weight=190 -email=$(ynh_user_get_info $admin mail) -password=$(ynh_string_random --length=30) - -exec_as "$app" php$YNH_PHP_VERSION "$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 +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 # Calculate and store the config file checksum into the app settings ynh_store_file_checksum "$final_path/config.php" @@ -140,6 +133,7 @@ ynh_store_file_checksum "$final_path/config.php" #================================================= # ACTIVATE LDAP SUPPORT #================================================= +ynh_script_progression --message="Activate ldap support..." ynh_psql_execute_as_root --database=$db_name --sql="UPDATE public.mdl_config SET value='ldap,email' WHERE name='auth';" ynh_psql_execute_as_root --database=$db_name --sql="UPDATE public.mdl_config_plugins SET value='ldap://127.0.0.1/' WHERE plugin='auth_ldap' AND name='host_url';" @@ -154,26 +148,37 @@ ynh_psql_execute_as_root --database=$db_name --sql="UPDATE public.mdl_config_plu # 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';" -exec_as "$app" php$YNH_PHP_VERSION "$final_path/admin/cli/purge_caches.php" +exec_as "$app" php$phpversion "$final_path/admin/cli/purge_caches.php" #================================================= # ADD CRON JOB #================================================= +ynh_script_progression --message="Adding cron job..." # Set up poller -sudo cp "../conf/cron" "/etc/cron.d/$app" +cp "../conf/cron" "/etc/cron.d/$app" ynh_replace_string "__APP__" "$app" "/etc/cron.d/$app" ynh_replace_string "__FINAL_PATH__" "$final_path" "/etc/cron.d/$app" -ynh_replace_string "__YNH_PHP_VERSION__" "$YNH_PHP_VERSION" "/etc/cron.d/$app" +ynh_replace_string "__PHPVERSION__" "$phpversion" "/etc/cron.d/$app" #================================================= # GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= +ynh_script_progression --message="Securing files and directories..." + +# Set permissions to app files +chown -R "$app": "$data_path" +chown -R "$app": "$final_path" + #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Configuring SSOwat..." # Make app public if necessary -if [ "$is_public" -eq 1 ] +if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" diff --git a/scripts/remove b/scripts/remove index 272d620..c79cc03 100644 --- a/scripts/remove +++ b/scripts/remove @@ -7,8 +7,6 @@ #================================================= source _common.sh -source ynh_add_extra_apt_repos -source ynh_install_php source /usr/share/yunohost/helpers #================================================= @@ -20,6 +18,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name final_path=$(ynh_app_setting_get --app=$app --key=final_path) data_path=$(ynh_app_setting_get --app=$app --key=data_path) @@ -28,10 +27,10 @@ data_path=$(ynh_app_setting_get --app=$app --key=data_path) #================================================= # REMOVE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Removing the PostgresSQL database..." +ynh_script_progression --message="Removing the PostgreSQL database..." # Remove a database if it exists, along with the associated user -ynh_psql_remove_db --db_user=$db_name --db_name=$db_name +ynh_psql_remove_db --db_user="$db_user" --db_name="$db_name" #================================================= # REMOVE DEPENDENCIES @@ -65,15 +64,12 @@ ynh_script_progression --message="Removing php-fpm configuration..." --weight=20 # Remove the dedicated php-fpm config ynh_remove_fpm_config -if [ "$(lsb_release --codename --short)" = "stretch" ]; then - ynh_remove_php -fi - #================================================= # SPECIFIC REMOVE #================================================= -# REMOVE THE CRON FILE +# REMOVE VARIOUS FILES #================================================= +ynh_script_progression --message="Removing various files..." # Remove a cron file ynh_secure_remove --file="/etc/cron.d/$app" diff --git a/scripts/restore b/scripts/restore index 4f7a287..5a22e72 100644 --- a/scripts/restore +++ b/scripts/restore @@ -7,8 +7,6 @@ #================================================= source ../settings/scripts/_common.sh -source ../settings/scripts/ynh_add_extra_apt_repos -source ../settings/scripts/ynh_install_php source /usr/share/yunohost/helpers #================================================= @@ -30,6 +28,8 @@ path_url=$(ynh_app_setting_get --app=$app --key=path) 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) +db_user=$db_name +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -48,6 +48,7 @@ test ! -d $data_path \ #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the nginx configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" @@ -71,6 +72,7 @@ ynh_system_user_create --username=$app #================================================= # RESTORE USER RIGHTS #================================================= +ynh_script_progression --message="Restoring user rights..." # Restore permissions on app files chown -R $app: $final_path @@ -79,23 +81,22 @@ chown -R $app: $data_path #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Restoring PHP-FPM configuration..." -ynh_restore_file --origin_path="/etc/php/$YNH_PHP_VERSION/fpm/pool.d/$app.conf" +ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" + +# Recreate a dedicated php-fpm config +ynh_add_fpm_config --package="$extra_php_dependencies" #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=60 +ynh_script_progression --message="Reinstalling dependencies..." -if [ "$(lsb_release --codename --short)" = "stretch" ]; then - ynh_install_app_dependencies $pkg_dependencies - ynh_install_php --phpversion="$YNH_PHP_VERSION" --package="$extra_pkg_dependencies" -else - pkg_dependencies="$pkg_dependencies $extra_pkg_dependencies" - ynh_install_app_dependencies $pkg_dependencies -fi +# Define and install dependencies +ynh_install_app_dependencies $pkg_dependencies #================================================= # RESTORE THE POSTGRESQL DATABASE @@ -105,12 +106,13 @@ ynh_script_progression --message="Restoring the PostgreSQL database..." --weight ynh_psql_test_if_first_run db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) -ynh_psql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd -ynh_psql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ./db.sql +ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql #================================================= # RESTORE THE CRON FILE #================================================= +ynh_script_progression --message="Restoring the cron file..." ynh_restore_file --origin_path="/etc/cron.d/$app" @@ -121,7 +123,7 @@ ynh_restore_file --origin_path="/etc/cron.d/$app" #================================================= ynh_script_progression --message="Reloading nginx web server and php-fpm..." -ynh_systemd_action --service_name=php$YNH_PHP_VERSION-fpm --action=reload +ynh_systemd_action --service_name=php$phpversion-fpm --action=reload ynh_systemd_action --service_name=nginx --action=reload #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 0c11d5c..a278430 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,8 +7,6 @@ #================================================= source _common.sh -source ynh_add_extra_apt_repos -source ynh_install_php source /usr/share/yunohost/helpers #================================================= @@ -29,6 +27,7 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) @@ -76,20 +75,14 @@ fi ynh_script_progression --message="Upgrading nginx web server configuration..." # Create a dedicated nginx config -ynh_add_nginx_config YNH_PHP_VERSION +ynh_add_nginx_config #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=30 +ynh_script_progression --message="Upgrading dependencies..." -if [ "$(lsb_release --codename --short)" = "stretch" ]; then - ynh_install_app_dependencies $pkg_dependencies - ynh_install_php --phpversion="$YNH_PHP_VERSION" --package="$extra_pkg_dependencies" -else - pkg_dependencies="$pkg_dependencies $extra_pkg_dependencies" - ynh_install_app_dependencies $pkg_dependencies -fi +ynh_install_app_dependencies "$pkg_dependencies" #================================================= # CREATE DEDICATED USER @@ -105,23 +98,23 @@ ynh_system_user_create --username=$app ynh_script_progression --message="Upgrading php-fpm configuration..." # Create a dedicated php-fpm config -ynh_add_fpm_config --phpversion="$YNH_PHP_VERSION" +ynh_add_fpm_config --package="$extra_php_dependencies" +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # SPECIFIC UPGRADE #================================================= -# STORE THE CONFIG FILE CHECKSUM +# UPGRADING THE APPLICATION #================================================= +ynh_script_progression --message="Upgrading the application..." ynh_backup_if_checksum_is_different --file="$final_path/config.php" -exec_as "$app" php$YNH_PHP_VERSION "$final_path/admin/cli/upgrade.php" --non-interactive +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" -#================================================= -# GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= @@ -130,19 +123,10 @@ ynh_store_file_checksum --file="$final_path/config.php" chown -R "$app": "$data_path" chown -R "$app": "$final_path" -#================================================= -# ADD CRON JOB -#================================================= - -# Set up poller -sudo cp "../conf/cron" "/etc/cron.d/$app" -ynh_replace_string "__APP__" "$app" "/etc/cron.d/$app" -ynh_replace_string "__FINAL_PATH__" "$final_path" "/etc/cron.d/$app" -ynh_replace_string "__YNH_PHP_VERSION__" "$YNH_PHP_VERSION" "/etc/cron.d/$app" - #================================================= # ACTIVATE LDAP SUPPORT #================================================= +ynh_script_progression --message="Activate ldap support..." ynh_psql_execute_as_root --database=$db_name --sql="UPDATE public.mdl_config SET value='ldap,email' WHERE name='auth';" ynh_psql_execute_as_root --database=$db_name --sql="UPDATE public.mdl_config_plugins SET value='ldap://127.0.0.1/' WHERE plugin='auth_ldap' AND name='host_url';" @@ -157,7 +141,29 @@ ynh_psql_execute_as_root --database=$db_name --sql="UPDATE public.mdl_config_plu # 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';" -exec_as "$app" php$YNH_PHP_VERSION "$final_path/admin/cli/purge_caches.php" +exec_as "$app" php$phpversion "$final_path/admin/cli/purge_caches.php" + +#================================================= +# ADD CRON JOB +#================================================= +ynh_script_progression --message="Adding cron job..." + +# Set up poller +cp "../conf/cron" "/etc/cron.d/$app" +ynh_replace_string "__APP__" "$app" "/etc/cron.d/$app" +ynh_replace_string "__FINAL_PATH__" "$final_path" "/etc/cron.d/$app" +ynh_replace_string "__PHPVERSION__" "$phpversion" "/etc/cron.d/$app" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= +ynh_script_progression --message="Securing files and directories..." + +# Set permissions on app files +chown -R "$app": "$data_path" +chown -R "$app": "$final_path" #================================================= # SETUP SSOWAT diff --git a/scripts/ynh_add_extra_apt_repos b/scripts/ynh_add_extra_apt_repos deleted file mode 100644 index df092aa..0000000 --- a/scripts/ynh_add_extra_apt_repos +++ /dev/null @@ -1,249 +0,0 @@ -# Add dependencies to install with ynh_install_app_dependencies -# -# [internal] -# -# usage: ynh_add_app_dependencies --package=phpversion [--replace] -# | arg: -p, --package - Packages to add as dependencies for the app. -# | arg: -r, --replace - Replace dependencies instead of adding to existing ones. -ynh_add_app_dependencies () { - # Declare an array to define the options of this helper. - local legacy_args=pr - declare -Ar args_array=( [p]=package= [r]=replace) - local package - local replace - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - replace=${replace:-0} - - local current_dependencies="" - if [ $replace -eq 0 ] - then - local dep_app=${app//_/-} # Replace all '_' by '-' - if ynh_package_is_installed --package="${dep_app}-ynh-deps" - then - current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) " - fi - - current_dependencies=${current_dependencies// | /|} - fi - - ynh_install_app_dependencies "${current_dependencies}${package}" -} - -# Install packages from an extra repository properly. -# -# usage: ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name] -# | arg: -r, --repo - Complete url of the extra repository. -# | arg: -p, --package - The packages to install from this extra repository -# | arg: -k, --key - url to get the public key. -# | arg: -n, --name - Name for the files for this repo, $app as default value. -ynh_install_extra_app_dependencies () { - # Declare an array to define the options of this helper. - local legacy_args=rpkn - declare -Ar args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= ) - local repo - local package - local key - local name - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - key=${key:-0} - - # Set a key only if asked - if [ -n "$key" ] - then - key="--key=$key" - fi - # Add an extra repository for those packages - ynh_install_extra_repo --repo="$repo" $key --priority=995 --name=$name - - # Install requested dependencies from this extra repository. - ynh_add_app_dependencies --package="$package" - - # Remove this extra repository after packages are installed - ynh_remove_extra_repo --name=$app -} - -# Add an extra repository correctly, pin it and get the key. -# -# [internal] -# -# usage: ynh_install_extra_repo --repo="repo" [--key=key_url] [--priority=priority_value] [--name=name] [--append] -# | arg: -r, --repo - Complete url of the extra repository. -# | arg: -k, --key - url to get the public key. -# | arg: -p, --priority - Priority for the pin -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -ynh_install_extra_repo () { - # Declare an array to define the options of this helper. - local legacy_args=rkpna - declare -Ar args_array=( [r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append ) - local repo - local key - local priority - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - append=${append:-0} - key=${key:-0} - priority=${priority:-} - - if [ $append -eq 1 ] - then - append="--append" - wget_append="tee -a" - else - append="" - wget_append="tee" - fi - - # Split the repository into uri, suite and components. - # Remove "deb " at the beginning of the repo. - repo="${repo#deb }" - - # Get the uri - local uri="$(echo "$repo" | awk '{ print $1 }')" - - # Get the suite - local suite="$(echo "$repo" | awk '{ print $2 }')" - - # Get the components - local component="${repo##$uri $suite }" - - # Add the repository into sources.list.d - ynh_add_repo --uri="$uri" --suite="$suite" --component="$component" --name="$name" $append - - # Pin the new repo with the default priority, so it won't be used for upgrades. - # Build $pin from the uri without http and any sub path - local pin="${uri#*://}" - pin="${pin%%/*}" - # Set a priority only if asked - if [ -n "$priority" ] - then - priority="--priority=$priority" - fi - ynh_pin_repo --package="*" --pin="origin \"$pin\"" $priority --name="$name" $append - - # Get the public key for the repo - if [ -n "$key" ] - then - mkdir -p "/etc/apt/trusted.gpg.d" - wget -q "$key" -O - | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.gpg > /dev/null - fi - - # Update the list of package with the new repo - ynh_package_update -} - -# Remove an extra repository and the assiociated configuration. -# -# [internal] -# -# usage: ynh_remove_extra_repo [--name=name] -# | arg: -n, --name - Name for the files for this repo, $app as default value. -ynh_remove_extra_repo () { - # Declare an array to define the options of this helper. - local legacy_args=n - declare -Ar args_array=( [n]=name= ) - local name - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - - ynh_secure_remove "/etc/apt/sources.list.d/$name.list" - ynh_secure_remove "/etc/apt/preferences.d/$name" - ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.gpg" - ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.asc" - - # Update the list of package to exclude the old repo - ynh_package_update -} - -# Add a repository. -# -# [internal] -# -# usage: ynh_add_repo --uri=uri --suite=suite --component=component [--name=name] [--append] -# | arg: -u, --uri - Uri of the repository. -# | arg: -s, --suite - Suite of the repository. -# | arg: -c, --component - Component of the repository. -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -# -# Example for a repo like deb http://forge.yunohost.org/debian/ stretch stable -# uri suite component -# ynh_add_repo --uri=http://forge.yunohost.org/debian/ --suite=stretch --component=stable -# -ynh_add_repo () { - # Declare an array to define the options of this helper. - local legacy_args=uscna - declare -Ar args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append ) - local uri - local suite - local component - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - append=${append:-0} - - if [ $append -eq 1 ] - then - append="tee -a" - else - append="tee" - fi - - mkdir -p "/etc/apt/sources.list.d" - # Add the new repo in sources.list.d - echo "deb $uri $suite $component" \ - | $append "/etc/apt/sources.list.d/$name.list" -} - -# Pin a repository. -# -# [internal] -# -# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append] -# | arg: -p, --package - Packages concerned by the pin. Or all, *. -# | arg: -i, --pin - Filter for the pin. -# | arg: -p, --priority - Priority for the pin -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -# -# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html for information about pinning. -# -ynh_pin_repo () { - # Declare an array to define the options of this helper. - local legacy_args=pirna - declare -Ar args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append ) - local package - local pin - local priority - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - package="${package:-*}" - priority=${priority:-50} - name="${name:-$app}" - append=${append:-0} - - if [ $append -eq 1 ] - then - append="tee -a" - else - append="tee" - fi - - mkdir -p "/etc/apt/preferences.d" - echo "Package: $package -Pin: $pin -Pin-Priority: $priority -" \ - | $append "/etc/apt/preferences.d/$name" -} \ No newline at end of file diff --git a/scripts/ynh_install_php b/scripts/ynh_install_php deleted file mode 100644 index 7ac4420..0000000 --- a/scripts/ynh_install_php +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/bash - -# Install another version of php. -# -# usage: ynh_install_php --phpversion=phpversion [--package=packages] -# | arg: -v, --phpversion - Version of php to install. Can be one of 7.1, 7.2 or 7.3 -# | arg: -p, --package - Additionnal php packages to install -ynh_install_php () { - # Declare an array to define the options of this helper. - local legacy_args=vp - declare -Ar args_array=( [v]=phpversion= [p]=package= ) - local phpversion - local package - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - package=${package:-} - - # Store php_version into the config of this app - ynh_app_setting_set $app php_version $phpversion - - if [ "$phpversion" == "7.0" ] - then - ynh_die "Do not use ynh_install_php to install php7.0" - fi - - # Store the ID of this app and the version of php requested for it - echo "$YNH_APP_INSTANCE_NAME:$phpversion" | tee --append "/etc/php/ynh_app_version" - - # Add an extra repository for those packages - ynh_install_extra_repo --repo="https://packages.sury.org/php/ $(lsb_release -sc) main" --key="https://packages.sury.org/php/apt.gpg" --priority=995 --name=extra_php_version - - # Install requested dependencies from this extra repository. - # Install php-fpm first, otherwise php will install apache as a dependency. - ynh_add_app_dependencies --package="php${phpversion}-fpm" - ynh_add_app_dependencies --package="php$phpversion php${phpversion}-common $package" - - # Set php7.0 back as the default version for php-cli. - update-alternatives --set php /usr/bin/php7.0 - - # Pin this extra repository after packages are installed to prevent sury of doing shit - ynh_pin_repo --package="*" --pin="origin \"packages.sury.org\"" --priority=200 --name=extra_php_version - ynh_pin_repo --package="php7.0*" --pin="origin \"packages.sury.org\"" --priority=600 --name=extra_php_version --append - - # Advertise service in admin panel - yunohost service add php${phpversion}-fpm --log "/var/log/php${phpversion}-fpm.log" -} - -ynh_remove_php () { - # Get the version of php used by this app - local phpversion=$(ynh_app_setting_get $app php_version) - - if [ "$phpversion" == "7.0" ] || [ -z "$phpversion" ] - then - if [ "$phpversion" == "7.0" ] - then - ynh_print_err "Do not use ynh_remove_php to install php7.0" - fi - return 0 - fi - - # Remove the line for this app - sed --in-place "/$YNH_APP_INSTANCE_NAME:$phpversion/d" "/etc/php/ynh_app_version" - - # If no other app uses this version of php, remove it. - if ! grep --quiet "$phpversion" "/etc/php/ynh_app_version" - then - # Purge php dependences for this version. - ynh_package_autopurge "php$phpversion php${phpversion}-fpm php${phpversion}-common" - # Remove the service from the admin panel - yunohost service remove php${phpversion}-fpm - fi - - # If no other app uses alternate php versions, remove the extra repo for php - if [ ! -s "/etc/php/ynh_app_version" ] - then - ynh_secure_remove /etc/php/ynh_app_version - fi -} \ No newline at end of file