From 675a1235dbec5f4e20f9a9dd5f48d81857efbcb1 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Fri, 20 May 2016 00:01:21 +0200 Subject: [PATCH] trap et maj ynh 2.4 --- manifest.json | 3 +++ manifest2.2.json | 67 +++++++++++++++++++++++++++++++++++++++++++++ scripts/backup | 7 ++++- scripts/install | 57 ++++++++++++++++++++++++++++++++------- scripts/remove | 70 +++++++++++++++++++++++++++++++++--------------- scripts/restore | 7 ++++- scripts/upgrade | 7 ++++- 7 files changed, 185 insertions(+), 33 deletions(-) create mode 100644 manifest2.2.json diff --git a/manifest.json b/manifest.json index 755e2b8..784aa7b 100644 --- a/manifest.json +++ b/manifest.json @@ -2,6 +2,9 @@ "name": "Lutim", "id": "lutim", "packaging_format": 1, + "requirements": { + "yunohost": ">= 2.4" + }, "description": { "en": "Self hosting images and sharing anonymous application", "fr": "Application d'hébergement et de partage d'images anonyme" diff --git a/manifest2.2.json b/manifest2.2.json new file mode 100644 index 0000000..755e2b8 --- /dev/null +++ b/manifest2.2.json @@ -0,0 +1,67 @@ +{ + "name": "Lutim", + "id": "lutim", + "packaging_format": 1, + "description": { + "en": "Self hosting images and sharing anonymous application", + "fr": "Application d'hébergement et de partage d'images anonyme" + }, + "version": "0.6 dev", + "url": "https://lut.im", + "licence": "free", + "maintainer": { + "name": "Maniack Crudelis et matlink", + "email": "maniackc_dev@crudelis.fr matlink@matlink.fr" + }, + "multi_instance": "false", + "services": [ + "nginx" + ], + "arguments": { + "install" : [ + { + "name": "domain", + "ask": { + "en": "Choose a domain for Lutim", + "fr": "Choisissez un domaine pour Lutim" + }, + "example": "domain.org" + }, + { + "name": "path", + "ask": { + "en": "Choose a path for Lutim", + "fr": "Choisissez un chemin pour Lutim" + }, + "example": "/lutim", + "default": "/lutim" + }, + { + "name": "admin", + "ask": { + "en": "Choose the Lutim administrator (must be an existing YunoHost user)", + "fr": "Choisissez un administrateur Lutim (doit être un utilisateur YunoHost)" + }, + "example": "john" + }, + { + "name": "is_public", + "ask": { + "en": "Uploading images is it public?", + "fr": "L'upload des images est-il public ?" + }, + "choices": ["Yes", "No"], + "default": "No" + }, + { + "name": "always_encrypt", + "ask": { + "en": "Force the encryption of images?", + "fr": "Forcer le chiffrement des images ?" + }, + "choices": ["Yes", "No"], + "default": "Yes" + } + ] + } +} diff --git a/scripts/backup b/scripts/backup index 3f5ecf1..2da9f45 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,12 @@ #!/bin/bash # Récupère les infos de l'application. -app=lutim +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=lutim +fi final_path=$(sudo yunohost app setting $app final_path) domain=$(sudo yunohost app setting $app domain) codename=$(sudo yunohost app setting $app codename) diff --git a/scripts/install b/scripts/install index a5a27c9..bc2c670 100644 --- a/scripts/install +++ b/scripts/install @@ -1,24 +1,63 @@ #!/bin/bash +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) # Retrieve arguments -domain=$1 -path=$2 -admin=$3 -is_public=$4 -always_encrypt=$5 -app=lutim +if [ $ynh_version = "2.4" ] +then + domain=$YNH_APP_ARG_DOMAIN + path=$YNH_APP_ARG_PATH + admin=$YNH_APP_ARG_ADMIN + is_public=$YNH_APP_ARG_IS_PUBLIC + always_encrypt=$YNH_APP_ARG_ALWAYS_ENCRYPT + + app=$YNH_APP_INSTANCE_NAME + + # Source app helpers + . /usr/share/yunohost/helpers +else + domain=$1 + path=$2 + admin=$3 + is_public=$4 + always_encrypt=$5 + app=lutim +fi +script_dir=$PWD + +# Delete files and db if exit with an error +EXIT_PROPERLY () { + trap '' ERR + echo -e "\e[91m \e[1m" # Shell in light red bold + echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!" + + if [ $ynh_version = "2.2" ]; then + /bin/bash $script_dir/remove # Appel le script remove. En 2.2, ce comportement n'est pas automatique. + fi + exit 1 +} +TRAP_ON () { # Activate signal capture + trap EXIT_PROPERLY ERR # Capturing exit signals on error +} +TRAP_OFF () { # Ignoring signal capture until TRAP_ON +# Pour une raison que j'ignore, la fonction TRAP_ON fonctionne très bien. +# Mais pas la fonction TRAP_OFF... +# Utiliser directement `trap '' ERR` dans le code pour l'utiliser, à la place de la fonction. + trap '' ERR # Ignoring exit signals +} +TRAP_ON + # Vérifie la validité de l'user admin sudo yunohost user list --json | grep -q "\"username\": \"$admin\"" if [[ ! $? -eq 0 ]]; then echo "Wrong admin" - exit 1 + touch /force_stop fi # Vérifie la disponibilité du path et du domaine. sudo yunohost app checkurl $domain$path -a $app if [[ ! $? -eq 0 ]]; then - exit 1 + touch /force_stop fi # Vérifie que le dossier de destination n'est pas déjà utilisé. @@ -26,7 +65,7 @@ final_path=/var/www/$app if [ -e "$final_path" ] then echo "This path already contains a folder" - exit 1 + touch /force_stop fi # Vérifie la présence du / en début de path diff --git a/scripts/remove b/scripts/remove index 0c305a9..302f9a8 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,43 +1,71 @@ #!/bin/bash -app=lutim - # Récupère les infos de l'application. +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME + + # Source app helpers + . /usr/share/yunohost/helpers +else + app=lutim +fi domain=$(sudo yunohost app setting $app domain) -codename=$(sudo yunohost app setting $app codename) # Arrêt du service -sudo service lutim stop +if [ -e "/etc/init.d/lutim" ]; then + echo "Delete init.d script" + sudo service lutim stop + sudo rm "/etc/init.d/lutim" + sudo rm "/etc/default/lutim" + sudo update-rc.d -f lutim remove +fi +if [ -e "/etc/systemd/system/lutim.service" ]; then + echo "Delete systemd script" + sudo service lutim stop + sudo rm "/etc/systemd/system/lutim.service" + sudo systemctl disable lutim.service +fi # Retire le service du monitoring de Yunohost. -sudo yunohost service remove lutim - -if [ "$codename" = "wheezy" ] -then # Suppression des fichiers init - sudo rm -f /etc/default/lutim - sudo rm -f /etc/init.d/lutim - sudo update-rc.d -f lutim remove -else # Suppression des fichiers systemd - sudo systemctl disable lutim.service - sudo rm -f /etc/systemd/system/lutim.service +if sudo yunohost service status | grep -q lutim # Test l'existence du service dans Yunohost +then + echo "Remove lutim service" + sudo yunohost service remove lutim fi # Suppression du dossier de l'application -sudo rm -rf /var/www/$app + if [ -e "/var/www/$app" ]; then # Delete final_path + echo "Delete app dir" + sudo rm -r "/var/www/$app" + fi # Suppression de la configuration nginx -sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf +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" + sudo service nginx reload +fi # Retirer le cron -sudo rm -f /etc/cron.d/$app +if [ -e "/etc/cron.d/$app" ]; then + echo "Delete cron" + sudo rm "/etc/cron.d/$app" +fi # Suppression des log -sudo rm -r /var/log/$app/ +if [ -e "/var/log/$app/" ]; then + echo "Delete log" + sudo rm -r "/var/log/$app/" +fi # Suppression de la configuration de logrotate -sudo rm /etc/logrotate.d/$app +if [ -e "/etc/logrotate.d/$app" ]; then + echo "Delete logrotate config" + sudo rm "/etc/logrotate.d/$app" +fi -# Recharge la configuration Nginx -sudo service nginx reload # Régénère la configuration de SSOwat sudo yunohost app ssowatconf + +echo -e "\e[0m" # Restore normal color diff --git a/scripts/restore b/scripts/restore index 95e8c7d..2c3f6b6 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,12 @@ #!/bin/bash # Récupère les infos de l'application. -app=lutim +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=lutim +fi final_path=$(sudo yunohost app setting $app final_path) domain=$(sudo yunohost app setting $app domain) codename=$(sudo yunohost app setting $app codename) diff --git a/scripts/upgrade b/scripts/upgrade index 01b1929..883d30a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,12 @@ #!/bin/bash # Récupère les infos de l'application. -app=lutim +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=lutim +fi domain=$(sudo yunohost app setting $app domain) path=$(sudo yunohost app setting $app path) is_public=$(sudo yunohost app setting $app is_public)