Newer
Older
cactus / run-shell.sh
@agalyaramadoss agalyaramadoss on 16 Feb 2 KB added document
#!/bin/bash

# CubeShell Launcher - Using Maven Exec Plugin
# This is the most reliable method to run CubeShell

set -e

# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

echo -e "${BLUE}╔══════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║              CubeShell v2.0.0                            ║${NC}"
echo -e "${BLUE}║         Distributed Database Interactive Shell          ║${NC}"
echo -e "${BLUE}║              Phase 2: Cluster Edition                   ║${NC}"
echo -e "${BLUE}╚══════════════════════════════════════════════════════════╝${NC}"
echo ""

# Check Java
if ! command -v java &> /dev/null; then
    echo -e "${RED}❌ Java not found. Please install Java 21+${NC}"
    exit 1
fi

JAVA_VERSION=$(java -version 2>&1 | head -1 | cut -d'"' -f2 | cut -d'.' -f1)
if [ "$JAVA_VERSION" -lt 21 ]; then
    echo -e "${RED}❌ Java 21+ required. Found: $JAVA_VERSION${NC}"
    exit 1
fi

# Check Maven
if ! command -v mvn &> /dev/null; then
    echo -e "${RED}❌ Maven not found. Please install Maven 3.6+${NC}"
    exit 1
fi

# Parse arguments
HOST="localhost"
PORT="8080"

while [[ $# -gt 0 ]]; do
    case $1 in
        --host|-h)
            HOST="$2"
            shift 2
            ;;
        --port|-p)
            PORT="$2"
            shift 2
            ;;
        --help)
            echo "Usage: $0 [OPTIONS]"
            echo ""
            echo "Options:"
            echo "  -h, --host HOST    Database host (default: localhost)"
            echo "  -p, --port PORT    Database port (default: 8080)"
            echo "  --help             Show this help message"
            exit 0
            ;;
        *)
            echo -e "${RED}Unknown option: $1${NC}"
            echo "Use --help for usage information"
            exit 1
            ;;
    esac
done

echo -e "${GREEN}✓ Java version: $JAVA_VERSION${NC}"
echo -e "${GREEN}✓ Connecting to: $HOST:$PORT${NC}"
echo ""

# Compile if needed
if [ ! -f "target/classes/com/cube/shell/CubeShell.class" ]; then
    echo -e "${BLUE}📦 Compiling project...${NC}"
    mvn compile -q
    if [ $? -ne 0 ]; then
        echo -e "${RED}❌ Compilation failed${NC}"
        exit 1
    fi
    echo -e "${GREEN}✓ Compilation successful${NC}"
    echo ""
fi

# Run using Maven exec plugin
echo -e "${BLUE}🚀 Starting CubeShell...${NC}"
echo ""

mvn exec:java \
    -Dexec.mainClass="com.cube.shell.CubeShell" \
    -Dexec.args="--host $HOST --port $PORT" \
    -Dexec.cleanupDaemonThreads=false \
    -q