1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dokuwiki_ynh.git synced 2024-09-03 18:26:20 +02:00

[enh] refactor 'remove' script to best practices

This commit is contained in:
Gofannon 2018-06-14 18:42:32 +02:00
parent 42a170b60c
commit bdf0f77c19

View file

@ -1,30 +1,82 @@
#!/bin/bash #!/bin/bash
# Exit on command errors and treat unset variables as an error #=================================================
set -u # GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Loads the generic functions usually used in the script domain=$(ynh_app_setting_get $app domain)
source .fonctions final_path=$(ynh_app_setting_get $app final_path)
# Source app helpers
. /usr/share/yunohost/helpers
# Retrieve app settings #=================================================
domain=$(ynh_app_setting_get "$app" domain) # STANDARD REMOVE
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
# Delete app directory and configurations # Remove the dedicated systemd config
sudo rm -rf "/var/www/${app}" ynh_remove_systemd_config
sudo rm -f "/etc/php5/fpm/pool.d/${app}.conf"
sudo rm -f "/etc/php5/fpm/conf.d/20-${app}.ini"
[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf"
# Reload services #=================================================
sudo systemctl reload php5-fpm # REMOVE SERVICE FROM ADMIN PANEL
sudo systemctl reload nginx #=================================================
# Delete system user dedicace for this app if yunohost service status | grep -q $app
then
echo "Remove $app service"
yunohost service remove $app
fi
#=================================================
# 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
#=================================================
# SPECIFIC REMOVE
#=================================================
# Remove the log files
ynh_secure_remove "/var/log/$app/"
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
# Delete a system user
ynh_system_user_delete $app ynh_system_user_delete $app
echo -e "\e[0m" # Restore normal color