Update setup.sh

This commit is contained in:
ilyastar9999
2025-12-02 15:19:14 +03:00
parent 26f246f756
commit b5091d615f

View File

@@ -1,28 +1,37 @@
#!/bin/bash
# Setuper script for A/D Infrastructure
# Installs and configures: Packmate, moded_distructive_farm, Firegex
# Don't exit on error - we want to continue even if API registration fails
#!/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 "${BASH_SOURCE[0]}")" && pwd)"
SERVICES_DIR="${SERVICES_DIR:-$SCRIPT_DIR/../services}"
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 '"')
CONTROLLER_API=$(grep '^CONTROLLER_API=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"')
SECRET_TOKEN=$(grep '^SECRET_TOKEN=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"')
# Defaults
CONTROLLER_API="${CONTROLLER_API:-http://localhost:8001}"
SECRET_TOKEN="${SECRET_TOKEN:-change-me-in-production}"
echo "=== A/D Infrastructure Setuper ==="
echo "Services directory: $SERVICES_DIR"
echo "=== A/D Infrastructure Setuper (NEW) ==="
echo "Game services directory: $SERVICES_DIR"
echo ""
# Create services directory
mkdir -p "$SERVICES_DIR"
# 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" \
@@ -34,12 +43,10 @@ call_api() {
fi
}
# Function to setup Packmate
# Function to setup and start Packmate
setup_packmate() {
echo "=== Setting up Packmate ==="
local packmate_dir="$SERVICES_DIR/packmate"
local packmate_dir="$ROOT_DIR/packmate"
if [ -d "$packmate_dir" ]; then
echo "Packmate directory already exists, updating..."
cd "$packmate_dir"
@@ -50,35 +57,27 @@ setup_packmate() {
git clone --recursive https://gitlab.com/packmate/Packmate.git "$packmate_dir"
cd "$packmate_dir"
fi
# Create necessary directories
mkdir -p pcaps rsa_keys Packmate_stuff
# Create .env file
# .env and config generation (minimal)
cat > .env <<'ENVEOF'
BUILD_TAG=latest
PACKMATE_DB_PASSWORD=${PACKMATE_DB_PASSWORD:-K604YnL3G1hp2RDkCZNjGpxbyNpNHTRb}
NET_INTERFACE=${NET_INTERFACE:-eth0}
PACKMATE_LOCAL_IP=${PACKMATE_LOCAL_IP:-10.60.0.1}
WEB_LOGIN=${WEB_LOGIN:-admin}
WEB_PASSWORD=${WEB_PASSWORD:-admin123}
PACKMATE_DB_PASSWORD=K604YnL3G1hp2RDkCZNjGpxbyNpNHTRb
NET_INTERFACE=eth0
PACKMATE_LOCAL_IP=10.60.0.1
WEB_LOGIN=admin
WEB_PASSWORD=admin123
ENVEOF
# Create PostgreSQL config
cat > Packmate_stuff/postgresql.conf <<'PGEOF'
port = 65001
max_connections = 100
shared_buffers = 128MB
PGEOF
# Create update script
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
# Create docker-compose.yml
# docker-compose.yml (minimal)
cat > docker-compose.yml <<'DCEOF'
version: '3.8'
services:
@@ -104,7 +103,6 @@ services:
depends_on:
db:
condition: service_healthy
db:
container_name: packmate-db
environment:
@@ -122,28 +120,17 @@ services:
timeout: 5s
retries: 15
DCEOF
echo "Packmate setup complete!"
# Register with controller
echo "Starting Packmate containers..."
docker compose up -d
echo "Registering Packmate with controller..."
if call_api "/services" "POST" "{\"name\": \"packmate\", \"path\": \"$packmate_dir\", \"git_url\": \"https://gitlab.com/packmate/Packmate.git\"}" 2>/dev/null; then
echo "✓ Packmate registered with controller"
else
echo "⚠ Warning: Could not register with controller (is it running?)"
echo " You can register manually later via the web dashboard"
fi
call_api "/services" "POST" "{\"name\": \"packmate\", \"path\": \"$packmate_dir\", \"git_url\": \"https://gitlab.com/packmate/Packmate.git\"}"
cd "$SCRIPT_DIR"
}
# Function to setup moded_distructive_farm
# Function to setup and start moded_distructive_farm
setup_farm() {
echo ""
echo "=== Setting up moded_distructive_farm ==="
local farm_dir="$SERVICES_DIR/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"
@@ -153,32 +140,19 @@ setup_farm() {
git clone https://github.com/ilyastar9999/moded_distructive_farm.git "$farm_dir"
cd "$farm_dir"
fi
# Create .env file
cat > .env <<'ENVEOF'
# Database configuration
DB_PORT=5432
DB_HOST=postgres
DB_USER=farm
DB_PASS=${FARM_DB_PASS:-farmpassword123}
DB_PASS=farmpassword123
DB_NAME=farm
# Scoreboard configuration
BOARD_URL=${BOARD_URL:-http://10.60.0.1}
TEAM_TOKEN=${TEAM_TOKEN:-your-team-token}
# Web interface
WEB_PASSWORD=${FARM_WEB_PASSWORD:-farmadmin}
# Game configuration
NUM_TEAMS=${NUM_TEAMS:-10}
IP_TEAM_BASE=${IP_TEAM_BASE:-10.60.}
# API Token
API_TOKEN=${FARM_API_TOKEN:-farm-api-token-123}
BOARD_URL=http://10.60.0.1
TEAM_TOKEN=your-team-token
WEB_PASSWORD=farmadmin
NUM_TEAMS=10
IP_TEAM_BASE=10.60.
API_TOKEN=farm-api-token-123
ENVEOF
# Create docker-compose.yml
cat > docker-compose.yml <<'DCEOF'
version: '3.8'
services:
@@ -205,7 +179,6 @@ services:
restart: always
ports:
- "3333:8000"
postgres:
image: postgres:18
environment:
@@ -219,32 +192,18 @@ services:
retries: 3
volumes:
- farm-db:/var/lib/postgresql/data
volumes:
farm-db:
DCEOF
echo "moded_distructive_farm setup complete!"
# Register with controller
echo "Registering farm with controller..."
if call_api "/services" "POST" "{\"name\": \"farm\", \"path\": \"$farm_dir\", \"git_url\": \"https://github.com/ilyastar9999/moded_distructive_farm.git\"}" 2>/dev/null; then
echo "✓ Farm registered with controller"
else
echo "⚠ Warning: Could not register with controller (is it running?)"
echo " You can register manually later via the web dashboard"
fi
echo "Starting moded_distructive_farm containers..."
docker compose up -d
cd "$SCRIPT_DIR"
}
# Function to setup Firegex
# Function to setup and start Firegex
setup_firegex() {
echo ""
echo "=== Setting up Firegex ==="
local firegex_dir="$SERVICES_DIR/firegex"
local firegex_dir="$ROOT_DIR/firegex"
if [ -d "$firegex_dir" ]; then
echo "Firegex directory already exists, updating..."
cd "$firegex_dir"
@@ -254,16 +213,11 @@ setup_firegex() {
git clone https://github.com/Pwnzer0tt1/firegex.git "$firegex_dir"
cd "$firegex_dir"
fi
# Create .env file
cat > .env <<'ENVEOF'
# Firegex configuration
TEAM_TOKEN=${TEAM_TOKEN:-your-team-token}
SCOREBOARD_URL=${BOARD_URL:-http://10.60.0.1}
FIREGEX_PORT=${FIREGEX_PORT:-5000}
TEAM_TOKEN=your-team-token
SCOREBOARD_URL=http://10.60.0.1
FIREGEX_PORT=5000
ENVEOF
# Create docker-compose.yml if not exists
if [ ! -f "docker-compose.yml" ]; then
cat > docker-compose.yml <<'DCEOF'
version: '3.8'
@@ -281,57 +235,53 @@ services:
- "${FIREGEX_PORT:-5000}:5000"
DCEOF
fi
echo "Firegex setup complete!"
# Register with controller
echo "Starting Firegex containers..."
docker compose up -d
echo "Registering Firegex with controller..."
if call_api "/services" "POST" "{\"name\": \"firegex\", \"path\": \"$firegex_dir\", \"git_url\": \"https://github.com/Pwnzer0tt1/firegex.git\"}" 2>/dev/null; then
echo "✓ Firegex registered with controller"
else
echo "⚠ Warning: Could not register with controller (is it running?)"
echo " You can register manually later via the web dashboard"
fi
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 configuration
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 "Services have been configured in: $SERVICES_DIR"
echo "Game services have been started from: $SERVICES_DIR"
echo ""
echo "Next steps:"
echo " 1. Start the infrastructure: docker-compose up -d"
echo " 2. Access web dashboard: http://localhost:8000"
echo " 3. Register services via the dashboard if auto-registration failed"
echo " 1. Access web dashboard: http://localhost:8000"
echo " 2. Register services via the dashboard if auto-registration failed"
echo ""
}
# Run main if executed directly
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
main
fi