1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mastodon_ynh.git synced 2024-09-03 19:46:02 +02:00
mastodon_ynh/scripts/remove
2019-03-20 03:44:43 +01:00

129 lines
3.8 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
source ynh_install_ruby
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
final_path=$(ynh_app_setting_get $app final_path)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
#=================================================
if yunohost service status "$app-web" >/dev/null 2>&1
then
ynh_print_info "Removing $app-web service"
yunohost service remove "$app-web"
fi
if yunohost service status "$app-sidekiq" >/dev/null 2>&1
then
ynh_print_info "Removing $app-sidekiq service"
yunohost service remove "$app-sidekiq"
fi
if yunohost service status "$app-streaming" >/dev/null 2>&1
then
ynh_print_info "Removing $app-streaming service"
yunohost service remove "$app-streaming"
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_print_info "Stopping and removing the systemd service"
# Remove the dedicated systemd config
ynh_remove_systemd_config "$app-web"
ynh_remove_systemd_config "$app-sidekiq"
ynh_remove_systemd_config "$app-streaming"
#=================================================
# REMOVE THE POSTGRESQL DATABASE
#=================================================
ynh_print_info "Removing the PostgreSQL database"
ynh_psql_execute_as_root "\connect $db_name
SELECT pg_terminate_backend (pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$db_name';"
# delete postgresql database & user
ynh_psql_remove_db $db_name $db_name
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_print_info "Removing dependencies"
# Remove metapackage and its dependencies
ynh_remove_ruby
ynh_remove_app_dependencies
ynh_remove_nodejs
#=================================================
# REMOVE APT SOURCES
#=================================================
ynh_print_info "Removing apt sources"
ynh_secure_remove "/etc/apt/sources.list.d/jessie-backports.list"
ynh_secure_remove "/etc/apt/sources.list.d/yarn.list"
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_print_info "Removing app main directory"
# Remove the app directory securely
ynh_secure_remove "$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_print_info "Removing nginx web server configuration"
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE THE CRON FILE
#=================================================
# Remove a cron file
ynh_secure_remove "/etc/cron.d/$app"
# Delete ruby exec
#ynh_secure_remove /usr/bin/ruby
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_print_info "Removing the dedicated system user"
# Delete a system user
ynh_system_user_delete $app
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Removal of $app completed"