From 936f2b78d8e41a89a26bd89cfee7cf9827073a8d Mon Sep 17 00:00:00 2001 From: frju365 Date: Sun, 11 Mar 2018 12:42:46 +0100 Subject: [PATCH] Update remove --- scripts/remove | 108 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 88 insertions(+), 20 deletions(-) diff --git a/scripts/remove b/scripts/remove index 90393e0..8c60b7f 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,34 +1,102 @@ #!/bin/bash -# Source app helpers +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh source /usr/share/yunohost/helpers -# Exit on command errors and treat unset variables as an error -set -u -set -eu +#================================================= +# LOAD SETTINGS +#================================================= + app=$YNH_APP_INSTANCE_NAME -# Retrieve app settings domain=$(ynh_app_setting_get $app domain) +port=$(ynh_app_setting_get $app port) +dbname=$(ynh_app_setting_get $app dbname) +dbuser=$dbname +final_path=$(ynh_app_setting_get $app final_path) -sudo systemctl stop $app.service +#================================================= +# STANDARD REMOVE +#================================================= +# STOP AND REMOVE SERVICE +#================================================= -# Remove sources -sudo rm -rf /var/www/$app +# Remove the dedicated systemd config +ynh_remove_systemd_config -# Remove nginx configuration file -[[ -n $domain ]] && sudo rm -f /etc/nginx/conf.d/${domain}.d/${app}.conf +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL +#================================================= -# Remove haste user and data -sudo userdel -r $app +if yunohost service status | grep -q $app +then + echo "Remove $app service" + yunohost service remove $app +fi -# Remove init script -sudo systemctl disable $app.service -sudo rm -f /etc/systemd/system/$app.service -sudo systemctl daemon-reload +#================================================= +# REMOVE DEPENDENCIES +#================================================= -# Remove monitor -sudo yunohost service remove $app +# Remove metapackage and its dependencies +ynh_remove_app_dependencies -# Reload nginx service -sudo systemctl reload nginx.service +#================================================= +# REMOVE THE MONGO DATABASE +#================================================= + +mongo --shell "$dbname" --eval 'db.dropUser('dbuser');' <<< exit +mongo --shell "$dbname" --eval 'db.dropDatabase();' <<< exit + +#================================================= +# REMOVE APP MAIN DIR +#================================================= + +# Remove the app directory securely +ynh_secure_remove "$final_path" + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= + +# Remove the dedicated nginx config +ynh_remove_nginx_config + +#================================================= +# REMOVE PHP-FPM CONFIGURATION +#================================================= + +# Remove the dedicated php-fpm config +#ynh_remove_fpm_config + +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= + +# Remove the app-specific logrotate config +ynh_remove_logrotate + +#================================================= +# CLOSE A PORT +#================================================= + +if yunohost firewall list | grep -q "\- $port$" +then + echo "Close port $port" + yunohost firewall disallow TCP $port 2>&1 +fi + +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= + +# Delete a system user +ynh_system_user_delete $app