From c9da4dd89978c6a540bd93c0b49cfca2b52a25da Mon Sep 17 00:00:00 2001 From: ljf Date: Mon, 31 Jul 2017 14:49:23 +0200 Subject: [PATCH] [enh] Upgrade script --- conf/app.src | 6 ++--- manifest.json | 2 +- scripts/future.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/upgrade | 46 +++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 4 deletions(-) diff --git a/conf/app.src b/conf/app.src index d3625ba..1c33fea 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://code.ffdn.org/FFDN/coin/archive/87a63df9409728e402301690a16aae2ad693c7ff.tar.gz -SOURCE_FILENAME=coin-2017-04-08.tar.gz +SOURCE_URL=https://code.ffdn.org/FFDN/coin/archive/b746cf1059cc3308e2e9e197a5e023522bf184ea.tar.gz +SOURCE_FILENAME=coin-2017-07-31.tar.gz SOURCE_FORMAT=tar.gz -SOURCE_SUM=be9c152a35bc45c14cb80bfb9d6912ecfaab001a669dc56e8a3ace45c199612c +SOURCE_SUM=de3807acef0069043be5376860e8bbabbb4cb4697778d37a031aa15ccfbae2dc SOURCE_SUM_PRG=sha256sum diff --git a/manifest.json b/manifest.json index e07cdcc..bee0b2a 100644 --- a/manifest.json +++ b/manifest.json @@ -13,7 +13,7 @@ "requirements": { "yunohost": ">> 2.5.0" }, - "version": "20170408", + "version": "20170731", "multi_instance": "false", "services": [ "nginx" diff --git a/scripts/future.sh b/scripts/future.sh index ecdfd29..3ead185 100644 --- a/scripts/future.sh +++ b/scripts/future.sh @@ -1,3 +1,21 @@ + +log() { + echo "${1}" +} + +info() { + log "[INFO] ${1}" +} + +warn() { + log "[WARN] ${1}" +} + +err() { + log "[ERR] ${1}" +} + + #====================================================================== # data/helpers.d/package #====================================================================== @@ -170,3 +188,54 @@ ynh_setup_source () { fi } + +ynh_exit_properly () { + exit_code=$? + if [ "$exit_code" -eq 0 ]; then + exit 0 + fi + trap '' EXIT + set +eu + echo -e "\e[91m \e[1m" + err "$app script has encountered an error." + + if type -t CLEAN_SETUP > /dev/null; then + CLEAN_SETUP + fi + + ynh_die +} + +# Activate signal capture +# Exit if a command fail, and if a variable is used unset. +# Capturing exit signals on shell script +# +# example: CLEAN_SETUP () { +# # Clean residual file un remove by remove script +# } +# ynh_trap_on +ynh_trap_on () { + set -eu + trap ynh_exit_properly EXIT # Capturing exit signals on shell script +} + +ynh_read_json () { + sudo python3 -c "import sys, json;print(json.load(open('$1'))['$2'])" +} + +ynh_read_manifest () { + if [ -f '../manifest.json' ] ; then + ynh_read_json '../manifest.json' "$1" + else + ynh_read_json '../settings/manifest.json' "$1" + fi +} + +ynh_exit_if_up_to_date () { + if [ "${version}" = "${last_version}" ]; then + info "Up-to-date, nothing to do" + exit 0 + fi +} + + diff --git a/scripts/upgrade b/scripts/upgrade index a9bf588..9e3b6b4 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1 +1,47 @@ #!/bin/bash +source /usr/share/yunohost/helpers +source common.sh +source future.sh + +export app=$YNH_APP_INSTANCE_NAME +user=$app + +export domain=$(ynh_app_setting_get $app domain) +export path=$(ynh_app_setting_get $app path) +export admin=$(ynh_app_setting_get $app admin) +export email=$(ynh_app_setting_get $app email) +export isp_name=$(ynh_app_setting_get $app isp_name) +export isp_site=$(ynh_app_setting_get $app isp_site) +export secret=$(ynh_app_setting_get $app secret) +version=$(ynh_read_json "/etc/yunohost/apps/$app/manifest.json" 'version' 2> /dev/null || echo '20170408') +last_version=$(ynh_read_manifest 'version') + +ynh_exit_if_up_to_date +ynh_check_var "$app" "app name not set" +ynh_user_exists "$admin" || err "User does not exist: $admin" +ynh_normalize_url_path "$path" + +#if [ "${version}" = "20170408" ]; then +#fi + +# Copy files to the right place +final_path=/opt/$app +ynh_setup_source $final_path + +set +o nounset +source $final_path/venv/bin/activate +set -o nounset +$final_path/venv/bin/pip install -r $final_path/requirements.txt + +# Set permissions +sudo useradd $app -d $final_path || echo "User already exists" +sudo chown -R $app:www-data $final_path + +pushd $final_path +$final_path/venv/bin/python manage.py migrate --noinput +$final_path/venv/bin/python manage.py collectstatic --noinput +popd + +# Set permissions to directory +sudo chown $app:www-data -R $final_path +