#!/bin/bash # Validate Complete Setup # Checks that everything is configured correctly echo -e "\n========================================" echo -e " SETUP VALIDATION" echo -e "========================================\n" # Colors GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[0;33m' CYAN='\033[0;36m' NC='\033[0m' PASSED=0 FAILED=0 WARNINGS=0 # Check 1: Environment files echo -e "${CYAN}1. Environment Files${NC}" if [ -f "webapp/.env.local" ]; then echo -e " ${GREEN}✅ webapp/.env.local exists${NC}" if grep -q "NEXT_PUBLIC_ORCH_URL" webapp/.env.local; then echo -e " ${GREEN}✅ NEXT_PUBLIC_ORCH_URL configured${NC}" ((PASSED++)) else echo -e " ${RED}❌ NEXT_PUBLIC_ORCH_URL missing${NC}" ((FAILED++)) fi else echo -e " ${RED}❌ webapp/.env.local missing${NC}" ((FAILED++)) fi if [ -f "orchestrator/.env" ]; then echo -e " ${GREEN}✅ orchestrator/.env exists${NC}" if grep -q "DATABASE_URL" orchestrator/.env; then echo -e " ${GREEN}✅ DATABASE_URL configured${NC}" ((PASSED++)) else echo -e " ${YELLOW}⚠️ DATABASE_URL not set${NC}" ((WARNINGS++)) fi if grep -q "SESSION_SECRET" orchestrator/.env; then SECRET_LEN=$(grep "SESSION_SECRET" orchestrator/.env | cut -d'=' -f2 | tr -d '"' | wc -c) if [ $SECRET_LEN -ge 32 ]; then echo -e " ${GREEN}✅ SESSION_SECRET configured (length: $SECRET_LEN)${NC}" ((PASSED++)) else echo -e " ${RED}❌ SESSION_SECRET too short (min 32 chars)${NC}" ((FAILED++)) fi else echo -e " ${RED}❌ SESSION_SECRET missing${NC}" ((FAILED++)) fi else echo -e " ${RED}❌ orchestrator/.env missing${NC}" ((FAILED++)) fi # Check 2: Dependencies echo -e "\n${CYAN}2. Dependencies${NC}" if [ -d "webapp/node_modules" ]; then echo -e " ${GREEN}✅ Webapp dependencies installed${NC}" ((PASSED++)) else echo -e " ${RED}❌ Webapp dependencies missing${NC}" ((FAILED++)) fi if [ -d "orchestrator/node_modules" ]; then echo -e " ${GREEN}✅ Orchestrator dependencies installed${NC}" ((PASSED++)) else echo -e " ${RED}❌ Orchestrator dependencies missing${NC}" ((FAILED++)) fi if [ -d "contracts/node_modules" ]; then echo -e " ${GREEN}✅ Contracts dependencies installed${NC}" ((PASSED++)) else echo -e " ${YELLOW}⚠️ Contracts dependencies missing (optional)${NC}" ((WARNINGS++)) fi # Check 3: Database echo -e "\n${CYAN}3. Database${NC}" if command -v docker &> /dev/null; then if docker ps --filter "name=combo-postgres" --format "{{.Names}}" | grep -q "combo-postgres"; then echo -e " ${GREEN}✅ PostgreSQL container running${NC}" ((PASSED++)) # Test connection if nc -z localhost 5432 2>/dev/null; then echo -e " ${GREEN}✅ PostgreSQL accessible on port 5432${NC}" ((PASSED++)) else echo -e " ${YELLOW}⚠️ PostgreSQL not accessible on port 5432${NC}" ((WARNINGS++)) fi else echo -e " ${YELLOW}⚠️ PostgreSQL container not running${NC}" echo -e " Run: ./scripts/setup-database.sh" ((WARNINGS++)) fi else echo -e " ${YELLOW}⚠️ Docker not available${NC}" ((WARNINGS++)) fi # Check 4: Services echo -e "\n${CYAN}4. Services${NC}" if nc -z localhost 3000 2>/dev/null; then echo -e " ${GREEN}✅ Webapp running on port 3000${NC}" ((PASSED++)) else echo -e " ${YELLOW}⚠️ Webapp not running on port 3000${NC}" ((WARNINGS++)) fi if nc -z localhost 8080 2>/dev/null; then echo -e " ${GREEN}✅ Orchestrator running on port 8080${NC}" ((PASSED++)) # Test health endpoint if curl -s http://localhost:8080/health > /dev/null 2>&1; then HEALTH=$(curl -s http://localhost:8080/health) if echo "$HEALTH" | grep -q "healthy\|status"; then echo -e " ${GREEN}✅ Health endpoint responding${NC}" if command -v jq &> /dev/null; then DB_STATUS=$(echo "$HEALTH" | jq -r '.checks.database // "unknown"' 2>/dev/null) if [ "$DB_STATUS" = "up" ]; then echo -e " ${GREEN}✅ Database connected${NC}" ((PASSED++)) else echo -e " ${YELLOW}⚠️ Database status: $DB_STATUS${NC}" ((WARNINGS++)) fi fi else echo -e " ${YELLOW}⚠️ Health endpoint returned unexpected response${NC}" ((WARNINGS++)) fi else echo -e " ${YELLOW}⚠️ Health endpoint not accessible${NC}" ((WARNINGS++)) fi else echo -e " ${YELLOW}⚠️ Orchestrator not running on port 8080${NC}" ((WARNINGS++)) fi # Check 5: Scripts echo -e "\n${CYAN}5. Scripts${NC}" SCRIPTS=("start-all.sh" "check-status.sh" "setup-database.sh" "run-migrations.sh" "test-curl.sh") for script in "${SCRIPTS[@]}"; do if [ -f "scripts/$script" ] && [ -x "scripts/$script" ]; then echo -e " ${GREEN}✅ scripts/$script (executable)${NC}" ((PASSED++)) elif [ -f "scripts/$script" ]; then echo -e " ${YELLOW}⚠️ scripts/$script (not executable)${NC}" echo -e " Run: chmod +x scripts/$script" ((WARNINGS++)) else echo -e " ${RED}❌ scripts/$script missing${NC}" ((FAILED++)) fi done # Summary echo -e "\n========================================" echo -e " VALIDATION SUMMARY" echo -e "========================================\n" echo -e "${GREEN}✅ Passed: $PASSED${NC}" echo -e "${YELLOW}⚠️ Warnings: $WARNINGS${NC}" echo -e "${RED}❌ Failed: $FAILED${NC}" if [ $FAILED -eq 0 ]; then if [ $WARNINGS -eq 0 ]; then echo -e "\n${GREEN}✅ Setup is complete and valid!${NC}\n" exit 0 else echo -e "\n${YELLOW}⚠️ Setup is mostly complete, but has some warnings.${NC}\n" exit 0 fi else echo -e "\n${RED}❌ Setup has errors. Please fix them before continuing.${NC}\n" exit 1 fi