diff --git a/bin/wild-app-config b/bin/wild-app-config index e43a3d1..3585e63 100755 --- a/bin/wild-app-config +++ b/bin/wild-app-config @@ -45,15 +45,13 @@ if [ -z "${APP_NAME}" ]; then exit 1 fi -if [ ! -d ".wildcloud" ]; then - echo "Error: .wildcloud directory not found in current directory" - echo "This script must be run from a directory that contains a .wildcloud directory" - exit 1 -fi - -if [ ! -f ".wildcloud/config.yaml" ]; then - echo "Error: .wildcloud/config.yaml not found" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi CACHE_APP_DIR=".wildcloud/cache/apps/${APP_NAME}" diff --git a/bin/wild-app-delete b/bin/wild-app-delete index 3f435db..b041f2f 100755 --- a/bin/wild-app-delete +++ b/bin/wild-app-delete @@ -61,6 +61,15 @@ if [ ! -d "apps/${APP_NAME}" ]; then exit 1 fi +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." + exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env +fi + # Confirmation prompt (unless --force or --dry-run) if [ "${FORCE}" != true ] && [ "${DRY_RUN:-}" != "--dry-run=client" ]; then echo "WARNING: This will delete all resources for app '${APP_NAME}'" diff --git a/bin/wild-app-deploy b/bin/wild-app-deploy index 17dd231..07071fb 100755 --- a/bin/wild-app-deploy +++ b/bin/wild-app-deploy @@ -43,6 +43,15 @@ if [ ! -d "apps/${APP_NAME}" ]; then exit 1 fi +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." + exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env +fi + # Function to deploy secrets for an app deploy_secrets() { local app_name="$1" diff --git a/bin/wild-app-doctor b/bin/wild-app-doctor index 3fce692..169bba5 100755 --- a/bin/wild-app-doctor +++ b/bin/wild-app-doctor @@ -7,13 +7,6 @@ KEEP_RESOURCES=false FOLLOW_LOGS=false TIMEOUT=120 -# Source environment variables from load-env.sh -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -REPO_DIR="$(dirname "$SCRIPT_DIR")" -if [ -f "$REPO_DIR/load-env.sh" ]; then - source "$REPO_DIR/load-env.sh" -fi - function show_help { echo "Usage: $0 APP_NAME [options]" echo "" @@ -85,6 +78,15 @@ if [[ -z "$APP_NAME" ]]; then show_help fi +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." + exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env +fi + # Check if doctor directory exists DOCTOR_DIR="$REPO_DIR/apps/$APP_NAME/doctor" if [[ ! -d "$DOCTOR_DIR" ]]; then diff --git a/bin/wild-app-fetch b/bin/wild-app-fetch index 5ced243..891dff0 100755 --- a/bin/wild-app-fetch +++ b/bin/wild-app-fetch @@ -45,25 +45,16 @@ if [ -z "${APP_NAME}" ]; then exit 1 fi -if [ ! -d ".wildcloud" ]; then - echo "Error: .wildcloud directory not found in current directory" - echo "This script must be run from a directory that contains a .wildcloud directory" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi -if [ ! -f ".wildcloud/config.yaml" ]; then - echo "Error: .wildcloud/config.yaml not found" - exit 1 -fi - -WILDCLOUD_REPO=$(yq eval '.wildcloud.repository' .wildcloud/config.yaml) - -if [ -z "${WILDCLOUD_REPO}" ] || [ "${WILDCLOUD_REPO}" = "null" ]; then - echo "Error: wildcloud.config not found in .wildcloud/config.yaml" - exit 1 -fi - -SOURCE_APP_DIR="${WILDCLOUD_REPO}/apps/${APP_NAME}" +SOURCE_APP_DIR="${WC_ROOT}/apps/${APP_NAME}" if [ ! -d "${SOURCE_APP_DIR}" ]; then echo "Error: App '${APP_NAME}' not found at ${SOURCE_APP_DIR}" exit 1 diff --git a/bin/wild-apps-list b/bin/wild-apps-list index 4cd4948..0a2a620 100755 --- a/bin/wild-apps-list +++ b/bin/wild-apps-list @@ -48,11 +48,16 @@ while [[ $# -gt 0 ]]; do esac done -# Get the path to the Wild-Cloud repository (where this script is located) -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -WILDCLOUD_REPO="$(dirname "${SCRIPT_DIR}")" -APPS_DIR="${WILDCLOUD_REPO}/apps" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." + exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env +fi +APPS_DIR="${WC_ROOT}/apps" if [ ! -d "${APPS_DIR}" ]; then echo "Error: Apps directory not found at ${APPS_DIR}" exit 1 diff --git a/bin/wild-cluster-config-generate b/bin/wild-cluster-config-generate index 56f0a15..4525e2f 100755 --- a/bin/wild-cluster-config-generate +++ b/bin/wild-cluster-config-generate @@ -3,12 +3,6 @@ set -e set -o pipefail -# Source common utilities -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" - -# Initialize Wild-Cloud environment -init_wild_env - # Usage function usage() { echo "Usage: wild-cluster-config-generate [options]" @@ -55,18 +49,13 @@ while [[ $# -gt 0 ]]; do esac done -# Check if we're in a wild-cloud directory -if [ ! -d ".wildcloud" ]; then - print_error "You must run this script from a wild-cloud directory" - print_info "Run 'wild-setup' or 'wild-init' first to initialize a wild-cloud project" - exit 1 -fi - -# Check if talosctl is available -if ! command -v talosctl >/dev/null 2>&1; then - print_error "talosctl not found in PATH" - print_info "Please install talosctl to generate cluster configurations" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi # ============================================================================= diff --git a/bin/wild-cluster-node-image-create b/bin/wild-cluster-node-image-create index b820366..d092bb8 100755 --- a/bin/wild-cluster-node-image-create +++ b/bin/wild-cluster-node-image-create @@ -3,12 +3,6 @@ set -e set -o pipefail -# Source common utilities -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" - -# Initialize Wild-Cloud environment -init_wild_env - # Usage function usage() { echo "Usage: wild-cluster-node-image-create [options]" @@ -48,11 +42,13 @@ while [[ $# -gt 0 ]]; do esac done -# Check if we're in a wild-cloud directory -if [ ! -d ".wildcloud" ]; then - print_error "You must run this script from a wild-cloud directory" - print_info "Run 'wild-setup' or 'wild-init' first to initialize a wild-cloud project" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi # Configure basic settings if needed diff --git a/bin/wild-cluster-node-machine-config-generate b/bin/wild-cluster-node-machine-config-generate index 659c832..a748f12 100755 --- a/bin/wild-cluster-node-machine-config-generate +++ b/bin/wild-cluster-node-machine-config-generate @@ -3,12 +3,6 @@ set -e set -o pipefail -# Source common utilities -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" - -# Initialize Wild-Cloud environment -init_wild_env - # Usage function usage() { echo "Usage: wild-cluster-node-machine-config-generate " @@ -72,7 +66,14 @@ if [ -z "$NODE_IP" ]; then exit 1 fi -check_wild_directory +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." + exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env +fi # Check required configuration if [ -z "$(get_current_config "cluster.name")" ]; then diff --git a/bin/wild-cluster-node-up b/bin/wild-cluster-node-up index 1bca18b..f0b68cc 100755 --- a/bin/wild-cluster-node-up +++ b/bin/wild-cluster-node-up @@ -3,12 +3,6 @@ set -e set -o pipefail -# Source common utilities -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" - -# Initialize Wild-Cloud environment -init_wild_env - # Usage function usage() { echo "Usage: wild-cluster-node-up [options]" @@ -84,8 +78,14 @@ if [ -z "$NODE_IP" ]; then exit 1 fi -# Check if we're in a wild-cloud directory -check_wild_directory +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." + exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env +fi # Check required configuration if [ -z "$(get_current_config "cluster.name")" ]; then diff --git a/bin/wild-cluster-services-generate b/bin/wild-cluster-services-generate index bde57f4..61d9396 100755 --- a/bin/wild-cluster-services-generate +++ b/bin/wild-cluster-services-generate @@ -3,13 +3,6 @@ set -e set -o pipefail -# Source common utilities -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" - -# Initialize Wild-Cloud environment -init_wild_env - - # Usage function usage() { echo "Usage: wild-cluster-services-generate [options]" @@ -56,18 +49,13 @@ while [[ $# -gt 0 ]]; do esac done -# Check if we're in a wild-cloud directory -if [ ! -d ".wildcloud" ]; then - print_error "You must run this script from a wild-cloud directory" - print_info "Run 'wild-setup' or 'wild-init' first to initialize a wild-cloud project" - exit 1 -fi - -# Check if basic configuration exists -if [ ! -f "${WC_HOME}/config.yaml" ]; then - print_error "Configuration file not found: ${WC_HOME}/config.yaml" - print_info "Run 'wild-setup' first to configure your cluster" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi # ============================================================================= diff --git a/bin/wild-cluster-services-up b/bin/wild-cluster-services-up index c51e5d8..b6a91af 100755 --- a/bin/wild-cluster-services-up +++ b/bin/wild-cluster-services-up @@ -3,13 +3,6 @@ set -e set -o pipefail -# Source common utilities -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" - -# Initialize Wild-Cloud environment -init_wild_env - - # Usage function usage() { echo "Usage: wild-cluster-services-up [options] [service...]" @@ -70,11 +63,13 @@ while [[ $# -gt 0 ]]; do esac done -# Check if we're in a wild-cloud directory -if [ ! -d ".wildcloud" ]; then - print_error "You must run this script from a wild-cloud directory" - print_info "Run 'wild-setup' or 'wild-init' first to initialize a wild-cloud project" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster" diff --git a/bin/wild-compile-template b/bin/wild-compile-template index 163244c..2a27c8d 100755 --- a/bin/wild-compile-template +++ b/bin/wild-compile-template @@ -37,10 +37,13 @@ while [[ $# -gt 0 ]]; do esac done -# Check if WC_HOME is set -if [ -z "${WC_HOME:-}" ]; then - echo "Error: WC_HOME environment variable not set" >&2 +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi CONFIG_FILE="${WC_HOME}/config.yaml" diff --git a/bin/wild-compile-template-dir b/bin/wild-compile-template-dir index 597629c..4e7defd 100755 --- a/bin/wild-compile-template-dir +++ b/bin/wild-compile-template-dir @@ -54,7 +54,6 @@ fi source_dir="$1" dest_dir="${2:-${source_dir}_compiled}" - # Validate source directory if [[ ! -d "$source_dir" ]]; then echo "Error: Source directory does not exist: $source_dir" >&2 diff --git a/bin/wild-config b/bin/wild-config index 6aa853b..4c2ab2a 100755 --- a/bin/wild-config +++ b/bin/wild-config @@ -49,10 +49,13 @@ if [ -z "${KEY_PATH}" ]; then exit 1 fi -# Check if WC_HOME is set -if [ -z "${WC_HOME:-}" ]; then - echo "Error: WC_HOME environment variable not set" >&2 +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi CONFIG_FILE="${WC_HOME}/config.yaml" diff --git a/bin/wild-config-set b/bin/wild-config-set index f23cf4e..3cb3881 100755 --- a/bin/wild-config-set +++ b/bin/wild-config-set @@ -57,10 +57,13 @@ if [ -z "${VALUE}" ]; then exit 1 fi -# Check if WC_HOME is set -if [ -z "${WC_HOME:-}" ]; then - echo "Error: WC_HOME environment variable not set" >&2 +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi CONFIG_FILE="${WC_HOME}/config.yaml" diff --git a/bin/wild-dnsmasq-install b/bin/wild-dnsmasq-install index 97645ef..13db936 100755 --- a/bin/wild-dnsmasq-install +++ b/bin/wild-dnsmasq-install @@ -17,14 +17,15 @@ while [[ $# -gt 0 ]]; do esac done -# Check if WC_HOME is set -if [ -z "${WC_HOME:-}" ]; then - echo "Error: WC_HOME environment variable not set. Run \`source ./env.sh\`." +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi -WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" - # --- SOURCE_DIR="${WC_ROOT}/setup/dnsmasq" diff --git a/bin/wild-secret b/bin/wild-secret index 350e758..9141922 100755 --- a/bin/wild-secret +++ b/bin/wild-secret @@ -49,10 +49,13 @@ if [ -z "${KEY_PATH}" ]; then exit 1 fi -# Check if WC_HOME is set -if [ -z "${WC_HOME:-}" ]; then - echo "Error: WC_HOME environment variable not set" >&2 +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi SECRETS_FILE="${WC_HOME}/secrets.yaml" diff --git a/bin/wild-secret-set b/bin/wild-secret-set index ca4301e..7be9c62 100755 --- a/bin/wild-secret-set +++ b/bin/wild-secret-set @@ -57,10 +57,13 @@ if [ -z "${VALUE}" ]; then exit 1 fi -# Check if WC_HOME is set -if [ -z "${WC_HOME:-}" ]; then - echo "Error: WC_HOME environment variable not set" >&2 +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi SECRETS_FILE="${WC_HOME}/secrets.yaml" diff --git a/bin/wild-setup b/bin/wild-setup index 31ed8b7..9917b1e 100755 --- a/bin/wild-setup +++ b/bin/wild-setup @@ -3,18 +3,12 @@ set -e set -o pipefail -# Source common utilities -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" +# Parse arguments -# Initialize Wild-Cloud environment -init_wild_env - -# Phase tracking variables SKIP_SCAFFOLD=false SKIP_CLUSTER=false SKIP_SERVICES=false -# Parse arguments while [[ $# -gt 0 ]]; do case $1 in --skip-scaffold) @@ -71,31 +65,37 @@ while [[ $# -gt 0 ]]; do esac done -# Set up cloud directory (WC_HOME is where user's cloud will be) -WC_HOME="$(pwd)" -export WC_HOME +# Initialize Wild-Cloud environment -print_header "Wild-Cloud Complete Setup" -print_info "Running complete Wild-Cloud setup using modular components" +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." + exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env +fi + +print_header "Wild-Cloud Setup" +print_info "Running complete Wild-Cloud setup." echo "" # ============================================================================= -# SCAFFOLD SETUP +# WC_HOME SCAFFOLDING # ============================================================================= if [ "${SKIP_SCAFFOLD}" = false ]; then - print_header "Component 1: Scaffold Setup" - print_info "Running wild-setup-scaffold..." + print_header "Cloud Home Setup" + print_info "Scaffolding your cloud home..." if wild-setup-scaffold; then - print_success "Component 1 completed: Scaffold setup" + print_success "Cloud home setup completed" else - print_error "Component 1 failed: Scaffold setup" + print_error "Cloud home setup failed" exit 1 fi echo "" else - print_info "Skipping Component 1: Scaffold Setup" + print_info "Skipping Component 1: Cloud Home Setup" fi # ============================================================================= @@ -103,13 +103,13 @@ fi # ============================================================================= if [ "${SKIP_CLUSTER}" = false ]; then - print_header "Component 2: Cluster Setup" + print_header "Cluster Setup" print_info "Running wild-setup-cluster..." if wild-setup-cluster; then - print_success "Component 2 completed: Cluster setup" + print_success "Cluster setup completed" else - print_error "Component 2 failed: Cluster setup" + print_error "Cluster setup failed" exit 1 fi echo "" @@ -122,13 +122,13 @@ fi # ============================================================================= if [ "${SKIP_SERVICES}" = false ]; then - print_header "Component 3: Services Setup" + print_header "Services Setup" print_info "Running wild-setup-services..." if wild-setup-services; then - print_success "Component 3 completed: Services setup" + print_success "Services setup completed" else - print_error "Component 3 failed: Services setup" + print_error "Services setup failed" exit 1 fi echo "" @@ -142,34 +142,6 @@ fi print_header "Wild-Cloud Complete Setup Finished!" -print_success "All components completed successfully!" -echo "" - -print_info "What was accomplished:" -if [ "${SKIP_SCAFFOLD}" = false ]; then - print_info "✅ Component 1: Scaffold setup (cloud initialization)" -else - print_info "⏸️ Component 1: Scaffold setup (skipped)" -fi - -if [ "${SKIP_CLUSTER}" = false ]; then - print_info "✅ Component 2: Cluster setup (Phases 1-3)" -else - print_info "⏸️ Component 2: Cluster setup (skipped)" -fi - -if [ "${SKIP_SERVICES}" = false ]; then - print_info "✅ Component 3: Services setup (Phase 4)" -else - print_info "⏸️ Component 3: Services setup (skipped)" -fi - -echo "" -print_info "Individual components can be run separately:" -echo " - wild-setup-scaffold # Cloud initialization" -echo " - wild-setup-cluster # Cluster infrastructure" -echo " - wild-setup-services # Cluster services" - echo "" if [ "${SKIP_SERVICES}" = false ] && command -v kubectl >/dev/null 2>&1; then if [ -f "${WC_HOME}/config.yaml" ]; then diff --git a/bin/wild-setup-cluster b/bin/wild-setup-cluster index d4795f7..504bbd4 100755 --- a/bin/wild-setup-cluster +++ b/bin/wild-setup-cluster @@ -3,18 +3,12 @@ set -e set -o pipefail -# Source common utilities -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" +# Parse arguments -# Initialize Wild-Cloud environment -init_wild_env - -# Phase tracking variables SKIP_INSTALLER=false SKIP_HARDWARE=false SKIP_CONFIGS=false -# Parse arguments while [[ $# -gt 0 ]]; do case $1 in --skip-installer) @@ -62,8 +56,15 @@ while [[ $# -gt 0 ]]; do esac done -# Check if we're in a wild-cloud directory -check_wild_directory +# Initialize Wild-Cloud environment + +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." + exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env +fi # Check basic configuration check_basic_config @@ -103,25 +104,11 @@ if [ "${SKIP_HARDWARE}" = false ]; then GATEWAY_IP=$(ip route | grep default | awk '{print $3; exit}' 2>/dev/null || echo "192.168.1.1") SUBNET_PREFIX=$(echo "${CURRENT_IP}" | cut -d. -f1-3) - current_router_ip=$(get_current_config "cloud.router.ip") - router_ip=$(prompt_with_default "Router/Gateway IP" "${GATEWAY_IP}" "${current_router_ip}") - wild-config-set "cloud.router.ip" "${router_ip}" - - current_dns_ip=$(get_current_config "cloud.dns.ip") - dns_ip=$(prompt_with_default "DNS server IP (dnsmasq machine)" "${SUBNET_PREFIX}.50" "${current_dns_ip}") - wild-config-set "cloud.dns.ip" "${dns_ip}" - - current_dhcp_range=$(get_current_config "cloud.dhcpRange") - dhcp_range=$(prompt_with_default "DHCP range for dnsmasq" "${SUBNET_PREFIX}.100,${SUBNET_PREFIX}.200" "${current_dhcp_range}") - wild-config-set "cloud.dhcpRange" "${dhcp_range}" - - current_interface=$(get_current_config "cloud.dnsmasq.interface") - interface=$(prompt_with_default "Network interface for dnsmasq" "eth0" "${current_interface}") - wild-config-set "cloud.dnsmasq.interface" "${interface}" - - current_external_resolver=$(get_current_config "cloud.dns.externalResolver") - external_resolver=$(prompt_with_default "External DNS resolver" "1.1.1.1" "${current_external_resolver}") - wild-config-set "cloud.dns.externalResolver" "${external_resolver}" + prompt_if_unset_config "cloud.router.ip" "Router/Gateway IP" "${GATEWAY_IP}" + prompt_if_unset_config "cloud.dns.ip" "DNS server IP (dnsmasq machine)" "${SUBNET_PREFIX}.50" + prompt_if_unset_config "cloud.dhcpRange" "DHCP range for dnsmasq" "${SUBNET_PREFIX}.100,${SUBNET_PREFIX}.200" + prompt_if_unset_config "cloud.dnsmasq.interface" "Network interface for dnsmasq" "eth0" + prompt_if_unset_config "cloud.dns.externalResolver" "External DNS resolver" "1.1.1.1" print_success "Network configuration completed" echo "" @@ -134,24 +121,14 @@ if [ "${SKIP_HARDWARE}" = false ]; then SUBNET_PREFIX=$(echo "${CURRENT_IP}" | cut -d. -f1-3) # Talos version - current_talos_version=$(get_current_config "cluster.nodes.talos.version") - if [ -z "$current_talos_version" ] || [ "$current_talos_version" = "null" ]; then - talos_version=$(prompt_with_default "Talos version" "v1.10.4" "${current_talos_version}") - wild-config-set "cluster.nodes.talos.version" "${talos_version}" - else - talos_version="$current_talos_version" - fi + prompt_if_unset_config "cluster.nodes.talos.version" "Talos version" "v1.10.4" + talos_version=$(wild-config "cluster.nodes.talos.version") # MetalLB IP address pool - current_ip_pool=$(get_current_config "cluster.ipAddressPool") - if [ -z "$current_ip_pool" ] || [ "$current_ip_pool" = "null" ]; then - ip_pool=$(prompt_with_default "MetalLB IP address pool" "${SUBNET_PREFIX}.80-${SUBNET_PREFIX}.89" "${current_ip_pool}") - wild-config-set "cluster.ipAddressPool" "${ip_pool}" - else - ip_pool="$current_ip_pool" - fi + prompt_if_unset_config "cluster.ipAddressPool" "MetalLB IP address pool" "${SUBNET_PREFIX}.80-${SUBNET_PREFIX}.89" + ip_pool=$(wild-config "cluster.ipAddressPool") - # Load balancer IP (automatically set to first address in the pool) + # Load balancer IP (automatically set to first address in the pool if not set) current_lb_ip=$(get_current_config "cluster.loadBalancerIp") if [ -z "$current_lb_ip" ] || [ "$current_lb_ip" = "null" ]; then lb_ip=$(echo "${ip_pool}" | cut -d'-' -f1) @@ -183,12 +160,8 @@ if [ "${SKIP_HARDWARE}" = false ]; then fi # External DNS - current_owner_id=$(get_current_config "cluster.externalDns.ownerId") - if [ -z "$current_owner_id" ] || [ "$current_owner_id" = "null" ]; then - cluster_name=$(get_current_config "cluster.name") - owner_id=$(prompt_with_default "External DNS owner ID" "external-dns-${cluster_name}" "${current_owner_id}") - wild-config-set "cluster.externalDns.ownerId" "${owner_id}" - fi + cluster_name=$(get_current_config "cluster.name") + prompt_if_unset_config "cluster.externalDns.ownerId" "External DNS owner ID" "external-dns-${cluster_name}" print_success "Cluster configuration completed" echo "" @@ -208,9 +181,8 @@ if [ "${SKIP_HARDWARE}" = false ]; then print_info "Configure control plane nodes (you need at least 3 for HA):" echo "" - current_vip=$(get_current_config "cluster.nodes.control.vip") - vip=$(prompt_with_default "Control plane virtual IP" "${SUBNET_PREFIX}.90" "${current_vip}") - wild-config-set "cluster.nodes.control.vip" "${vip}" + prompt_if_unset_config "cluster.nodes.control.vip" "Control plane virtual IP" "${SUBNET_PREFIX}.90" + vip=$(wild-config "cluster.nodes.control.vip") # Automatically configure the first three IPs after VIP for control plane nodes vip_last_octet=$(echo "$vip" | cut -d. -f4) diff --git a/bin/wild-setup-scaffold b/bin/wild-setup-scaffold index dc50607..a15d44d 100755 --- a/bin/wild-setup-scaffold +++ b/bin/wild-setup-scaffold @@ -3,15 +3,11 @@ set -e set -o pipefail -# Source common utilities -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" -# Initialize Wild-Cloud environment -init_wild_env +# Parse arguments UPDATE=false -# Parse arguments while [[ $# -gt 0 ]]; do case $1 in --update) @@ -52,19 +48,18 @@ while [[ $# -gt 0 ]]; do esac done -# Set up cloud directory (WC_HOME is where user's cloud will be) -WC_HOME="$(pwd)" -export WC_HOME +# Initialize Wild-Cloud environment -# Template directory (in WC_ROOT, never written to) -TEMPLATE_DIR="${WC_ROOT}/setup/home-scaffold" -echo "Using template directory: ${TEMPLATE_DIR}" - -if [ ! -d "${TEMPLATE_DIR}" ]; then - echo "Error: Template directory not found at ${TEMPLATE_DIR}" +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi +TEMPLATE_DIR="${WC_ROOT}/setup/home-scaffold" + # Check if cloud already exists if [ -d ".wildcloud" ]; then echo "Wild-Cloud already exists in this directory." @@ -164,27 +159,26 @@ if [ ! -f "${WC_HOME}/config.yaml" ] || [ -z "$(get_current_config "operator.ema echo "" # Basic Information - current_email=$(get_current_config "operator.email") - email=$(prompt_with_default "Your email address (for Let's Encrypt certificates)" "" "${current_email}") - wild-config-set "operator.email" "${email}" + prompt_if_unset_config "operator.email" "Your email address (for Let's Encrypt certificates)" "" # Domain Configuration - current_base_domain=$(get_current_config "cloud.baseDomain") - base_domain=$(prompt_with_default "Your base domain name (e.g., example.com)" "" "${current_base_domain}") - wild-config-set "cloud.baseDomain" "${base_domain}" + prompt_if_unset_config "cloud.baseDomain" "Your base domain name (e.g., example.com)" "" + + # Get base domain to use as default for cloud domain + base_domain=$(wild-config "cloud.baseDomain") + prompt_if_unset_config "cloud.domain" "Your public cloud domain" "cloud.${base_domain}" + + # Get cloud domain to use as default for internal domain + domain=$(wild-config "cloud.domain") + prompt_if_unset_config "cloud.internalDomain" "Your internal cloud domain" "internal.${domain}" - current_domain=$(get_current_config "cloud.domain") - domain=$(prompt_with_default "Your public cloud domain" "cloud.${base_domain}" "${current_domain}") - wild-config-set "cloud.domain" "${domain}" - - current_internal_domain=$(get_current_config "cloud.internalDomain") - internal_domain=$(prompt_with_default "Your internal cloud domain" "internal.${domain}" "${current_internal_domain}") - wild-config-set "cloud.internalDomain" "${internal_domain}" - - # Derive cluster name from domain - cluster_name=$(echo "${domain}" | tr '.' '-' | tr '[:upper:]' '[:lower:]') - wild-config-set "cluster.name" "${cluster_name}" - print_info "Set cluster name to: ${cluster_name}" + # Derive cluster name from domain if not already set + current_cluster_name=$(get_current_config "cluster.name") + if [ -z "$current_cluster_name" ] || [ "$current_cluster_name" = "null" ]; then + cluster_name=$(echo "${domain}" | tr '.' '-' | tr '[:upper:]' '[:lower:]') + wild-config-set "cluster.name" "${cluster_name}" + print_info "Set cluster name to: ${cluster_name}" + fi print_success "Basic configuration completed" echo "" diff --git a/bin/wild-setup-services b/bin/wild-setup-services index f131c45..fb19e4e 100755 --- a/bin/wild-setup-services +++ b/bin/wild-setup-services @@ -3,13 +3,8 @@ set -e set -o pipefail -# Source common utilities -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" - -# Initialize Wild-Cloud environment -init_wild_env - # Parse arguments + SKIP_INSTALL=false while [[ $# -gt 0 ]]; do @@ -53,8 +48,15 @@ while [[ $# -gt 0 ]]; do esac done -# Check if we're in a wild-cloud directory -check_wild_directory +# Initialize Wild-Cloud environment + +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." + exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env +fi # Check basic configuration check_basic_config diff --git a/bin/wild-talos-iso b/bin/wild-talos-iso index cb3f47c..3715847 100755 --- a/bin/wild-talos-iso +++ b/bin/wild-talos-iso @@ -5,10 +5,13 @@ set -euo pipefail -# Check if WC_HOME is set -if [ -z "${WC_HOME:-}" ]; then - echo "Error: WC_HOME environment variable not set. Run \`source .env\`." +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi CONFIG_FILE="${WC_HOME}/config.yaml" diff --git a/bin/wild-talos-schema b/bin/wild-talos-schema index 28ddb69..64e23c0 100755 --- a/bin/wild-talos-schema +++ b/bin/wild-talos-schema @@ -6,10 +6,13 @@ set -euo pipefail -# Check if WC_HOME is set -if [ -z "${WC_HOME:-}" ]; then - echo "Error: WC_HOME environment variable not set. Run \`source .env\`." +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi CONFIG_FILE="${WC_HOME}/config.yaml" diff --git a/bin/wild-common.sh b/scripts/common.sh similarity index 92% rename from bin/wild-common.sh rename to scripts/common.sh index 303a42e..d4660ae 100644 --- a/bin/wild-common.sh +++ b/scripts/common.sh @@ -183,20 +183,28 @@ find_wc_home() { # Initialize common Wild-Cloud environment variables # Call this function at the beginning of scripts init_wild_env() { - # Get WC_ROOT (where this script and templates live) if [ -z "${WC_ROOT}" ]; then - WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[1]}")/.." && pwd)" - export WC_ROOT + print "Fail" + exit 1 + else + + # Check if WC_ROOT is a valid directory + if [ ! -d "${WC_ROOT}" ]; then + echo "ERROR: WC_ROOT directory does not exist! Did you install the wild-cloud root?" + exit 1 fi - # Set up cloud directory (WC_HOME is where user's cloud is) - # Look for .wildcloud directory in current path or ancestors + # Check if WC_ROOT/bin is in path + if [[ ":$PATH:" != *":$WC_ROOT/bin:"* ]]; then + echo "ERROR: Your wildcloud seed bin path should be in your PATH environment." + exit 1 + fi + + WC_HOME="$(find_wc_home)" if [ -z "${WC_HOME}" ]; then - local found_home - if found_home="$(find_wc_home)"; then - WC_HOME="$found_home" - export WC_HOME - fi + echo "ERROR: This command must be run from within a wildcloud home directory." + exit 1 + fi fi } diff --git a/setup/cluster/docker-registry/install.sh b/setup/cluster/docker-registry/install.sh index 1da4f56..988857d 100755 --- a/setup/cluster/docker-registry/install.sh +++ b/setup/cluster/docker-registry/install.sh @@ -2,13 +2,15 @@ set -e set -o pipefail -if [ -z "${WC_HOME}" ]; then - echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi -source "${WC_ROOT}/bin/wild-common.sh" - CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster" DOCKER_REGISTRY_DIR="${CLUSTER_SETUP_DIR}/docker-registry" diff --git a/setup/cluster/externaldns/install.sh b/setup/cluster/externaldns/install.sh index 7323844..dcf822f 100755 --- a/setup/cluster/externaldns/install.sh +++ b/setup/cluster/externaldns/install.sh @@ -2,13 +2,15 @@ set -e set -o pipefail -if [ -z "${WC_HOME}" ]; then - echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi -source "${WC_ROOT}/bin/wild-common.sh" - CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster" EXTERNALDNS_DIR="${CLUSTER_SETUP_DIR}/externaldns" diff --git a/setup/cluster/install-all.sh b/setup/cluster/install-all.sh index a469258..55a99e1 100755 --- a/setup/cluster/install-all.sh +++ b/setup/cluster/install-all.sh @@ -21,14 +21,8 @@ echo echo "Infrastructure setup complete!" echo -echo "Next steps:" -echo "1. Install Helm charts for non-infrastructure components" -INTERNAL_DOMAIN=$(wild-config cloud.internalDomain) -echo "2. Access the dashboard at: https://dashboard.${INTERNAL_DOMAIN}" -echo "3. Get the dashboard token with: ./bin/dashboard-token" -echo echo "To verify components, run:" echo "- kubectl get pods -n cert-manager" echo "- kubectl get pods -n externaldns" echo "- kubectl get pods -n kubernetes-dashboard" -echo "- kubectl get clusterissuers" \ No newline at end of file +echo "- kubectl get clusterissuers" diff --git a/setup/cluster/kubernetes-dashboard/install.sh b/setup/cluster/kubernetes-dashboard/install.sh index d16e551..1de2574 100755 --- a/setup/cluster/kubernetes-dashboard/install.sh +++ b/setup/cluster/kubernetes-dashboard/install.sh @@ -2,13 +2,15 @@ set -e set -o pipefail -if [ -z "${WC_HOME}" ]; then - echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi -source "${WC_ROOT}/bin/wild-common.sh" - CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster" KUBERNETES_DASHBOARD_DIR="${CLUSTER_SETUP_DIR}/kubernetes-dashboard" diff --git a/setup/cluster/longhorn/install.sh b/setup/cluster/longhorn/install.sh index 9116739..bf63898 100755 --- a/setup/cluster/longhorn/install.sh +++ b/setup/cluster/longhorn/install.sh @@ -2,9 +2,13 @@ set -e set -o pipefail -if [ -z "${WC_HOME}" ]; then - echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi source "${WC_ROOT}/bin/wild-common.sh" diff --git a/setup/cluster/metallb/install.sh b/setup/cluster/metallb/install.sh index 5a37eb6..425dc09 100755 --- a/setup/cluster/metallb/install.sh +++ b/setup/cluster/metallb/install.sh @@ -2,13 +2,15 @@ set -e set -o pipefail -if [ -z "${WC_HOME}" ]; then - echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi -source "${WC_ROOT}/bin/wild-common.sh" - CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster" METALLB_DIR="${CLUSTER_SETUP_DIR}/metallb" diff --git a/setup/cluster/nfs/install.sh b/setup/cluster/nfs/install.sh index e4c5e5b..67c8f88 100755 --- a/setup/cluster/nfs/install.sh +++ b/setup/cluster/nfs/install.sh @@ -2,13 +2,15 @@ set -e set -o pipefail -if [ -z "${WC_HOME}" ]; then - echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi -source "${WC_ROOT}/bin/wild-common.sh" - CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster" NFS_DIR="${CLUSTER_SETUP_DIR}/nfs" diff --git a/setup/cluster/traefik/install.sh b/setup/cluster/traefik/install.sh index 6c63bf8..151e55d 100755 --- a/setup/cluster/traefik/install.sh +++ b/setup/cluster/traefik/install.sh @@ -2,13 +2,15 @@ set -e set -o pipefail -if [ -z "${WC_HOME}" ]; then - echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi -source "${WC_ROOT}/bin/wild-common.sh" - CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster" TRAEFIK_DIR="${CLUSTER_SETUP_DIR}/traefik" diff --git a/setup/cluster/utils/install.sh b/setup/cluster/utils/install.sh index b02bbe7..045385f 100755 --- a/setup/cluster/utils/install.sh +++ b/setup/cluster/utils/install.sh @@ -2,13 +2,15 @@ set -e set -o pipefail -if [ -z "${WC_HOME}" ]; then - echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi -source "${WC_ROOT}/bin/wild-common.sh" - CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster" UTILS_DIR="${CLUSTER_SETUP_DIR}/utils" diff --git a/setup/cluster/validate-setup.sh b/setup/cluster/validate-setup.sh index e3e0aaa..628813b 100755 --- a/setup/cluster/validate-setup.sh +++ b/setup/cluster/validate-setup.sh @@ -1,10 +1,13 @@ #!/bin/bash set -e -# Check if WC_HOME is set (wildcloud environment sourced) -if [ -z "${WC_HOME}" ]; then - echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)" +# Initialize Wild-Cloud environment +if [ -z "${WC_ROOT}" ]; then + print "WC_ROOT is not set." exit 1 +else + source "${WC_ROOT}/scripts/common.sh" + init_wild_env fi # Navigate to script directory