From 3cfaaaa5d36ed38464f110319c181fe1da147ec0 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Fri, 20 May 2016 00:00:38 +0200 Subject: [PATCH] trap et maj ynh 2.4 --- manifest.json | 3 ++ manifest2.2.json | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ scripts/backup | 7 +++- scripts/install | 78 +++++++++++++++++++++++++++++++++++-------- scripts/remove | 60 +++++++++++++++++++++++++-------- scripts/restore | 7 +++- scripts/upgrade | 10 ++++-- 7 files changed, 219 insertions(+), 33 deletions(-) create mode 100644 manifest2.2.json diff --git a/manifest.json b/manifest.json index 3bd7897..4f0a880 100644 --- a/manifest.json +++ b/manifest.json @@ -2,6 +2,9 @@ "name": "Leed", "id": "leed", "packaging_format": 1, + "requirements": { + "yunohost": ">= 2.4" + }, "description": { "en": "Leed is a minimalistic RSS feed aggregator which allows quick and non-intrusive reading of feeds.", "fr": "Leed est un agrégateur RSS minimaliste qui permet la consultation de flux RSS de manière rapide et non intrusive." diff --git a/manifest2.2.json b/manifest2.2.json new file mode 100644 index 0000000..3bd7897 --- /dev/null +++ b/manifest2.2.json @@ -0,0 +1,87 @@ +{ + "name": "Leed", + "id": "leed", + "packaging_format": 1, + "description": { + "en": "Leed is a minimalistic RSS feed aggregator which allows quick and non-intrusive reading of feeds.", + "fr": "Leed est un agrégateur RSS minimaliste qui permet la consultation de flux RSS de manière rapide et non intrusive." + }, + "version": "1.6", + "url": "http://leed.idleman.fr/", + "licence": "free", + "maintainer": { + "name": "Maniack Crudelis", + "email": "maniackc_dev@crudelis.fr" + }, + "multi_instance": "true", + "services": [ + "nginx", + "php5-fpm", + "mysql" + ], + "arguments": { + "install" : [ + { + "name": "domain", + "ask": { + "en": "Choose a domain for Leed", + "fr": "Choisissez un domaine pour Leed" + }, + "example": "domain.org" + }, + { + "name": "path", + "ask": { + "en": "Choose a path for Leed", + "fr": "Choisissez un chemin pour Leed" + }, + "example": "/leed", + "default": "/leed" + }, + { + "name": "admin", + "ask": { + "en": "Choose the Leed administrator (must be an existing YunoHost user)", + "fr": "Choisissez un administrateur Leed (doit être un utilisateur YunoHost)" + }, + "example": "john" + }, + { + "name": "password", + "type": "password", + "ask": { + "en": "Set the administrator password Leed", + "fr": "Définissez le mot de passe administrateur de Leed" + }, + "example": "Choose a password" + }, + { + "name": "language", + "ask": { + "en": "Choose your agregator's language", + "fr": "Choisissez la langue de votre agrégateur" + }, + "choices" : ["en", "fr", "es"], + "default" : "en" + }, + { + "name": "market", + "ask": { + "en": "Do you want to activate the Leed Market?", + "fr": "Voulez-vous activer le Leed Market ?" + }, + "choices": ["Yes", "No"], + "default": "No" + }, + { + "name": "is_public", + "ask": { + "en": "Is it a public website ?", + "fr": "Est-ce un site public ?" + }, + "choices": ["Yes", "No"], + "default": "No" + } + ] + } +} diff --git a/scripts/backup b/scripts/backup index ecfbb65..5e72260 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,12 @@ #!/bin/bash # Récupère les infos de l'application. -app=leed +version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=leed +fi final_path=$(sudo yunohost app setting $app final_path) domain=$(sudo yunohost app setting $app domain) diff --git a/scripts/install b/scripts/install index f60f8c6..542b30e 100644 --- a/scripts/install +++ b/scripts/install @@ -1,32 +1,78 @@ #!/bin/bash +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) # Retrieve arguments -domain=$1 -path=$2 -admin=$3 -user_pwd=$4 -language=$5 -market=$6 -is_public=$7 -app=leed +if [ $ynh_version = "2.4" ] +then + domain=$YNH_APP_ARG_DOMAIN + path=$YNH_APP_ARG_PATH + admin=$YNH_APP_ARG_ADMIN + user_pwd=$YNH_APP_ARG_PASSWORD + language=$YNH_APP_ARG_LANGUAGE + market=$YNH_APP_ARG_MARKET + is_public=$YNH_APP_ARG_IS_PUBLIC + + app=$YNH_APP_INSTANCE_NAME + + # Source app helpers + . /usr/share/yunohost/helpers +else + domain=$1 + path=$2 + admin=$3 + user_pwd=$4 + language=$5 + market=$6 + is_public=$7 + app=leed +fi + + +# 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!!" + + echo -e "\e[22m" # Remove bold + + # Clean hosts + sudo sed -i '/#leed/d' /etc/hosts + + if [ $ynh_version = "2.2" ]; then + /bin/bash ./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 mot de passe n'est pas vide. if [[ -z $user_pwd ]]; then echo "Mot de passe incorrect" - exit 1 + touch /force_stop fi # Vérifie que le dossier de destination n'est pas déjà utilisé. @@ -34,7 +80,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 @@ -49,11 +95,15 @@ sudo yunohost app setting $app language -v $language sudo yunohost app setting $app domain -v $domain # Génère un mot de passe aléatoire. -db_pwd=$(cat /dev/urandom | head -n20 | tr -c -d 'A-Za-z0-9' | head -c20) +db_pwd=$(head -n20 /dev/urandom | tr -c -d 'A-Za-z0-9' | head -c20) # Utilise '$app' comme nom d'utilisateur et de base de donnée db_user=$app # Initialise la base de donnée et stocke le mot de passe mysql. -sudo yunohost app initdb $db_user -p $db_pwd +if [ $ynh_version = "2.4" ]; then + ynh_mysql_create_db $db_user $db_user $db_pwd +else + sudo yunohost app initdb $db_user -p $db_pwd +fi sudo yunohost app setting $app mysqlpwd -v $db_pwd diff --git a/scripts/remove b/scripts/remove index 208cebc..105333b 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,30 +1,62 @@ #!/bin/bash -app=leed - # Récupère les infos de l'application. -root_pwd=$(sudo cat /etc/yunohost/mysql) +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=leed + MYSQL_ROOT_PWD_FILE="/etc/yunohost/mysql" +fi domain=$(sudo yunohost app setting $app domain) +# Suppression de la base de donnée et de l'utilisateur associé. # Utilise '$app' comme nom d'utilisateur et de base de donnée db_user=$app -mysql -u root -p$root_pwd -e "DROP DATABASE $db_user ; DROP USER $db_user@localhost ;" +if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $db_user"; then + echo "Delete db" + if [ $ynh_version = "2.4" ]; then + ynh_mysql_drop_db $db_user + ynh_mysql_drop_user $db_user + else + mysql -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) -e "DROP DATABASE $db_user ; DROP USER $db_user@localhost ;" + fi +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 - -# Retirer le cron -sudo rm -f /etc/cron.d/$app +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 # Suppression de la configuration du pool php-fpm -sudo rm -f /etc/php5/fpm/pool.d/$app.conf -sudo rm -f /etc/php5/fpm/conf.d/20-$app.ini - -# Recharge la configuration Nginx et php5-fpm -sudo service nginx reload +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 +if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then # Delete php config + echo "Delete php config" + sudo rm "/etc/php5/fpm/conf.d/20-$app.ini" +fi sudo service php5-fpm reload + +# Retirer le cron +if [ -e "/etc/cron.d/$app" ]; then + echo "Delete cron" + sudo rm "/etc/cron.d/$app" +fi + # 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 fac446c..2e5e2b6 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,12 @@ #!/bin/bash # Récupère les infos de l'application. -app=leed +version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=leed +fi final_path=$(sudo yunohost app setting $app final_path) domain=$(sudo yunohost app setting $app domain) diff --git a/scripts/upgrade b/scripts/upgrade index 345b694..1905f9b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,12 @@ #!/bin/bash # Récupère les infos de l'application. -app=app_name +version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=leed +fi domain=$(sudo yunohost app setting $app domain) path=$(sudo yunohost app setting $app path) admin=$(sudo yunohost app setting $app admin) @@ -72,8 +77,7 @@ else # Si l'app est publique sudo yunohost app setting $app unprotected_uris -v "/" fi -# Recharge la configuration Nginx et php5-fpm +# Recharge la configuration Nginx sudo service nginx reload -# sudo service php5-fpm reload # Régénère la configuration de SSOwat sudo yunohost app ssowatconf