diff --git a/.github/workflows/build-lxd.yml b/.github/workflows/build-lxd.yml index 1d9404856..95cb48ede 100644 --- a/.github/workflows/build-lxd.yml +++ b/.github/workflows/build-lxd.yml @@ -362,7 +362,7 @@ jobs: - name: Checkout code uses: actions/checkout@v3 with: - ref: "${{ env.VERSION }}" + ref: "v1.54.3" - name: Setup Firefox continue-on-error: true id: setup-firefox-browser-action @@ -422,7 +422,7 @@ jobs: sudo "$LXC" exec ncp -- "tail -n20 /var/log/ncp.log" || true exit 1 } - python nextcloud_tests.py --no-gui --skip-release-check "nextcloudpi.local" 443 4443 || { + python nextcloud_tests.py --skip-release-check --no-gui "nextcloudpi.local" 443 4443 || { echo "Nextcloud test failed!" echo "Geckodriver logs:" tail -n 20 geckodriver.log >&2 || true @@ -457,7 +457,7 @@ jobs: echo "Running update to ${VERSION}" current_nc_version="$(sudo "$LXC" exec ncp -- ncc status | grep "version:" | awk '{ print $3 }')" - latest_nc_version="$(cat etc/ncp.cfg | jq -r '.nextcloud_version')" + latest_nc_version="27.0.1" sudo "$LXC" exec ncp -- bash -c "DBG=x ncp-update ${UPDATE_ARGS[*]}" sudo "$LXC" exec ncp -- /usr/local/bin/ncc status @@ -467,6 +467,7 @@ jobs: echo "Nextcloud is up to date - skipping NC update test." else sudo "$LXC" exec ncp -- bash -c "DBG=x ncp-update-nc ${latest_nc_version?}" + sudo "$LXC" exec ncp -- /usr/local/bin/ncc status fi sudo "$LXC" exec ncp -- rm -f /opt/ncdata/data/nextcloud.log @@ -506,6 +507,10 @@ jobs: echo "System test failed!" exit 1 } + - name: Checkout current version + run: | + git fetch origin + git checkout "${{ env.VERSION }}" - name: NCP distupgrade id: distupgrade run: | @@ -514,7 +519,21 @@ jobs: echo "can't upgrade from Debian $(sudo "$LXC" exec ncp -- cat /etc/os-release | grep VERSION_ID=)" exit 1 } + current_nc_version="$(sudo "$LXC" exec ncp -- ncc status | grep "version:" | awk '{ print $3 }')" + latest_nc_version="$(cat etc/ncp.cfg | jq -r '.nextcloud_version')" + sudo "$LXC" exec ncp -- bash -c "DEBIAN_FRONTEND=noninteractive ncp-dist-upgrade" + sudo "$LXC" exec ncp -- /usr/local/bin/ncc status + + if [[ "$current_nc_version" =~ "$latest_nc_version".* ]] + then + echo "Nextcloud is up to date - skipping NC update test." + else + sudo "$LXC" exec ncp -- bash -c "DBG=x ncp-update-nc ${latest_nc_version?}" + sudo "$LXC" exec ncp -- /usr/local/bin/ncc status + fi + + sudo "$LXC" exec ncp -- rm -f /opt/ncdata/data/nextcloud.log sudo "$LXC" exec ncp -- rm -f /opt/ncdata/data/nextcloud.log diff --git a/.github/workflows/build-sd-images.yml b/.github/workflows/build-sd-images.yml index 9aaebb2e5..a44780818 100644 --- a/.github/workflows/build-sd-images.yml +++ b/.github/workflows/build-sd-images.yml @@ -191,9 +191,9 @@ jobs: echo '[Service]' | sudo tee raspbian_root/etc/systemd/system/redis-server.service.d/ncp.conf echo 'PrivateUsers=false' | sudo tee -a raspbian_root/etc/systemd/system/redis-server.service.d/ncp.conf - sudo mkdir -p raspbian_root/etc/systemd/system/php8.1-fpm.service.d - echo '[Service]' | sudo tee raspbian_root/etc/systemd/system/php8.1-fpm.service.d/ncp.conf - echo 'ExecStartPre=mkdir -p /var/run/php' | sudo tee -a raspbian_root/etc/systemd/system/php8.1-fpm.service.d/ncp.conf + sudo mkdir -p raspbian_root/etc/systemd/system/php8.2-fpm.service.d + echo '[Service]' | sudo tee raspbian_root/etc/systemd/system/php8.2-fpm.service.d/ncp.conf + echo 'ExecStartPre=mkdir -p /var/run/php' | sudo tee -a raspbian_root/etc/systemd/system/php8.2-fpm.service.d/ncp.conf - name: Test image id: test run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b92f3cf95..4c86bf7c8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -324,6 +324,12 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | + + NC_VERSION="$(jq -r '.nextcloud_version' < etc/ncp.cfg)" + PHP_VERSION="$(jq -r '.php_version' < etc/ncp.cfg)" + DEBIAN_VERSION="$(jq -r '.release' < etc/ncp.cfg)" + ARMBIAN_VERSIOn="$(cat build/armbian/armbian_version)" + subject="$(git tag -n10 --format="%(contents:subject)" "${{ env.VERSION }}")" body="$(git tag -n30 --format="%(contents:body)" "${{ env.VERSION }}")" separator=" @@ -334,6 +340,12 @@ jobs: gh release create --draft -F - "${{ env.VERSION }}" <"; exit 1; } -[[ -f /.docker-image ]] && BASEDIR=/data || BASEDIR=/var/www -cd "$BASEDIR" -DATADIR="$( get_nc_config_value datadirectory )" -ncc status &>/dev/null || { [[ "$DBG" == x ]] && ncc status; echo "Nextcloud is currently down"; exit 1; } -[[ -d "${BASEDIR}/nextcloud-old" ]] && { echo "Nextcloud backup directory found. Interrupted or already running installation?"; exit 1; } -[[ -d "${BASEDIR}/nextcloud" ]] || { echo "Nextcloud directory not found" ; exit 1; } -[[ -d "$DATADIR" ]] || { echo "Nextcloud data directory not found" ; exit 1; } -# check version -#################### - -[[ ${EUID} -eq 0 ]] && SUDO="sudo -u www-data" -CURRENT="$(nc_version)" -TARGET_VERSION="$(determine_nc_upgrade_version "${CURRENT?}" "${VER?}")" -[[ "$TARGET_VERSION" == "$CURRENT" ]] && { - echo "Nextcloud version ${CURRENT} is already installed. Nothing to do." - exit 0 -} -[[ -n "$TARGET_VERSION" ]] || { - echo "Could not find a valid upgrade path from '${CURRENT}' to '${TARGET_VERSION}'. Nothing to update." - exit 1 +connect_to_nc_update() { + tail -f "/var/log/ncp-update-nc.log" & + tail_pid=$! + while [[ "$(systemctl is-active ncp-update-nc ||:)" =~ ^(active|activating|deactivating)$ ]] + do + sleep 3 + done + + kill "$tail_pid" + if [[ "$(systemctl is-active ncp-update-nc ||:)" == "inactive" ]] + then + echo "Nextcloud update finished successfully." + return 0 + elif [[ "$(systemctl is-active ncp-update-nc ||:)" == "failed" ]] + then + echo "Nextcloud update failed." + return 1 + else + echo "Nextcloud update was not found or failed (unexpected status: '$(systemctl is-active ncp-update-nc ||:)')" + fi } -MAJOR_NEW="${TARGET_VERSION%%.*}" - -if [[ "$MAJOR_NEW" -ge 24 ]] && [[ "$(lsb_release -r)" =~ .*10 ]] +if [[ "$(systemctl is-active ncp-update-nc ||:)" =~ ^(active|activating|deactivating)$ ]] then - echo -e "NCP doesn't support Nextcloud versions greater than 23 with Debian 10 (Buster). Please run ncp-dist-upgrade." - exit 1 -fi - -if [[ "$MAJOR_NEW" -ge 29 ]] && [[ "$(lsb_release -r)" =~ .*12 ]] -then - echo -e "NCP doesn't support Nextcloud versions greater than 28 with Debian 11 (Bullseye). Please run ncp-dist-upgrade." - exit 1 -fi - -grep -qP "\d+\.\d+\.\d+" <<<"$CURRENT" || { echo "Malformed version $CURRENT"; 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 $TARGET_VERSION" -if [[ "$TARGET_VERSION" != "$VER" ]] -then - echo "INFO: You have requested an update to '$VER', but a direct update to '$VER' cannot be performed, so the latest available version that can be updated to has been selected automatically." -fi - -# make sure that cron.php is not running and there are no pending jobs -# https://github.com/nextcloud/server/issues/10949 -pgrep -cf cron.php &>/dev/null && { pkill -f cron.php; sleep 3; } -pgrep -cf cron.php &>/dev/null && { echo "cron.php running. Abort"; exit 1; } -mysql nextcloud <<<"UPDATE ${DB_PREFIX}jobs SET reserved_at=0;" - -# cleanup -#################### -cleanup() { - local RET=$? - set +eE - echo "Clean up..." - rm -rf "$BASEDIR"/nextcloud.tar.bz2 "$BASEDIR"/nextcloud-old - trap "" EXIT - exit $RET -} -trap cleanup EXIT - -# get new code -#################### -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 -#################### -BKPDIR="$BASEDIR" -WITH_DATA=no -COMPRESSED=yes -LIMIT=0 - -echo "Back up current instance..." -set +eE -ncp-backup "$BKPDIR" "$WITH_DATA" "$COMPRESSED" "$LIMIT" # && false # test point -RET=$? -sync -set -eE - -BKP_="$( ls -1t "$BKPDIR"/nextcloud-bkp_*.tar.gz 2>/dev/null | head -1 )" -[[ -f "$BKP_" ]] || { set +eE; echo "Error backing up"; false || cleanup; } -[[ $RET -ne 0 ]] && { rm -f "$BKP_"; set +eE; echo "Error backing up"; false || cleanup; } -BKP="$( dirname "$BKP_" )/$( basename "$BKP_" .tar.gz )-${CURRENT}.tar.gz" -echo "Storing backup at '$BKP'..." -mv "$BKP_" "$BKP" - -# simple restore if anything fails from here -#################### -rollback_simple() { - set +eE - trap "" INT TERM HUP ERR - echo -e "Abort\nSimple roll back..." - rm -rf "$BASEDIR"/nextcloud - mv "$BASEDIR"/nextcloud-old "$BASEDIR"/nextcloud - false || cleanup # so cleanup exits with 1 -} -trap rollback_simple INT TERM HUP ERR - -# replace code -#################### -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 - -# copy old config -#################### -cp nextcloud-old/config/config.php nextcloud/config/ - -# copy old themes -#################### -cp -raT nextcloud-old/themes/ nextcloud/themes/ - -# copy old NCP apps -#################### -for app in nextcloudpi previewgenerator; do - if [[ -d nextcloud-old/apps/"${app}" ]]; then - cp -r -L nextcloud-old/apps/"${app}" /var/www/nextcloud/apps/ - fi -done - -#false # test point - -# copy data if it was at the default location -#################### -if [[ "$DATADIR" == "/var/www/nextcloud/data" ]] || [[ "$DATADIR" == "/data/nextcloud/data" ]]; then - echo "Restore data..." - mv -T nextcloud-old/data nextcloud/data + echo "Existing ncp-update-nc process detected. Connecting..." + connect_to_nc_update + exit $? fi -# nc-restore if anything fails from here -#################### -rollback() { - set +eE - trap "" INT TERM HUP ERR EXIT - echo -e "Abort\nClean up..." - rm -rf /var/www/nextcloud.tar.bz2 "$BASEDIR"/nextcloud-old - echo "Rolling back to backup $BKP..." - local TMPDATA - mkdir -p "$BASEDIR/recovery/" - TMPDATA="$( mktemp -d "$BASEDIR/recovery/ncp-data.XXXXXX" )" || { echo "Failed to create temp dir" >&2; exit 1; } - [[ "$DATADIR" == "$BASEDIR/nextcloud/data" ]] && mv -T "$DATADIR" "$TMPDATA" - ncp-restore "$BKP" || { echo "Rollback failed! Data left at $TMPDATA"; exit 1; } - [[ "$DATADIR" == "$BASEDIR/nextcloud/data" ]] && { rm -rf "$DATADIR"; mv -T "$TMPDATA" "$DATADIR"; } - rm "$BKP" - echo "Rollback successful. Nothing was updated" - exit 1 -} -trap rollback INT TERM HUP ERR - -# fix permissions -#################### -echo "Fix permissions..." -chown -R www-data:www-data nextcloud -find nextcloud/ -type d -exec chmod 750 {} \; -find nextcloud/ -type f -exec chmod 640 {} \; - -# upgrade -#################### -echo "Upgrade..." -ncc='sudo -u www-data php nextcloud/occ' -$ncc upgrade # && false # test point -$ncc | grep -q db:add-missing-indices && $ncc db:add-missing-indices -n -$ncc | grep -q db:add-missing-columns && $ncc db:add-missing-columns -n -$ncc | grep -q db:add-missing-primary-keys && $ncc db:add-missing-primary-keys -n -$ncc | grep -q db:convert-filecache-bigint && $ncc db:convert-filecache-bigint -n - -# use the correct version for custom apps -NCVER="$(nc_version)" -if is_more_recent_than "21.0.0" "${NCVER}"; then - NCPREV=/var/www/ncp-previewgenerator/ncp-previewgenerator-nc20 -else - # Install notify_push if not installed - if ! is_app_enabled notify_push; then - ncc app:install notify_push - ncc app:enable notify_push - install_template nextcloud.conf.sh /etc/apache2/sites-available/nextcloud.conf - a2enmod proxy proxy_http proxy_wstunnel - apachectl -k graceful - ## make sure the notify_push daemon is runnnig - - install_template systemd/notify_push.service.sh /etc/systemd/system/notify_push.service - start_notify_push - nc_domain="$(ncc config:system:get overwrite.cli.url)" - set-nc-domain "${nc_domain}" || { - echo "notify_push setup failed. You are probably behind a proxy" - echo "Run 'ncc config:system:set trusted_proxies 15 --value=' and then 'ncc notify_push:setup https:///push to enable" - echo "Check https://help.nextcloud.com/tags/ncp for support" - } - - fi - NCPREV=/var/www/ncp-previewgenerator/ncp-previewgenerator-nc21 -fi -rm -rf /var/www/nextcloud/apps/previewgenerator -ln -snf "${NCPREV}" /var/www/nextcloud/apps/previewgenerator +systemctl reset-failed ncp-encrypt ||: +systemd-run -u 'ncp-update-nc' bash -c "DBG='${DBG:-}' /usr/local/bin/ncp-update-nc.d/update-nc.sh '${VER}' |& tee /var/log/ncp-update-nc.log" +sleep 5 -if ! is_docker && ! is_more_recent_than "24.0.0" "${NCVER}" && is_more_recent_than "8.1.0" "${PHPVER}.0" +if ! [[ "$(systemctl is-active ncp-update-nc ||:)" =~ ^(active|inactive|activating|deactivating)$ ]] then - ( - echo "Upgrading PHP..." - export DEBIAN_FRONTEND=noninteractive - PHPVER_OLD="$PHPVER" - PHPVER_NEW="8.1" - PHP_PACKAGES_OLD=(php-{common,igbinary,redis,json} "php${PHPVER_OLD}" \ - "php${PHPVER_OLD}"-{curl,gd,fpm,cli,opcache,mbstring,xml,zip,fileinfo,ldap,intl,bz2,json,common,readline,mysql,bcmath,gmp}) - PHP_PACKAGES_NEW=("php${PHPVER_NEW}" \ - "php${PHPVER_NEW}"-{curl,gd,fpm,cli,opcache,mbstring,xml,zip,fileinfo,ldap,intl,bz2,mysql,bcmath,gmp,redis,common}) - - php_restore() { - trap "" INT TERM HUP ERR - echo "Something went wrong while upgrading PHP. Rolling back to version ${PHPVER_OLD}..." - set +e - service "php${PHPVER_NEW}-fpm" stop - a2disconf php${PHPVER_NEW}-fpm - rm /etc/apt/sources.list.d/php.list - apt-get update - apt-get remove --purge -y "${PHP_PACKAGES_NEW[@]}" - apt-get install -y --no-install-recommends -t "$RELEASE" "${PHP_PACKAGES_OLD[@]}" - set_ncpcfg "php_version" "${PHPVER_OLD}" - install_template "php/opcache.ini.sh" "/etc/php/${PHPVER_NEW}/mods-available/opcache.ini" - run_app nc-limits - a2enconf "php${PHPVER_OLD}-fpm" - service "php${PHPVER_OLD}-fpm" start - service apache2 restart - echo "PHP upgrade has been successfully reverted" - set -e - } - - trap php_restore INT TERM HUP ERR - - # Setup apt repository for php 8 - wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg - echo "deb https://packages.sury.org/php/ ${RELEASE%-security} main" > /etc/apt/sources.list.d/php.list - apt-get update - - clear_opcache - - echo "Stopping apache and php-fpm..." - service "php${PHPVER_OLD}-fpm" stop - service apache2 stop - - echo "Remove old PHP (${PHPVER_OLD})..." - a2disconf "php${PHPVER_OLD}-fpm" - - apt-get remove --purge -y "${PHP_PACKAGES_OLD[@]}" - - echo "Install PHP ${PHPVER_NEW}..." - install_with_shadow_workaround --no-install-recommends systemd - apt-get install -y --no-install-recommends -t "$RELEASE" "${PHP_PACKAGES_NEW[@]}" - - set_ncpcfg "php_version" "${PHPVER_NEW}" - install_template "php/opcache.ini.sh" "/etc/php/${PHPVER_NEW}/mods-available/opcache.ini" - ( set -e; export PHPVER="${PHPVER_NEW}"; run_app nc-limits ) - - a2enconf "php${PHPVER_NEW}-fpm" - - echo "Starting apache and php-fpm..." - service "php${PHPVER_NEW}-fpm" start - service apache2 start - ncc status - ) - - # Reload library.sh to reset PHPVER - source /usr/local/etc/library.sh - + echo "Failed to start ncp-update-nc" + [[ -f /var/log/ncp-update-nc.log ]] && cat /var/log/ncp-update-nc.log + systemctl status --no-pager ncp-update-nc ||: fi -# refresh completions -ncc _completion -g --shell-type bash -p ncc | sed 's|/var/www/nextcloud/occ|ncc|g' > /usr/share/bash-completion/completions/ncp - -is_docker && { - killall notify_push - sleep 1 - start_notify_push -} - -echo "Update completed successfully." -# done -#################### -mkdir -p "$DATADIR"/ncp-update-backups -mv "$BKP" "$DATADIR"/ncp-update-backups -chown -R www-data:www-data "$DATADIR"/ncp-update-backups -BKP="$DATADIR"/ncp-update-backups/"$( basename "$BKP" )" -echo "Backup stored at $BKP" - -bash -c "sleep 5; source /usr/local/etc/library.sh; clear_opcache;" &>/dev/null & +connect_to_nc_update diff --git a/bin/ncp-update-nc.d/update-nc.sh b/bin/ncp-update-nc.d/update-nc.sh new file mode 100755 index 000000000..499d1c0bf --- /dev/null +++ b/bin/ncp-update-nc.d/update-nc.sh @@ -0,0 +1,242 @@ +#!/bin/bash + +set -eE${DBG} + +VER="$1" +source /usr/local/etc/library.sh +export RELEASE +export PHPVER + +# pre-checks +#################### +BASEDIR=/var/www +cd "$BASEDIR" +DATADIR="$( get_nc_config_value datadirectory )" +ncc status &>/dev/null || { [[ "$DBG" == x ]] && ncc status; echo "Nextcloud is currently down"; exit 1; } +[[ -d "${BASEDIR}/nextcloud-old" ]] && { echo "Nextcloud backup directory found. Interrupted or already running installation?"; exit 1; } +[[ -d "${BASEDIR}/nextcloud" ]] || { echo "Nextcloud directory not found" ; exit 1; } +[[ -d "$DATADIR" ]] || { echo "Nextcloud data directory not found" ; exit 1; } + +# check version +#################### + +[[ ${EUID} -eq 0 ]] && SUDO="sudo -u www-data" +CURRENT="$(nc_version)" +TARGET_VERSION="$(determine_nc_upgrade_version "${CURRENT?}" "${VER?}")" +[[ "$TARGET_VERSION" == "$CURRENT" ]] && { + echo "Nextcloud version ${CURRENT} is already installed. Nothing to do." + exit 0 +} +[[ -n "$TARGET_VERSION" ]] || { + echo "Could not find a valid upgrade path from '${CURRENT}' to '${TARGET_VERSION}'. Nothing to update." + exit 1 +} + +MAJOR_NEW="${TARGET_VERSION%%.*}" +DEBIAN_VERSION="$(. /etc/os-release; echo "$VERSION_ID")" + +if [[ "$MAJOR_NEW" -ge 24 ]] && [[ $DEBIAN_VERSION -le 10 ]] +then + echo -e "NCP doesn't support Nextcloud versions greater than 23 with Debian 10 (Buster). Please run ncp-dist-upgrade." + exit 1 +fi + +if [[ "$MAJOR_NEW" -ge 29 ]] && [[ $DEBIAN_VERSION -le 11 ]] +then + echo -e "NCP doesn't support Nextcloud versions greater than 28 with Debian 11 (Bullseye). Please run ncp-dist-upgrade." + exit 1 +fi + +grep -qP "\d+\.\d+\.\d+" <<<"$CURRENT" || { echo "Malformed version $CURRENT"; 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 $TARGET_VERSION" +if [[ "$TARGET_VERSION" != "$VER" ]] +then + echo "INFO: You have requested an update to '$VER', but a direct update to '$VER' cannot be performed, so the latest available version that can be updated to has been selected automatically." +fi + +# make sure that cron.php is not running and there are no pending jobs +# https://github.com/nextcloud/server/issues/10949 +pgrep -cf cron.php &>/dev/null && { pkill -f cron.php; sleep 3; } +pgrep -cf cron.php &>/dev/null && { echo "cron.php running. Abort"; exit 1; } +mysql nextcloud <<<"UPDATE ${DB_PREFIX}jobs SET reserved_at=0;" + +# cleanup +#################### +cleanup() { + local RET=$? + set +eE + echo "Clean up..." + rm -rf "$BASEDIR"/nextcloud.tar.bz2 "$BASEDIR"/nextcloud-old + trap "" EXIT + exit $RET +} +trap cleanup EXIT + +# get new code +#################### +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 +#################### +BKPDIR="$BASEDIR" +WITH_DATA=no +COMPRESSED=yes +LIMIT=0 + +echo "Back up current instance..." +set +eE +ncp-backup "$BKPDIR" "$WITH_DATA" "$COMPRESSED" "$LIMIT" # && false # test point +RET=$? +sync +set -eE + +BKP_="$( ls -1t "$BKPDIR"/nextcloud-bkp_*.tar.gz 2>/dev/null | head -1 )" +[[ -f "$BKP_" ]] || { set +eE; echo "Error backing up"; false || cleanup; } +[[ $RET -ne 0 ]] && { rm -f "$BKP_"; set +eE; echo "Error backing up"; false || cleanup; } +BKP="$( dirname "$BKP_" )/$( basename "$BKP_" .tar.gz )-${CURRENT}.tar.gz" +echo "Storing backup at '$BKP'..." +mv "$BKP_" "$BKP" + +# simple restore if anything fails from here +#################### +rollback_simple() { + set +eE + trap "" INT TERM HUP ERR + echo -e "Abort\nSimple roll back..." + rm -rf "$BASEDIR"/nextcloud + mv "$BASEDIR"/nextcloud-old "$BASEDIR"/nextcloud + false || cleanup # so cleanup exits with 1 +} +trap rollback_simple INT TERM HUP ERR + +# replace code +#################### +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 + +# copy old config +#################### +cp nextcloud-old/config/config.php nextcloud/config/ + +# copy old themes +#################### +cp -raT nextcloud-old/themes/ nextcloud/themes/ + +# copy old NCP apps +#################### +for app in nextcloudpi previewgenerator; do + if [[ -d nextcloud-old/apps/"${app}" ]]; then + cp -r -L nextcloud-old/apps/"${app}" /var/www/nextcloud/apps/ + fi +done + +#false # test point + +# copy data if it was at the default location +#################### +if [[ "$DATADIR" == "/var/www/nextcloud/data" ]] || [[ "$DATADIR" == "/data/nextcloud/data" ]]; then + echo "Restore data..." + mv -T nextcloud-old/data nextcloud/data +fi + +# nc-restore if anything fails from here +#################### +rollback() { + set +eE + trap "" INT TERM HUP ERR EXIT + echo -e "Abort\nClean up..." + rm -rf /var/www/nextcloud.tar.bz2 "$BASEDIR"/nextcloud-old + echo "Rolling back to backup $BKP..." + local TMPDATA + mkdir -p "$BASEDIR/recovery/" + TMPDATA="$( mktemp -d "$BASEDIR/recovery/ncp-data.XXXXXX" )" || { echo "Failed to create temp dir" >&2; exit 1; } + [[ "$DATADIR" == "$BASEDIR/nextcloud/data" ]] && mv -T "$DATADIR" "$TMPDATA" + ncp-restore "$BKP" || { echo "Rollback failed! Data left at $TMPDATA"; exit 1; } + [[ "$DATADIR" == "$BASEDIR/nextcloud/data" ]] && { rm -rf "$DATADIR"; mv -T "$TMPDATA" "$DATADIR"; } + rm "$BKP" + echo "Rollback successful. Nothing was updated" + exit 1 +} +trap rollback INT TERM HUP ERR + +# fix permissions +#################### +echo "Fix permissions..." +chown -R www-data:www-data nextcloud +find nextcloud/ -type d -exec chmod 750 {} \; +find nextcloud/ -type f -exec chmod 640 {} \; + +# upgrade +#################### +echo "Upgrade..." +ncc='sudo -u www-data php nextcloud/occ' +$ncc upgrade # && false # test point +$ncc | grep -q db:add-missing-indices && $ncc db:add-missing-indices -n +$ncc | grep -q db:add-missing-columns && $ncc db:add-missing-columns -n +$ncc | grep -q db:add-missing-primary-keys && $ncc db:add-missing-primary-keys -n +$ncc | grep -q db:convert-filecache-bigint && $ncc db:convert-filecache-bigint -n +$ncc maintenance:repair --help | grep -q -e '--include-expensive' && $ncc maintenance:repair --include-expensive + +# use the correct version for custom apps +NCVER="$(nc_version)" +if is_more_recent_than "21.0.0" "${NCVER}"; then + NCPREV=/var/www/ncp-previewgenerator/ncp-previewgenerator-nc20 +else + # Install notify_push if not installed + if ! is_app_enabled notify_push; then + ncc app:install notify_push + ncc app:enable notify_push + install_template nextcloud.conf.sh /etc/apache2/sites-available/nextcloud.conf + a2enmod proxy proxy_http proxy_wstunnel + apachectl -k graceful + ## make sure the notify_push daemon is runnnig + + install_template systemd/notify_push.service.sh /etc/systemd/system/notify_push.service + start_notify_push + nc_domain="$(ncc config:system:get overwrite.cli.url)" + set-nc-domain "${nc_domain}" || { + echo "notify_push setup failed. You are probably behind a proxy" + echo "Run 'ncc config:system:set trusted_proxies 15 --value=' and then 'ncc notify_push:setup https:///push to enable" + echo "Check https://help.nextcloud.com/tags/ncp for support" + } + + fi + NCPREV=/var/www/ncp-previewgenerator/ncp-previewgenerator-nc21 +fi +rm -rf /var/www/nextcloud/apps/previewgenerator +ln -snf "${NCPREV}" /var/www/nextcloud/apps/previewgenerator + +if ! is_more_recent_than "24.0.0" "${NCVER}" && is_more_recent_than "8.1.0" "${PHPVER}.0" +then + /usr/local/bin/ncp-update-nc.d/upgrade-php-bullseye-8.1.sh + + # Reload library.sh to reset PHPVER + source /usr/local/etc/library.sh +elif ! is_more_recent_than "29.0.0" "${NCVER}" && is_more_recent_than "8.3.0" "${PHPVER}.0" && [[ "$DEBIAN_VERSION" -ge 12 ]] +then + /usr/local/bin/ncp-update-nc.d/upgrade-php-bookworm-8.3.sh + + # Reload library.sh to reset PHPVER + source /usr/local/etc/library.sh +fi + +# refresh completions +ncc _completion -g --shell-type bash -p ncc | sed 's|/var/www/nextcloud/occ|ncc|g' > /usr/share/bash-completion/completions/ncp + +echo "Update completed successfully." +# done +#################### +mkdir -p "$DATADIR"/ncp-update-backups +mv "$BKP" "$DATADIR"/ncp-update-backups +chown -R www-data:www-data "$DATADIR"/ncp-update-backups +BKP="$DATADIR"/ncp-update-backups/"$( basename "$BKP" )" +echo "Backup stored at $BKP" + +bash -c "sleep 5; source /usr/local/etc/library.sh; clear_opcache;" &>/dev/null & diff --git a/bin/ncp-update-nc.d/upgrade-php-bookworm-8.3.sh b/bin/ncp-update-nc.d/upgrade-php-bookworm-8.3.sh new file mode 100755 index 000000000..c84c322a8 --- /dev/null +++ b/bin/ncp-update-nc.d/upgrade-php-bookworm-8.3.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +source /usr/local/etc/library.sh + +echo "Upgrading PHP..." +export DEBIAN_FRONTEND=noninteractive +PHPVER_OLD="$PHPVER" +PHPVER_NEW="8.3" +PHP_PACKAGES_OLD=("php${PHPVER_OLD}" \ + "php${PHPVER_OLD}"-{curl,gd,fpm,cli,opcache,mbstring,xml,zip,fileinfo,ldap,intl,bz2,mysql,bcmath,gmp,redis,common}) +PHP_PACKAGES_NEW=("php${PHPVER_NEW}" \ + "php${PHPVER_NEW}"-{curl,gd,fpm,cli,opcache,mbstring,xml,zip,fileinfo,ldap,intl,bz2,mysql,bcmath,gmp,redis,common}) + +php_restore() { + trap "" INT TERM HUP ERR + echo "Something went wrong while upgrading PHP. Rolling back to version ${PHPVER_OLD}..." + set +e + service "php${PHPVER_NEW}-fpm" stop + a2disconf php${PHPVER_NEW}-fpm + wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg + echo "deb https://packages.sury.org/php/ ${RELEASE%-security} main" > /etc/apt/sources.list.d/php.list + apt-get update + apt-get remove --purge -y "${PHP_PACKAGES_NEW[@]}" + apt-get install -y --no-install-recommends -t "$RELEASE" "${PHP_PACKAGES_OLD[@]}" + set_ncpcfg "php_version" "${PHPVER_OLD}" + install_template "php/opcache.ini.sh" "/etc/php/${PHPVER_NEW}/mods-available/opcache.ini" + run_app nc-limits + a2enconf "php${PHPVER_OLD}-fpm" + service "php${PHPVER_OLD}-fpm" start + service apache2 restart + echo "PHP upgrade has been successfully reverted" + set -e +} + +trap php_restore INT TERM HUP ERR + +apt-get update + +clear_opcache + +echo "Stopping apache and php-fpm..." +service "php${PHPVER_OLD}-fpm" stop +service apache2 stop + +echo "Remove old PHP (${PHPVER_OLD})..." +a2disconf "php${PHPVER_OLD}-fpm" + +apt-get remove --purge -y "${PHP_PACKAGES_OLD[@]}" + +echo "Install PHP ${PHPVER_NEW}..." +install_with_shadow_workaround --no-install-recommends systemd +apt-get install -y --no-install-recommends -t "$RELEASE" "${PHP_PACKAGES_NEW[@]}" + +set_ncpcfg "php_version" "${PHPVER_NEW}" +install_template "php/opcache.ini.sh" "/etc/php/${PHPVER_NEW}/mods-available/opcache.ini" +( set -e; export PHPVER="${PHPVER_NEW}"; run_app nc-limits ) + +a2enconf "php${PHPVER_NEW}-fpm" + +[[ -f "/etc/systemd/system/php${PHPVER_OLD}-fpm.service.d/ncp.conf" ]] && { + mkdir -p "/etc/systemd/system/php${PHPVER_NEW}-fpm.service.d" + cp "/etc/systemd/system/php${PHPVER_OLD}-fpm.service.d/ncp.conf" "/etc/systemd/system/php${PHPVER_NEW}-fpm.service.d/ncp.conf" +} + +echo "Starting apache and php-fpm..." +service "php${PHPVER_NEW}-fpm" start +service apache2 start +ncc status \ No newline at end of file diff --git a/bin/ncp-update-nc.d/upgrade-php-bullseye-8.1.sh b/bin/ncp-update-nc.d/upgrade-php-bullseye-8.1.sh new file mode 100755 index 000000000..4df0f7a95 --- /dev/null +++ b/bin/ncp-update-nc.d/upgrade-php-bullseye-8.1.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +source /usr/local/etc/library.sh + +echo "Upgrading PHP..." +export DEBIAN_FRONTEND=noninteractive +PHPVER_OLD="$PHPVER" +PHPVER_NEW="8.1" +PHP_PACKAGES_OLD=(php-{common,igbinary,redis,json} "php${PHPVER_OLD}" \ + "php${PHPVER_OLD}"-{curl,gd,fpm,cli,opcache,mbstring,xml,zip,fileinfo,ldap,intl,bz2,json,common,readline,mysql,bcmath,gmp}) +PHP_PACKAGES_NEW=("php${PHPVER_NEW}" \ + "php${PHPVER_NEW}"-{curl,gd,fpm,cli,opcache,mbstring,xml,zip,fileinfo,ldap,intl,bz2,mysql,bcmath,gmp,redis,common}) + +php_restore() { + trap "" INT TERM HUP ERR + echo "Something went wrong while upgrading PHP. Rolling back to version ${PHPVER_OLD}..." + set +e + service "php${PHPVER_NEW}-fpm" stop + a2disconf php${PHPVER_NEW}-fpm + rm /etc/apt/sources.list.d/php.list + apt-get update + apt-get remove --purge -y "${PHP_PACKAGES_NEW[@]}" + apt-get install -y --no-install-recommends -t "$RELEASE" "${PHP_PACKAGES_OLD[@]}" + set_ncpcfg "php_version" "${PHPVER_OLD}" + install_template "php/opcache.ini.sh" "/etc/php/${PHPVER_NEW}/mods-available/opcache.ini" + run_app nc-limits + a2enconf "php${PHPVER_OLD}-fpm" + service "php${PHPVER_OLD}-fpm" start + service apache2 restart + echo "PHP upgrade has been successfully reverted" + set -e +} + +trap php_restore INT TERM HUP ERR + +# Setup apt repository for php 8 +wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg +echo "deb https://packages.sury.org/php/ ${RELEASE%-security} main" > /etc/apt/sources.list.d/php.list +apt-get update + +clear_opcache + +echo "Stopping apache and php-fpm..." +service "php${PHPVER_OLD}-fpm" stop +service apache2 stop + +echo "Remove old PHP (${PHPVER_OLD})..." +a2disconf "php${PHPVER_OLD}-fpm" + +apt-get remove --purge -y "${PHP_PACKAGES_OLD[@]}" + +echo "Install PHP ${PHPVER_NEW}..." +install_with_shadow_workaround --no-install-recommends systemd +apt-get install -y --no-install-recommends -t "$RELEASE" "${PHP_PACKAGES_NEW[@]}" + +set_ncpcfg "php_version" "${PHPVER_NEW}" +install_template "php/opcache.ini.sh" "/etc/php/${PHPVER_NEW}/mods-available/opcache.ini" +( set -e; export PHPVER="${PHPVER_NEW}"; run_app nc-limits ) + +a2enconf "php${PHPVER_NEW}-fpm" + +echo "Starting apache and php-fpm..." +service "php${PHPVER_NEW}-fpm" start +service apache2 start +ncc status \ No newline at end of file diff --git a/bin/ncp/CONFIG/nc-init.sh b/bin/ncp/CONFIG/nc-init.sh index 7892b8e2d..0bc62554c 100644 --- a/bin/ncp/CONFIG/nc-init.sh +++ b/bin/ncp/CONFIG/nc-init.sh @@ -127,11 +127,11 @@ EOF } mysql nextcloud <&1 | sed /^Switch/d + systemctl reset-failed ncp-encrypt ||: + systemd-run -u ncp-encrypt -E PASSWORD bash -c "gocryptfs -allow_other -q '${encdir}' '${datadir}' <<<\"\${PASSWORD}\" 2>&1 | sed /^Switch/d |& tee /var/log/ncp-encrypt.log" # switch to the regular virtual hosts after we decrypt, so we can access NC and ncp-web a2ensite ncp 001-nextcloud @@ -75,7 +77,8 @@ configure() mv "${datadir?}" "${tmpdir?}" mkdir "${datadir}" - echo "${PASSWORD}" | gocryptfs -allow_other -q "${encdir}" "${datadir}" 2>&1 | sed /^Switch/d + systemctl reset-failed ncp-encrypt ||: + systemd-run -u ncp-encrypt -E PASSWORD bash -c "gocryptfs -allow_other -q '${encdir}' '${datadir}' <<<\"\${PASSWORD}\" 2>&1 | sed /^Switch/d |& tee /var/log/ncp-encrypt.log" echo "Encrypting data..." mv "${tmpdir}"/* "${tmpdir}"/.[!.]* "${datadir}" diff --git a/build/armbian/armbian_version b/build/armbian/armbian_version new file mode 100644 index 000000000..3e5291183 --- /dev/null +++ b/build/armbian/armbian_version @@ -0,0 +1 @@ +v24.08 \ No newline at end of file diff --git a/build/build-SD-armbian.sh b/build/build-SD-armbian.sh index 69dae6814..a642411d0 100755 --- a/build/build-SD-armbian.sh +++ b/build/build-SD-armbian.sh @@ -31,7 +31,7 @@ prepare_dirs # tmp cache output # get latest armbian [[ -d armbian ]] || { - git clone --depth 1 --branch v24.08 https://github.com/armbian/build armbian + git clone --depth 1 --branch "$(cat "${0}/../armbian/armbian_version")" https://github.com/armbian/build armbian } #( cd armbian && git pull --ff-only --tags && git checkout v23.02 ) #sed -i -e '/export rootfs_size=/s/du -sm/du --apparent-size -sm/' armbian/lib/functions/image/partitioning.sh diff --git a/etc/ncp-config.d/nc-nextcloud.cfg b/etc/ncp-config.d/nc-nextcloud.cfg index 8f7efa697..a3c428d17 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.7" + "value": "29.0.4" }, { "id": "MAXFILESIZE", diff --git a/etc/ncp.cfg b/etc/ncp.cfg index 86fae7fec..19b3afcdd 100644 --- a/etc/ncp.cfg +++ b/etc/ncp.cfg @@ -1,5 +1,5 @@ { - "nextcloud_version": "28.0.7", - "php_version": "8.1", + "nextcloud_version": "29.0.4", + "php_version": "8.3", "release": "bookworm" } diff --git a/ncp-app/appinfo/info.xml b/ncp-app/appinfo/info.xml index f182f0487..fbf207ddb 100644 --- a/ncp-app/appinfo/info.xml +++ b/ncp-app/appinfo/info.xml @@ -12,7 +12,7 @@ tools https://github.com/nextcloud/nextcloudpi/issues - + diff --git a/ncp-app/lib/Service/SettingsService.php b/ncp-app/lib/Service/SettingsService.php index dfc25d3c5..4db7da964 100644 --- a/ncp-app/lib/Service/SettingsService.php +++ b/ncp-app/lib/Service/SettingsService.php @@ -132,7 +132,7 @@ private function runCommand(string $cmd): array { 2 => ["pipe", "w"] ]; - $proc = proc_open($cmd, $descriptorSpec, $pipes, "/home/www-data", null); + $proc = proc_open($cmd, $descriptorSpec, $pipes, "/var/www", null); $stdout = stream_get_contents($pipes[1]); fclose($pipes[1]); $stderr = stream_get_contents($pipes[2]); diff --git a/ncp-previewgenerator/ncp-previewgenerator-nc21/appinfo/info.xml b/ncp-previewgenerator/ncp-previewgenerator-nc21/appinfo/info.xml index 82fc3a652..8d09f5387 100644 --- a/ncp-previewgenerator/ncp-previewgenerator-nc21/appinfo/info.xml +++ b/ncp-previewgenerator/ncp-previewgenerator-nc21/appinfo/info.xml @@ -25,7 +25,7 @@ The first time you install this app, before using a cron job, you properly want - + diff --git a/ncp.sh b/ncp.sh index 8813c60cd..c2caedcd3 100644 --- a/ncp.sh +++ b/ncp.sh @@ -22,7 +22,8 @@ install() { # NCP-CONFIG apt-get update - $APTINSTALL git dialog whiptail jq file lsb-release tmux + $APTINSTALL git dialog whiptail jq file lsb-release tmux logrotate + mkdir -p "$CONFDIR" "$BINDIR" # This has changed, pi user no longer exists by default, the user needs to create it with Raspberry Pi imager diff --git a/tests/nextcloud_tests.py b/tests/nextcloud_tests.py index f4fbe209e..cbc87d83c 100755 --- a/tests/nextcloud_tests.py +++ b/tests/nextcloud_tests.py @@ -27,7 +27,8 @@ from selenium.webdriver.remote.webelement import WebElement from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.firefox.options import Options -from selenium.common.exceptions import NoSuchElementException, WebDriverException, TimeoutException +from selenium.webdriver.support import expected_conditions as EC +from selenium.common.exceptions import NoSuchElementException, WebDriverException, TimeoutException, ElementNotInteractableException from typing import List, Tuple import traceback @@ -122,21 +123,32 @@ def is_admin_notifications_checkbox(item: WebElement): def close_first_run_wizard(driver: WebDriver): - wait = WebDriverWait(driver, 60) + wait = WebDriverWait(driver, 20) first_run_wizard = None try: first_run_wizard = driver.find_element(By.CSS_SELECTOR, "#firstrunwizard") except NoSuchElementException: pass if first_run_wizard is not None and first_run_wizard.is_displayed(): - wait.until(VisibilityOfElementLocatedByAnyLocator([(By.CLASS_NAME, "modal-container__close"), - (By.CLASS_NAME, "first-run-wizard__close-button")])) + for i in range(3): + try: + wait.until(VisibilityOfElementLocatedByAnyLocator([(By.CSS_SELECTOR, '.modal-container__content button[aria-label=Close]'), + (By.CLASS_NAME, "modal-container__close"), + (By.CLASS_NAME, "first-run-wizard__close-button")])) + except TimeoutException as e: + if i == 3: + raise e try: - overlay_close_btn = driver.find_element(By.CLASS_NAME, "first-run-wizard__close-button") - overlay_close_btn.click() - except NoSuchElementException: - overlay_close_btn = driver.find_element(By.CLASS_NAME, "modal-container__close") + overlay_close_btn = driver.find_element(By.CSS_SELECTOR, '.modal-container__content button[aria-label=Close]') overlay_close_btn.click() + except (NoSuchElementException, ElementNotInteractableException): + try: + overlay_close_btn = driver.find_element(By.CLASS_NAME, "modal-container__close") + overlay_close_btn.click() + except (NoSuchElementException, ElementNotInteractableException): + overlay_close_btn = driver.find_element(By.CLASS_NAME, "first-run-wizard__close-button") + overlay_close_btn.click() + time.sleep(3) diff --git a/updates/1.55.0.sh b/updates/1.55.0.sh new file mode 100644 index 000000000..45033e31f --- /dev/null +++ b/updates/1.55.0.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +apt-get update +apt-get install -y --no-install-recommends logrotate