#!/bin/bash
# vim:set noexpandtab:

# Exit on command errors and treat unset variables as an error
set -u

source .fonctions	# Loads the generic functions usually used in the script
source /usr/share/yunohost/helpers # Source app helpers

# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME

domain=$(ynh_app_setting_get $app domain)

# Stop lstu service
if [ -e "/etc/systemd/system/lstu.service" ]; then
	echo "Delete systemd script"
	sudo systemctl stop lstu.service
	sudo systemctl disable lstu.service
	sudo rm "/etc/systemd/system/lstu.service"
	systemctl daemon-reload
fi

# Remove monitoring service Yunohost.
if sudo yunohost service status | grep -q lstu	# Test the existence of the service in Yunohost
then
	echo "Remove lstu service"
	sudo yunohost service remove lstu
fi

SECURE_REMOVE '/var/www/$app'	# Delete directory application

REMOVE_NGINX_CONF	# Delete nginx configuration


SECURE_REMOVE '/var/log/$app/'	# Delete log

REMOVE_LOGROTATE_CONF	# Delete logrotate configuration

ynh_package_remove build-essential	|| echo "build-essential already uninstalled"
ynh_package_remove libssl-dev		|| echo "libssl-dev already uninstalled"
ynh_package_remove libpq-dev		|| echo "libpq-dev already uninstalled"

# Reload SSOwat configuration
sudo yunohost app ssowatconf

echo -e "\e[0m"	# Restore normal color