292 lines
8.7 KiB
Bash
292 lines
8.7 KiB
Bash
|
|
#!/bin/bash
|
|
# New Setuper script for A/D Infrastructure
|
|
# Downloads Packmate, moded_distructive_farm, Firegex OUTSIDE SERVICES_DIR, starts them, then starts all game services from SERVICES_DIR, and registers only Packmate and Firegex with controller.
|
|
|
|
set +e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
ROOT_DIR="$SCRIPT_DIR/.."
|
|
|
|
# Read .env for SERVICES_DIR, CONTROLLER_API, SECRET_TOKEN
|
|
ENV_FILE="$ROOT_DIR/.env"
|
|
if [ ! -f "$ENV_FILE" ]; then
|
|
echo ".env file not found in $ROOT_DIR. Exiting."
|
|
exit 1
|
|
fi
|
|
|
|
SERVICES_DIR=$(grep '^SERVICES_DIR=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
|
CONTROLLER_API=$(grep '^CONTROLLER_API=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
|
SECRET_TOKEN=$(grep '^SECRET_TOKEN=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
|
|
|
# Defaults
|
|
if [ -z "$CONTROLLER_API" ]; then
|
|
CONTROLLER_API="http://localhost:8001"
|
|
fi
|
|
if [ -z "$SECRET_TOKEN" ]; then
|
|
SECRET_TOKEN="change-me-in-production"
|
|
fi
|
|
|
|
echo "=== A/D Infrastructure Setuper (NEW) ==="
|
|
echo "Game services directory: $SERVICES_DIR"
|
|
echo ""
|
|
|
|
# Function to call controller API
|
|
call_api() {
|
|
local endpoint="$1"
|
|
local method="${2:-GET}"
|
|
local data="${3:-}"
|
|
if [ "$method" = "POST" ]; then
|
|
curl -s -X POST "$CONTROLLER_API$endpoint" \
|
|
-H "Authorization: Bearer $SECRET_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$data"
|
|
else
|
|
curl -s "$CONTROLLER_API$endpoint" \
|
|
-H "Authorization: Bearer $SECRET_TOKEN"
|
|
fi
|
|
}
|
|
|
|
# Function to setup and start Packmate
|
|
setup_packmate() {
|
|
echo "=== Setting up Packmate ==="
|
|
local packmate_dir="$ROOT_DIR/packmate"
|
|
if [ -d "$packmate_dir" ]; then
|
|
echo "Packmate directory already exists, updating..."
|
|
cd "$packmate_dir"
|
|
git pull
|
|
git submodule update --init --recursive
|
|
else
|
|
echo "Cloning Packmate with submodules..."
|
|
git clone --recursive https://gitlab.com/packmate/Packmate.git "$packmate_dir"
|
|
cd "$packmate_dir"
|
|
fi
|
|
mkdir -p pcaps rsa_keys Packmate_stuff
|
|
# Read config from parent .env
|
|
BOARD_URL=$(grep '^BOARD_URL=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
|
PACKMATE_LOCAL_IP=$(grep '^PACKMATE_LOCAL_IP=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
|
NET_INTERFACE=$(grep '^NET_INTERFACE=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
|
# Defaults if not set
|
|
if [ -z "$PACKMATE_LOCAL_IP" ]; then
|
|
PACKMATE_LOCAL_IP="10.60.1.2"
|
|
fi
|
|
if [ -z "$NET_INTERFACE" ]; then
|
|
NET_INTERFACE="eth0"
|
|
fi
|
|
# .env and config generation (minimal)
|
|
cat > .env <<ENVEOF
|
|
BUILD_TAG=latest
|
|
PACKMATE_DB_PASSWORD=K604YnL3G1hp2RDkCZNjGpxbyNpNHTRb
|
|
NET_INTERFACE=$NET_INTERFACE
|
|
PACKMATE_LOCAL_IP=$PACKMATE_LOCAL_IP
|
|
WEB_LOGIN=admin
|
|
WEB_PASSWORD=admin123
|
|
POSTGRES_USER=packmate
|
|
POSTGRES_PASSWORD=K604YnL3G1hp2RDkCZNjGpxbyNpNHTRb
|
|
POSTGRES_DB=packmate
|
|
DB_PASSWORD=K604YnL3G1hp2RDkCZNjGpxbyNpNHTRb
|
|
INTERFACE=$NET_INTERFACE
|
|
LOCAL_IP=$PACKMATE_LOCAL_IP
|
|
MODE=LIVE
|
|
OLD_STREAMS_CLEANUP_ENABLED=true
|
|
OLD_STREAMS_CLEANUP_INTERVAL=5
|
|
OLD_STREAMS_CLEANUP_THRESHOLD=240
|
|
ENVEOF
|
|
cat > Packmate_stuff/postgresql.conf <<'PGEOF'
|
|
port = 65001
|
|
max_connections = 100
|
|
shared_buffers = 128MB
|
|
PGEOF
|
|
cat > Packmate_stuff/update_db_config.sh <<'SHEOF'
|
|
#!/bin/bash
|
|
cp /tmp/postgresql.conf /var/lib/postgresql/data/postgresql.conf
|
|
SHEOF
|
|
chmod +x Packmate_stuff/update_db_config.sh
|
|
# docker-compose.yml (minimal)
|
|
cat > docker-compose.yml <<'DCEOF'
|
|
services:
|
|
packmate:
|
|
env_file:
|
|
- .env
|
|
container_name: packmate-app
|
|
network_mode: "host"
|
|
image: registry.gitlab.com/packmate/packmate:latest
|
|
volumes:
|
|
- "./pcaps/:/app/pcaps/:ro"
|
|
- "./rsa_keys/:/app/rsa_keys/:ro"
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
db:
|
|
container_name: packmate-db
|
|
env_file:
|
|
- .env
|
|
network_mode: "host"
|
|
image: postgres:15.2
|
|
volumes:
|
|
- "./Packmate_stuff/postgresql.conf:/tmp/postgresql.conf:ro"
|
|
- "./Packmate_stuff/update_db_config.sh:/docker-entrypoint-initdb.d/_update_db_config.sh:ro"
|
|
healthcheck:
|
|
test: [ "CMD-SHELL", "pg_isready -U packmate -p 65001" ]
|
|
interval: 2s
|
|
timeout: 5s
|
|
retries: 15
|
|
DCEOF
|
|
echo "Starting Packmate containers..."
|
|
docker compose up -d --no-build
|
|
echo "Registering Packmate with controller..."
|
|
call_api "/services" "POST" "{\"name\": \"packmate\", \"path\": \"$packmate_dir\", \"git_url\": \"https://gitlab.com/packmate/Packmate.git\"}"
|
|
cd "$SCRIPT_DIR"
|
|
}
|
|
|
|
# Function to setup and start moded_distructive_farm
|
|
setup_farm() {
|
|
echo "=== Setting up moded_distructive_farm ==="
|
|
local farm_dir="$ROOT_DIR/moded_distructive_farm"
|
|
if [ -d "$farm_dir" ]; then
|
|
echo "Farm directory already exists, updating..."
|
|
cd "$farm_dir"
|
|
git pull
|
|
else
|
|
echo "Cloning moded_distructive_farm..."
|
|
git clone https://github.com/ilyastar9999/moded_distructive_farm.git "$farm_dir"
|
|
cd "$farm_dir"
|
|
fi
|
|
# Read config from parent .env
|
|
BOARD_URL=$(grep '^BOARD_URL=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
|
TEAM_TOKEN=$(grep '^TEAM_TOKEN=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
|
NUM_TEAMS=$(grep '^NUM_TEAMS=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
|
IP_TEAM_BASE=$(grep '^IP_TEAM_BASE=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
|
cat > .env <<ENVEOF
|
|
DB_PORT=5432
|
|
DB_HOST=postgres
|
|
DB_USER=farm
|
|
DB_PASS=farmpassword123
|
|
DB_NAME=farm
|
|
BOARD_URL=$BOARD_URL
|
|
TEAM_TOKEN=$TEAM_TOKEN
|
|
WEB_PASSWORD=farmadmin
|
|
NUM_TEAMS=$NUM_TEAMS
|
|
IP_TEAM_BASE=$IP_TEAM_BASE
|
|
API_TOKEN=farm-api-token-123
|
|
POSTGRES_USER=farm
|
|
POSTGRES_PASSWORD=farmpassword123
|
|
POSTGRES_DB=farm
|
|
ENVEOF
|
|
cat > docker-compose.yml <<'DCEOF'
|
|
services:
|
|
farm:
|
|
image: ghcr.io/ilyastar9999/moded_distructive_farm:latest
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
env_file:
|
|
- .env
|
|
container_name: farm-app
|
|
restart: always
|
|
ports:
|
|
- "3333:8000"
|
|
postgres:
|
|
image: postgres:18
|
|
environment:
|
|
- POSTGRES_USER=farm
|
|
- POSTGRES_PASSWORD=farmpassword123
|
|
- POSTGRES_DB=farm
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U farm -d farm"]
|
|
interval: 10s
|
|
timeout: 3s
|
|
retries: 3
|
|
volumes:
|
|
- farm-db:/var/lib/postgresql/data
|
|
volumes:
|
|
farm-db:
|
|
DCEOF
|
|
echo "Starting moded_distructive_farm containers..."
|
|
docker compose up -d --no-build
|
|
cd "$SCRIPT_DIR"
|
|
}
|
|
|
|
# Function to setup and start Firegex
|
|
setup_firegex() {
|
|
echo "=== Setting up Firegex ==="
|
|
local firegex_dir="$ROOT_DIR/firegex"
|
|
if [ -d "$firegex_dir" ]; then
|
|
echo "Firegex directory already exists, updating..."
|
|
cd "$firegex_dir"
|
|
git pull
|
|
else
|
|
echo "Cloning Firegex..."
|
|
git clone https://github.com/Pwnzer0tt1/firegex.git "$firegex_dir"
|
|
cd "$firegex_dir"
|
|
fi
|
|
# Read config from parent .env
|
|
BOARD_URL=$(grep '^BOARD_URL=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
|
TEAM_TOKEN=$(grep '^TEAM_TOKEN=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
|
cat > .env <<ENVEOF
|
|
TEAM_TOKEN=$TEAM_TOKEN
|
|
SCOREBOARD_URL=$BOARD_URL
|
|
FIREGEX_PORT=5000
|
|
ENVEOF
|
|
if [ ! -f "docker-compose.yml" ]; then
|
|
cat > docker-compose.yml <<'DCEOF'
|
|
services:
|
|
firegex:
|
|
image: ghcr.io/pwnzer0tt1/firegex:latest
|
|
env_file:
|
|
- .env
|
|
container_name: firegex-app
|
|
restart: always
|
|
ports:
|
|
- "5000:5000"
|
|
DCEOF
|
|
fi
|
|
echo "Starting Firegex containers..."
|
|
docker compose up -d --no-build
|
|
echo "Registering Firegex with controller..."
|
|
call_api "/services" "POST" "{\"name\": \"firegex\", \"path\": \"$firegex_dir\", \"git_url\": \"https://github.com/Pwnzer0tt1/firegex.git\"}"
|
|
cd "$SCRIPT_DIR"
|
|
}
|
|
|
|
# Start all game services from SERVICES_DIR
|
|
start_game_services() {
|
|
echo "=== Starting all game services from $SERVICES_DIR ==="
|
|
if [ -f "$SERVICES_DIR/docker-compose.yml" ]; then
|
|
cd "$SERVICES_DIR"
|
|
docker compose up -d
|
|
cd "$SCRIPT_DIR"
|
|
else
|
|
echo "No docker-compose.yml found in $SERVICES_DIR, skipping game services startup."
|
|
fi
|
|
}
|
|
|
|
# Main setup flow
|
|
main() {
|
|
echo "Starting setup process..."
|
|
echo ""
|
|
read -p "Setup Packmate? (y/n): " setup_pm
|
|
read -p "Setup moded_distructive_farm? (y/n): " setup_fm
|
|
read -p "Setup Firegex? (y/n): " setup_fg
|
|
echo ""
|
|
if [ "$setup_pm" = "y" ]; then
|
|
setup_packmate
|
|
fi
|
|
if [ "$setup_fm" = "y" ]; then
|
|
setup_farm
|
|
fi
|
|
if [ "$setup_fg" = "y" ]; then
|
|
setup_firegex
|
|
fi
|
|
start_game_services
|
|
echo ""
|
|
echo "=== Setup Complete! ==="
|
|
echo "Game services have been started from: $SERVICES_DIR"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Access web dashboard: http://localhost:8000"
|
|
echo " 2. Register services via the dashboard if auto-registration failed"
|
|
echo ""
|
|
}
|
|
|
|
main
|