From bd834f690a358e0a69f43130247ee93f96fffeea Mon Sep 17 00:00:00 2001 From: MickLesk Date: Mon, 20 Jul 2026 20:23:05 +0200 Subject: [PATCH] Fix CLEAN_INSTALL to wipe dotfiles too CLEAN_INSTALL now removes dotfiles (e.g. .env) along with other files, using `find -mindepth 1 -delete` instead of `rm -rf *`. Update scripts for affine, nametag, and postiz are updated to explicitly back up and restore .env (via create_backup/restore_backup or cp) BEFORE the build step that sources it, rather than relying on the wipe preserving dotfiles. --- ct/affine.sh | 13 ++++++++++--- ct/nametag.sh | 3 +++ ct/postiz.sh | 6 ++++-- misc/tools.func | 19 +++++++++---------- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/ct/affine.sh b/ct/affine.sh index 911f51f61..b910afe5d 100644 --- a/ct/affine.sh +++ b/ct/affine.sh @@ -38,10 +38,19 @@ function update_script() { ensure_dependencies cmake - create_backup /root/.affine/config /root/.affine/storage + create_backup /opt/affine/.env /root/.affine/config /root/.affine/storage CLEAN_INSTALL=1 fetch_and_deploy_gh_release "affine_app" "toeverything/AFFiNE" "tarball" "${RELEASE}" "/opt/affine" + # Restore BEFORE the build: CLEAN_INSTALL wiped /opt/affine including .env, + # and the build below sources it + restore_backup + + if [[ ! -f /opt/affine/.env ]]; then + msg_error "/opt/affine/.env is missing (lost by an earlier update). Recreate it before retrying — see the AFFiNE install script for the expected variables." + exit 1 + fi + msg_info "Rebuilding Application (Patience ~25 mins, don't close the console!)" cd /opt/affine source /root/.profile @@ -111,8 +120,6 @@ TURBO set -a && source /opt/affine/.env && set +a $STD node ./scripts/self-host-predeploy.js - restore_backup - msg_info "Starting Services" systemctl start affine-web affine-worker msg_ok "Started Services" diff --git a/ct/nametag.sh b/ct/nametag.sh index 9346a80f7..69fd34777 100644 --- a/ct/nametag.sh +++ b/ct/nametag.sh @@ -42,6 +42,9 @@ function update_script() { CLEAN_INSTALL=1 fetch_and_deploy_gh_release "nametag" "mattogodoy/nametag" "tarball" "latest" "/opt/nametag" + # Restore .env BEFORE the build: CLEAN_INSTALL wiped it and the build sources it + cp /opt/nametag.env.bak /opt/nametag/.env + msg_info "Rebuilding Application" cd /opt/nametag $STD npm ci diff --git a/ct/postiz.sh b/ct/postiz.sh index dc004abb5..bf488bf98 100644 --- a/ct/postiz.sh +++ b/ct/postiz.sh @@ -41,9 +41,12 @@ function update_script() { CLEAN_INSTALL=1 fetch_and_deploy_gh_release "postiz" "gitroomhq/postiz-app" "tarball" + # Restore BEFORE the build: CLEAN_INSTALL wiped /opt/postiz including .env, + # and the build below sources it + restore_backup + msg_info "Building Application" cd /opt/postiz - cp /opt/postiz_env.bak /opt/postiz/.env set -a && source /opt/postiz/.env && set +a export NODE_OPTIONS="--max-old-space-size=4096" $STD pnpm install @@ -57,7 +60,6 @@ function update_script() { msg_ok "Ran Database Migrations" mkdir -p /opt/postiz/uploads - restore_backup msg_info "Starting Services" systemctl start postiz-backend postiz-frontend postiz-orchestrator diff --git a/misc/tools.func b/misc/tools.func index b31ae72d3..a45667e66 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -2523,9 +2523,9 @@ _download_source_tarball() { # directory). Extracts into , then copies the contents # of that top-level directory into . # -# - Honors CLEAN_INSTALL=1 (wipes first, but PRESERVES dotfiles -# like .env — update scripts rely on config dotfiles surviving the wipe; -# deleting them broke every "backup → deploy → source .env" update flow). +# - Honors CLEAN_INSTALL=1 (wipes first, dotfiles included — back +# up config dotfiles like .env via create_backup and call restore_backup +# BEFORE any build step that sources them). # - Does NOT own : the caller creates it and is responsible for its # cleanup (typically via a RETURN trap on its tmpdir). # - cp failures are non-fatal here, matching the previous inline behavior. @@ -2537,7 +2537,7 @@ _deploy_source_tarball() { mkdir -p "$target" if [[ "${CLEAN_INSTALL:-0}" == "1" ]]; then - rm -rf "${target:?}/"* + find "${target:?}" -mindepth 1 -delete fi tar --no-same-owner -xzf "$tarball" -C "$workdir" || { @@ -2563,8 +2563,9 @@ _deploy_source_tarball() { # a single top-level directory, that directory is stripped (its contents land # directly in ); otherwise the archive contents are copied as-is. # -# - Honors CLEAN_INSTALL=1 (wipes first, but PRESERVES dotfiles -# like .env — update scripts rely on config dotfiles surviving the wipe). +# - Honors CLEAN_INSTALL=1 (wipes first, dotfiles included — back +# up config dotfiles like .env via create_backup and call restore_backup +# BEFORE any build step that sources them). # - Does NOT own : the caller creates it and cleans it up. # # Returns: 0 on success, 65 on unsupported format, 251 on extraction failure, @@ -2576,7 +2577,7 @@ _deploy_unpacked_archive() { mkdir -p "$target" if [[ "${CLEAN_INSTALL:-0}" == "1" ]]; then - rm -rf "${target:?}/"* + find "${target:?}" -mindepth 1 -delete fi if [[ "$filename" == *.zip ]]; then @@ -9269,10 +9270,8 @@ fetch_and_deploy_from_url() { mkdir -p "$directory" - # CLEAN_INSTALL wipe PRESERVES dotfiles (.env etc.) — update scripts rely on - # config dotfiles surviving the wipe if [[ "${CLEAN_INSTALL:-0}" == "1" ]]; then - rm -rf "${directory:?}/"* + find "${directory:?}" -mindepth 1 -delete fi local unpack_tmp