#!/bin/bash

#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source /usr/share/yunohost/helpers

#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression "Ensuring downward compatibility..."

ynh_app_setting_set_default --key=php_upload_max_filesize --value=250M
ynh_app_setting_set_default --key=php_post_max_size --value=260M

#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression "Upgrading source files..."

ynh_setup_source --dest_dir="$install_dir" --full_replace --keep=".env"

#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression "Updating $app's configuration files..."

ynh_config_add --template=".env" --destination="$install_dir/.env"

#=================================================
# REAPPLY SYSTEM CONFIGURATION
#=================================================
ynh_script_progression "Upgrading system configurations related to $app..."

ynh_config_add_phpfpm

ynh_config_add_nginx

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression "Upgrade of $app completed"
