From 3c9a39d446d5b3ed71dc113dd169fc14f4f482c8 Mon Sep 17 00:00:00 2001 From: Yury Kossakovsky Date: Sat, 24 May 2025 10:15:04 -0600 Subject: [PATCH] Enhance domain input handling in 03_generate_secrets.sh and update apply_update.sh - Introduced logic to infer the current domain from N8N_HOSTNAME or SUPABASE_HOSTNAME for user prompts in 03_generate_secrets.sh. - Improved user prompts to display the current domain as a default suggestion, enhancing user experience. - Updated apply_update.sh to ensure the .env file is checked and updated by calling 03_generate_secrets.sh during the update process. --- scripts/03_generate_secrets.sh | 28 +++++++++++++++++++++++----- scripts/apply_update.sh | 9 +++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/scripts/03_generate_secrets.sh b/scripts/03_generate_secrets.sh index 1fefec9..4187f72 100755 --- a/scripts/03_generate_secrets.sh +++ b/scripts/03_generate_secrets.sh @@ -91,27 +91,45 @@ if ! command -v caddy &> /dev/null; then fi # Prompt for the domain name +CURRENT_DOMAIN="" +# Try to infer current domain from N8N_HOSTNAME or SUPABASE_HOSTNAME for the prompt +if [[ -n "${existing_env_vars[N8N_HOSTNAME]}" ]]; then + CURRENT_DOMAIN=$(echo "${existing_env_vars[N8N_HOSTNAME]}" | sed -E 's/^[a-zA-Z0-9-]+\.(.+)/\1/') +elif [[ -n "${existing_env_vars[SUPABASE_HOSTNAME]}" ]]; then + CURRENT_DOMAIN=$(echo "${existing_env_vars[SUPABASE_HOSTNAME]}" | sed -E 's/^[a-zA-Z0-9-]+\.(.+)/\1/') +fi + while true; do echo "" - read -p "Enter the primary domain name for your services (e.g., example.com): " DOMAIN + prompt_text="Enter the primary domain name for your services (e.g., example.com)" + if [[ -n "$CURRENT_DOMAIN" ]]; then + prompt_text+=" [current: $CURRENT_DOMAIN]: " + else + prompt_text+=": " + fi + read -p "$prompt_text" DOMAIN_INPUT + + DOMAIN_TO_USE="${DOMAIN_INPUT:-$CURRENT_DOMAIN}" # Validate domain input - if [[ -z "$DOMAIN" ]]; then + if [[ -z "$DOMAIN_TO_USE" ]]; then log_error "Domain name cannot be empty." >&2 continue # Ask again fi # Basic check for likely invalid domain characters (very permissive) - if [[ "$DOMAIN" =~ [^a-zA-Z0-9.-] ]]; then - log_warning "Warning: Domain name contains potentially invalid characters: '$DOMAIN'" >&2 + if [[ "$DOMAIN_TO_USE" =~ [^a-zA-Z0-9.-] ]]; then + log_warning "Warning: Domain name contains potentially invalid characters: '$DOMAIN_TO_USE'" >&2 fi echo "" - read -p "Are you sure '$DOMAIN' is correct? (y/N): " confirm_domain + read -p "Are you sure '$DOMAIN_TO_USE' is correct? (y/N): " confirm_domain if [[ "$confirm_domain" =~ ^[Yy]$ ]]; then + DOMAIN="$DOMAIN_TO_USE" # Set the final DOMAIN variable break # Confirmed, exit loop else log_info "Please try entering the domain name again." + # CURRENT_DOMAIN remains for the next prompt iteration if user wants to retry with current default fi done diff --git a/scripts/apply_update.sh b/scripts/apply_update.sh index 916d61b..e950034 100755 --- a/scripts/apply_update.sh +++ b/scripts/apply_update.sh @@ -27,6 +27,15 @@ fi cd "$PROJECT_ROOT" +# --- Call 03_generate_secrets.sh in update mode --- +log_info "Ensuring .env file is up-to-date with all variables..." +bash "$SCRIPT_DIR/03_generate_secrets.sh" --update || { + log_error "Failed to update .env configuration via 03_generate_secrets.sh. Update process cannot continue." + exit 1 +} +log_success ".env file checked and updated." +# --- End of .env update --- + # Stop all services for project 'localai' log_info "Stopping all services for project 'localai'..." PROJECT_CONTAINERS=$(docker ps -a -q --filter "label=com.docker.compose.project=localai")