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.
This commit is contained in:
Yury Kossakovsky
2025-05-14 14:26:01 -06:00
parent 96e640b33c
commit 4022be004d

View File

@@ -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