8585# https://github.com/nextcloud/vm/pull/2040
8686if pecl list | grep apcu > /dev/null 2>&1
8787then
88- sed -i " / memcache.local/ d" " $NCPATH " /config/config.php
88+ sed -i " \| memcache.local| d" " $NCPATH " /config/config.php
8989 if pecl list | grep redis > /dev/null 2>&1
9090 then
9191 nextcloud_occ config:system:set memcache.local --value=' \OC\Memcache\Redis'
265265
266266# Since the branch change, always get the latest update script
267267download_script STATIC update
268- chmod +x $SCRIPTS /update.sh
268+ chmod +x " $SCRIPTS " /update.sh
269269
270270# Ubuntu 16.04 is deprecated
271271check_distro_version
@@ -346,6 +346,15 @@ then
346346 export NEEDRESTART_SUSPEND=1
347347fi
348348
349+ # Save the list of enabled apps before upgrade (to re-enable them after upgrade)
350+ # https://github.com/nextcloud/vm/issues/2797
351+ print_text_in_color " $ICyan " " Saving list of enabled apps before upgrade..."
352+ if [ ! -d " $BACKUP " ]
353+ then
354+ mkdir -p " $BACKUP "
355+ fi
356+ nextcloud_occ app:list --enabled | sed ' \|Disabled|,$d' | awk ' {print$2}' | tr -d ' :' | sed ' \|^$|d' > " $BACKUP /enabled_apps_before_upgrade.txt"
357+
349358# Enter maintenance:mode
350359print_text_in_color " $IGreen " " Enabling maintenance:mode..."
351360sudo -u www-data php " $NCPATH " /occ maintenance:mode --on
458467# Remove old redis
459468if grep -qFx extension=redis.so " $PHP_INI "
460469then
461- sed -i " / extension=redis.so/ d" " $PHP_INI "
470+ sed -i " \| extension=redis.so| d" " $PHP_INI "
462471fi
463472# Check if redis is enabled and create the file if not
464473if [ ! -f " $PHP_MODS_DIR " /redis.ini ]
489498 check_command phpdismod -v ALL apcu
490499 rm -f " $PHP_MODS_DIR " /apcu.ini
491500 rm -f " $PHP_MODS_DIR " /apcu_bc.ini
492- sed -i " / extension=apcu.so/ d" " $PHP_INI "
493- sed -i " / APCu/ d" " $PHP_INI "
494- sed -i " / apc./ d" " $PHP_INI "
501+ sed -i " \| extension=apcu.so| d" " $PHP_INI "
502+ sed -i " \| APCu| d" " $PHP_INI "
503+ sed -i " \| apc.| d" " $PHP_INI "
495504 fi
496505fi
497506
519528 # Remove old igbinary
520529 if grep -qFx extension=igbinary.so " $PHP_INI "
521530 then
522- sed -i " / extension=igbinary.so/ d" " $PHP_INI "
531+ sed -i " \| extension=igbinary.so| d" " $PHP_INI "
523532 fi
524533 # Check if igbinary is enabled and create the file if not
525534 if [ ! -f " $PHP_MODS_DIR " /igbinary.ini ]
@@ -552,15 +561,15 @@ then
552561 # Remove old smbclient
553562 if grep -qFx extension=smbclient.so " $PHP_INI "
554563 then
555- sed -i " / extension=smbclient.so/ d" " $PHP_INI "
564+ sed -i " \| extension=smbclient.so| d" " $PHP_INI "
556565 fi
557566 fi
558567 if pecl list | grep -q inotify
559568 then
560569 # Remove old inotify
561570 if grep -qFx extension=inotify.so " $PHP_INI "
562571 then
563- sed -i " / extension=inotify.so/ d" " $PHP_INI "
572+ sed -i " \| extension=inotify.so| d" " $PHP_INI "
564573 fi
565574 yes no | pecl upgrade inotify
566575 if [ ! -f " $PHP_MODS_DIR " /inotify.ini ]
@@ -779,7 +788,7 @@ sudo -u www-data php "$NCPATH"/occ maintenance:mode --off
779788
780789# Make all previous files executable
781790print_text_in_color " $ICyan " " Finding all executable files in $NC_APPS_PATH "
782- find_executables=" $( find $NC_APPS_PATH -type f -executable) "
791+ find_executables=" $( find " $NC_APPS_PATH " -type f -executable) "
783792
784793# Update all Nextcloud apps
785794if [ " ${CURRENTVERSION%% .* } " -ge " 15" ]
817826fi
818827
819828# Apply correct redirect rule to avoid security check errors
820- REDIRECTRULE=" $( grep -r " \[R=301,L\]" $SITES_AVAILABLE | cut -d " :" -f1) "
829+ REDIRECTRULE=" $( grep -r " \[R=301,L\]" " $SITES_AVAILABLE " | cut -d " :" -f1) "
821830if [ -n " $REDIRECTRULE " ]
822831then
823832 # Change the redirect rule in all files in Apache available
@@ -1312,7 +1321,8 @@ then
13121321 fi
13131322fi
13141323
1315- # If the app isn't installed (maybe because it's incompatible), then at least restore from backup and make sure it's disabled
1324+ # Restore apps from backup that are missing in the new Nextcloud installation
1325+ # (occ upgrade will automatically disable incompatible apps)
13161326BACKUP_APPS=" $( find " $BACKUP /apps" -maxdepth 1 -mindepth 1 -type d) "
13171327mapfile -t BACKUP_APPS <<< " $BACKUP_APPS"
13181328for app in " ${BACKUP_APPS[@]} "
@@ -1323,10 +1333,9 @@ do
13231333 print_text_in_color " $ICyan " " Restoring $app from $BACKUP /apps..."
13241334 rsync -Aaxz " $BACKUP /apps/$app " " $NC_APPS_PATH /"
13251335 bash " $SECURE "
1326- nextcloud_occ_no_check app:disable " $app "
13271336 # Don't execute the update before all cronjobs are finished
13281337 check_running_cronjobs
1329- # Execute the update
1338+ # Execute the update (will disable incompatible apps automatically)
13301339 nextcloud_occ upgrade
13311340 fi
13321341done
@@ -1339,12 +1348,40 @@ then
13391348 nextcloud_occ_no_check app:update --all
13401349fi
13411350
1351+ # Re-enable previously enabled apps after upgrade
1352+ # https://github.com/nextcloud/vm/issues/2797
1353+ if [ -f " $BACKUP /enabled_apps_before_upgrade.txt" ]
1354+ then
1355+ print_text_in_color " $ICyan " " Attempting to re-enable previously enabled apps..."
1356+ while IFS= read -r app
1357+ do
1358+ # Skip empty lines
1359+ if [ -z " $app " ]
1360+ then
1361+ continue
1362+ fi
1363+ # Check if app directory exists and try to enable it
1364+ if [ -d " $NC_APPS_PATH /$app " ]
1365+ then
1366+ if ! is_app_enabled " $app "
1367+ then
1368+ if nextcloud_occ_no_check app:enable " $app " > /dev/null 2>&1
1369+ then
1370+ print_text_in_color " $IGreen " " Re-enabled $app "
1371+ else
1372+ print_text_in_color " $IRed " " Could not re-enable $app (may be incompatible with Nextcloud $CURRENTVERSION_after )"
1373+ fi
1374+ fi
1375+ fi
1376+ done < " $BACKUP /enabled_apps_before_upgrade.txt"
1377+ fi
1378+
13421379# Remove header for Nextcloud 14 (already in .htaccess)
13431380if [ -f /etc/apache2/sites-available/" $( hostname -f) " .conf ]
13441381then
13451382 if grep -q ' Header always set Referrer-Policy' /etc/apache2/sites-available/" $( hostname -f) " .conf
13461383 then
1347- sed -i ' / Header always set Referrer-Policy/ d' /etc/apache2/sites-available/" $( hostname -f) " .conf
1384+ sed -i ' \| Header always set Referrer-Policy| d' /etc/apache2/sites-available/" $( hostname -f) " .conf
13481385 restart_webserver
13491386 fi
13501387fi
0 commit comments