Script 16 ยท Erupe Service

16. Setup Erupe Auto-Update & Management Script

Installs Erupe directory registration, update automation, service management shortcuts, logging helpers, and an interactive manager.

Category: Erupe Service Risk: High Lines: calculating Language: Bash / Linux
Back to index

What this script does

  • Standardize local Erupe management.
  • Build/restart Erupe service through systemd.
  • Expose shortcuts for logs, status, updates, and diagnostics.

Prerequisites

  • Erupe source/binary directory
  • Go toolchain if rebuilding
  • PostgreSQL reachable
  • Root access

Execution flow

  1. Registers Erupe path
  2. Creates validator/helper commands
  3. Builds update flow
  4. Writes systemd service
  5. Creates manager and shortcuts

Validation checklist

  • erupe-dir
  • erupe-manager
  • systemctl status erupe
  • journalctl -u erupe -f

Operational cautions

  • Restarts disconnect players.
  • Build failures can stop service deployment.
  • Service runs as root in the original flow; consider hardening.

Original script notes

โ„น๏ธ Script Info: Installs an intelligent updater and a comprehensive interactive management dashboard (`erupe-manager`). It dynamically detects your Erupe directory and creates shortcuts for logs, service controls, and network checks.

Script source
sudo bash -c "cat > /usr/local/bin/erupe-dir" << 'EOF'
#!/bin/bash
CONF_FILE="/opt/erupe_local_path.conf"

echo -e "\033[1;36m========================================================================================\033[0m"
echo -e "\033[1;33m๐Ÿ“‚ ERUPE DIRECTORY REGISTRY (erupe-dir)\033[0m"
echo -e "\033[1;36m========================================================================================\033[0m"
echo -e "This system requires you to register the \033[1;32mABSOLUTE PATH\033[0m of your Erupe server folder."
echo -e "This allows all management tools (erupe-manager, erupe-update) to dynamically adapt"
echo -e "to your installation location (e.g., /Erupe9.3b, /root/erupe-server, /home/ubuntu/erupe)."
echo -e "----------------------------------------------------------------------------------------"

if [ -f "$CONF_FILE" ]; then
    CUR_DIR=$(cat "$CONF_FILE")
    echo -e "Current Registered Directory: \033[1;32m$CUR_DIR\033[0m"
    if [ ! -d "$CUR_DIR" ]; then
        echo -e "\033[1;31mโš ๏ธ  WARNING: The registered directory no longer exists on this server!\033[0m"
    fi
    echo -e "----------------------------------------------------------------------------------------"
fi

while true; do
    read -p "Enter the absolute path to your Erupe server folder (or type 'cancel'): " NEW_DIR
    
    if [[ "${NEW_DIR,,}" == "cancel" ]]; then
        echo "โŒ Setup canceled."
        exit 0
    fi
    
    NEW_DIR=${NEW_DIR%/}
    
    if [ -z "$NEW_DIR" ]; then
        echo "โŒ Path cannot be empty."
        continue
    fi
    
    if [ ! -d "$NEW_DIR" ]; then
        echo -e "\033[1;31mโŒ ERROR: Directory '$NEW_DIR' does not exist.\033[0m"
        read -p "Are you sure you want to register a non-existent path? (y/N): " FORCE_REG
        if [[ "${FORCE_REG,,}" != "y" ]]; then
            continue
        fi
    fi
    
    echo "$NEW_DIR" > "$CONF_FILE"
    chmod 644 "$CONF_FILE"
    echo -e "\033[1;32mโœ… SUCCESS: Erupe directory globally registered to: $NEW_DIR\033[0m"
    echo -e "You can now use \033[1;33merupe-manager\033[0m and \033[1;33merupe-update\033[0m."
    break
done
EOF
sudo chmod +x /usr/local/bin/erupe-dir

# Helper script to retrieve the directory and enforce validation across all tools
sudo bash -c "cat > /usr/local/bin/erupe-path-validator" << 'EOF'
#!/bin/bash
CONF_FILE="/opt/erupe_local_path.conf"

