mirror of
https://github.com/YunoHost-Apps/flarum_ynh.git
synced 2024-09-03 18:36:24 +02:00
72 lines
2.3 KiB
Bash
72 lines
2.3 KiB
Bash
#!/bin/bash
|
||
|
||
# See comments in install script
|
||
app=$YNH_APP_INSTANCE_NAME
|
||
|
||
# Source 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 surtout du / et d'un éventuel chemin derrière.
|
||
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
|
||
}
|
||
|
||
# Retrieve app settings
|
||
domain=$(ynh_app_setting_get "$app" domain)
|
||
|
||
# Remove sources
|
||
SECURE_REMOVE "/tmp/composerinstall"
|
||
SECURE_REMOVE "/var/www/$app"
|
||
SECURE_REMOVE "/opt/${app}_composer"
|
||
|
||
# Remove nginx and PHP-FPM files and restart services
|
||
REMOVE_NGINX_CONF
|
||
REMOVE_FPM_CONF
|
||
sudo service nginx reload
|
||
sudo service php5-fpm reload
|
||
|
||
### MySQL ###
|
||
# If a MySQL database is used:
|
||
# # Drop MySQL database and user
|
||
dbname=$app
|
||
dbuser=$app
|
||
ynh_mysql_drop_db "$dbname" || true
|
||
ynh_mysql_drop_user "$dbuser" || true
|
||
### MySQL end ###
|