mirror of
https://github.com/YunoHost-Apps/rainloop_ynh.git
synced 2024-09-03 20:16:18 +02:00
apply example_ynh to remove
This commit is contained in:
parent
0e08080457
commit
a9a5c35826
1 changed files with 108 additions and 65 deletions
173
scripts/remove
173
scripts/remove
|
@ -1,79 +1,122 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -u
|
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Source app helpers
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
REMOVE_NGINX_CONF () { # Suppression de la configuration nginx
|
#=================================================
|
||||||
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config
|
# LOAD SETTINGS
|
||||||
echo "Delete nginx config"
|
#=================================================
|
||||||
sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
REMOVE_FPM_CONF () { # Suppression de la configuration du pool php-fpm
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then # Delete fpm config
|
|
||||||
echo "Delete fpm config"
|
|
||||||
sudo rm "/etc/php5/fpm/pool.d/$app.conf"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
SECURE_REMOVE () { # Suppression de dossier avec vérification des variables
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
chaine="$1" # L'argument doit être donné entre quotes simple '', pour éviter d'interpréter les variables.
|
port=$(ynh_app_setting_get $app port)
|
||||||
no_var=0
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
while (echo "$chaine" | grep -q '\$') # Boucle tant qu'il y a des $ dans la chaine
|
db_user=$db_name
|
||||||
do
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
no_var=1
|
|
||||||
global_var=$(echo "$chaine" | cut -d '$' -f 2) # Isole la première variable trouvée.
|
|
||||||
only_var=\$$(expr "$global_var" : '\([A-Za-z0-9_]*\)') # Isole complètement la variable en ajoutant le $ au début et en gardant uniquement le nom de la variable. Se débarrasse$
|
|
||||||
real_var=$(eval "echo ${only_var}") # `eval "echo ${var}` permet d'interpréter une variable contenue dans une variable.
|
|
||||||
if test -z "$real_var" || [ "$real_var" = "/" ]; then
|
|
||||||
echo "Variable $only_var is empty, suppression of $chaine cancelled." >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
chaine=$(echo "$chaine" | sed "s@$only_var@$real_var@") # remplace la variable par sa valeur dans la chaine.
|
|
||||||
done
|
|
||||||
if [ "$no_var" -eq 1 ]
|
|
||||||
then
|
|
||||||
if [ -e "$chaine" ]; then
|
|
||||||
echo "Delete directory $chaine"
|
|
||||||
sudo rm -r "$chaine"
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
echo "No detected variable." >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
REMOVE_BDD () { # Suppression de la base de donnée et de l'utilisateur associé.
|
#=================================================
|
||||||
# $1 = Nom de la base de donnée
|
# STANDARD REMOVE
|
||||||
# Utilise '$app' comme nom d'utilisateur et de base de donnée
|
#=================================================
|
||||||
db_user=$1
|
# REMOVE SERVICE FROM ADMIN PANEL
|
||||||
if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $db_user"; then
|
#=================================================
|
||||||
echo "Delete db"
|
|
||||||
ynh_mysql_drop_db $db_user
|
|
||||||
ynh_mysql_drop_user $db_user
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Retrieve parameters
|
# Remove a service from the admin panel, added by `yunohost service add`
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
#if yunohost service status | grep -q $app
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
#then
|
||||||
|
# echo "Remove $app service"
|
||||||
|
# yunohost service remove $app
|
||||||
|
#fi
|
||||||
|
|
||||||
# Drop MySQL database and user
|
#=================================================
|
||||||
REMOVE_BDD "$app"
|
# STOP AND REMOVE SERVICE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Delete app directory and configurations using secure remove
|
# Remove the dedicated systemd config
|
||||||
SECURE_REMOVE '/var/www/$app'
|
#ynh_remove_systemd_config
|
||||||
REMOVE_NGINX_CONF
|
|
||||||
REMOVE_FPM_CONF
|
#=================================================
|
||||||
|
# REMOVE DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Remove metapackage and its dependencies
|
||||||
|
#ynh_remove_app_dependencies
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE THE MYSQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Remove a database if it exists, along with the associated user
|
||||||
|
ynh_mysql_remove_db $db_user $db_name
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# 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" >&2
|
||||||
|
# yunohost firewall disallow TCP $port 2>&1
|
||||||
|
#fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC REMOVE
|
||||||
|
#=================================================
|
||||||
|
# REMOVE THE CRON FILE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Remove a cron file
|
||||||
|
#ynh_secure_remove "/etc/cron.d/$app"
|
||||||
|
|
||||||
|
# Remove a directory securely
|
||||||
|
#ynh_secure_remove "/etc/$app/"
|
||||||
|
|
||||||
|
# Remove the log files
|
||||||
|
#ynh_secure_remove "/var/log/$app/"
|
||||||
|
|
||||||
# Remove GPG key
|
# Remove GPG key
|
||||||
sudo gpg --batch --delete-key --yes Rainloop
|
sudo gpg --batch --delete-key --yes Rainloop
|
||||||
|
|
||||||
# Reload services
|
|
||||||
sudo service php5-fpm reload
|
#=================================================
|
||||||
sudo service nginx reload
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# REMOVE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Delete a system user
|
||||||
|
#ynh_system_user_delete $app
|
||||||
|
|
Loading…
Add table
Reference in a new issue