Implement n8n workflow import logic in secret generation script

- Added RUN_N8N_IMPORT_COMPLETE variable to .env.example to track the completion status of n8n workflow imports.
- Updated 03_generate_secrets.sh to manage user prompts for importing workflows and preserve the import status across sessions.
- Refined the logic for determining whether to prompt the user for importing workflows based on previous completion status.
This commit is contained in:
Yury Kossakovsky
2025-05-28 17:08:21 -06:00
parent 93ab91f392
commit 47cfef0698
2 changed files with 35 additions and 20 deletions

View File

@@ -136,6 +136,7 @@ LETSENCRYPT_EMAIL=
# Default values will suffice unless you need more features/customization.
RUN_N8N_IMPORT=
RUN_N8N_IMPORT_COMPLETE=false
#
#

View File

@@ -193,24 +193,38 @@ else
read -p "OpenAI API Key: " OPENAI_API_KEY
fi
# Ask if user wants to import ready-made workflow for n8n
# Logic for n8n workflow import (RUN_N8N_IMPORT and RUN_N8N_IMPORT_COMPLETE)
echo ""
echo "Do you want to import 300 ready-made workflows for n8n? This process may take about 30 minutes to complete."
if [[ -n "${existing_env_vars[RUN_N8N_IMPORT]}" ]]; then
RUN_N8N_IMPORT="${existing_env_vars[RUN_N8N_IMPORT]}"
log_info "Using existing RUN_N8N_IMPORT value from .env: $RUN_N8N_IMPORT"
else
echo ""
read -p "Import workflows? (y/n): " import_workflow
if [[ "$import_workflow" =~ ^[Yy]$ ]]; then
RUN_N8N_IMPORT="true"
else
RUN_N8N_IMPORT="false"
fi
# Determine the current state of RUN_N8N_IMPORT_COMPLETE from .env
# This variable tracks if the import has ever been successfully initiated.
run_n8n_import_complete_from_env="false"
if [[ "${existing_env_vars[RUN_N8N_IMPORT_COMPLETE]}" == "true" ]]; then
run_n8n_import_complete_from_env="true"
fi
# Set N8N_WORKFLOWS_IMPORTED_EVER_VALUE based on RUN_N8N_IMPORT
N8N_WORKFLOWS_IMPORTED_EVER_VALUE="$RUN_N8N_IMPORT"
# These will be the final values decided for this run and to be saved in .env
# 'final_run_n8n_import_decision' is for the current session's import action
# 'final_run_n8n_import_complete_status' is the persistent flag
final_run_n8n_import_decision="false"
final_run_n8n_import_complete_status="$run_n8n_import_complete_from_env" # Preserve existing 'true' state by default
if [[ "$run_n8n_import_complete_from_env" == "true" ]]; then
final_run_n8n_import_decision="false"
# final_run_n8n_import_complete_status remains "true"
else
# RUN_N8N_IMPORT_COMPLETE is false or not set, so we ask the user.
echo "Do you want to import 300 ready-made workflows for n8n? This process may take about 30 minutes to complete."
echo ""
read -p "Import workflows? (y/n): " import_workflow_choice
if [[ "$import_workflow_choice" =~ ^[Yy]$ ]]; then
final_run_n8n_import_decision="true"
final_run_n8n_import_complete_status="true" # Mark as complete for this and future runs
else
final_run_n8n_import_decision="false"
# final_run_n8n_import_complete_status remains "false" because user declined and it wasn't true before.
fi
fi
# Prompt for number of n8n workers
echo "" # Add a newline for better formatting
@@ -325,12 +339,12 @@ done
generated_values["FLOWISE_USERNAME"]="$USER_EMAIL"
generated_values["DASHBOARD_USERNAME"]="$USER_EMAIL"
generated_values["LETSENCRYPT_EMAIL"]="$USER_EMAIL"
generated_values["RUN_N8N_IMPORT"]="$RUN_N8N_IMPORT"
generated_values["RUN_N8N_IMPORT"]="$final_run_n8n_import_decision"
generated_values["RUN_N8N_IMPORT_COMPLETE"]="$final_run_n8n_import_complete_status"
generated_values["PROMETHEUS_USERNAME"]="$USER_EMAIL"
generated_values["SEARXNG_USERNAME"]="$USER_EMAIL"
generated_values["LANGFUSE_INIT_USER_EMAIL"]="$USER_EMAIL"
generated_values["N8N_WORKER_COUNT"]="$N8N_WORKER_COUNT"
generated_values["N8N_WORKFLOWS_IMPORTED_EVER"]="$N8N_WORKFLOWS_IMPORTED_EVER_VALUE"
generated_values["WEAVIATE_USERNAME"]="$USER_EMAIL" # Set Weaviate username for Caddy
if [[ -n "$OPENAI_API_KEY" ]]; then
generated_values["OPENAI_API_KEY"]="$OPENAI_API_KEY"
@@ -347,12 +361,12 @@ found_vars["FLOWISE_USERNAME"]=0
found_vars["DASHBOARD_USERNAME"]=0
found_vars["LETSENCRYPT_EMAIL"]=0
found_vars["RUN_N8N_IMPORT"]=0
found_vars["RUN_N8N_IMPORT_COMPLETE"]=0
found_vars["PROMETHEUS_USERNAME"]=0
found_vars["SEARXNG_USERNAME"]=0
found_vars["OPENAI_API_KEY"]=0
found_vars["LANGFUSE_INIT_USER_EMAIL"]=0
found_vars["N8N_WORKER_COUNT"]=0
found_vars["N8N_WORKFLOWS_IMPORTED_EVER"]=0
found_vars["WEAVIATE_USERNAME"]=0
found_vars["vEO4J_AUTH_USERNAME"]=0
@@ -400,7 +414,7 @@ while IFS= read -r line || [[ -n "$line" ]]; do
# This 'else' block is for lines from template not covered by existing values or VARS_TO_GENERATE.
# Check if it is one of the user input vars - these are handled by found_vars later if not in template.
is_user_input_var=0 # Reset for each line
user_input_vars=("FLOWISE_USERNAME" "DASHBOARD_USERNAME" "LETSENCRYPT_EMAIL" "RUN_N8N_IMPORT" "PROMETHEUS_USERNAME" "SEARXNG_USERNAME" "OPENAI_API_KEY" "LANGFUSE_INIT_USER_EMAIL" "N8N_WORKER_COUNT" "N8N_WORKFLOWS_IMPORTED_EVER" "WEAVIATE_USERNAME")
user_input_vars=("FLOWISE_USERNAME" "DASHBOARD_USERNAME" "LETSENCRYPT_EMAIL" "RUN_N8N_IMPORT" "RUN_N8N_IMPORT_COMPLETE" "PROMETHEUS_USERNAME" "SEARXNG_USERNAME" "OPENAI_API_KEY" "LANGFUSE_INIT_USER_EMAIL" "N8N_WORKER_COUNT" "WEAVIATE_USERNAME")
for uivar in "${user_input_vars[@]}"; do
if [[ "$varName" == "$uivar" ]]; then
is_user_input_var=1
@@ -488,7 +502,7 @@ else
fi
# Add any custom variables that weren't found in the template
for var in "FLOWISE_USERNAME" "DASHBOARD_USERNAME" "LETSENCRYPT_EMAIL" "RUN_N8N_IMPORT" "OPENAI_API_KEY" "PROMETHEUS_USERNAME" "SEARXNG_USERNAME" "LANGFUSE_INIT_USER_EMAIL" "N8N_WORKER_COUNT" "N8N_WORKFLOWS_IMPORTED_EVER" "WEAVIATE_USERNAME"; do
for var in "FLOWISE_USERNAME" "DASHBOARD_USERNAME" "LETSENCRYPT_EMAIL" "RUN_N8N_IMPORT" "RUN_N8N_IMPORT_COMPLETE" "OPENAI_API_KEY" "PROMETHEUS_USERNAME" "SEARXNG_USERNAME" "LANGFUSE_INIT_USER_EMAIL" "N8N_WORKER_COUNT" "WEAVIATE_USERNAME"; do
if [[ ${found_vars["$var"]} -eq 0 && -v generated_values["$var"] ]]; then
# Before appending, check if it's already in TMP_ENV_FILE to avoid duplicates
if ! grep -q -E "^${var}=" "$TMP_ENV_FILE"; then