From b01711c4e7ac2230aa5246ec4962e7edb9b57077 Mon Sep 17 00:00:00 2001 From: "courtmanr@gmail.com" Date: Thu, 29 May 2025 09:29:53 +0100 Subject: [PATCH] fix: preserve .env file during automatic updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Backup .env file before git clean to prevent configuration loss - Restore .env file after git operations with proper ownership - Ensures user configuration survives cron-based updates 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- scripts/install-pulse.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/scripts/install-pulse.sh b/scripts/install-pulse.sh index ed8ad4837..fa6bb159a 100755 --- a/scripts/install-pulse.sh +++ b/scripts/install-pulse.sh @@ -1047,10 +1047,36 @@ perform_update() { return 1 fi + # Backup .env file before cleaning to preserve user configuration + local env_backup_path="" + if [ -f "$PULSE_DIR/.env" ]; then + env_backup_path="/tmp/.env.backup.$$" + print_info "Backing up .env file to preserve user configuration..." + if cp "$PULSE_DIR/.env" "$env_backup_path"; then + print_success ".env file backed up temporarily." + else + print_warning "Failed to backup .env file. Configuration may be lost." + env_backup_path="" + fi + fi + print_info "Cleaning untracked files and directories..." if ! sudo -u "$PULSE_USER" git clean -fd; then print_warning "Failed to clean untracked files, continuing anyway." fi + + # Restore .env file after cleaning + if [ -n "$env_backup_path" ] && [ -f "$env_backup_path" ]; then + print_info "Restoring .env file..." + if cp "$env_backup_path" "$PULSE_DIR/.env"; then + chown "$PULSE_USER":"$PULSE_USER" "$PULSE_DIR/.env" + chmod 600 "$PULSE_DIR/.env" + print_success ".env file restored successfully." + else + print_warning "Failed to restore .env file from backup." + fi + rm -f "$env_backup_path" + fi print_info "Fetching latest changes from git [running as user $PULSE_USER]..." if [ -n "$TARGET_TAG" ]; then