if [ ! -f "$CONF_FILE" ]; then
    echo -e "\033[1;31m====================================================================\033[0m"
    echo -e "\033[1;31m๐Ÿ›‘ FATAL ERROR: ERUPE DIRECTORY NOT CONFIGURED\033[0m"
    echo -e "\033[1;31m====================================================================\033[0m"
    echo -e "You must register your server's installation path before using this tool."
    echo -e "Please run the following command in your terminal:"
    echo -e "\n   \033[1;33msudo erupe-dir\033[0m\n"
    exit 1
fi

ERUPE_DIR=$(cat "$CONF_FILE")

if [ ! -d "$ERUPE_DIR" ]; then
    echo -e "\033[1;31m====================================================================\033[0m"
    echo -e "\033[1;31m๐Ÿ›‘ FATAL ERROR: REGISTERED DIRECTORY MISSING\033[0m"
    echo -e "\033[1;31m====================================================================\033[0m"
    echo -e "The system is looking for the Erupe server at: \033[1;33m$ERUPE_DIR\033[0m"
    echo -e "However, this directory no longer exists (it may have been deleted or moved)."
    echo -e "Please update the registry by running:"
    echo -e "\n   \033[1;33msudo erupe-dir\033[0m\n"
    exit 1
fi

export ERUPE_DIR
EOF
sudo chmod +x /usr/local/bin/erupe-path-validator

sudo bash -c "cat > /usr/local/bin/erupe-update" << 'EOF'
#!/bin/bash
source /usr/local/bin/erupe-path-validator || exit 1

echo "================================================="
echo "๐Ÿ›‘ Ensuring Erupe Server is Stopped..."
echo "================================================="
sudo systemctl stop erupe 2>/dev/null || true
echo "โœ… Server safely stopped for maintenance."

TOTAL_RAM=$(free -m | awk '/^Mem:/{print $2}')
echo "================================================="
echo "๐Ÿ–ฅ๏ธ  System Detection: Total VPS RAM = ${TOTAL_RAM} MB"
echo "๐Ÿ“‚ Target Directory: $ERUPE_DIR"
echo "================================================="

echo "โš™๏ธ  Setup Mode Selection:"
echo "   1. Express Mode (Auto-apply recommended settings)"
echo "   2. Manual Mode  (Customize all settings)"
echo "   3. Base Mode    (Use system/Golang defaults for RAM & GOGC)"
read -p "Choose a setup mode (1, 2, or 3, default is 1) : " SETUP_MODE

if [[ -z "$SETUP_MODE" ]]; then SETUP_MODE="1"; fi
SKIP_MEM_CONF="n"

if [[ "$SETUP_MODE" == "1" ]]; then
    echo "================================================="
    echo "๐Ÿš€ EXPRESS MODE INITIATED..."
    echo "================================================="
    RAM_PCT=95
    GOGC_VAL=150
    LOG_CHOICE=4
    REBUILD_CHOICE="y"
    LOG_SAVE_CHOICE="n"
    
    echo "๐Ÿ‘‰ RAM Allocation : ${RAM_PCT}%"
    echo "๐Ÿ‘‰ GOGC Value     : ${GOGC_VAL}"
    echo "๐Ÿ‘‰ Log Level      : Error (Level 4)"
    echo "๐Ÿ‘‰ Rebuild Server : Yes"
    echo "๐Ÿ‘‰ Local Log File : No (Using journalctl only)"

elif [[ "$SETUP_MODE" == "3" ]]; then
    echo "================================================="
    echo "๐Ÿ› ๏ธ  BASE MODE INITIATED..."
    echo "================================================="
    echo "โญ๏ธ  Skipping RAM & GOGC limitation config (Using Golang Defaults)."
    SKIP_MEM_CONF="y"
    
    echo "================================================="
    echo "๐ŸŽ›๏ธ  Select Log Level for Erupe:"
    echo "   1. Debug  (Very detailed, for development)"
    echo "   2. Info   (Standard logging, shows connections)"
    echo "   3. Warn   (Warnings and errors only)"
    echo "   4. Error  (Critical errors only)"
    echo "   5. Silent (Minimum/No logs output)"
    read -p "Enter your choice (1-5, default is 4) : " LOG_CHOICE

