From 42540d82b51e78b96517b8e4dbffd2395b18477f Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 5 Feb 2019 23:28:45 +0100 Subject: [PATCH] revert back from ynh_check_app_version_changed to abort_if_up_to_date --- scripts/_future.sh | 22 ++++++++++++ scripts/upgrade | 4 +-- scripts/ynh_check_app_version_changed | 46 ------------------------ scripts/ynh_read_manifest_2 | 51 --------------------------- 4 files changed, 23 insertions(+), 100 deletions(-) delete mode 100644 scripts/ynh_check_app_version_changed delete mode 100644 scripts/ynh_read_manifest_2 diff --git a/scripts/_future.sh b/scripts/_future.sh index 0b48576..816f97a 100644 --- a/scripts/_future.sh +++ b/scripts/_future.sh @@ -1,3 +1,25 @@ +#!/bin/bash + +read_json () { + sudo python3 -c "import sys, json;print(json.load(open('$1'))['$2'])" +} + +read_manifest () { + if [ -f '../manifest.json' ] ; then + read_json '../manifest.json' "$1" + else + read_json '../settings/manifest.json' "$1" + fi +} +abort_if_up_to_date () { + version=$(read_json "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" 'version' 2> /dev/null || echo '20160501-7') + last_version=$(read_manifest 'version') + if [ "${version}" = "${last_version}" ]; then + info "Up-to-date, nothing to do" + ynh_die "" 0 + fi +} + ynh_version_gt () { dpkg --compare-versions "$1" gt "$2" diff --git a/scripts/upgrade b/scripts/upgrade index 543fc89..6f78b8f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,8 +8,6 @@ source _common.sh source ynh_systemd_action -source ynh_read_manifest_2 -source ynh_check_app_version_changed source /usr/share/yunohost/helpers #================================================= @@ -35,7 +33,7 @@ fi # CHECK VERSION #================================================= -ynh_check_app_version_changed +abort_if_up_to_date # previous function is what defines 'version', more precisely the 'previous version' previous_version="${version}" diff --git a/scripts/ynh_check_app_version_changed b/scripts/ynh_check_app_version_changed deleted file mode 100644 index 641815c..0000000 --- a/scripts/ynh_check_app_version_changed +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -# Checks the app version to upgrade with the existing app version and returns: -# - UPGRADE_APP if the upstream app version has changed -# - UPGRADE_PACKAGE if only the YunoHost package has changed -# -## It stops the current script without error if the package is up-to-date -# -# This helper should be used to avoid an upgrade of an app, or the upstream part -# of it, when it's not needed -# -# To force an upgrade, even if the package is up to date, -# you have to set the variable YNH_FORCE_UPGRADE before. -# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp - -# usage: ynh_check_app_version_changed -ynh_check_app_version_changed () { - local force_upgrade=${YNH_FORCE_UPGRADE:-0} - local package_check=${PACKAGE_CHECK_EXEC:-0} - - # By default, upstream app version has changed - local return_value="UPGRADE_APP" - - local current_version=$(ynh_read_manifest "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) - local current_upstream_version="${current_version/~ynh*/}" - local update_version=$(ynh_read_manifest "../manifest.json" "version" || echo 1.0) - local update_upstream_version="${update_version/~ynh*/}" - - if [ "$current_version" == "$update_version" ] ; then - # Complete versions are the same - if [ "$force_upgrade" != "0" ] - then - echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2 - unset YNH_FORCE_UPGRADE - elif [ "$package_check" != "0" ] - then - echo "Upgrade forced for package check." >&2 - else - ynh_die "Up-to-date, nothing to do" 0 - fi - elif [ "$current_upstream_version" == "$update_upstream_version" ] ; then - # Upstream versions are the same, only YunoHost package versions differ - return_value="UPGRADE_PACKAGE" - fi - echo $return_value -} diff --git a/scripts/ynh_read_manifest_2 b/scripts/ynh_read_manifest_2 deleted file mode 100644 index c2dd5a3..0000000 --- a/scripts/ynh_read_manifest_2 +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args - -# Read the value of a key in a ynh manifest file -# -# usage: ynh_read_manifest manifest key -# | arg: -m, --manifest= - Path of the manifest to read -# | arg: -k, --key= - Name of the key to find -ynh_read_manifest () { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [m]=manifest= [k]=key= ) - local manifest - local key - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - python3 -c "import sys, json;print(json.load(open('$manifest', encoding='utf-8'))['$key'])" -} - -# Read the upstream version from the manifest -# The version number in the manifest is defined by ~ynh -# For example : 4.3-2~ynh3 -# This include the number before ~ynh -# In the last example it return 4.3-2 -# -# usage: ynh_app_upstream_version -ynh_app_upstream_version () { - manifest_path="../manifest.json" - if [ ! -e "$manifest_path" ]; then - manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place - fi - version_key=$(ynh_read_manifest --manifest="$manifest_path" --key="version") - echo "${version_key/~ynh*/}" -} - -# Read package version from the manifest -# The version number in the manifest is defined by ~ynh -# For example : 4.3-2~ynh3 -# This include the number after ~ynh -# In the last example it return 3 -# -# usage: ynh_app_package_version -ynh_app_package_version () { - manifest_path="../manifest.json" - if [ ! -e "$manifest_path" ]; then - manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place - fi - version_key=$(ynh_read_manifest --manifest="$manifest_path" --key="version") - echo "${version_key/*~ynh/}" -}