library.sh: Fix resolution of target nextcloud version if requesting older version than current

Signed-off-by: Tobias Knöppler <6317548+theCalcaholic@users.noreply.github.com>
This commit is contained in:
Tobias Knöppler 2024-09-08 23:15:20 +02:00
parent d52b8dcdf1
commit 848ddad7d4
No known key found for this signature in database
GPG Key ID: 44FD368932E645C1
3 changed files with 90 additions and 6 deletions

View File

@ -24,7 +24,7 @@ ncc status &>/dev/null || { [[ "$DBG" == x ]] && ncc status; echo "Next
CURRENT="$(nc_version)" CURRENT="$(nc_version)"
if [[ "$VER" == "0" ]] || [[ "$VER" == "" ]] if [[ "$VER" == "0" ]] || [[ "$VER" == "" ]]
then then
REQUESTED_VERSION="${NCLATESTVER?}" REQUESTED_VERSION="latest"
else else
REQUESTED_VERSION="$VER" REQUESTED_VERSION="$VER"
fi fi
@ -57,10 +57,11 @@ grep -qP "\d+\.\d+\.\d+" <<<"$CURRENT" || { echo "Malformed version $CURRENT"; e
grep -qP "\d+\.\d+\.\d+" <<<"$TARGET_VERSION" || { echo "Malformed version $TARGET_VERSION" ; exit 1; } grep -qP "\d+\.\d+\.\d+" <<<"$TARGET_VERSION" || { echo "Malformed version $TARGET_VERSION" ; exit 1; }
echo "Current Nextcloud version $CURRENT" echo "Current Nextcloud version $CURRENT"
echo "Available Nextcloud version $TARGET_VERSION" echo "Requested Nextcloud version $REQUESTED_VERSION"
echo "Selected Nextcloud version $TARGET_VERSION"
if [[ "$TARGET_VERSION" != "$REQUESTED_VERSION" ]] if [[ "$TARGET_VERSION" != "$REQUESTED_VERSION" ]]
then then
echo "INFO: You have requested an update to '${REQUESTED_VERSION}', but a direct update to '${REQUESTED_VERSION}' cannot be performed, so the latest available version that can be updated to has been selected automatically." echo "INFO: You have requested an update to '${REQUESTED_VERSION}', but a direct update to '${REQUESTED_VERSION}' cannot be performed, so the latest available version that can be updated to (${TARGET_VERSION}) has been selected automatically."
fi fi
# make sure that cron.php is not running and there are no pending jobs # make sure that cron.php is not running and there are no pending jobs

View File

@ -531,10 +531,17 @@ function determine_nc_update_version() {
supported_maj="${supported%%.*}" supported_maj="${supported%%.*}"
# If valid version is requested -> direct update, don't consider anything else # If valid version is requested -> direct update, don't consider anything else
if [[ "$requested" =~ ^[0-9.]*$ ]] && [[ "$requested_maj" -le "$((current_maj + 1))" ]] if [[ "$requested" =~ ^[0-9]*.[0-9]*.[0-9]*$ ]]
then then
echo "$requested" if ! is_more_recent_than "${requested}" "${current}"
return 0 then
echo "$current"
return 0
elif [[ "$requested_maj" -le "$((current_maj + 1))" ]]
then
echo "$requested"
return 0
fi
fi fi
versions="$(curl -q -L -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/nextcloud/server/releases?per_page=100 | jq -r '.[].tag_name' | grep -v -e 'rc.$' -e 'beta.$' | sort -V)" versions="$(curl -q -L -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/nextcloud/server/releases?per_page=100 | jq -r '.[].tag_name' | grep -v -e 'rc.$' -e 'beta.$' | sort -V)"

76
etc/library.test Normal file
View File

@ -0,0 +1,76 @@
#!/bin/bash
set -ex
fail() {
echo "$@"
exit 1
}
#shellcheck source=./library.sh
. "$(dirname "$0")/library.sh" ||:
case=1
current=27.0.1
supported=27.0.8
requested=""
expected=27.1.11
actual="$(determine_nc_update_version "$current" "$supported" "$requested")"
[[ "$expected" == "$actual" ]] || fail "C$case: unexpected nc target version: $actual (expected: $expected)"
case=2
# TODO: Set to 26.0.1
current=26.0.13
supported=27.0.8
requested=""
expected=27.1.11
actual="$(determine_nc_update_version "$current" "$supported" "$requested")"
[[ "$expected" == "$actual" ]] || fail "C$case: unexpected nc target version: $actual (expected: $expected)"
case=3
current=26.0.1
supported=27.0.8
requested="27.1.3"
expected=27.1.3
actual="$(determine_nc_update_version "$current" "$supported" "$requested")"
[[ "$expected" == "$actual" ]] || fail "C$case: unexpected nc target version: $actual (expected: $expected)"
case=4
current=29.0.5
supported=27.0.8
requested=""
expected=29.0.6
actual="$(determine_nc_update_version "$current" "$supported" "$requested")"
[[ "$expected" == "$actual" ]] || fail "C$case: unexpected nc target version: $actual (expected: $expected)"
case=5
current=29.0.5
supported=27.0.8
requested="27.0.8"
expected="29.0.5"
actual="$(determine_nc_update_version "$current" "$supported" "$requested")"
[[ "$expected" == "$actual" ]] || fail "C$case: unexpected nc target version: $actual (expected: $expected)"