else
    echo "================================================="
    echo "๐Ÿ› ๏ธ  MANUAL MODE INITIATED..."
    echo "================================================="
    read -p "What percentage (%) of RAM for Erupe-CE? (Recommended: 45) : " RAM_PCT
    read -p "Enter GOGC value (example: 200)                            : " GOGC_VAL

    echo "================================================="
    echo "๐ŸŽ›๏ธ  Select Log Level for Erupe:"
    echo "   1. Debug  (Very detailed, for development)"
    echo "   2. Info   (Standard logging, shows connections)"
    echo "   3. Warn   (Warnings and errors only)"
    echo "   4. Error  (Critical errors only)"
    echo "   5. Silent (Minimum/No logs output)"
    read -p "Enter your choice (1-5, default is 4) : " LOG_CHOICE
fi

case $LOG_CHOICE in
    1) LOG_ENV="debug"; LOG_FILTER="" ;;
    2) LOG_ENV="info";  LOG_FILTER="" ;;
    3) LOG_ENV="warn";  LOG_FILTER="| grep --line-buffered -iE \"warn|error|fatal\"" ;;
    4) LOG_ENV="error"; LOG_FILTER="| grep --line-buffered -iE \"error|fatal\"" ;;
    5) LOG_ENV="fatal"; LOG_FILTER="> /dev/null" ;;
    *) LOG_ENV="error"; LOG_FILTER="| grep --line-buffered -iE \"error|fatal\"" ;;
esac

# Generate Systemd memory configuration strings conditionally
SYS_GOGC=""
SYS_GOMEM=""
SYS_MEMMAX=""

if [[ "$SKIP_MEM_CONF" != "y" ]]; then
    LIMIT_MB=$((TOTAL_RAM * RAM_PCT / 100))
    MEM_MAX=$((LIMIT_MB + 100))
    SYS_GOGC="Environment=\"GOGC=${GOGC_VAL}\""
    SYS_GOMEM="Environment=\"GOMEMLIMIT=${LIMIT_MB}MiB\""
    SYS_MEMMAX="MemoryMax=${MEM_MAX}M"
fi

echo "๐Ÿ” Reading config.json to detect Database..."
if [ ! -f "$ERUPE_DIR/config.json" ]; then
    echo "โš ๏ธ  WARNING: config.json not found in $ERUPE_DIR! Database detection skipped."
    DB_HOST="127.0.0.1"
    DB_PORT="5432"
else
    DB_BLOCK=$(awk '/"Database":/,/}/' "$ERUPE_DIR/config.json")
    DB_HOST=$(echo "$DB_BLOCK" | grep -ioP '"Host"\s*:\s*"\K[^"]+' | head -n 1)
    DB_PORT=$(echo "$DB_BLOCK" | grep -ioP '"Port"\s*:\s*\K[0-9]+' | head -n 1)

    if [ -z "$DB_HOST" ]; then DB_HOST="127.0.0.1"; fi
    if [ -z "$DB_PORT" ]; then DB_PORT="5432"; fi
    echo "โœ… Target Database found: $DB_HOST:$DB_PORT"

    echo "โš™๏ธ  Forcing Log Level update in config.json to '${LOG_ENV}'..."
    sed -i -E "s/\"Level\":\s*\"[a-zA-Z]+\"/\"Level\": \"${LOG_ENV}\"/" "$ERUPE_DIR/config.json"
    echo "โœ… config.json Log Level updated!"
fi

echo "================================================="
echo "๐Ÿ› ๏ธ  Compilation Phase"
echo "================================================="
cd "$ERUPE_DIR" || exit 1

if [[ "$SETUP_MODE" == "2" || "$SETUP_MODE" == "3" ]]; then
    read -p "Do you want to rebuild erupe-ce? (y/n) : " REBUILD_CHOICE
