1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mastodon_ynh.git synced 2024-09-03 19:46:02 +02:00

Standardization of removal

This commit is contained in:
Jean-Baptiste Holcroft 2018-05-01 18:49:32 +02:00
parent 00a9710a4e
commit c3f2f5c64f

View file

@ -1,104 +1,114 @@
#!/bin/bash #!/bin/bash
# Exit on command errors and treat unset variables as an error #=================================================
set -u # GENERIC START
#=================================================
if [ ! -e _common.sh ]; then # IMPORT GENERIC HELPERS
# Get file fonction if not been to the current directory #=================================================
sudo cp ../settings/scripts/_common.sh ./_common.sh
sudo chmod a+rx _common.sh
fi
source _common.sh # Loads the generic functions usually used in the script source _common.sh # Loads the generic functions usually used in the script
# Source app helpers # Source app helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _future.sh
#=================================================
# LOAD SETTINGS
#=================================================
# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Retrieve app settings # Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain) domain=$(ynh_app_setting_get "$app" domain)
db_name=$(ynh_app_setting_get "$app" db_name)
# Stop mastodon-web
if [ -e "/etc/systemd/system/mastodon-web.service" ]; then
echo "Delete systemd script"
sudo systemctl stop mastodon-web.service
ynh_secure_remove "/etc/systemd/system/mastodon-web.service"
sudo systemctl disable mastodon-web.service
fi
# Stop mastodon-sidekiq
if [ -e "/etc/systemd/system/mastodon-sidekiq.service" ]; then
echo "Delete systemd script"
sudo systemctl stop mastodon-sidekiq.service
ynh_secure_remove "/etc/systemd/system/mastodon-sidekiq.service"
sudo systemctl disable mastodon-sidekiq.service
fi
# Stop mastodon-sidekiq
if [ -e "/etc/systemd/system/mastodon-streaming.service" ]; then
echo "Delete systemd script"
sudo systemctl stop mastodon-streaming.service
ynh_secure_remove "/etc/systemd/system/mastodon-streaming.service"
sudo systemctl disable mastodon-streaming.service
fi
# Delete service on Yunohost monitoring
if sudo yunohost service status | grep -q mastodon-web
then
echo "Remove mastodon-web service"
sudo yunohost service remove mastodon-web
fi
# Delete service on Yunohost monitoring
if sudo yunohost service status | grep -q mastodon-sidekiq
then
echo "Remove mastodon-sidekiq service"
sudo yunohost service remove mastodon-sidekiq
fi
# Delete service on Yunohost monitoring
if sudo yunohost service status | grep -q mastodon-streaming
then
echo "Remove mastodon-streaming service"
sudo yunohost service remove mastodon-streaming
fi
# delete postgresql database & user
db_user=$(ynh_sanitize_dbid "$app") db_user=$(ynh_sanitize_dbid "$app")
db_name=$(ynh_sanitize_dbid "$app") db_name=$(ynh_sanitize_dbid "$app")
final_path=$(ynh_app_setting_get "$app" final_path)
#=================================================
# STANDARD REMOVE
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_remove_systemd_config "$app-web"
ynh_remove_systemd_config "$app-sidekiq"
ynh_remove_systemd_config "$app-streaming"
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
#==============================================
if yunohost service status | grep -q "$app-web"
then
echo "Remove $app-web service"
yunohost service remove "$app-web"
fi
if yunohost service status | grep -q "$app-sidekiq"
then
echo "Remove $app-sidekiq service"
yunohost service remove "$app-sidekiq"
fi
if yunohost service status | grep -q "$app-streaming"
then
echo "Remove $app-streaming service"
yunohost service remove "$app-streaming"
fi
#=================================================
# REMOVE DEPENDENCIES
#=================================================
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# REMOVE THE PostgreSQL DATABASE
#=================================================
# delete postgresql database & user
ynh_psql_remove_db "$db_name" "$db_user" ynh_psql_remove_db "$db_name" "$db_user"
# Remove Debian package #=================================================
sudo apt-get remove --purge -y yarn # REMOVE APP MAIN DIR
#sudo apt-get remove --purge -y imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file curl git #=================================================
# Delete redis package
#sudo apt-get remove --purge -y redis-server redis-tools
# Delete postgresql package
#sudo apt-get remove --purge -y postgresql postgresql-contrib
# Delete Ruby package
#sudo apt-get remove --purge -y autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
# Delete app directory and configurations # Remove the app directory securely
ynh_secure_remove /opt/$app ynh_secure_remove "$final_path"
[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf"
# Delete nginx configuration #=================================================
REMOVE_NGINX_CONF # REMOVE NGINX CONFIGURATION
#=================================================
ynh_secure_remove "/etc/nginx/conf.d/${domain}.d/${app}.conf"
systemctl reload nginx
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE THE CRON FILE
#=================================================
# Delete cronlog # Delete cronlog
ynh_secure_remove /etc/cron.d/$app ynh_secure_remove /etc/cron.d/$app
# Delete source.list
#=================================================
# REMOVE source.list
#=================================================
ynh_secure_remove /etc/apt/sources.list.d/backports.list ynh_secure_remove /etc/apt/sources.list.d/backports.list
ynh_secure_remove /etc/apt/sources.list.d/yarn.list ynh_secure_remove /etc/apt/sources.list.d/yarn.list
# Delete ruby exec # Delete ruby exec
ynh_secure_remove /usr/bin/ruby ynh_secure_remove /usr/bin/ruby
# Remove user #=================================================
sudo userdel -f $app # GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
# Reload services userdel -f $app
sudo systemctl reload nginx
echo -e "\e[0m" # Restore normal color