Skip to content

Commit

Permalink
Merge pull request #1971 from nextcloud/devel
Browse files Browse the repository at this point in the history
[hotfix] library.sh: Fix resolution of target nextcloud version if requesting older version than current
  • Loading branch information
theCalcaholic authored Sep 8, 2024
2 parents 47f79b7 + 848ddad commit 63b6aca
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 6 deletions.
7 changes: 4 additions & 3 deletions bin/ncp-update-nc.d/update-nc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ncc status &>/dev/null || { [[ "$DBG" == x ]] && ncc status; echo "Next
CURRENT="$(nc_version)"
if [[ "$VER" == "0" ]] || [[ "$VER" == "" ]]
then
REQUESTED_VERSION="${NCLATESTVER?}"
REQUESTED_VERSION="latest"
else
REQUESTED_VERSION="$VER"
fi
Expand Down Expand Up @@ -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; }

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" ]]
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

# make sure that cron.php is not running and there are no pending jobs
Expand Down
13 changes: 10 additions & 3 deletions etc/library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,17 @@ function determine_nc_update_version() {
supported_maj="${supported%%.*}"

# 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
echo "$requested"
return 0
if ! is_more_recent_than "${requested}" "${current}"
then
echo "$current"
return 0
elif [[ "$requested_maj" -le "$((current_maj + 1))" ]]
then
echo "$requested"
return 0
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)"
Expand Down
76 changes: 76 additions & 0 deletions etc/library.test
Original file line number Diff line number Diff line change
@@ -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)"

0 comments on commit 63b6aca

Please sign in to comment.