#!/bin/bash # FunMC Relay Server - Ubuntu Deployment Script # Usage: bash install.sh [master|worker] set -e MODE=${1:-master} INSTALL_DIR="/opt/funmc" NODE_NAME=${2:-"relay-node-1"} echo "==========================================" echo " FunMC Relay Server Installer" echo " Mode: $MODE" echo "==========================================" # Check if running as root if [ "$EUID" -ne 0 ]; then echo "Please run as root (sudo bash install.sh)" exit 1 fi # Install Node.js if not present if ! command -v node &> /dev/null; then echo "[1/6] Installing Node.js 20.x..." curl -fsSL https://deb.nodesource.com/setup_20.x | bash - apt-get install -y nodejs else echo "[1/6] Node.js already installed: $(node -v)" fi # Create installation directory echo "[2/6] Creating installation directory..." mkdir -p $INSTALL_DIR mkdir -p $INSTALL_DIR/logs # Copy server files echo "[3/6] Copying server files..." cp -r server/* $INSTALL_DIR/ # Install dependencies echo "[4/6] Installing dependencies..." cd $INSTALL_DIR npm install --production npm run build # Create .env file echo "[5/6] Creating configuration..." if [ "$MODE" = "master" ]; then cat > $INSTALL_DIR/.env << EOF RELAY_PORT=25565 API_PORT=3000 NODE_NAME=$NODE_NAME IS_MASTER=true SECRET=$(openssl rand -hex 16) MAX_ROOMS=100 MAX_PLAYERS_PER_ROOM=20 HEARTBEAT_INTERVAL=10000 LOG_LEVEL=info PUBLIC_HOST=0.0.0.0 EOF else read -p "Enter master node URL (e.g. http://master-ip:3000): " MASTER_URL cat > $INSTALL_DIR/.env << EOF RELAY_PORT=25565 API_PORT=3000 NODE_NAME=$NODE_NAME IS_MASTER=false MASTER_URL=$MASTER_URL SECRET=your-secret-key MAX_ROOMS=100 MAX_PLAYERS_PER_ROOM=20 HEARTBEAT_INTERVAL=10000 LOG_LEVEL=info PUBLIC_HOST=$(hostname -I | awk '{print $1}') EOF fi # Create systemd service echo "[6/6] Creating systemd service..." cat > /etc/systemd/system/funmc.service << EOF [Unit] Description=FunMC Minecraft Relay Server After=network.target [Service] Type=simple User=root WorkingDirectory=$INSTALL_DIR ExecStart=/usr/bin/node dist/index.js Restart=always RestartSec=5 Environment=NODE_ENV=production [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable funmc systemctl start funmc echo "" echo "==========================================" echo " FunMC Relay Server Installed!" echo "==========================================" echo " Mode: $MODE" echo " Install Dir: $INSTALL_DIR" echo " Relay Port: 25565" echo " API Port: 3000" echo "" echo " Commands:" echo " systemctl status funmc - Check status" echo " systemctl restart funmc - Restart" echo " systemctl stop funmc - Stop" echo " journalctl -u funmc -f - View logs" echo "" echo " Web UI: http://$(hostname -I | awk '{print $1}'):3000" echo "=========================================="