fi

if [[ "$REBUILD_CHOICE" == "y" || "$REBUILD_CHOICE" == "Y" ]]; then
    echo "โš™๏ธ  Rebuilding erupe-ce..."
    rm -f erupe-ce || true
    go clean && go build -ldflags="-s -w" -o erupe-ce
    echo "โœ… Compilation complete!"
else
    echo "โญ๏ธ  Skipping compilation. Using existing erupe-ce binary."
fi

echo "================================================="
echo "๐Ÿ“ Log Management Setup"
echo "================================================="
if [[ "$SETUP_MODE" == "2" || "$SETUP_MODE" == "3" ]]; then
    read -p "Do you want to save logs automatically in the Erupe folder with a 25MB limit? (y/n) : " LOG_SAVE_CHOICE
fi

if [[ "$LOG_SAVE_CHOICE" == "y" || "$LOG_SAVE_CHOICE" == "Y" ]]; then
    echo "โš™๏ธ  Creating Game Server Executor & Log Monitor..."
    cat > "$ERUPE_DIR/run_erupe.sh" << SCRIPT_EOF
#!/bin/bash

LOG_FILE="$ERUPE_DIR/erupe_error.log"
MAX_LOG_SIZE=\$((25 * 1024 * 1024))

monitor_log_size() {
    while true; do
        if [ -f "\$LOG_FILE" ]; then
            FILE_SIZE=\$(stat -c%s "\$LOG_FILE" 2>/dev/null || echo 0)
            if [ "\$FILE_SIZE" -ge "\$MAX_LOG_SIZE" ]; then
                TIMESTAMP=\$(date +"%Y%m%d_%H%M%S")
                cp "\$LOG_FILE" "\${LOG_FILE}.\${TIMESTAMP}.bak"
                truncate -s 0 "\$LOG_FILE"
                echo "๐Ÿ“ [\$(date)] Log exceeded 25MB. Rotated to erupe_error.log.\${TIMESTAMP}.bak" >> "\$LOG_FILE"
            fi
        fi
        sleep 300
    done
}

monitor_log_size &
MONITOR_PID=\$!
trap "kill \$MONITOR_PID; exit" SIGINT SIGTERM

echo "๐Ÿš€ Starting Erupe-CE with local log monitoring..."
echo "" | $ERUPE_DIR/erupe-ce 2>&1 ${LOG_FILTER} | tee -a "\$LOG_FILE" &

ERUPE_PID=\$!
wait \$ERUPE_PID
SCRIPT_EOF
    
    chmod +x "$ERUPE_DIR/run_erupe.sh"
    EXEC_START_CMD="$ERUPE_DIR/run_erupe.sh"
    echo "โœ… run_erupe.sh log wrapper created."
else
    echo "โญ๏ธ  Skipping log file wrapper. Logs will only be managed internally by systemd journalctl."
    rm -f "$ERUPE_DIR/run_erupe.sh" || true
    EXEC_START_CMD="/bin/bash -c 'echo \"\" | exec $ERUPE_DIR/erupe-ce 2>&1 ${LOG_FILTER}'"
fi

echo "================================================="
echo "๐Ÿงน Safe Cache & Swap Clearance..."
echo "================================================="
sync; echo 1 > /proc/sys/vm/drop_caches 
echo "โœ… Page-cache safely cleared."

FREE_RAM=$(free -m | awk '/^Mem:/{print $7}') 
SWAP_USED=$(free -m | awk '/^Swap:/{print $3}')

if [ "$SWAP_USED" -gt 0 ] 2>/dev/null; then
    if [ "$FREE_RAM" -gt "$SWAP_USED" ] 2>/dev/null; then
        echo "๐Ÿ”„ Sufficient free RAM available ($FREE_RAM MB). Clearing Swap safely..."
        swapoff -a && swapon -a
        echo "โœ… Swap cleared."
    else
        echo "โš ๏ธ  WARNING: Not enough free RAM ($FREE_RAM MB) to absorb Swap usage ($SWAP_USED MB)."
        echo "โญ๏ธ  Skipping Swap clear to prevent Out-Of-Memory (OOM) Crash!"
    fi
