mirror of
https://github.com/nextcloud/nextcloudpi.git
synced 2026-01-09 22:52:00 -03:30
ncp-update-nc, nc-autoupdate-nc, ncp-check-nc-version: Dynamically determine upgrade path and auto-upgrade to latest minor version
Signed-off-by: Tobias Knöppler <6317548+theCalcaholic@users.noreply.github.com>
This commit is contained in:
parent
0c023d95a5
commit
323a202785
@ -6,18 +6,20 @@ set -e
|
|||||||
|
|
||||||
source /usr/local/etc/library.sh # sets NCLATESTVER
|
source /usr/local/etc/library.sh # sets NCLATESTVER
|
||||||
|
|
||||||
CURRENT="$(ncc status | grep "version:" | awk '{ print $3 }')"
|
CURRENT="$(nc_version)"
|
||||||
LATEST="$(wget -qO- https://raw.githubusercontent.com/nextcloud/nextcloudpi/master/etc/ncp.cfg | jq -r .nextcloud_version)"
|
NEXT_VERSION="$(determine_nc_upgrade_version "${CURRENT}" "${NCLATESTVER?}")"
|
||||||
|
[[ -n "$NEXT_VERSION" ]] || exit 0
|
||||||
|
|
||||||
NOTIFIED=/var/run/.nc-version-notified
|
NOTIFIED=/var/run/.nc-version-notified
|
||||||
|
|
||||||
test -e "${NOTIFIED}" && [[ "${LATEST}" == "$( cat "${NOTIFIED}" )" ]] && {
|
test -e "${NOTIFIED}" && [[ "${NEXT_VERSION}" == "$( cat "${NOTIFIED}" )" ]] && {
|
||||||
echo "Found update from ${CURRENT} to ${LATEST}. Already notified"
|
echo "Found update from ${CURRENT} to ${NEXT_VERSION}. Already notified"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_more_recent_than "${LATEST}" "${CURRENT}"; then
|
if is_more_recent_than "${NEXT_VERSION}" "${CURRENT}"; then
|
||||||
notify_admin \
|
notify_admin \
|
||||||
"Nextcloud update" \
|
"Nextcloud update" \
|
||||||
"Update from ${CURRENT} to ${LATEST} is available. Update from https://$(get_ip):4443"
|
"Update from ${CURRENT} to ${NEXT_VERSION} is available. Update from https://$(get_ip):4443"
|
||||||
echo "${LATEST}" > "${NOTIFIED}"
|
echo "${NEXT_VERSION}" > "${NOTIFIED}"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -39,14 +39,14 @@ ncc status &>/dev/null || { [[ "$DBG" == x ]] && ncc status; echo "Next
|
|||||||
####################
|
####################
|
||||||
|
|
||||||
[[ ${EUID} -eq 0 ]] && SUDO="sudo -u www-data"
|
[[ ${EUID} -eq 0 ]] && SUDO="sudo -u www-data"
|
||||||
CURRENT="$( $SUDO php /var/www/nextcloud/occ status | grep "version:" | awk '{ print $3 }' )"
|
CURRENT="$(nc_version)"
|
||||||
|
TARGET_VERSION="$(determine_nc_upgrade_version "${CURRENT?}" "${VER?}")"
|
||||||
MAJOR_CUR=$( cut -d. -f1 <<<"${CURRENT}" )
|
[[ -n "$TARGET_VERSION" ]] || {
|
||||||
MAJOR_NEW=$( cut -d. -f1 <<<"${VER}" )
|
echo "Could not find a valid upgrade path from '${CURRENT}' to '${TARGET_VERSION}'. Nothing to update."
|
||||||
if [[ $((MAJOR_NEW - MAJOR_CUR)) -gt 1 ]]; then
|
|
||||||
echo "Upgrade cannot skip major versions. Please upgrade one major version at a time" >&2
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
}
|
||||||
|
|
||||||
|
MAJOR_NEW="${TARGET_VERSION%%.*}"
|
||||||
|
|
||||||
if [[ "$MAJOR_NEW" -ge 24 ]] && [[ "$(lsb_release -r)" =~ .*10 ]]
|
if [[ "$MAJOR_NEW" -ge 24 ]] && [[ "$(lsb_release -r)" =~ .*10 ]]
|
||||||
then
|
then
|
||||||
@ -55,18 +55,10 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
grep -qP "\d+\.\d+\.\d+" <<<"$CURRENT" || { echo "Malformed version $CURRENT"; exit 1; }
|
grep -qP "\d+\.\d+\.\d+" <<<"$CURRENT" || { echo "Malformed version $CURRENT"; exit 1; }
|
||||||
grep -qP "\d+\.\d+\.\d+" <<<"$VER" || { echo "Malformed version $VER" ; 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 $VER"
|
echo "Available Nextcloud version $TARGET_VERSION"
|
||||||
is_more_recent_than "${VER}" "${CURRENT}" || { echo "Nothing to update"; exit 1; } # we want `exit 1` so the autoupdate doesn't notify success in this case
|
|
||||||
|
|
||||||
|
|
||||||
if ! is_more_recent_than '25.0.0' "${VER}" && is_more_recent_than "8.1.0" "${PHPVER}.0" && is_docker
|
|
||||||
then
|
|
||||||
echo 'You need to upgrade to a later docker image in order to upgrade to Nextcloud 25+'
|
|
||||||
exit 1
|
|
||||||
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
|
||||||
# https://github.com/nextcloud/server/issues/10949
|
# https://github.com/nextcloud/server/issues/10949
|
||||||
@ -88,8 +80,8 @@ trap cleanup EXIT
|
|||||||
|
|
||||||
# get new code
|
# get new code
|
||||||
####################
|
####################
|
||||||
URL="https://download.nextcloud.com/server/releases/nextcloud-$VER.tar.bz2"
|
URL="https://download.nextcloud.com/server/releases/nextcloud-$TARGET_VERSION.tar.bz2"
|
||||||
echo "Download Nextcloud $VER..."
|
echo "Download Nextcloud $TARGET_VERSION..."
|
||||||
wget -q "$URL" -O nextcloud.tar.bz2 || { echo "Error downloading"; exit 1; }
|
wget -q "$URL" -O nextcloud.tar.bz2 || { echo "Error downloading"; exit 1; }
|
||||||
|
|
||||||
# backup
|
# backup
|
||||||
@ -127,7 +119,7 @@ trap rollback_simple INT TERM HUP ERR
|
|||||||
|
|
||||||
# replace code
|
# replace code
|
||||||
####################
|
####################
|
||||||
echo "Install Nextcloud $VER..."
|
echo "Install Nextcloud $TARGET_VERSION..."
|
||||||
mv -T nextcloud nextcloud-old
|
mv -T nextcloud nextcloud-old
|
||||||
tar -xf nextcloud.tar.bz2 # && false # test point
|
tar -xf nextcloud.tar.bz2 # && false # test point
|
||||||
rm -rf /var/www/nextcloud.tar.bz2
|
rm -rf /var/www/nextcloud.tar.bz2
|
||||||
@ -195,7 +187,7 @@ $ncc | grep -q db:add-missing-primary-keys && $ncc db:add-missing-primary-keys -
|
|||||||
$ncc | grep -q db:convert-filecache-bigint && $ncc db:convert-filecache-bigint -n
|
$ncc | grep -q db:convert-filecache-bigint && $ncc db:convert-filecache-bigint -n
|
||||||
|
|
||||||
# use the correct version for custom apps
|
# use the correct version for custom apps
|
||||||
NCVER="$(ncc status | grep "version:" | awk '{ print $3 }')"
|
NCVER="$(nc_version)"
|
||||||
if is_more_recent_than "21.0.0" "${NCVER}"; then
|
if is_more_recent_than "21.0.0" "${NCVER}"; then
|
||||||
NCPREV=/var/www/ncp-previewgenerator/ncp-previewgenerator-nc20
|
NCPREV=/var/www/ncp-previewgenerator/ncp-previewgenerator-nc20
|
||||||
else
|
else
|
||||||
|
|||||||
@ -27,7 +27,7 @@ echo -e "[ncp-update-nc]" >> /var/log/ncp.log
|
|||||||
|
|
||||||
if [[ \${PIPESTATUS[0]} -eq 0 ]]; then
|
if [[ \${PIPESTATUS[0]} -eq 0 ]]; then
|
||||||
|
|
||||||
VER="\$( /usr/local/bin/ncc status | grep "version:" | awk '{ print \$3 }' )"
|
VER="\$(nc_version)"
|
||||||
|
|
||||||
notify_admin "NextCloudPi" "Nextcloud was updated to \$VER"
|
notify_admin "NextCloudPi" "Nextcloud was updated to \$VER"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -516,7 +516,32 @@ function check_distro()
|
|||||||
|
|
||||||
function nc_version()
|
function nc_version()
|
||||||
{
|
{
|
||||||
ncc status | grep "version:" | awk '{ print $3 }'
|
ncc status | grep "versionstring:" | awk '{ print $3 }'
|
||||||
|
}
|
||||||
|
|
||||||
|
function determine_nc_upgrade_version() {
|
||||||
|
local current supported current_maj supported_maj versions next_version
|
||||||
|
current="${1?}"
|
||||||
|
supported="${2?}"
|
||||||
|
|
||||||
|
#CURRENT="$(ncc status | grep "versionstring:" | awk '{ print $3 }')"
|
||||||
|
current_maj="${current%%.*}"
|
||||||
|
supported_maj="${supported%%.*}"
|
||||||
|
versions="$(curl -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)"
|
||||||
|
next_version="$(grep "v${current_maj}." <<<"${versions}" | tail -n 1 | tr -d 'v')"
|
||||||
|
if [[ "${next_version}" == "${current}" ]]
|
||||||
|
then
|
||||||
|
|
||||||
|
if [[ "${supported_maj}" -le "${current_maj}" ]]
|
||||||
|
then
|
||||||
|
# No update available
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
next_version="$(grep "$v$((current_maj + 1))." <<< "${versions}" | tail -n 1 | tr -d 'v')"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -z "${next_version}" ]] || echo -n "${next_version}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_ip()
|
function get_ip()
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
{
|
{
|
||||||
"id": "VER",
|
"id": "VER",
|
||||||
"name": "Version",
|
"name": "Version",
|
||||||
"value": "28.0.5"
|
"value": "28.0.7"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "MAXFILESIZE",
|
"id": "MAXFILESIZE",
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"nextcloud_version": "28.0.5",
|
"nextcloud_version": "28.0.7",
|
||||||
"php_version": "8.1",
|
"php_version": "8.1",
|
||||||
"release": "bookworm"
|
"release": "bookworm"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user