1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/z-push_ynh.git synced 2024-09-03 18:05:58 +02:00
This commit is contained in:
polytan02 2017-02-24 23:49:07 +00:00
parent a0028ddf75
commit c75fc4cf7e
2 changed files with 57 additions and 20 deletions

View file

@ -1,23 +1,10 @@
#!/bin/bash #!/bin/bash
# Exit on command errors and treat unset variables as an error
#set -eu
#TRAP_ON () { # Activate signal capture
# trap EXIT_PROPERLY ERR # Capturing ex it signals on error
#}
# Active trap pour arrêter le script si une erreur est détectée.
#TRAP_ON
# See comments in install script
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers # Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
path=$(ynh_app_setting_get $app path)
domain=$(ynh_app_setting_get $app domain)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
statedir=$(ynh_app_setting_get $app statedir) statedir=$(ynh_app_setting_get $app statedir)
final_logpath=$(ynh_app_setting_get $app final_logpath) final_logpath=$(ynh_app_setting_get $app final_logpath)

View file

@ -3,17 +3,67 @@
# Source app helpers # Source app helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
SECURE_REMOVE () { # Suppression de dossier avec vérification des variables
chaine="$1" # L'argument doit être donné entre quotes simple '', pour éviter d'interpréter les variables.
no_var=0
while (echo "$chaine" | grep -q '\$') # Boucle tant qu'il y a des $ dans la chaine
do
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_NGINX_CONF () { # Suppression de la configuration nginx
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config
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
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
}
REMOVE_LOGROTATE_CONF () { # Suppression de la configuration de logrotate
if [ -e "/etc/logrotate.d/$app" ]; then
echo "Delete logrotate config"
sudo rm "/etc/logrotate.d/$app"
fi
}
# We retrieve app parameters # We retrieve app parameters
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get "$app" domain)
# Cleaning # Cleaning
sudo rm -rf /var/www/$app SECURE_REMOVE '/var/www/$app'
sudo rm -rf /home/yunohost.app/$app SECURE_REMOVE '/home/yunohost.app/$app'
sudo rm -rf /var/log/$app SECURE_REMOVE '/var/log/$app'
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
sudo rm -f /etc/php5/fpm/pool.d/$app.conf REMOVE_NGINX_CONF
sudo rm -f /etc/logrotate.d/$app REMOVE_FPM_CONF
REMOVE_LOGROTATE_CONF
# Remove app dependencies # Remove app dependencies
if ynh_package_is_installed "z-push-deps"; then if ynh_package_is_installed "z-push-deps"; then