else
    echo "โœ… No Swap in use. Skipping clear."
fi

echo "================================================="
echo "โš™๏ธ  Cleaning Up Previous Service and Updating systemd..."
echo "================================================="
systemctl disable erupe 2>/dev/null || true
rm -f /etc/systemd/system/erupe.service

sudo bash -c "cat > /etc/systemd/system/erupe.service" << INNER_EOF
[Unit]
Description=Erupe CE Game Server
After=network-online.target

[Service]
Type=simple
User=root
WorkingDirectory=${ERUPE_DIR}
SyslogIdentifier=ErupeCE
LimitNOFILE=65535

ExecStartPre=-/usr/bin/fuser -k 53310/tcp 53312/tcp
ExecStartPre=/bin/bash -c 'echo "Waiting for database at ${DB_HOST}:${DB_PORT}..."; while ! 2>/dev/null >/dev/tcp/${DB_HOST}/${DB_PORT}; do sleep 2; done; echo "Database connected!"'

${SYS_GOGC}
${SYS_GOMEM}
Environment="LOG_LEVEL=${LOG_ENV}"

ExecStart=${EXEC_START_CMD}

KillMode=control-group
KillSignal=SIGTERM
TimeoutStopSec=20
Restart=always
RestartSec=10
${SYS_MEMMAX}

[Install]
WantedBy=multi-user.target
INNER_EOF

echo "================================================="
echo "๐Ÿ•’ Setting up Automatic Log Cleanup (Cron)..."
echo "================================================="
echo "0 0 */4 * * root /usr/bin/journalctl --vacuum-time=3d" > /etc/cron.d/clear-journal
chmod 644 /etc/cron.d/clear-journal
echo "โœ… Cron job added: System logs will be cleared every 4 days."

echo "๐Ÿ”„ Reloading systemd, enabling, and restarting service..."
systemctl daemon-reload
systemctl enable erupe
systemctl restart erupe

echo "================================================="
echo "โœ… Rebuild and Setup Fully Completed!"
echo "================================================="
EOF
sudo chmod +x /usr/local/bin/erupe-update

echo "================================================="
echo "๐Ÿ”— Generating Quick Command Shortcuts..."
echo "================================================="
create_shortcut() {
    { echo '#!/bin/bash'; echo "source /usr/local/bin/erupe-path-validator || exit 1"; echo "$2"; } | sudo tee "/usr/local/bin/$1" > /dev/null
    sudo chmod +x "/usr/local/bin/$1"
}

create_shortcut "erupe-livelog" "sudo journalctl -u erupe -f"
create_shortcut "erupe-errlog" "sudo journalctl -u erupe -p err -f"
create_shortcut "erupe-clearlog" "sudo journalctl --vacuum-time=3d"
create_shortcut "erupe-locallog" "tail -f \$ERUPE_DIR/erupe_error.log"
create_shortcut "erupe-start" "sudo systemctl start erupe"
create_shortcut "erupe-stop" "sudo systemctl stop erupe"
create_shortcut "erupe-restart" "sudo systemctl restart erupe"
create_shortcut "erupe-status" "sudo systemctl status erupe"
create_shortcut "erupe-enable" "sudo systemctl enable erupe"
create_shortcut "erupe-disable" "sudo systemctl disable erupe"
create_shortcut "erupe-check" "sudo ss -tulpn | grep erupe"
create_shortcut "erupe-grep" "ps aux | grep erupe | grep -v grep"
create_shortcut "erupe-pgready" "pg_isready -p 5444"

create_shortcut "update-erupe" "erupe-update"
create_shortcut "help-erupe" "erupe-help"

