mirror of
https://github.com/YunoHost-Apps/wekan_ynh.git
synced 2024-09-03 20:36:09 +02:00
replacing abort_if_up_to_date by ynh_check_app_version_changed
This commit is contained in:
parent
f74bf0581d
commit
ef02ee6a09
3 changed files with 48 additions and 23 deletions
|
@ -25,28 +25,6 @@ to_logs() {
|
|||
fi
|
||||
}
|
||||
|
||||
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"
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
source _common.sh
|
||||
source ynh_systemd_action
|
||||
source ynh_check_app_version_changed
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
|
@ -33,7 +34,7 @@ fi
|
|||
# CHECK VERSION
|
||||
#=================================================
|
||||
|
||||
abort_if_up_to_date
|
||||
ynh_check_app_version_changed
|
||||
# previous function is what defines 'version', more precisely the 'previous version'
|
||||
previous_version="${version}"
|
||||
|
||||
|
|
46
scripts/ynh_check_app_version_changed
Normal file
46
scripts/ynh_check_app_version_changed
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/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
|
||||
}
|
Loading…
Add table
Reference in a new issue