diff --git a/bin/cubesh b/bin/cubesh new file mode 100755 index 0000000..91a9a7f --- /dev/null +++ b/bin/cubesh @@ -0,0 +1,75 @@ +#!/bin/bash + +# CubeShell - Interactive cluster management shell + +echo "═══════════════════════════════════════════════════════════" +echo " CubeShell - Distributed Database Management Shell " +echo "═══════════════════════════════════════════════════════════" +echo "" + +# Check if Java is installed +if ! command -v java &> /dev/null; then + echo "❌ Java is not installed. Please install Java 21 or later." + exit 1 +fi + +# Check if Maven is installed +if ! command -v mvn &> /dev/null; then + echo "❌ Maven is not installed. Please install Maven 3.6+." + exit 1 +fi + +# Build if needed +if [ ! -f "target/cubecactus-1.0.0.jar" ]; then + echo "📦 Building Cube database..." + mvn clean package -DskipTests + if [ $? -ne 0 ]; then + echo "❌ Build failed" + exit 1 + fi +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 + ;; + *) + echo "Unknown option: $1" + echo "Usage: $0 [--host HOST] [--port PORT]" + exit 1 + ;; + esac +done + +echo "Connecting to: $HOST:$PORT" +echo "" + +# Build classpath with all dependencies +CLASSPATH="target/classes" + +# Add all Maven dependencies to classpath +if [ -d "target/lib" ]; then + for jar in target/lib/*.jar; do + CLASSPATH="$CLASSPATH:$jar" + done +fi + +# If lib directory doesn't exist, use Maven to get classpath +if [ ! -d "target/lib" ]; then + echo "📦 Resolving dependencies..." + CP=$(mvn dependency:build-classpath -q -Dmdep.outputFile=/dev/stdout) + CLASSPATH="target/classes:$CP" +fi + +# Start CubeShell +java -cp "$CLASSPATH" com.cube.shell.CubeShell --host "$HOST" --port "$PORT"