From 4022be004de3df939fe8bea559fd840e46df152c Mon Sep 17 00:00:00 2001 From: Yury Kossakovsky Date: Wed, 14 May 2025 14:26:01 -0600 Subject: [PATCH] Refactor n8n workflow import prompt in apply_update.sh - Simplified the user prompt for importing n8n workflows by removing the check for the RUN_N8N_IMPORT variable being true, allowing users to indicate if they have already imported the workflow. - Retained the logic for modifying the RUN_N8N_IMPORT variable based on user input, ensuring flexibility in workflow management. --- scripts/apply_update.sh | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/scripts/apply_update.sh b/scripts/apply_update.sh index 543fd0d..af67224 100755 --- a/scripts/apply_update.sh +++ b/scripts/apply_update.sh @@ -40,28 +40,23 @@ $COMPOSE_CMD pull || { log_error "Failed to pull Docker images. Check network co # Ask user about n8n import and modify .env file if [ -f "$ENV_FILE" ]; then - # Check if RUN_N8N_IMPORT is already true - if grep -q "^RUN_N8N_IMPORT=true" "$ENV_FILE"; then - log_info "RUN_N8N_IMPORT is already set to true in $ENV_FILE. Skipping import." - else - read -p "Import n8n workflow? (y/n): " import_choice - case "$import_choice" in - [yY] | [yY][eE][sS] ) - # Use a temporary file for sed portability - sed 's/^RUN_N8N_IMPORT=.*/RUN_N8N_IMPORT=true/' "$ENV_FILE" > "${ENV_FILE}.tmp" && mv "${ENV_FILE}.tmp" "$ENV_FILE" || { - log_error "Failed to set RUN_N8N_IMPORT in $ENV_FILE. Check permissions." - rm -f "${ENV_FILE}.tmp" # Clean up temp file on failure - } - ;; - * ) - # Use a temporary file for sed portability - sed 's/^RUN_N8N_IMPORT=.*/RUN_N8N_IMPORT=false/' "$ENV_FILE" > "${ENV_FILE}.tmp" && mv "${ENV_FILE}.tmp" "$ENV_FILE" || { - log_error "Failed to set RUN_N8N_IMPORT in $ENV_FILE. Check permissions." - rm -f "${ENV_FILE}.tmp" # Clean up temp file on failure - } - ;; - esac - fi + read -p "Import n8n workflow? (y/n). Select N if you did it already: " import_choice + case "$import_choice" in + [yY] | [yY][eE][sS] ) + # Use a temporary file for sed portability + sed 's/^RUN_N8N_IMPORT=.*/RUN_N8N_IMPORT=true/' "$ENV_FILE" > "${ENV_FILE}.tmp" && mv "${ENV_FILE}.tmp" "$ENV_FILE" || { + log_error "Failed to set RUN_N8N_IMPORT in $ENV_FILE. Check permissions." + rm -f "${ENV_FILE}.tmp" # Clean up temp file on failure + } + ;; + * ) + # Use a temporary file for sed portability + sed 's/^RUN_N8N_IMPORT=.*/RUN_N8N_IMPORT=false/' "$ENV_FILE" > "${ENV_FILE}.tmp" && mv "${ENV_FILE}.tmp" "$ENV_FILE" || { + log_error "Failed to set RUN_N8N_IMPORT in $ENV_FILE. Check permissions." + rm -f "${ENV_FILE}.tmp" # Clean up temp file on failure + } + ;; + esac # Ask user about n8n worker count if grep -q "^N8N_WORKER_COUNT=" "$ENV_FILE"; then