From 735e9a758b542a541f458fd829e21bd553bd7792 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sun, 28 Dec 2025 18:30:33 -0600 Subject: [PATCH] started setup_wizard --- scripts/setup_wizard.sh | 103 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100755 scripts/setup_wizard.sh diff --git a/scripts/setup_wizard.sh b/scripts/setup_wizard.sh new file mode 100755 index 0000000..6ab32b5 --- /dev/null +++ b/scripts/setup_wizard.sh @@ -0,0 +1,103 @@ +#!/bin/bash + +set -e + +# Colors +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +RED='\033[0;31m' +NC='\033[0m' # No Color + +# ----------------------------------------------------------------------------- +# Input Framework +# ----------------------------------------------------------------------------- + +# Ensure we have a tty for input +if [ ! -e /dev/tty ]; then + echo "Error: Script must be run in an interactive terminal (cannot find /dev/tty)." >&2 + exit 1 +fi + +# Function to prompt for user input +# Usage: get_input "VARIABLE_NAME" "Prompt Text" "Default Value" "is_secret(true/false)" +get_input() { + local var_name="$1" + local prompt_text="$2" + local default_value="$3" + local is_secret="$4" + + local input_val="" + local prompt_full="${GREEN}${prompt_text}${NC}" + + if [ -n "$default_value" ]; then + prompt_full+=" ${YELLOW}[$default_value]${NC}" + fi + prompt_full+=": " + + while true; do + # Print prompt to stderr so it shows up even if stdout is redirected + if [ "$is_secret" == "true" ]; then + echo -ne "$prompt_full" >&2 + read -s input_val < /dev/tty + echo "" >&2 # Newline after secret input + else + echo -ne "$prompt_full" >&2 + read input_val < /dev/tty + fi + + # Use default if input is empty + if [ -z "$input_val" ] && [ -n "$default_value" ]; then + input_val="$default_value" + fi + + # Validation: Require input if no default exists + if [ -z "$input_val" ]; then + echo -e "${RED}Error: This value is required.${NC}" >&2 + else + break + fi + done + + # Set the variable dynamically in the parent scope + printf -v "$var_name" "%s" "$input_val" +} + +# Function to confirm collected inputs +# Usage: confirm_inputs "VAR1" "VAR2" "VAR3" ... +confirm_inputs() { + echo "" >&2 + echo -e "${GREEN}=== Configuration Summary ===${NC}" >&2 + + for var in "$@"; do + local val="${!var}" + # Mask secrets in summary if needed, or just show length + # For now, just printing value. + # To improve: pass a list of secret vars to mask them. + echo -e "${YELLOW}$var:${NC} $val" >&2 + done + echo "" >&2 + + get_input "CONFIRM" "Is this correct? (y/n)" "y" "false" + if [[ "${CONFIRM,,}" != "y" ]]; then + echo -e "${RED}Aborted by user.${NC}" >&2 + exit 1 + fi +} + +# ----------------------------------------------------------------------------- +# Script Logic +# ----------------------------------------------------------------------------- + +echo "Starting Interactive Setup..." +echo "-----------------------------" + +# 1. Collect Inputs +# Example: +get_input "HOST_NAME" "Enter Hostname" "$(hostname)" "false" +# get_input "ADMIN_PASS" "Enter Admin Password" "" "true" + +# 2. Confirm +# confirm_inputs "HOST_NAME" "ADMIN_PASS" + +# 3. Execute +# echo "Configuring $HOST_NAME..."