From d1d000d8d9fa1993e35486c6ad0600790a9774a1 Mon Sep 17 00:00:00 2001 From: ewilly Date: Mon, 23 May 2016 21:40:55 +0200 Subject: [PATCH] trap et maj ynh 2.4 --- manifest.json | 6 ++-- manifest2.2.json | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ scripts/backup | 18 +++++++--- scripts/install | 61 +++++++++++++++++++++++++------- scripts/remove | 33 +++++++++++++++--- scripts/restore | 15 +++++--- scripts/upgrade | 7 +++- 7 files changed, 200 insertions(+), 30 deletions(-) create mode 100644 manifest2.2.json diff --git a/manifest.json b/manifest.json index 9727a46..cb94ea8 100644 --- a/manifest.json +++ b/manifest.json @@ -13,7 +13,7 @@ "email": "ewilly@neuf.fr" }, "requirements": { - "yunohost": ">> 2.2.1.1" + "yunohost": ">= 2.4" }, "multi_instance": "false", "services": [ @@ -42,7 +42,7 @@ "default": "/bozon" }, { - "name": "public_site", + "name": "is_public", "ask": { "en": "Should this application be public ? (if not, sharing file with unregistered users still work)", "fr": "Est-ce que cette application doit être visible publiquement ? (dans le cas contraire, le partage de fichiers avec des utilisateurs externes fonctionnera tout de même)" @@ -51,7 +51,7 @@ "default": "No" }, { - "name": "default_lang", + "name": "language", "ask": { "en": "Default language", "fr": "Langue par défaut" diff --git a/manifest2.2.json b/manifest2.2.json new file mode 100644 index 0000000..ca59df7 --- /dev/null +++ b/manifest2.2.json @@ -0,0 +1,90 @@ +{ + "name": "BoZoN", + "id": "bozon", + "packaging_format": 1, + "description": { + "en": "Minimalist Drag & drop file sharing app", + "fr": "Application minimaliste de partage de fichiers" + }, + "url": "http://bozon.pw", + "license": "free", + "maintainer": { + "name": "ewilly", + "email": "ewilly@neuf.fr" + }, + "requirements": { + "yunohost": ">> 2.2.1.1" + }, + "multi_instance": "false", + "services": [ + "nginx", + "php5-fpm" + ], + "arguments": { + "install" : [ + { + "name": "domain", + "type": "domain", + "ask": { + "en": "Choose a domain for BoZoN", + "fr": "Choisissez un domaine pour BoZoN" + }, + "example": "domain.org" + }, + { + "name": "path", + "type": "path", + "ask": { + "en": "Choose a path for BoZoN", + "fr": "Choisissez un chemin pour BoZoN" + }, + "example": "/bozon", + "default": "/bozon" + }, + { + "name": "is_public", + "ask": { + "en": "Should this application be public ? (if not, sharing file with unregistered users still work)", + "fr": "Est-ce que cette application doit être visible publiquement ? (dans le cas contraire, le partage de fichiers avec des utilisateurs externes fonctionnera tout de même)" + }, + "choices": ["Yes", "No"], + "default": "No" + }, + { + "name": "language", + "ask": { + "en": "Default language", + "fr": "Langue par défaut" + }, + "choices": ["de","en","es","fr"], + "default": "en" + }, + { + "name": "filesize", + "ask": { + "en": "Define the file upload size limit", + "fr": "Définissez la taille limite de téléchargement" + }, + "default": "2G" + }, + { + "name": "admin", + "type": "user", + "ask": { + "en": "Choose an admin user for BoZoN", + "fr": "Choisissez un administrateur pour BoZoN" + }, + "example": "homer" + }, + { + "name": "password", + "type": "password", + "ask": { + "en": "Choose an admin password for BoZoN", + "fr": "Choisissez un mot de passe administrateur pour BoZoN" + }, + "example": "super_secret_password" + } + ] + } +} diff --git a/scripts/backup b/scripts/backup index 63b2665..b799e2c 100644 --- a/scripts/backup +++ b/scripts/backup @@ -2,17 +2,25 @@ # causes the shell to exit if any subcommand or pipeline returns a non-zero status set -e +# causes the shell to exit if you try to use an uninitialised variable +set -u + +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) + +# retrieve arguments +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=bozon +fi +save_path=$1 +domain=$(sudo yunohost app setting $app domain) # definie useful vars -app=bozon parent_path=/var/www final_path=$parent_path/$app data_path=/home/yunohost.app/$app -#retrieve arguments -save_path=$1 -domain=$(sudo yunohost app setting $app domain) - # backup sources & data sudo cp -R $final_path/. $save_path/www/ sudo cp -R $data_path/. $save_path/datas/ diff --git a/scripts/install b/scripts/install index 7bfe9de..fa6c172 100644 --- a/scripts/install +++ b/scripts/install @@ -5,17 +5,54 @@ set -e # causes the shell to exit if you try to use an uninitialised variable set -u +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) + # retrieve arguments -domain=$1 -path=$2 -is_public=$3 -default_lang=$4 -filesize=$5 -admin=$6 -password=$7 +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME + domain=$YNH_APP_ARG_DOMAIN + path=$YNH_APP_ARG_PATH + is_public=$YNH_APP_ARG_IS_PUBLIC + language=$YNH_APP_ARG_LANGUAGE + filesize=$YNH_APP_ARG_FILESIZE + admin=$YNH_APP_ARG_ADMIN + password_admin=$YNH_APP_ARG_PASSWORD + # Source app helpers + . /usr/share/yunohost/helpers +else + app=bozon + domain=$1 + path=$2 + is_public=$3 + language=$4 + filesize=$5 + admin=$6 + password=$7 +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!!" + + 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 # definie useful vars -app=bozon parent_path=/var/www final_path=$parent_path/$app data_path=/home/yunohost.app/$app @@ -26,14 +63,14 @@ data_path=/home/yunohost.app/$app # check domain/path availability sudo yunohost app checkurl $domain$path -a $app if [[ ! $? -eq 0 ]]; then - exit 1 + touch /force_stop fi # check that admin user is an existing account sudo yunohost user list --json | grep -q "\"username\": \"$admin\"" if [[ ! $? -eq 0 ]]; then - echo "Error : the chosen admin user does not exist" - exit 1 + echo "Error : the chosen admin user does not exist" + touch /force_stop fi # retrieve stable version of bozon @@ -63,7 +100,7 @@ sudo find $final_path -type f | xargs sudo chmod 644 sudo find $final_path -type d | xargs sudo chmod 755 # configure config file -sudo sed -i "s@default_language='en';@default_language='$default_lang';@g" $final_path/config.php +sudo sed -i "s@languageuage='en';@languageuage='$language';@g" $final_path/config.php # create data folders sudo mkdir -p $final_path/private diff --git a/scripts/remove b/scripts/remove index 24f0957..6d19449 100644 --- a/scripts/remove +++ b/scripts/remove @@ -5,15 +5,38 @@ set -e # causes the shell to exit if you try to use an uninitialised variable set -u -app=bozon +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) + +#retrieve arguments +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME + # Source app helpers + . /usr/share/yunohost/helpers +else + app=bozon +fi domain=$(sudo yunohost app setting $app domain) -sudo rm -rf /var/www/$app -sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf -sudo rm -f /etc/php5/fpm/pool.d/$app.conf -sudo rm -rf /home/yunohost.app/$app +if [ -e "/var/www/$app" ]; then + echo "Delete app" + sudo rm -rf /var/www/$app +fi +if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then + echo "Delete Nginx config" + sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf +fi +if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then + echo "Delete fpm config" + sudo rm -f /etc/php5/fpm/pool.d/$app.conf +fi +if [ -e "/home/yunohost.app/$app" ]; then + echo "Delete datas" + sudo rm -rf /home/yunohost.app/$app +fi # Restart services sudo service php5-fpm restart || true sudo service nginx restart || true sudo yunohost app ssowatconf + +echo -e "\e[0m" diff --git a/scripts/restore b/scripts/restore index 5b62d98..7f1b0fd 100644 --- a/scripts/restore +++ b/scripts/restore @@ -5,16 +5,23 @@ set -e # causes the shell to exit if you try to use an uninitialised variable set -u +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) + +#retrieve arguments +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=bozon +fi +save_path=$1 +domain=$(sudo yunohost app setting $app domain) + # definie useful vars app=bozon parent_path=/var/www final_path=$parent_path/$app data_path=/home/yunohost.app/$app -# retrieve arguments -save_path=$1 -domain=$(sudo yunohost app setting $app domain) - # restore sources & data sudo mv $save_path/www/. $final_path/ sudo mv $save_path/datas/. $data_path/ diff --git a/scripts/upgrade b/scripts/upgrade index a8751d3..cad831d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -5,9 +5,14 @@ set -e # causes the shell to exit if you try to use an uninitialised variable set -u -app=bozon +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) # retrieve arguments +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=bozon +fi path=$(sudo yunohost app setting $app path) stable=$(sudo yunohost app setting $app version) is_public=$(sudo yunohost app setting $app is_public)