sudo bash -c "cat > /usr/local/bin/erupe-help" << 'EOF'
#!/bin/bash
source /usr/local/bin/erupe-path-validator || exit 1
echo -e "\033[1;34m========================================================================================\033[0m"
echo -e "\033[1;32m๐ŸŽฎ ERUPE SERVICE MANAGEMENT COMMANDS\033[0m"
echo -e "\033[1;34m========================================================================================\033[0m"
printf "\033[1;37m %-15s | %-18s | %s\033[0m\n" "ACTION" "TERMINAL COMMAND" "DESCRIPTION"
echo -e "\033[1;34m----------------------------------------------------------------------------------------\033[0m"
printf " %-15s | \033[1;33m%-18s\033[0m | %s\n" "Manager Menu" "erupe-manager" "Opens the Interactive Erupe Command Menu"
printf " %-15s | \033[1;33m%-18s\033[0m | %s\n" "Set Directory" "erupe-dir" "Update the global Erupe installation path"
printf " %-15s | \033[1;33m%-18s\033[0m | %s\n" "Command Help" "erupe-help" "Displays this help menu"

echo -e "\n\033[1;36m--- LOG MANAGEMENT ---\033[0m"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "Live Log" "erupe-livelog" "Monitor server logs in real-time (Live)"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "Error Log" "erupe-errlog" "Displays only ERROR logs in real-time"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "Local Log" "erupe-locallog" "Monitors the local log file in your Erupe dir"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "Clear Logs" "erupe-clearlog" "Deletes system logs older than 3 days"

echo -e "\n\033[1;36m--- SERVICE CONTROL ---\033[0m"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "Start" "erupe-start" "Starts the Erupe server"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "Stop" "erupe-stop" "Stops the Erupe server safely"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "Restart" "erupe-restart" "Restarts the server (Disconnects players)"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "Status" "erupe-status" "Checks if the server is running & shows uptime"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "Enable" "erupe-enable" "Enables auto-start for the server on VPS reboot"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "Disable" "erupe-disable" "Disables the auto-start feature on reboot"

echo -e "\n\033[1;36m--- NETWORK & PROCESS ---\033[0m"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "Check Ports" "erupe-check" "Checks if game ports (53310, etc) are Open"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "Check Usage" "erupe-grep" "Checks CPU/RAM usage of the Erupe process"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "HTOP" "htop" "Monitors VPS resources visually"

echo -e "\n\033[1;36m--- DATABASE & UTILITY ---\033[0m"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "Update/Config" "erupe-update" "Runs the rebuild & optimization script"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "Check DB" "erupe-pgready" "Checks if the Postgres Database is ready"
printf " %-15s | \033[1;32m%-18s\033[0m | %s\n" "PgBouncer" "systemctl..." "Checks PgBouncer status (If installed)"

echo -e "\033[1;34m========================================================================================\033[0m"
EOF
sudo chmod +x /usr/local/bin/erupe-help

sudo bash -c "cat > /usr/local/bin/erupe-manager" << 'SCRIPT_EOF'
#!/bin/bash
source /usr/local/bin/erupe-path-validator || exit 1

