1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dont-code_ynh.git synced 2024-09-03 18:26:34 +02:00
dont-code_ynh/scripts/remove

153 lines
5.1 KiB
Text
Raw Normal View History

2022-12-27 17:59:56 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source ynh_mongo_db__2
source ynh_java
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
2022-12-29 10:06:04 +01:00
port_ide=$(ynh_app_setting_get --app=$app --key=port_ide)
port_preview=$(ynh_app_setting_get --app=$app --key=port_preview)
port_project=$(ynh_app_setting_get --app=$app --key=port_project)
port_data=$(ynh_app_setting_get --app=$app --key=port_data)
2022-12-30 10:21:10 +01:00
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
2022-12-27 17:59:56 +01:00
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
2023-01-03 14:51:52 +01:00
html_path=$(ynh_app_setting_get --app=$app --key=html_path)
2022-12-30 10:21:10 +01:00
document_path=$(ynh_app_setting_get --app=$app --key=document_path)
2022-12-27 17:59:56 +01:00
2022-12-29 10:06:04 +01:00
PORT_LIST=($port_ide $port_preview $port_project $port_data)
2022-12-27 17:59:56 +01:00
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
2022-12-29 10:06:04 +01:00
ynh_script_progression --message="Removing $app services..." --weight=1
2022-12-27 17:59:56 +01:00
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
2022-12-29 10:06:04 +01:00
for service_name in "${SERVICES_LIST[@]}"
do
if ynh_exec_warn_less yunohost service status "${app}-${service_name}" >/dev/null
then
yunohost service remove "${app}-${service_name}"
fi
done
2022-12-27 17:59:56 +01:00
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
# Remove the dedicated systemd config
2022-12-29 10:06:04 +01:00
for service_name in "${SERVICES_LIST[@]}"
do
ynh_remove_systemd_config --service="${app}-${service_name}"
done
2022-12-27 17:59:56 +01:00
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# REMOVE THE MONGO DATABASE
#=================================================
2023-01-03 14:51:52 +01:00
ynh_script_progression --message="Removing the Mongo databases..." --weight=1
2022-12-27 17:59:56 +01:00
# Remove a database if it exists, along with the associated user
2022-12-30 10:21:10 +01:00
for db_name in "${MONGO_DB_LIST[@]}"
do
ynh_mongo_remove_db --db_user=$db_user --db_name=$db_name
done
2022-12-27 17:59:56 +01:00
# Remove mongo itself if not used anymore
ynh_remove_mongo
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
2022-12-30 10:21:10 +01:00
#=================================================
# REMOVE DOCUMENT DIR
#=================================================
2023-01-03 14:51:52 +01:00
ynh_script_progression --message="Removing html directory..." --weight=1
2022-12-30 10:21:10 +01:00
# Remove the app directory securely
2023-01-03 14:51:52 +01:00
ynh_secure_remove --file="$html_path"
2022-12-30 10:21:10 +01:00
2022-12-27 17:59:56 +01:00
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
# Remove the dedicated NGINX config
ynh_remove_nginx_config
2023-01-07 10:31:21 +01:00
ynh_secure_remove --file="/etc/sudoers.d/$app-sudoers"
2022-12-27 17:59:56 +01:00
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=1
# Remove metapackage and its dependencies, including java
ynh_remove_app_dependencies
#=================================================
2022-12-29 10:06:04 +01:00
# CLOSE ALL PORTS
2022-12-27 17:59:56 +01:00
#=================================================
2022-12-29 10:06:04 +01:00
for port in "${PORT_LIST[@]}"
do
if yunohost firewall list | grep -q "\- $port$"
then
ynh_script_progression --message="Closing port $port..." --weight=1
ynh_exec_warn_less yunohost firewall disallow TCP $port
fi
done
2022-12-27 17:59:56 +01:00
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..." --weight=1
# Remove the log files
ynh_secure_remove --file="/var/log/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last