diff --git a/README.md b/README.md
index ecb5093..607a312 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# Moodle app for YunoHost
[![Install Moodle with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=Moodle)
-Version: **3.5.1**
+Version: **3.8.1**
Moodle - the world's open source learning platform
Moodle is a learning platform designed to provide
@@ -11,12 +11,38 @@ integrated system to create personalised learning environments.
Moodle is widely used around the world by universities, schools, companies and
all manner of organisations and individuals.
-# Installation
-** After the installation go to your domain https://domain.tld/moodle and create the admin account. **
+
+### Installing guide
+
+ App can be installed by YunoHost **admin web-interface** or by **running following command**:
+
+ $ sudo yunohost app install https://github.com/YunoHost-Apps/moodle_ynh
+
+ After install :
+
+ 1. Login in moodle exemple : https://domain.tld/moodle
+ 2. Create admin account
+
+
+### Upgrade this package:
+
+ $ sudo yunohost app upgrade moodle -u https://github.com/YunoHost-Apps/moodle_ynh
+
+ After upgrade :
+
+ 1. If you have custom plugins or themes need to move your plugins
+ 2. Moodle is saved in /var/www/moodle.backup
+ 3. Moove your plugins / themes exemple "cp -a moodle.backup/mod/hvp moodle/mod/hvp"
+ 4. After moving your plugins and themes make "rm -r moodle.backup"
+ 5. Login in moodle for complete upgrade
+
+More informations : https://docs.moodle.org/26/en/Upgrading
+
+
## To-do
- [X] Install script
- [X] Remove script
-- [ ] Upgrade script
+- [x] Upgrade script
- [X] Backup and Restore scripts(need testing)
- [ ] LDAP integration
diff --git a/conf/app.src b/conf/app.src
index 7c17c2d..743fc5a 100644
--- a/conf/app.src
+++ b/conf/app.src
@@ -1,6 +1,7 @@
-SOURCE_URL=https://github.com/moodle/moodle/archive/v3.5.1.tar.gz
-SOURCE_SUM=ccabd372fcdb253a404428196c1cf0a16529797717b443572250103a29ce1799
-SOURCE_SUM_PRG=sha256sum
+SOURCE_URL=https://download.moodle.org/stable38/moodle-3.8.1.tgz
+SOURCE_SUM=bec050a92f682cee03cb70abfc350b7741522898dd21f5b5847f5c2ddfdd785ad404f6f06ed17b31bfa031aebe42bd35e3a205de686bd8627e92b9a919addb4c
+SOURCE_SUM_PRG=sha512sum
SOURCE_FORMAT=tar.gz
-SOURCE_IN_SUBDIR=
-SOURCE_FILENAME=
+SOURCE_IN_SUBDIR=true
+SOURCE_EXTRACT=true
+SOURCE_FILENAME=moodle.tgz
diff --git a/manifest.json b/manifest.json
index 3d07b1b..5160959 100644
--- a/manifest.json
+++ b/manifest.json
@@ -6,9 +6,9 @@
"en": "Moodle package for YunoHost application.",
"fr": "Moodle de package d’application pour YunoHost."
},
- "version": "3.5.1",
+ "version": "3.8.1",
"url": "https://moodle.org/",
- "license": "free",
+ "license": "GPL-3.0",
"maintainer": {
"name": "Anmol Sharma",
"email": "anmol@datamol.org"
diff --git a/scripts/_common.sh b/scripts/_common.sh
index c726850..b8c5f97 100644
--- a/scripts/_common.sh
+++ b/scripts/_common.sh
@@ -12,6 +12,8 @@ ynh_delete_file_checksum () {
ynh_app_setting_delete $app $checksum_setting_name
}
+extra_pkg_dependencies="php7.1-zip php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring php7.1-gd php7.1-curl php7.1-soap php7.1-pgsql php7.1-xmlrpc"
+
# Send an email to inform the administrator
#
# usage: ynh_send_readme_to_admin app_message [recipients]
diff --git a/scripts/backup b/scripts/backup
index 4e4230b..f501e0e 100644
--- a/scripts/backup
+++ b/scripts/backup
@@ -27,9 +27,9 @@ ynh_abort_if_errors
app=$YNH_APP_INSTANCE_NAME
-final_path=$(ynh_app_setting_get $app final_path)
-domain=$(ynh_app_setting_get $app domain)
-db_name=$(ynh_app_setting_get $app psql_db)
+final_path=$(ynh_app_setting_get "$app" final_path)
+domain=$(ynh_app_setting_get "$app" domain)
+db_name=$(ynh_app_setting_get "$app" psql_db)
#=================================================
# STANDARD BACKUP STEPS
diff --git a/scripts/install b/scripts/install
index 9cdc109..6f6c0de 100644
--- a/scripts/install
+++ b/scripts/install
@@ -8,6 +8,8 @@
source _common.sh
source psql.sh
+source ynh_install_php
+source ynh_add_extra_apt_repos
source /usr/share/yunohost/helpers
#=================================================
@@ -49,49 +51,53 @@ final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Normalize the url path syntax
-path_url=$(ynh_normalize_url_path $path_url)
+path_url=$(ynh_normalize_url_path "$path_url")
# Check web path availability
-ynh_webpath_available $domain $path_url
+ynh_webpath_available "$domain" "$path_url"
# Register (book) web path
-ynh_webpath_register $app $domain $path_url
+ynh_webpath_register "$app" "$domain" "$path_url"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
-ynh_app_setting_set $app domain $domain
-ynh_app_setting_set $app path $path_url
-ynh_app_setting_set $app is_public $is_public
+ynh_app_setting_set "$app" domain "$domain"
+ynh_app_setting_set "$app" path "$path_url"
+ynh_app_setting_set "$app" is_public "$is_public"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
#=================================================
-# INSTALL DEPENDENCIES
+# INSTALL PHP7.3 AND DEPENDENCIES (EXP HELPER)
#=================================================
-ynh_install_app_dependencies php-zip php-mysql php-xml php-intl php-mbstring php-gd php-curl php-soap php-pgsql php-xmlrpc postgresql
+ynh_print_info --message="Installing php7.1..."
+
+ynh_install_php --phpversion="7.1" --package="$extra_pkg_dependencies"
+ynh_install_app_dependencies postgresql
+
#=================================================
# Create postgresql database
#=================================================
db_name=$app
db_pwd=$(ynh_string_random 30)
-ynh_app_setting_set $app psql_db $db_name
-ynh_app_setting_set $app psqlpwd $db_pwd
+ynh_app_setting_set "$app" psql_db "$db_name"
+ynh_app_setting_set "$app" psqlpwd "$db_pwd"
ynh_psql_test_if_first_run
-ynh_psql_create_user $app $db_pwd
+ynh_psql_create_user "$app" "$db_pwd"
ynh_psql_execute_as_root \
"CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
-ynh_app_setting_set $app final_path $final_path
+ynh_app_setting_set "$app" final_path "$final_path"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
-cp ../conf/config.php $final_path/.
+cp ../conf/config.php "$final_path"/.
#=================================================
# NGINX CONFIGURATION
@@ -105,7 +111,7 @@ ynh_add_nginx_config
#=================================================
# Create a system user
-ynh_system_user_create $app
+ynh_system_user_create "$app"
#=================================================
# PHP-FPM CONFIGURATION
@@ -123,7 +129,7 @@ ynh_system_user_create $app
### - And the section "PHP-FPM CONFIGURATION" in the upgrade script
# Create a dedicated php-fpm config
-ynh_add_fpm_config
+ynh_add_fpm_config --phpversion="7.1"
#=================================================
# SPECIFIC SETUP
@@ -147,16 +153,16 @@ ynh_replace_string "YNH_VAR_ROOT" "$var_root" "$final_path/config.php"
ynh_store_file_checksum "$final_path/config.php"
# Create the home directory
-mkdir -p $var_root
-chown -R $app: $var_root
-chmod -R 700 $var_root
+mkdir -p "$var_root"
+chown -R "$app": "$var_root"
+chmod -R 700 "$var_root"
#=================================================
# SETUP APPLICATION WITH CURL
#=================================================
# Set right permissions for curl install
-chown -R $app: $final_path
+chown -R "$app": "$final_path"
# Reload Nginx
systemctl reload nginx
@@ -168,26 +174,26 @@ systemctl reload nginx
#=================================================
# Set permissions to app files
-chown root: $final_path/config.php
+chown root: "$final_path"/config.php
# Set up poller
-sudo cp ../conf/cron /etc/cron.d/$app
+sudo cp ../conf/cron /etc/cron.d/"$app"
ynh_replace_string "YNH_DOMAIN" "$final_path" "/etc/cron.d/$app"
#=================================================
# SETUP SSOWAT
#=================================================
-if [ $is_public -eq 0 ]
+if [ "$is_public" -eq 0 ]
then # Remove the public access
- ynh_app_setting_delete $app skipped_uris
+ ynh_app_setting_delete "$app" skipped_uris
fi
# 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 unprotected_uris "/"
+ ynh_app_setting_set "$app" unprotected_uris "/"
fi
yunohost app ssowatconf
diff --git a/scripts/remove b/scripts/remove
index 778e471..5f4e91e 100644
--- a/scripts/remove
+++ b/scripts/remove
@@ -8,37 +8,63 @@
source _common.sh
source psql.sh
+source ynh_install_php
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
+ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
-domain=$(ynh_app_setting_get $app domain)
-db_name=$(ynh_app_setting_get $app psql_db)
-final_path=$(ynh_app_setting_get $app final_path)
+domain=$(ynh_app_setting_get "$app" domain)
+db_name=$(ynh_app_setting_get "$app" psql_db)
+db_user=$db_name
+final_path=$(ynh_app_setting_get "$app" final_path)
#=================================================
# STANDARD REMOVE
#=================================================
+# REMOVE SERVICE FROM ADMIN PANEL
+#=================================================
+
+# Remove a service from the admin panel, added by `yunohost service add`
+if yunohost service status "$app" >/dev/null 2>&1
+then
+ ynh_print_info "Removing $app service"
+ yunohost service remove "$app"
+fi
+
+#=================================================
+# STOP AND REMOVE SERVICE
+#=================================================
+ynh_print_info "Stopping and removing the systemd service"
+
+# Remove the dedicated systemd config
+ynh_remove_systemd_config
+
+#=================================================
+# REMOVE THE POSTGRESQL DATABASE
+#=================================================
+ynh_print_info "Removing the PostgreSQL database"
+
+# Remove a database if it exists, along with the associated user
+ynh_psql_remove_db "$db_name" "$db_name"
+
#=================================================
# REMOVE DEPENDENCIES
#=================================================
+ynh_print_info "Removing dependencies"
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
-#=================================================
-# REMOVE THE psql DATABASE
-#=================================================
-# Remove a database if it exists, along with the associated user
-ynh_psql_remove_db "$db_name" "$app"
-
+ynh_remove_php
#=================================================
# REMOVE APP MAIN DIR
#=================================================
+ynh_print_info "Removing app main directory"
# Remove the app directory securely
ynh_secure_remove "$final_path"
@@ -46,17 +72,27 @@ ynh_secure_remove "$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
+ynh_print_info "Removing nginx web server configuration"
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
-# REMOVE PHP-FPM CONFIGURATION
+# REMOVE PHP-FPM CONFIGURATION
#=================================================
+ynh_print_info "Removing php-fpm configuration"
# Remove the dedicated php-fpm config
ynh_remove_fpm_config
+#=================================================
+# REMOVE LOGROTATE CONFIGURATION
+#=================================================
+ynh_print_info "Removing logrotate configuration"
+
+# Remove the app-specific logrotate config
+ynh_remove_logrotate
+
#=================================================
# SPECIFIC REMOVE
#=================================================
@@ -67,13 +103,24 @@ ynh_remove_fpm_config
ynh_secure_remove "/etc/cron.d/$app"
# Remove a directory securely
+ynh_secure_remove "/etc/$app/"
ynh_secure_remove "/home/yunohost.app/$app"
+# Remove the log files
+ynh_secure_remove "/var/log/$app/"
+
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
+ynh_print_info "Removing the dedicated system user"
# Delete a system user
-ynh_system_user_delete $app
+ynh_system_user_delete "$app"
+
+#=================================================
+# END OF SCRIPT
+#=================================================
+
+ynh_print_info "Removal of $app completed"
diff --git a/scripts/upgrade b/scripts/upgrade
new file mode 100644
index 0000000..ae1b135
--- /dev/null
+++ b/scripts/upgrade
@@ -0,0 +1,176 @@
+#!/bin/bash
+
+#=================================================
+# GENERIC START
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
+
+source /usr/share/yunohost/helpers
+
+#=================================================
+# LOAD SETTINGS
+#=================================================
+ynh_print_info "Loading installation settings..."
+
+app=$YNH_APP_INSTANCE_NAME
+
+domain=$(ynh_app_setting_get $app domain)
+path_url=$(ynh_app_setting_get $app path)
+admin=$(ynh_app_setting_get $app admin)
+is_public=$(ynh_app_setting_get $app is_public)
+final_path=$(ynh_app_setting_get $app final_path)
+#language=$(ynh_app_setting_get $app language)
+db_name=$(ynh_app_setting_get $app db_name)
+
+#=================================================
+# ENSURE DOWNWARD COMPATIBILITY
+#=================================================
+ynh_print_info "Ensuring downward compatibility..."
+
+# Fix is_public as a boolean value
+if [ "$is_public" = "Yes" ]; then
+ ynh_app_setting_set $app is_public 1
+ is_public=1
+elif [ "$is_public" = "No" ]; then
+ ynh_app_setting_set $app is_public 0
+ is_public=0
+fi
+
+# If db_name doesn't exist, create it
+if [ -z $db_name ]; then
+ db_name=$(ynh_sanitize_dbid $app)
+ ynh_app_setting_set $app db_name $db_name
+fi
+
+# If final_path doesn't exist, create it
+if [ -z $final_path ]; then
+ final_path=/var/www/$app
+ ynh_app_setting_set $app final_path $final_path
+fi
+
+#=================================================
+# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
+#=================================================
+ynh_print_info "Backing up the app before upgrading (may take a while)..."
+
+# 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
+
+cp -a $final_path $final_path.backup
+
+#=================================================
+# CHECK THE PATH
+#=================================================
+
+# Normalize the URL path syntax
+path_url=$(ynh_normalize_url_path $path_url)
+
+#=================================================
+# STANDARD UPGRADE STEPS
+#=================================================
+# DOWNLOAD, CHECK AND UNPACK SOURCE
+#=================================================
+ynh_print_info "Upgrading source files..."
+
+# Download, check integrity, uncompress and patch the source from app.src
+ynh_setup_source "$final_path"
+
+#=================================================
+# NGINX CONFIGURATION
+#=================================================
+ynh_print_info "Upgrading nginx web server configuration..."
+
+# Create a dedicated nginx config
+ynh_add_nginx_config
+
+#=================================================
+# UPGRADE DEPENDENCIES
+#=================================================
+#ynh_print_info "Upgrading dependencies..."
+
+#ynh_install_app_dependencies $pkg_dependencies
+
+#=================================================
+# CREATE DEDICATED USER
+#=================================================
+ynh_print_info "Making sure dedicated system user exists..."
+
+# Create a dedicated user (if not existing)
+ynh_system_user_create $app
+
+#=================================================
+# PHP-FPM CONFIGURATION
+#=================================================
+ynh_print_info "Upgrading php-fpm configuration..."
+
+# Create a dedicated php-fpm config
+ynh_add_fpm_config
+
+#=================================================
+# SPECIFIC UPGRADE
+#=================================================
+# ...
+#=================================================
+
+### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
+### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
+ynh_backup_if_checksum_is_different "$final_path/config.php"
+# Recalculate and store the checksum of the file for the next upgrade.
+ynh_store_file_checksum "$final_path/config.php"
+
+#=================================================
+# SETUP LOGROTATE
+#=================================================
+ynh_print_info "Upgrading logrotate configuration..."
+
+# Use logrotate to manage app-specific logfile(s)
+ynh_use_logrotate --non-append
+
+#=================================================
+# SETUP SYSTEMD
+#=================================================
+#ynh_print_info "Upgrading systemd configuration..."
+
+# Create a dedicated systemd config
+#ynh_add_systemd_config
+
+#=================================================
+# GENERIC FINALIZATION
+#=================================================
+# SECURE FILES AND DIRECTORIES
+#=================================================
+
+# Set permissions on app files
+chown root: $final_path/config.php
+
+#=================================================
+# SETUP SSOWAT
+#=================================================
+ynh_print_info "Upgrading SSOwat configuration..."
+
+# Make app public if necessary
+if [ $is_public -eq 1 ]
+then
+ # unprotected_uris allows SSO credentials to be passed anyway
+ ynh_app_setting_set $app unprotected_uris "/"
+fi
+
+#=================================================
+# RELOAD NGINX
+#=================================================
+ynh_print_info "Reloading nginx web server..."
+
+systemctl reload nginx
+
+#=================================================
+# END OF SCRIPT
+#=================================================
+
+ynh_print_info "Upgrade of $app completed"
diff --git a/scripts/ynh_add_extra_apt_repos b/scripts/ynh_add_extra_apt_repos
new file mode 100644
index 0000000..3276f00
--- /dev/null
+++ b/scripts/ynh_add_extra_apt_repos
@@ -0,0 +1,294 @@
+#!/bin/bash
+
+# Pin a repository.
+#
+# 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"
+}
+
+# Add a repository.
+#
+# 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"
+}
+
+# Add an extra repository correctly, pin it and get the key.
+#
+# 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.
+#
+# 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
+}
+
+# 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
+}
+
+#=================================================
+
+# patched version of ynh_install_app_dependencies to be used with ynh_add_app_dependencies
+
+# Define and install dependencies with a equivs control file
+# This helper can/should only be called once per app
+#
+# usage: ynh_install_app_dependencies dep [dep [...]]
+# | arg: dep - the package name to install in dependence
+# You can give a choice between some package with this syntax : "dep1|dep2"
+# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5"
+# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5)
+#
+# Requires YunoHost version 2.6.4 or higher.
+ynh_install_app_dependencies () {
+ local dependencies=$@
+ dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')"
+ dependencies=${dependencies//|/ | }
+ local manifest_path="../manifest.json"
+ if [ ! -e "$manifest_path" ]; then
+ manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
+ fi
+
+ local version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file.
+ if [ ${#version} -eq 0 ]; then
+ version="1.0"
+ fi
+ local dep_app=${app//_/-} # Replace all '_' by '-'
+
+ # Handle specific versions
+ if [[ "$dependencies" =~ [\<=\>] ]]
+ then
+ # Replace version specifications by relationships syntax
+ # https://www.debian.org/doc/debian-policy/ch-relationships.html
+ # Sed clarification
+ # [^(\<=\>] ignore if it begins by ( or < = >. To not apply twice.
+ # [\<=\>] matches < = or >
+ # \+ matches one or more occurence of the previous characters, for >= or >>.
+ # [^,]\+ matches all characters except ','
+ # Ex: package>=1.0 will be replaced by package (>= 1.0)
+ dependencies="$(echo "$dependencies" | sed 's/\([^(\<=\>]\)\([\<=\>]\+\)\([^,]\+\)/\1 (\2 \3)/g')"
+ fi
+
+ cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build
+Section: misc
+Priority: optional
+Package: ${dep_app}-ynh-deps
+Version: ${version}
+Depends: ${dependencies}
+Architecture: all
+Description: Fake package for $app (YunoHost app) dependencies
+ This meta-package is only responsible of installing its dependencies.
+EOF
+ ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \
+ || ynh_die --message="Unable to install dependencies" # Install the fake package and its dependencies
+ rm /tmp/${dep_app}-ynh-deps.control
+ ynh_app_setting_set --app=$app --key=apt_dependencies --value="$dependencies"
+}
+
+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}"
+}
diff --git a/scripts/ynh_install_php b/scripts/ynh_install_php
new file mode 100644
index 0000000..1066727
--- /dev/null
+++ b/scripts/ynh_install_php
@@ -0,0 +1,77 @@
+#!/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
+
+ # Remove this extra repository after packages are installed
+ ynh_remove_extra_repo --name=extra_php_version
+
+ # 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
+}