From 323a202785a6e8d68deb3da9826b65ed21791747 Mon Sep 17 00:00:00 2001 From: Tobias K <6317548+thecalcaholic@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:22:45 +0200 Subject: [PATCH 1/9] ncp-update-nc, nc-autoupdate-nc, ncp-check-nc-version: Dynamically determine upgrade path and auto-upgrade to latest minor version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tobias Knöppler <6317548+theCalcaholic@users.noreply.github.com> --- bin/ncp-check-nc-version | 16 ++++++++------ bin/ncp-update-nc | 34 +++++++++++------------------ bin/ncp/UPDATES/nc-autoupdate-nc.sh | 2 +- etc/library.sh | 27 ++++++++++++++++++++++- etc/ncp-config.d/nc-nextcloud.cfg | 2 +- etc/ncp.cfg | 2 +- 6 files changed, 51 insertions(+), 32 deletions(-) diff --git a/bin/ncp-check-nc-version b/bin/ncp-check-nc-version index 493187892..a89c63273 100755 --- a/bin/ncp-check-nc-version +++ b/bin/ncp-check-nc-version @@ -6,18 +6,20 @@ set -e source /usr/local/etc/library.sh # sets NCLATESTVER -CURRENT="$(ncc status | grep "version:" | awk '{ print $3 }')" -LATEST="$(wget -qO- https://raw.githubusercontent.com/nextcloud/nextcloudpi/master/etc/ncp.cfg | jq -r .nextcloud_version)" +CURRENT="$(nc_version)" +NEXT_VERSION="$(determine_nc_upgrade_version "${CURRENT}" "${NCLATESTVER?}")" +[[ -n "$NEXT_VERSION" ]] || exit 0 + NOTIFIED=/var/run/.nc-version-notified -test -e "${NOTIFIED}" && [[ "${LATEST}" == "$( cat "${NOTIFIED}" )" ]] && { - echo "Found update from ${CURRENT} to ${LATEST}. Already notified" +test -e "${NOTIFIED}" && [[ "${NEXT_VERSION}" == "$( cat "${NOTIFIED}" )" ]] && { + echo "Found update from ${CURRENT} to ${NEXT_VERSION}. Already notified" exit 0 } -if is_more_recent_than "${LATEST}" "${CURRENT}"; then +if is_more_recent_than "${NEXT_VERSION}" "${CURRENT}"; then notify_admin \ "Nextcloud update" \ - "Update from ${CURRENT} to ${LATEST} is available. Update from https://$(get_ip):4443" - echo "${LATEST}" > "${NOTIFIED}" + "Update from ${CURRENT} to ${NEXT_VERSION} is available. Update from https://$(get_ip):4443" + echo "${NEXT_VERSION}" > "${NOTIFIED}" fi diff --git a/bin/ncp-update-nc b/bin/ncp-update-nc index 635434535..90213241c 100755 --- a/bin/ncp-update-nc +++ b/bin/ncp-update-nc @@ -39,14 +39,14 @@ ncc status &>/dev/null || { [[ "$DBG" == x ]] && ncc status; echo "Next #################### [[ ${EUID} -eq 0 ]] && SUDO="sudo -u www-data" -CURRENT="$( $SUDO php /var/www/nextcloud/occ status | grep "version:" | awk '{ print $3 }' )" - -MAJOR_CUR=$( cut -d. -f1 <<<"${CURRENT}" ) -MAJOR_NEW=$( cut -d. -f1 <<<"${VER}" ) -if [[ $((MAJOR_NEW - MAJOR_CUR)) -gt 1 ]]; then - echo "Upgrade cannot skip major versions. Please upgrade one major version at a time" >&2 +CURRENT="$(nc_version)" +TARGET_VERSION="$(determine_nc_upgrade_version "${CURRENT?}" "${VER?}")" +[[ -n "$TARGET_VERSION" ]] || { + echo "Could not find a valid upgrade path from '${CURRENT}' to '${TARGET_VERSION}'. Nothing to update." exit 1 -fi +} + +MAJOR_NEW="${TARGET_VERSION%%.*}" if [[ "$MAJOR_NEW" -ge 24 ]] && [[ "$(lsb_release -r)" =~ .*10 ]] then @@ -55,18 +55,10 @@ then fi 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 "Available Nextcloud version $VER" -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 +echo "Available Nextcloud version $TARGET_VERSION" # make sure that cron.php is not running and there are no pending jobs # https://github.com/nextcloud/server/issues/10949 @@ -88,8 +80,8 @@ trap cleanup EXIT # get new code #################### -URL="https://download.nextcloud.com/server/releases/nextcloud-$VER.tar.bz2" -echo "Download Nextcloud $VER..." +URL="https://download.nextcloud.com/server/releases/nextcloud-$TARGET_VERSION.tar.bz2" +echo "Download Nextcloud $TARGET_VERSION..." wget -q "$URL" -O nextcloud.tar.bz2 || { echo "Error downloading"; exit 1; } # backup @@ -127,7 +119,7 @@ trap rollback_simple INT TERM HUP ERR # replace code #################### -echo "Install Nextcloud $VER..." +echo "Install Nextcloud $TARGET_VERSION..." mv -T nextcloud nextcloud-old tar -xf nextcloud.tar.bz2 # && false # test point 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 # 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 NCPREV=/var/www/ncp-previewgenerator/ncp-previewgenerator-nc20 else diff --git a/bin/ncp/UPDATES/nc-autoupdate-nc.sh b/bin/ncp/UPDATES/nc-autoupdate-nc.sh index 613e7803f..ee95ee238 100644 --- a/bin/ncp/UPDATES/nc-autoupdate-nc.sh +++ b/bin/ncp/UPDATES/nc-autoupdate-nc.sh @@ -27,7 +27,7 @@ echo -e "[ncp-update-nc]" >> /var/log/ncp.log 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" fi diff --git a/etc/library.sh b/etc/library.sh index ab472bdfc..9fb197068 100644 --- a/etc/library.sh +++ b/etc/library.sh @@ -516,7 +516,32 @@ function check_distro() 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() diff --git a/etc/ncp-config.d/nc-nextcloud.cfg b/etc/ncp-config.d/nc-nextcloud.cfg index 85dc839c4..8f7efa697 100644 --- a/etc/ncp-config.d/nc-nextcloud.cfg +++ b/etc/ncp-config.d/nc-nextcloud.cfg @@ -9,7 +9,7 @@ { "id": "VER", "name": "Version", - "value": "28.0.5" + "value": "28.0.7" }, { "id": "MAXFILESIZE", diff --git a/etc/ncp.cfg b/etc/ncp.cfg index c638b358b..86fae7fec 100644 --- a/etc/ncp.cfg +++ b/etc/ncp.cfg @@ -1,5 +1,5 @@ { - "nextcloud_version": "28.0.5", + "nextcloud_version": "28.0.7", "php_version": "8.1", "release": "bookworm" } From 1a210e9f122810bd418ed723d63adcbb33e3dbfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Kn=C3=B6ppler?= <6317548+theCalcaholic@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:34:30 +0200 Subject: [PATCH 2/9] Replace 'NextCloudPi' with 'NextcloudPi' in localization and code comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tobias Knöppler <6317548+theCalcaholic@users.noreply.github.com> --- .github/ISSUE_TEMPLATE/1_Bug_report.md | 4 ++-- .github/ISSUE_TEMPLATE/3_Support_question.md | 8 ++++---- .github/ISSUE_TEMPLATE/4_Documentation_issue.md | 4 ++-- .github/ISSUE_TEMPLATE/5_Security_issue.md | 13 ------------- bin/ncp-check-updates | 4 ++-- bin/ncp-config | 8 ++++---- bin/ncp-report | 2 +- bin/ncp-suggestions | 2 +- bin/ncp-update | 4 ++-- bin/ncp/BACKUPS/nc-export-ncp.sh | 2 +- bin/ncp/BACKUPS/nc-import-ncp.sh | 2 +- bin/ncp/BACKUPS/nc-snapshot-auto.sh | 2 +- bin/ncp/CONFIG/nc-database.sh | 2 +- bin/ncp/CONFIG/nc-datadir.sh | 2 +- bin/ncp/CONFIG/nc-httpsonly.sh | 2 +- bin/ncp/CONFIG/nc-limits.sh | 2 +- bin/ncp/CONFIG/nc-trusted-domains.sh | 2 +- bin/ncp/NETWORKING/duckDNS.sh | 2 +- bin/ncp/NETWORKING/letsencrypt.sh | 2 +- bin/ncp/NETWORKING/nc-forward-ports.sh | 2 +- bin/ncp/NETWORKING/nc-trusted-proxies.sh | 2 +- bin/ncp/NETWORKING/no-ip.sh | 2 +- bin/ncp/NETWORKING/spDYN.sh | 2 +- bin/ncp/SECURITY/fail2ban.sh | 2 +- bin/ncp/SECURITY/nc-audit.sh | 2 +- bin/ncp/SECURITY/nc-encrypt.sh | 2 +- bin/ncp/SYSTEM/nc-automount.sh | 2 +- bin/ncp/SYSTEM/nc-ramlogs.sh | 2 +- bin/ncp/SYSTEM/nc-swapfile.sh | 2 +- bin/ncp/SYSTEM/nc-zram.sh | 2 +- bin/ncp/UPDATES/nc-autoupdate-ncp.sh | 2 +- bin/ncp/UPDATES/nc-update.sh | 2 +- bin/ncp/UPDATES/unattended-upgrades.sh | 2 +- etc/library.sh | 2 +- etc/ncp-config.d/l10n/nc-export-ncp/es.json | 2 +- etc/ncp-config.d/l10n/nc-export-ncp/pt.json | 2 +- etc/ncp-config.d/l10n/nc-export-ncp/zh.json | 2 +- etc/ncp-config.d/l10n/nc-forward-ports/es.json | 2 +- etc/ncp-config.d/l10n/nc-forward-ports/pt.json | 2 +- etc/ncp-config.d/l10n/nc-forward-ports/zh.json | 2 +- etc/ncp-config.d/l10n/nc-import-ncp/es.json | 2 +- etc/ncp-config.d/l10n/nc-import-ncp/pt.json | 2 +- etc/ncp-config.d/l10n/nc-import-ncp/zh.json | 2 +- etc/ncp-config.d/l10n/nc-info/pt.json | 2 +- etc/ncp-config.d/l10n/nc-info/zh.json | 2 +- etc/ncp-config.d/l10n/nc-limits/es.json | 2 +- etc/ncp-config.d/l10n/nc-limits/pt.json | 2 +- etc/ncp-config.d/l10n/nc-limits/zh.json | 2 +- etc/ncp-config.d/l10n/nc-nextcloud/pt.json | 2 +- etc/ncp-config.d/l10n/nc-nextcloud/zh.json | 2 +- etc/ncp-config.d/l10n/nc-notify-updates/pt.json | 2 +- etc/ncp-config.d/l10n/nc-passwd/es.json | 2 +- etc/ncp-config.d/l10n/nc-passwd/pt.json | 2 +- etc/ncp-config.d/l10n/nc-passwd/zh.json | 2 +- etc/ncp-config.d/l10n/nc-update/pt.json | 2 +- etc/ncp-config.d/l10n/nc-update/zh.json | 2 +- etc/ncp-config.d/nc-passwd.cfg | 2 +- ncp-web/backups.php | 2 +- ncp-web/csrf.php | 2 +- ncp-web/download.php | 2 +- ncp-web/download_logs.php | 2 +- ncp-web/elements.php | 2 +- ncp-web/index.php | 12 ++++++------ ncp-web/l10n/de.json | 2 +- ncp-web/l10n/es.json | 2 +- ncp-web/ncp-launcher.php | 2 +- ncp-web/upload.php | 2 +- run_update_history.sh | 2 +- tests/activation_tests.py | 2 +- update.sh | 2 +- 70 files changed, 84 insertions(+), 97 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/5_Security_issue.md diff --git a/.github/ISSUE_TEMPLATE/1_Bug_report.md b/.github/ISSUE_TEMPLATE/1_Bug_report.md index d31d1c46b..44ceab9c8 100644 --- a/.github/ISSUE_TEMPLATE/1_Bug_report.md +++ b/.github/ISSUE_TEMPLATE/1_Bug_report.md @@ -5,7 +5,7 @@ about: Report errors and problems ---