From c0e4dabe44072d5e2d9e3447c805b77304d385c7 Mon Sep 17 00:00:00 2001 From: "courtmanr@gmail.com" Date: Mon, 21 Apr 2025 20:06:07 +0100 Subject: [PATCH] fix: Improve update robustness in install script --- scripts/install-pulse.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/install-pulse.sh b/scripts/install-pulse.sh index dc9b29ab7..67fe64eba 100644 --- a/scripts/install-pulse.sh +++ b/scripts/install-pulse.sh @@ -132,14 +132,37 @@ perform_update() { print_info "Attempting to update Pulse..." cd "$PULSE_DIR" || { print_error "Failed to change directory to $PULSE_DIR"; return 1; } + # Add safe directory config for root user, in case it's needed for stash/other ops + # Might not be strictly necessary if only pulse user runs git, but adds robustness + git config --global --add safe.directory "$PULSE_DIR" > /dev/null 2>&1 || print_warning "Could not configure safe.directory for root user." + + print_info "Stashing potential local changes..." + # Stash changes as the pulse user to avoid ownership issues with the stash itself + if ! sudo -u "$PULSE_USER" git stash push -m "Auto-stash before update"; then + print_warning "Failed to stash local changes. Update might fail if conflicts exist." + # Decide if this should be fatal or just a warning + fi + print_info "Fetching latest changes from git (running as user $PULSE_USER)..." # Run git pull as the pulse user to avoid ownership issues if ! sudo -u "$PULSE_USER" git pull origin main; then print_error "Failed to pull latest changes from git." + # Attempt to restore stashed changes on failure + sudo -u "$PULSE_USER" git stash pop > /dev/null 2>&1 || true # Ignore pop errors if stash failed/empty cd .. return 1 fi + # Attempt to pop stashed changes after successful pull + # This might cause conflicts if the stashed changes conflict with pulled changes + # Alternatively, could just drop the stash: git stash drop + print_info "Attempting to restore stashed changes..." + if ! sudo -u "$PULSE_USER" git stash pop > /dev/null 2>&1; then + print_warning "Could not automatically restore stashed changes. Manual check might be needed if you had local modifications." + else + print_success "Stashed changes restored (if any)." + fi + print_info "Re-installing npm dependencies (root)..." if ! npm install --omit=dev --unsafe-perm > /dev/null 2>&1; then print_warning "Failed to install root npm dependencies during update. Continuing..."