From 4963385bf9406b5d1bce49c6fe0d6e206277f49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Taha=20=C3=96ztop?= Date: Sun, 26 Apr 2026 09:51:33 +0300 Subject: [PATCH] fix(2fauth): make update_script idempotent and preserve ownership (#14018) The update was failing with 'mv: cannot stat /opt/2fauth-backup/.env: No such file or directory' on a system where a previous run had left /opt/2fauth-backup behind. mv would then nest /opt/2fauth inside the existing backup directory (as /opt/2fauth-backup/2fauth/), so the restore step looked at the wrong path. After fixing that, the app returned a 500 ('Key path file:///opt/2fauth/storage/oauth-public.key does not exist or is not readable') because chown/chmod ran before composer install and php artisan 2fauth:install, leaving vendor/, bootstrap/cache/* and the regenerated oauth keys owned by root and unreadable by www-data. - Remove any stale /opt/2fauth-backup before creating the backup, and remove it again at the end so the next run starts clean - Use cp instead of mv when restoring .env/storage so the backup is preserved until the update completes - Move chown/chmod to AFTER composer + artisan, matching the order in install/2fauth-install.sh - Restart php8.4-fpm in addition to nginx so opcache picks up the new cached config - Drop redundant quotes around literal paths to match the rest of the codebase --- ct/2fauth.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ct/2fauth.sh b/ct/2fauth.sh index deee15371..2d984da37 100644 --- a/ct/2fauth.sh +++ b/ct/2fauth.sh @@ -24,7 +24,7 @@ function update_script() { check_container_storage check_container_resources - if [[ ! -d "/opt/2fauth" ]]; then + if [[ ! -d /opt/2fauth ]]; then msg_error "No ${APP} Installation Found!" exit fi @@ -34,7 +34,8 @@ function update_script() { $STD apt -y upgrade msg_info "Creating Backup" - mv "/opt/2fauth" "/opt/2fauth-backup" + rm -rf /opt/2fauth-backup + mv /opt/2fauth /opt/2fauth-backup if ! dpkg -l | grep -q 'php8.4'; then cp /etc/nginx/conf.d/2fauth.conf /etc/nginx/conf.d/2fauth.conf.bak fi @@ -46,15 +47,17 @@ function update_script() { fi fetch_and_deploy_gh_release "2fauth" "Bubka/2FAuth" "tarball" setup_composer - mv "/opt/2fauth-backup/.env" "/opt/2fauth/.env" - mv "/opt/2fauth-backup/storage" "/opt/2fauth/storage" - cd "/opt/2fauth" || return - chown -R www-data: "/opt/2fauth" - chmod -R 755 "/opt/2fauth" + cp /opt/2fauth-backup/.env /opt/2fauth/.env + cp -r /opt/2fauth-backup/storage /opt/2fauth/storage + cd /opt/2fauth || return export COMPOSER_ALLOW_SUPERUSER=1 $STD composer install --no-dev --prefer-dist php artisan 2fauth:install + chown -R www-data: /opt/2fauth + chmod -R 755 /opt/2fauth + $STD systemctl restart php8.4-fpm $STD systemctl restart nginx + rm -rf /opt/2fauth-backup msg_ok "Updated successfully!" fi exit