while true; do
    echo ""
    echo -e "\033[1;34m========================================================================================\033[0m"
    echo -e "\033[1;32m๐ŸŽฎ ERUPE SERVER MANAGER\033[0m"
    echo -e "   \033[1;37mActive Directory: \033[1;33m$ERUPE_DIR\033[0m"
    echo -e "\033[1;34m========================================================================================\033[0m"
    printf "\033[1;37m %-3s | %-15s | %-18s | %s\033[0m\n" "NO" "ACTION" "TERMINAL COMMAND" "DESCRIPTION"
    echo -e "\033[1;34m----------------------------------------------------------------------------------------\033[0m"
    
    echo -e "\033[1;36m--- PATH CONFIGURATION ---\033[0m"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "1." "Change Directory" "[erupe-dir]" "Modify the global Erupe installation path"
    echo ""

    echo -e "\033[1;36m--- LOG MANAGEMENT ---\033[0m"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "2." "Live Log" "[erupe-livelog]" "Monitor server logs in real-time"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "3." "Error Log" "[erupe-errlog]" "Displays only ERROR logs in real-time"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "4." "Local Log" "[erupe-locallog]" "Monitors the local log file"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "5." "Clear Logs" "[erupe-clearlog]" "Deletes system logs older than 3 days"
    echo ""
    
    echo -e "\033[1;36m--- SERVICE CONTROL ---\033[0m"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "6." "Start" "[erupe-start]" "Starts the Erupe server"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "7." "Stop" "[erupe-stop]" "Stops the Erupe server safely"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "8." "Restart" "[erupe-restart]" "Restarts the server (Disconnects players)"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "9." "Status" "[erupe-status]" "Checks if the server is running & shows uptime"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "10." "Enable" "[erupe-enable]" "Enables auto-start for the server on VPS reboot"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "11." "Disable" "[erupe-disable]" "Disables the auto-start feature on reboot"
    echo ""
    
    echo -e "\033[1;36m--- NETWORK & PROCESS ---\033[0m"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "12." "Check Ports" "[erupe-check]" "Checks if game ports (53310, etc) are Open"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "13." "Check Usage" "[erupe-grep]" "Checks CPU/RAM usage of the Erupe process"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "14." "HTOP" "[htop]" "Monitors VPS resources visually"
    echo ""
    
    echo -e "\033[1;36m--- DATABASE & UTILITY ---\033[0m"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "15." "Update/Config" "[erupe-update]" "Runs the rebuild & optimization script"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "16." "Check DB" "[erupe-pgready]" "Checks if the Postgres Database is ready"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "17." "PgBouncer" "[systemctl...]" "Checks PgBouncer status (If installed)"
    printf " %-3s | %-15s | \033[1;33m%-18s\033[0m | %s\n" "18." "Command Help" "[erupe-help]" "Displays a list of all commands"
    echo ""
    
    printf "\033[1;31m %-3s | %-15s | %-18s | %s\033[0m\n" "19." "Exit Manager" "[-]" "Close this menu"
    echo -e "\033[1;34m========================================================================================\033[0m"
    
    read -p "Select an option (1-19): " MENU_OPT

    case $MENU_OPT in
        1) /usr/local/bin/erupe-dir ;;
        2) sudo journalctl -u erupe -f ;;
        3) sudo journalctl -u erupe -p err -f ;;
        4) tail -f "$ERUPE_DIR/erupe_error.log" ;;
        5) sudo journalctl --vacuum-time=3d ;;
        6) sudo systemctl start erupe; echo "โœ… Server Started." ;;
        7) sudo systemctl stop erupe; echo "โœ… Server Stopped." ;;
        8) sudo systemctl restart erupe; echo "โœ… Server Restarted." ;;
        9) sudo systemctl status erupe ;;
        10) sudo systemctl enable erupe; echo "โœ… Auto-start Enabled." ;;
        11) sudo systemctl disable erupe; echo "โœ… Auto-start Disabled." ;;
        12) sudo ss -tulpn | grep erupe ;;
        13) ps aux | grep erupe | grep -v grep ;;
        14) htop ;;
        15) /usr/local/bin/erupe-update ;;
        16) pg_isready -p 5444 ;;
        17) sudo systemctl status pgbouncer ;;
        18) /usr/local/bin/erupe-help ;;
        19) echo "โœ… Exiting Erupe Manager."; break ;;
        *) echo "โŒ Invalid option!" ;;
    esac
    
    if [[ "$MENU_OPT" != "1" && "$MENU_OPT" != "2" && "$MENU_OPT" != "3" && "$MENU_OPT" != "4" && "$MENU_OPT" != "14" && "$MENU_OPT" != "15" && "$MENU_OPT" != "19" ]]; then
        echo ""
        read -p "Press Enter to return to the menu..."
    fi
    
    source /usr/local/bin/erupe-path-validator || break
done
SCRIPT_EOF
sudo chmod +x /usr/local/bin/erupe-manager

echo "================================================="
echo "โœ… Setup Complete!"
echo "โš ๏ธ  IMPORTANT: You must register your Erupe directory first."
echo "๐Ÿ‘‰ Run 'erupe-dir' in your terminal."
echo "================================================="
EOF
Done