From ba32d63175ef8d359b8a85c1e3b2d1dbb21c6343 Mon Sep 17 00:00:00 2001 From: enoch85 Date: Fri, 23 Jan 2026 10:49:19 +0000 Subject: [PATCH 1/3] Save and restore enabled apps during Nextcloud upgrade process --- nextcloud_update.sh | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/nextcloud_update.sh b/nextcloud_update.sh index b274794ced..ca7357e5ad 100644 --- a/nextcloud_update.sh +++ b/nextcloud_update.sh @@ -346,6 +346,15 @@ then export NEEDRESTART_SUSPEND=1 fi +# Save the list of enabled apps before upgrade (to re-enable them after upgrade) +# https://github.com/nextcloud/vm/issues/2797 +print_text_in_color "$ICyan" "Saving list of enabled apps before upgrade..." +if [ ! -d "$BACKUP" ] +then + mkdir -p "$BACKUP" +fi +nextcloud_occ app:list --enabled | sed '/Disabled/,$d' | awk '{print$2}' | tr -d ':' | sed '/^$/d' > "$BACKUP/enabled_apps_before_upgrade.txt" + # Enter maintenance:mode print_text_in_color "$IGreen" "Enabling maintenance:mode..." sudo -u www-data php "$NCPATH"/occ maintenance:mode --on @@ -1312,7 +1321,8 @@ then fi fi -# If the app isn't installed (maybe because it's incompatible), then at least restore from backup and make sure it's disabled +# Restore apps from backup that are missing in the new Nextcloud installation +# (occ upgrade will automatically disable incompatible apps) BACKUP_APPS="$(find "$BACKUP/apps" -maxdepth 1 -mindepth 1 -type d)" mapfile -t BACKUP_APPS <<< "$BACKUP_APPS" for app in "${BACKUP_APPS[@]}" @@ -1323,10 +1333,9 @@ do print_text_in_color "$ICyan" "Restoring $app from $BACKUP/apps..." rsync -Aaxz "$BACKUP/apps/$app" "$NC_APPS_PATH/" bash "$SECURE" - nextcloud_occ_no_check app:disable "$app" # Don't execute the update before all cronjobs are finished check_running_cronjobs - # Execute the update + # Execute the update (will disable incompatible apps automatically) nextcloud_occ upgrade fi done @@ -1339,6 +1348,34 @@ then nextcloud_occ_no_check app:update --all fi +# Re-enable previously enabled apps after upgrade +# https://github.com/nextcloud/vm/issues/2797 +if [ -f "$BACKUP/enabled_apps_before_upgrade.txt" ] +then + print_text_in_color "$ICyan" "Attempting to re-enable previously enabled apps..." + while IFS= read -r app + do + # Skip empty lines + if [ -z "$app" ] + then + continue + fi + # Check if app directory exists and try to enable it + if [ -d "$NC_APPS_PATH/$app" ] + then + if ! is_app_enabled "$app" + then + if nextcloud_occ_no_check app:enable "$app" >/dev/null 2>&1 + then + print_text_in_color "$IGreen" "Re-enabled $app" + else + print_text_in_color "$IRed" "Could not re-enable $app (may be incompatible with Nextcloud $CURRENTVERSION_after)" + fi + fi + fi + done < "$BACKUP/enabled_apps_before_upgrade.txt" +fi + # Remove header for Nextcloud 14 (already in .htaccess) if [ -f /etc/apache2/sites-available/"$(hostname -f)".conf ] then From af50f0999c5ee439b6a0e86d79381523f9073986 Mon Sep 17 00:00:00 2001 From: enoch85 Date: Fri, 23 Jan 2026 11:01:42 +0000 Subject: [PATCH 2/3] minor syntax fixes (not related to fix) --- nextcloud_update.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/nextcloud_update.sh b/nextcloud_update.sh index b064e8be2a..997fd8bd6f 100644 --- a/nextcloud_update.sh +++ b/nextcloud_update.sh @@ -85,7 +85,7 @@ fi # https://github.com/nextcloud/vm/pull/2040 if pecl list | grep apcu >/dev/null 2>&1 then - sed -i "/memcache.local/d" "$NCPATH"/config/config.php + sed -i "\|memcache.local|d" "$NCPATH"/config/config.php if pecl list | grep redis >/dev/null 2>&1 then nextcloud_occ config:system:set memcache.local --value='\OC\Memcache\Redis' @@ -265,7 +265,7 @@ fi # Since the branch change, always get the latest update script download_script STATIC update -chmod +x $SCRIPTS/update.sh +chmod +x "$SCRIPTS"/update.sh # Ubuntu 16.04 is deprecated check_distro_version @@ -353,7 +353,7 @@ if [ ! -d "$BACKUP" ] then mkdir -p "$BACKUP" fi -nextcloud_occ app:list --enabled | sed '/Disabled/,$d' | awk '{print$2}' | tr -d ':' | sed '/^$/d' > "$BACKUP/enabled_apps_before_upgrade.txt" +nextcloud_occ app:list --enabled | sed '\|Disabled|,$d' | awk '{print$2}' | tr -d ':' | sed '\|^$|d' > "$BACKUP/enabled_apps_before_upgrade.txt" # Enter maintenance:mode print_text_in_color "$IGreen" "Enabling maintenance:mode..." @@ -467,7 +467,7 @@ fi # Remove old redis if grep -qFx extension=redis.so "$PHP_INI" then - sed -i "/extension=redis.so/d" "$PHP_INI" + sed -i "\|extension=redis.so|d" "$PHP_INI" fi # Check if redis is enabled and create the file if not if [ ! -f "$PHP_MODS_DIR"/redis.ini ] @@ -498,9 +498,9 @@ then check_command phpdismod -v ALL apcu rm -f "$PHP_MODS_DIR"/apcu.ini rm -f "$PHP_MODS_DIR"/apcu_bc.ini - sed -i "/extension=apcu.so/d" "$PHP_INI" - sed -i "/APCu/d" "$PHP_INI" - sed -i "/apc./d" "$PHP_INI" + sed -i "\|extension=apcu.so|d" "$PHP_INI" + sed -i "\|APCu|d" "$PHP_INI" + sed -i "\|apc.|d" "$PHP_INI" fi fi @@ -528,7 +528,7 @@ then # Remove old igbinary if grep -qFx extension=igbinary.so "$PHP_INI" then - sed -i "/extension=igbinary.so/d" "$PHP_INI" + sed -i "\|extension=igbinary.so|d" "$PHP_INI" fi # Check if igbinary is enabled and create the file if not if [ ! -f "$PHP_MODS_DIR"/igbinary.ini ] @@ -561,7 +561,7 @@ then # Remove old smbclient if grep -qFx extension=smbclient.so "$PHP_INI" then - sed -i "/extension=smbclient.so/d" "$PHP_INI" + sed -i "\|extension=smbclient.so|d" "$PHP_INI" fi fi if pecl list | grep -q inotify @@ -569,7 +569,7 @@ then # Remove old inotify if grep -qFx extension=inotify.so "$PHP_INI" then - sed -i "/extension=inotify.so/d" "$PHP_INI" + sed -i "\|extension=inotify.so|d" "$PHP_INI" fi yes no | pecl upgrade inotify if [ ! -f "$PHP_MODS_DIR"/inotify.ini ] @@ -788,7 +788,7 @@ sudo -u www-data php "$NCPATH"/occ maintenance:mode --off # Make all previous files executable print_text_in_color "$ICyan" "Finding all executable files in $NC_APPS_PATH" -find_executables="$(find $NC_APPS_PATH -type f -executable)" +find_executables="$(find "$NC_APPS_PATH" -type f -executable)" # Update all Nextcloud apps if [ "${CURRENTVERSION%%.*}" -ge "15" ] @@ -826,7 +826,7 @@ else fi # Apply correct redirect rule to avoid security check errors -REDIRECTRULE="$(grep -r "\[R=301,L\]" $SITES_AVAILABLE | cut -d ":" -f1)" +REDIRECTRULE="$(grep -r "\[R=301,L\]" "$SITES_AVAILABLE" | cut -d ":" -f1)" if [ -n "$REDIRECTRULE" ] then # Change the redirect rule in all files in Apache available @@ -1381,7 +1381,7 @@ if [ -f /etc/apache2/sites-available/"$(hostname -f)".conf ] then if grep -q 'Header always set Referrer-Policy' /etc/apache2/sites-available/"$(hostname -f)".conf then - sed -i '/Header always set Referrer-Policy/d' /etc/apache2/sites-available/"$(hostname -f)".conf + sed -i '\|Header always set Referrer-Policy|d' /etc/apache2/sites-available/"$(hostname -f)".conf restart_webserver fi fi From fbe0ee8947b674293c437a617a99dd802e13e61a Mon Sep 17 00:00:00 2001 From: enoch85 Date: Sun, 25 Jan 2026 13:18:12 +0000 Subject: [PATCH 3/3] feat(nextcloud_update.sh): add reboot handling for update script --- nextcloud_update.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/nextcloud_update.sh b/nextcloud_update.sh index 997fd8bd6f..5554dc6fbd 100644 --- a/nextcloud_update.sh +++ b/nextcloud_update.sh @@ -263,10 +263,23 @@ then fi fi +# Check if reboot was enabled before downloading new script +if [ -f "$SCRIPTS/update.sh" ] && grep -q "shutdown -r" "$SCRIPTS/update.sh" +then + REBOOT_ENABLED=1 +fi + # Since the branch change, always get the latest update script download_script STATIC update chmod +x "$SCRIPTS"/update.sh +# Restore reboot if it was enabled +if [ "$REBOOT_ENABLED" = 1 ] +then + sed -i "s|exit|/sbin/shutdown -r +10|g" "$SCRIPTS"/update.sh + echo "exit" >> "$SCRIPTS"/update.sh +fi + # Ubuntu 16.04 is deprecated check_distro_version