#!/bin/bash

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

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

#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=2

with_mysql=$(ynh_app_setting_get --app=$app --key=with_mysql)
with_sftp=$(ynh_app_setting_get --app=$app --key=with_sftp)

#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================

if [ $with_mysql -eq 1 ]; then
    ynh_script_progression --message="Removing the MySQL database..." --weight=2

    db_name=$(ynh_app_setting_get --app=$app --key=db_name)
    db_user=$db_name

    # Remove a database if it exists, along with the associated user
    ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
fi

#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=2

# Remove the dedicated NGINX config
ynh_remove_nginx_config

#=================================================
# REMOVE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Removing PHP-FPM configuration..."

# Remove the dedicated PHP-FPM config
ynh_remove_fpm_config

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

ynh_script_progression --message="Removal of $app completed" --last