From f4ba74d60e863d2a02a5557493ea932b8fe31e8a Mon Sep 17 00:00:00 2001 From: opi Date: Sat, 14 May 2016 13:57:42 +0200 Subject: [PATCH] [enh] Update every script according to 2.4.0 release --- manifest.json | 3 +++ scripts/backup | 23 +++++++++++++---------- scripts/install | 27 ++++++++++++++++----------- scripts/remove | 10 +++++++--- scripts/restore | 33 ++++++++++++++++++--------------- scripts/upgrade | 27 +++++++++++++++------------ 6 files changed, 72 insertions(+), 51 deletions(-) diff --git a/manifest.json b/manifest.json index 7ac137f..b0034af 100644 --- a/manifest.json +++ b/manifest.json @@ -2,6 +2,9 @@ "name": "Strut", "id": "strut", "packaging_format": 1, + "requirements": { + "yunohost": ">= 2.4.0" + }, "description": { "en": "Strut is a slide editor creating impress.js presentations.", "fr": "Strut est un éditeur de slide permetant de créer des présentation impress.js." diff --git a/scripts/backup b/scripts/backup index dcadfab..00f6fc3 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,18 +1,21 @@ #!/bin/bash -# The parameter $1 is the backup directory location dedicated to the app -BACKUP_DIR=$1 +# causes the shell to exit if any subcommand or pipeline returns a non-zero status +set -e -# The parameter $2 is theid of the app instance ex: strut__2 -APP=$2 +# Source YNH helpers +. /usr/share/yunohost/helpers -domain=$(sudo yunohost app setting $APP domain) +# Get app instance name +app=$YNH_APP_INSTANCE_NAME + +# Retrieve arguments +domain=$(sudo yunohost app setting $app domain) +path=$(sudo yunohost app setting $app path) +public_site=$(sudo yunohost app setting $app public_site) # Copy the app files -final_path=/var/www/$APP -sudo cp -a $final_path "${BACKUP_DIR}/www" +ynh_backup "/var/www/$app" "sources" # Copy the conf files -sudo mkdir -p "${BACKUP_DIR}/conf" -sudo cp -a /etc/nginx/conf.d/$domain.d/$APP.conf "${BACKUP_DIR}/conf/nginx.conf" - +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf" diff --git a/scripts/install b/scripts/install index 1493c5b..aaf8bab 100644 --- a/scripts/install +++ b/scripts/install @@ -1,22 +1,27 @@ #!/bin/bash -APP='strut' -# Retrieve arguments -domain=$1 -path=$2 -public_site=$3 +# causes the shell to exit if any subcommand or pipeline returns a non-zero status +set -e -sudo yunohost app setting $APP public_site -v $public_site +# Get app instance name +app=$YNH_APP_INSTANCE_NAME + +# Retrieve arguments +domain=$YNH_APP_ARG_DOMAIN +path=$YNH_APP_ARG_PATH +public_site=$YNH_APP_ARG_PUBLIC_SITE + +sudo yunohost app setting $app public_site -v $public_site # Check domain/path availability -sudo yunohost app checkurl $domain$path -a $APP +sudo yunohost app checkurl $domain$path -a $app if [[ ! $? -eq 0 ]]; then exit 1 fi # Copy files to the right place -final_path=/var/www/$APP +final_path=/var/www/$app sudo mkdir -p $final_path sudo cp -a ../sources/* $final_path @@ -27,12 +32,12 @@ sudo chown -R www-data: $final_path # Modify Nginx configuration file and copy it to Nginx conf directory sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$APP.conf +sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf # Reload Nginx and regenerate SSOwat conf sudo service nginx reload -sudo yunohost app setting $APP skipped_uris -v "/" +sudo yunohost app setting $app skipped_uris -v "/" if [ "$public_site" = "No" ]; then - sudo yunohost app setting $APP protected_uris -v "/index.html,/scripts" + sudo yunohost app setting $app protected_uris -v "/index.html,/scripts" fi sudo yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove index f61a3ed..f277c53 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,6 +1,10 @@ #!/bin/bash -domain=$(sudo yunohost app setting strut domain) +# Get app instance name +app=$YNH_APP_INSTANCE_NAME -sudo rm -rf /var/www/strut -sudo rm -f /etc/nginx/conf.d/$domain.d/strut.conf +# Retrieve arguments +domain=$(sudo yunohost app setting $app domain) + +sudo rm -rf /var/www/$app +sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf diff --git a/scripts/restore b/scripts/restore index 43b44a4..ed193b5 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,47 +1,50 @@ #!/bin/bash -# The parameter $1 is the backup directory location dedicated to the app -BACKUP_DIR=$1 +# causes the shell to exit if any subcommand or pipeline returns a non-zero status +set -e -# The parameter $2 is the id of the app instance ex: strut__2 -APP=$2 +# Source YNH helpers +. /usr/share/yunohost/helpers -domain=$(sudo yunohost app setting $APP domain) -path=$(sudo yunohost app setting $APP path) -public_site=$(sudo yunohost app setting $APP public_site) +# Get app instance name +app=$YNH_APP_INSTANCE_NAME + +# Retrieve arguments +domain=$(sudo yunohost app setting $app domain) +path=$(sudo yunohost app setting $app path) +public_site=$(sudo yunohost app setting $app public_site) # Check domain/path availability -sudo yunohost app checkurl $domain$path -a $APP +sudo yunohost app checkurl $domain$path -a $app if [[ ! $? -eq 0 ]]; then echo "There is already an app on this URL : $domain$path" | sudo tee /dev/stderr exit 1 fi # Restore the app files -final_path=/var/www/$APP - +final_path=/var/www/$app if [ -d $final_path ]; then echo "There is already a directory: $final_path " | sudo tee /dev/stderr exit 1 fi -sudo cp -a "${BACKUP_DIR}/www" $final_path +sudo cp -a "sources" $final_path sudo chown -R www-data: $final_path # Restore the conf files -conf=/etc/nginx/conf.d/$domain.d/$APP.conf +conf=/etc/nginx/conf.d/$domain.d/$app.conf if [ -f $conf ]; then echo "There is already a nginx conf file at this path: $conf " | sudo tee /dev/stderr exit 1 fi -sudo cp -a "${BACKUP_DIR}/conf/nginx.conf" $conf +sudo cp -a "conf/nginx.conf" $conf # Reload Nginx sudo service nginx reload # Set ssowat config -sudo yunohost app setting $APP skipped_uris -v "/" +sudo yunohost app setting $app skipped_uris -v "/" if [ "$public_site" = "No" ]; then - sudo yunohost app setting $APP protected_uris -v "/index.html,/scripts" + sudo yunohost app setting $app protected_uris -v "/index.html,/scripts" fi sudo yunohost app ssowatconf diff --git a/scripts/upgrade b/scripts/upgrade index 34147a6..d9b65ef 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,16 +1,18 @@ #!/bin/bash -APP='strut' + +# causes the shell to exit if any subcommand or pipeline returns a non-zero status +set -e + +# Get app instance name +app=$YNH_APP_INSTANCE_NAME # Retrieve arguments -domain=$(sudo yunohost app setting $APP domain) -path=$(sudo yunohost app setting $APP path) -public_site=$(sudo yunohost app setting $APP public_site) - - -### Execute potential SQL statements here +domain=$(sudo yunohost app setting $app domain) +path=$(sudo yunohost app setting $app path) +public_site=$(sudo yunohost app setting $app public_site) # Copy files to the right place -final_path=/var/www/$APP +final_path=/var/www/$app sudo mkdir -p $final_path sudo cp -a ../sources/* $final_path @@ -21,14 +23,15 @@ sudo chown -R www-data: $final_path sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf* sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf* -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$APP.conf - +sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf # Reload Nginx sudo service nginx reload -sudo yunohost app setting $APP skipped_uris -v "/" + +# SSO configuration +sudo yunohost app setting $app skipped_uris -v "/" if [ "$public_site" = "No" ]; then - sudo yunohost app setting $APP protected_uris -v "/index.html,/scripts" + sudo yunohost app setting $app protected_uris -v "/index.html,/scripts" fi sudo yunohost app ssowatconf