Shatteredvoid/scripts/setup.sh
MegaProxy 1a60cf55a3 Initial commit: Shattered Void MMO foundation
- Complete PostgreSQL database schema with 21+ tables
- Express.js server with dual authentication (player/admin)
- WebSocket support for real-time features
- Comprehensive middleware (auth, validation, logging, security)
- Game systems: colonies, resources, fleets, research, factions
- Plugin-based combat architecture
- Admin panel foundation
- Production-ready logging and error handling
- Docker support and CI/CD ready
- Complete project structure following CLAUDE.md patterns

🤖 Generated with Claude Code (https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-02 02:13:05 +00:00

172 lines
No EOL
4.9 KiB
Bash
Executable file

#!/bin/bash
# Shattered Void MMO - Setup Script
# Automates the initial setup process for development environment
set -e # Exit on any error
echo "🌌 Shattered Void MMO - Development Setup"
echo "========================================"
# Check prerequisites
echo "📋 Checking prerequisites..."
if ! command -v node &> /dev/null; then
echo "❌ Node.js is not installed. Please install Node.js 16+ and try again."
exit 1
fi
if ! command -v npm &> /dev/null; then
echo "❌ npm is not installed. Please install npm 8+ and try again."
exit 1
fi
if ! command -v psql &> /dev/null; then
echo "❌ PostgreSQL client is not installed. Please install PostgreSQL and try again."
exit 1
fi
if ! command -v redis-cli &> /dev/null; then
echo "⚠️ Redis client not found. Make sure Redis server is running."
fi
echo "✅ Prerequisites check passed"
# Check Node.js version
NODE_VERSION=$(node --version | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$NODE_VERSION" -lt 16 ]; then
echo "❌ Node.js version $NODE_VERSION is not supported. Please upgrade to Node.js 16+"
exit 1
fi
echo "✅ Node.js version check passed"
# Install dependencies
echo ""
echo "📦 Installing npm dependencies..."
npm install
echo "✅ Dependencies installed"
# Check for .env file
echo ""
echo "⚙️ Checking environment configuration..."
if [ ! -f ".env" ]; then
echo "📝 Creating .env file from template..."
cp .env.example .env
echo "⚠️ Please edit .env file with your database credentials and configuration"
echo " Database settings, JWT secret, and other configurations need to be updated"
else
echo "✅ .env file already exists"
fi
# Check database connection
echo ""
echo "🗄️ Checking database setup..."
# Load environment variables
if [ -f ".env" ]; then
export $(grep -v '^#' .env | xargs)
fi
# Set defaults if not in .env
DB_HOST=${DB_HOST:-localhost}
DB_PORT=${DB_PORT:-5432}
DB_NAME=${DB_NAME:-shattered_void_dev}
DB_USER=${DB_USER:-postgres}
echo "Attempting to connect to database: $DB_NAME@$DB_HOST:$DB_PORT"
# Test database connection
if ! pg_isready -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" 2>/dev/null; then
echo "❌ Cannot connect to PostgreSQL database"
echo " Please ensure PostgreSQL is running and the database exists"
echo " Run these commands to create the database:"
echo " sudo -u postgres psql"
echo " CREATE DATABASE $DB_NAME;"
echo " CREATE USER $DB_USER WITH PASSWORD 'your_password';"
echo " GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;"
echo " \\q"
exit 1
fi
echo "✅ Database connection successful"
# Apply database schema
echo ""
echo "🏗️ Setting up database schema..."
if psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -f database-schema.sql > /dev/null 2>&1; then
echo "✅ Database schema applied successfully"
else
echo "❌ Failed to apply database schema"
echo " Please check your database credentials and permissions"
exit 1
fi
# Run migrations
echo ""
echo "🔄 Running database migrations..."
if npm run db:migrate > /dev/null 2>&1; then
echo "✅ Database migrations completed"
else
echo "⚠️ Database migrations failed - this may be normal if already applied"
fi
# Run seeds
echo ""
echo "🌱 Seeding initial data..."
if npm run db:seed > /dev/null 2>&1; then
echo "✅ Initial data seeded successfully"
else
echo "❌ Failed to seed initial data"
echo " You may need to run: npm run db:seed manually"
fi
# Test Redis connection
echo ""
echo "📡 Testing Redis connection..."
REDIS_HOST=${REDIS_HOST:-localhost}
REDIS_PORT=${REDIS_PORT:-6379}
if redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" ping > /dev/null 2>&1; then
echo "✅ Redis connection successful"
else
echo "⚠️ Redis connection failed"
echo " Redis is optional but recommended for production"
echo " Install and start Redis server for optimal performance"
fi
# Create logs directory
echo ""
echo "📝 Setting up logging..."
mkdir -p logs
touch logs/combined.log
touch logs/error.log
echo "✅ Log directory created"
# Run linting
echo ""
echo "🔍 Running code quality checks..."
if npm run lint:check > /dev/null 2>&1; then
echo "✅ Code quality checks passed"
else
echo "⚠️ Code quality issues found - run 'npm run lint' to fix"
fi
# Final setup complete
echo ""
echo "🎉 Setup completed successfully!"
echo ""
echo "Next steps:"
echo "1. Review and update the .env file with your configuration"
echo "2. Start the development server: npm run dev"
echo "3. Visit http://localhost:3000 to verify the server is running"
echo ""
echo "Development commands:"
echo " npm run dev - Start development server with hot reload"
echo " npm test - Run test suite"
echo " npm run lint - Check and fix code style"
echo ""
echo "For more information, see README.md"
echo ""
echo "🌌 Welcome to Shattered Void MMO development!"