Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 52 additions & 15 deletions nextcloud_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -458,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 ]
Expand Down Expand Up @@ -489,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

Expand Down Expand Up @@ -519,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 ]
Expand Down Expand Up @@ -552,15 +561,15 @@ 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
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 ]
Expand Down Expand Up @@ -779,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" ]
Expand Down Expand Up @@ -817,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
Expand Down Expand Up @@ -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[@]}"
Expand All @@ -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
Expand All @@ -1339,12 +1348,40 @@ 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
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
Expand Down