#!/bin/bash # Spinifex Platform Development Environment Setup # This script sets up a complete development environment for the Spinifex platform set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" MULGA_ROOT="$(cd "$PROJECT_ROOT/.." && pwd)" # Default configuration NATS_PORT=4222 PREDASTORE_PORT=8443 SPINIFEX_GATEWAY_PORT=9999 echo "๐Ÿš€ Setting up Spinifex development environment..." echo "Project root: $PROJECT_ROOT" # Function to check if command exists command_exists() { command -v "$1" >/dev/null 2>&1 } # Function to check if port is available port_available() { ! nc -z localhost "$1" 2>/dev/null } # Check dependencies echo "๐Ÿ” Checking dependencies..." # Check for required commands required_commands=("go" "make") missing_required=false for cmd in "${required_commands[@]}"; do if command_exists "$cmd"; then echo "โœ… $cmd found" else echo "โŒ $cmd not found. Please install $cmd" missing_required=true case "$cmd" in "go") echo " Install Go: https://golang.org/dl/" ;; esac fi done if [ "$missing_required" = true ]; then echo "โŒ Missing required dependencies. Cannot continue." exit 1 fi # Check optional commands optional_commands=("air" "nbdkit") for cmd in "${optional_commands[@]}"; do if command_exists "$cmd"; then echo "โœ… $cmd found (optional)" else echo "โš ๏ธ $cmd not found (optional)" case "$cmd" in "air") echo " Install air for hot reloading: go install github.com/air-verse/air@latest" ;; "nbdkit") echo " Install nbdkit: sudo apt-get install nbdkit (Ubuntu/Debian)" ;; esac fi done # Check OVN/OVS commands (required for VPC networking) echo "" echo "๐Ÿ” Checking OVN/OVS dependencies..." ovn_commands=("ovs-vsctl" "ovn-controller" "ovn-nbctl") ovn_ready=true for cmd in "${ovn_commands[@]}"; do if command_exists "$cmd"; then echo "โœ… $cmd found" else echo "โš ๏ธ $cmd not found (required for VPC networking)" ovn_ready=false fi done if [ "$ovn_ready" = false ]; then echo " Install OVN: sudo apt-get install ovn-central ovn-host openvswitch-switch" echo " Or run: make quickinstall" fi # Initialize br-int if OVS is available if command_exists "ovs-vsctl"; then echo "" echo "๐ŸŒ Checking OVS br-int bridge..." if ovs-vsctl br-exists br-int 2>/dev/null; then echo "โœ… br-int already exists" else echo "โš ๏ธ br-int not found. Run ./scripts/setup-ovn.sh to initialize OVN networking" fi fi # Check component repositories echo "" echo "๐Ÿ“ฆ Checking component repositories..." components=("viperblock" "predastore") for component in "${components[@]}"; do component_path="$MULGA_ROOT/$component" if [[ -d "$component_path" ]]; then echo "โœ… $component found at $component_path" if [[ -f "$component_path/go.mod" ]]; then echo " Go module verified" else echo " โš ๏ธ No go.mod found in $component" fi else echo "โŒ $component not found at $component_path" echo " Run: ./scripts/clone-deps.sh" fi done # Check port availability echo "" echo "๐Ÿ”Œ Checking port availability..." ports=("$NATS_PORT:NATS" "$PREDASTORE_PORT:Predastore" "$SPINIFEX_GATEWAY_PORT:Spinifex Gateway") for port_info in "${ports[@]}"; do port="${port_info%:*}" service="${port_info#*:}" if port_available "$port"; then echo "โœ… Port $port available for $service" else echo "โš ๏ธ Port $port already in use (needed for $service)" fi done # Build Spinifex first (needed for admin init) echo "" echo "๐Ÿ”จ Building Spinifex..." cd "$PROJECT_ROOT" make build echo "โœ… Spinifex built successfully" # Build components echo "" echo "๐Ÿ”จ Building components..." # Build Viperblock if [[ -d "$MULGA_ROOT/viperblock" ]]; then echo "๐Ÿ“ฆ Building Viperblock..." cd "$MULGA_ROOT/viperblock" make build echo "โœ… Viperblock built successfully" else echo "โš ๏ธ Viperblock directory not found, skipping build" fi # Build Predastore if [[ -d "$MULGA_ROOT/predastore" ]]; then echo "๐Ÿ“ฆ Building Predastore..." cd "$MULGA_ROOT/predastore" make build echo "โœ… Predastore built successfully" else echo "โš ๏ธ Predastore directory not found, skipping build" fi echo "" echo "๐ŸŽ‰ Development environment setup complete!" echo "" echo "๐Ÿ“‹ Next steps:" echo "" echo " 1. Setup OVN networking:" echo " ./scripts/setup-ovn.sh --management" echo "" echo " 2. Initialize Spinifex (creates ~/spinifex/ directories, config, certs, and installs CA):" echo " sudo ./bin/spx admin init --region ap-southeast-2 --az ap-southeast-2a --node node1 --nodes 1" echo "" echo " 3. Start services:" echo " ./scripts/start-dev.sh" echo "" echo "๐Ÿ”ง Development endpoints:" echo " - Spinifex Gateway: https://localhost:$SPINIFEX_GATEWAY_PORT" echo " - Predastore S3: https://localhost:$PREDASTORE_PORT" echo " - NATS: nats://localhost:$NATS_PORT" echo "" echo "๐Ÿงช Test with AWS CLI:" echo " export AWS_PROFILE=spinifex" echo " aws ec2 describe-instances"