#!/bin/bash

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

source scripts/_common.sh
source /usr/share/yunohost/helpers

#=================================================
# MANAGE SCRIPT FAILURE
#=================================================

ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
	ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors

#=================================================
# RETRIEVE ARGUMENTS
#=================================================

app=$YNH_APP_INSTANCE_NAME

type=$1

domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)

#=================================================
# SPECIFIC ACTION
#=================================================
# RESET THE CONFIG FILE
#=================================================

if [ $type == nginx ]; then
	name=Nginx
elif [ $type == phpfpm ]; then
	name=PHP-FPM
else
	ynh_die --message="The type $type is not recognized"
fi

ynh_script_progression --message="Resetting the specific configuration of $name for the app $app..." --weight=3

if [ $type == nginx ]
then
	(cd scripts; ynh_add_nginx_config)

elif [ $type == phpfpm ]
then
	(cd scripts; ynh_add_fpm_config --usage=low --footprint=low --dedicated_service)
fi

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

ynh_script_progression --message="Execution completed" --last
