#!/bin/bash


# See comments in install script
app=$YNH_APP_INSTANCE_NAME

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

# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
dbuser=$(ynh_app_setting_get "$app" dbuser)
dbname=$(ynh_app_setting_get "$app" dbname)

root_pwd=$(sudo cat /etc/yunohost/mysql)

mysql -u root -p $root_pwd -e "DROP DATABASE $dbname ; DROP USER $dbuser@localhost ;"
sudo rm -rf /var/www/$app

sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
sudo service nginx reload
sudo rm -Rf /var/log/$app

sudo update-rc.d $app remove
sudo service $app stop
sudo rm /etc/init.d/$app