#!/bin/bash

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

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

#=================================================
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1

ynh_exec_warn_less yunohost user delete $zabbix_username --purge

# need remove pinning
if [ -f /etc/apt/preferences.d/zabbix_repo ]
ynh_secure_remove --file="/etc/apt/preferences.d/zabbix_repo"
fi

# Remove the dedicated systemd config
ynh_systemd_action --service_name="$app-server" --action="stop" --log_path="/var/log/$app/${app}_server.log"
ynh_systemd_action --service_name="$app-agent" --action="stop" --log_path="/var/log/$app/${app}_agent.log"
systemctl disable zabbix-server --quiet
systemctl disable zabbix-agent --quiet
ynh_exec_warn_less killall zabbix_server
ynh_exec_warn_less killall zabbix_agentd

yunohost service remove snmpd
yunohost service remove zabbix-server
yunohost service remove zabbix-agent

ynh_remove_nginx_config

ynh_remove_fpm_config

# Remove other various files specific to the app... such as:

delete_initZabbixConf
ynh_secure_remove --file="/usr/share/$app"
ynh_secure_remove --file="/etc/$app"
ynh_secure_remove --file="/run/$app"

ynh_secure_remove --file="/etc/sudoers.d/$app"

ynh_secure_remove --file="/usr/share/zabbix-cli"

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

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