#!/bin/bash

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

# Source YunoHost helpers
source /usr/share/yunohost/helpers

# Load common variables and helpers
source ./_common.sh

#=================================================
# LOAD SETTINGS
#=================================================

# See comments in install script
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
port=$(ynh_app_setting_get "$app" port)

#=================================================
# STANDARD REMOVE
#=================================================
# STOP AND REMOVE SERVICE
#=================================================

# Remove the dedicated systemd config
ynh_remove_systemd_config

#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
#=================================================

# Remove a service from the admin panel, added by `yunohost service add`
if yunohost service status | grep -q $app
then
	echo "Remove $app service"
	yunohost service remove $app
fi

#=================================================
# REMOVE CONF FILE
#=================================================

# Remove Config
remove_config_jupyterlab

#=================================================
# REMOVE APP MAIN DIR
#=================================================

ynh_secure_remove "$final_path"
ynh_secure_remove "$config_path"

# Remove the log files
ynh_secure_remove "/var/log/$app.log"

#=================================================
# CLOSE PORTS
#=================================================

if yunohost firewall list | grep -q "\- $port$"
then
	echo "Close port $port" >&2
	yunohost firewall disallow TCP $port 2>&1
fi

#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================

ynh_remove_nginx_config

#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================

#ynh_remove_logrotate