mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
helpers 2.1: replace ynh_compare_current_package_version with simpler ynh_if_upgrading_from_version_prior_to and ynh_if_upgrading_from_version_prior_or_equal_to
This commit is contained in:
parent
70f5154130
commit
84a7b23e8a
1 changed files with 17 additions and 37 deletions
|
@ -937,48 +937,28 @@ ynh_check_app_version_changed() {
|
||||||
echo $return_value
|
echo $return_value
|
||||||
}
|
}
|
||||||
|
|
||||||
# Compare the current package version against another version given as an argument.
|
# Compare the current package version is strictly lower than another version given as an argument
|
||||||
#
|
#
|
||||||
# usage: ynh_compare_current_package_version --comparison (lt|le|eq|ne|ge|gt) --version <X~ynhY>
|
# example: if ynh_if_upgrading_from_version_prior_to 2.3.2~ynh1; then ...
|
||||||
# | arg: --comparison - Comparison type. Could be : `lt` (lower than), `le` (lower or equal), `eq` (equal), `ne` (not equal), `ge` (greater or equal), `gt` (greater than)
|
|
||||||
# | arg: --version - The version to compare. Need to be a version in the yunohost package version type (like `2.3.1~ynh4`)
|
|
||||||
# | ret: 0 if the evaluation is true, 1 if false.
|
|
||||||
#
|
#
|
||||||
# example: ynh_compare_current_package_version --comparison lt --version 2.3.2~ynh1
|
# Requires YunoHost version 11.2 or higher.
|
||||||
#
|
ynh_if_upgrading_from_version_prior_to() {
|
||||||
# This helper is usually used when we need to do some actions only for some old package versions.
|
local version=$1
|
||||||
#
|
[[ $version =~ '~ynh' ]] || ynh_die --message="Invalid argument for version, should include the ~ynhX prefix"
|
||||||
# Generally you might probably use it as follow in the upgrade script :
|
|
||||||
# ```
|
|
||||||
# if ynh_compare_current_package_version --comparison lt --version 2.3.2~ynh1
|
|
||||||
# then
|
|
||||||
# # Do something that is needed for the package version older than 2.3.2~ynh1
|
|
||||||
# fi
|
|
||||||
# ```
|
|
||||||
#
|
|
||||||
# Requires YunoHost version 3.8.0 or higher.
|
|
||||||
ynh_compare_current_package_version() {
|
|
||||||
# ============ Argument parsing =============
|
|
||||||
local -A args_array=([c]=comparison= [v]=version=)
|
|
||||||
local version
|
|
||||||
local comparison
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
# ===========================================
|
|
||||||
|
|
||||||
local current_version=$YNH_APP_CURRENT_VERSION
|
dpkg --compare-versions $YNH_APP_CURRENT_VERSION lt $version
|
||||||
|
}
|
||||||
|
|
||||||
# Check the syntax of the versions
|
# Compare the current package version is lower or equal to another version given as an argument
|
||||||
if [[ ! $version =~ '~ynh' ]] || [[ ! $current_version =~ '~ynh' ]]; then
|
#
|
||||||
ynh_die --message="Invalid argument for version."
|
# example: if ynh_if_upgrading_from_version_prior_or_equal_to 2.3.2~ynh1; then ...
|
||||||
fi
|
#
|
||||||
|
# Requires YunoHost version 11.2 or higher.
|
||||||
|
ynh_if_upgrading_from_version_prior_or_equal_to() {
|
||||||
|
local version=$1
|
||||||
|
[[ $version =~ '~ynh' ]] || ynh_die --message="Invalid argument for version, should include the ~ynhX prefix"
|
||||||
|
|
||||||
# Check validity of the comparator
|
dpkg --compare-versions $YNH_APP_CURRENT_VERSION le $version
|
||||||
if [[ ! $comparison =~ (lt|le|eq|ne|ge|gt) ]]; then
|
|
||||||
ynh_die --message="Invalid comparator must be : lt, le, eq, ne, ge, gt"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Return the return value of dpkg --compare-versions
|
|
||||||
dpkg --compare-versions $current_version $comparison $version
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if we should enforce sane default permissions (= disable rwx for 'others')
|
# Check if we should enforce sane default permissions (= disable rwx for 'others')
|
||||||
|
|
Loading…
Add table
Reference in a new issue