Update setup.sh
This commit is contained in:
184
setuper/setup.sh
184
setuper/setup.sh
@@ -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
|
set +e
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
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}"
|
CONTROLLER_API="${CONTROLLER_API:-http://localhost:8001}"
|
||||||
SECRET_TOKEN="${SECRET_TOKEN:-change-me-in-production}"
|
SECRET_TOKEN="${SECRET_TOKEN:-change-me-in-production}"
|
||||||
|
|
||||||
echo "=== A/D Infrastructure Setuper ==="
|
echo "=== A/D Infrastructure Setuper (NEW) ==="
|
||||||
echo "Services directory: $SERVICES_DIR"
|
echo "Game services directory: $SERVICES_DIR"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Create services directory
|
|
||||||
mkdir -p "$SERVICES_DIR"
|
|
||||||
|
|
||||||
# Function to call controller API
|
# Function to call controller API
|
||||||
call_api() {
|
call_api() {
|
||||||
local endpoint="$1"
|
local endpoint="$1"
|
||||||
local method="${2:-GET}"
|
local method="${2:-GET}"
|
||||||
local data="${3:-}"
|
local data="${3:-}"
|
||||||
|
|
||||||
if [ "$method" = "POST" ]; then
|
if [ "$method" = "POST" ]; then
|
||||||
curl -s -X POST "$CONTROLLER_API$endpoint" \
|
curl -s -X POST "$CONTROLLER_API$endpoint" \
|
||||||
-H "Authorization: Bearer $SECRET_TOKEN" \
|
-H "Authorization: Bearer $SECRET_TOKEN" \
|
||||||
@@ -34,12 +43,10 @@ call_api() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to setup Packmate
|
# Function to setup and start Packmate
|
||||||
setup_packmate() {
|
setup_packmate() {
|
||||||
echo "=== Setting up Packmate ==="
|
echo "=== Setting up Packmate ==="
|
||||||
|
local packmate_dir="$ROOT_DIR/packmate"
|
||||||
local packmate_dir="$SERVICES_DIR/packmate"
|
|
||||||
|
|
||||||
if [ -d "$packmate_dir" ]; then
|
if [ -d "$packmate_dir" ]; then
|
||||||
echo "Packmate directory already exists, updating..."
|
echo "Packmate directory already exists, updating..."
|
||||||
cd "$packmate_dir"
|
cd "$packmate_dir"
|
||||||
@@ -50,35 +57,27 @@ setup_packmate() {
|
|||||||
git clone --recursive https://gitlab.com/packmate/Packmate.git "$packmate_dir"
|
git clone --recursive https://gitlab.com/packmate/Packmate.git "$packmate_dir"
|
||||||
cd "$packmate_dir"
|
cd "$packmate_dir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create necessary directories
|
|
||||||
mkdir -p pcaps rsa_keys Packmate_stuff
|
mkdir -p pcaps rsa_keys Packmate_stuff
|
||||||
|
# .env and config generation (minimal)
|
||||||
# Create .env file
|
|
||||||
cat > .env <<'ENVEOF'
|
cat > .env <<'ENVEOF'
|
||||||
BUILD_TAG=latest
|
BUILD_TAG=latest
|
||||||
PACKMATE_DB_PASSWORD=${PACKMATE_DB_PASSWORD:-K604YnL3G1hp2RDkCZNjGpxbyNpNHTRb}
|
PACKMATE_DB_PASSWORD=K604YnL3G1hp2RDkCZNjGpxbyNpNHTRb
|
||||||
NET_INTERFACE=${NET_INTERFACE:-eth0}
|
NET_INTERFACE=eth0
|
||||||
PACKMATE_LOCAL_IP=${PACKMATE_LOCAL_IP:-10.60.0.1}
|
PACKMATE_LOCAL_IP=10.60.0.1
|
||||||
WEB_LOGIN=${WEB_LOGIN:-admin}
|
WEB_LOGIN=admin
|
||||||
WEB_PASSWORD=${WEB_PASSWORD:-admin123}
|
WEB_PASSWORD=admin123
|
||||||
ENVEOF
|
ENVEOF
|
||||||
|
|
||||||
# Create PostgreSQL config
|
|
||||||
cat > Packmate_stuff/postgresql.conf <<'PGEOF'
|
cat > Packmate_stuff/postgresql.conf <<'PGEOF'
|
||||||
port = 65001
|
port = 65001
|
||||||
max_connections = 100
|
max_connections = 100
|
||||||
shared_buffers = 128MB
|
shared_buffers = 128MB
|
||||||
PGEOF
|
PGEOF
|
||||||
|
|
||||||
# Create update script
|
|
||||||
cat > Packmate_stuff/update_db_config.sh <<'SHEOF'
|
cat > Packmate_stuff/update_db_config.sh <<'SHEOF'
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
cp /tmp/postgresql.conf /var/lib/postgresql/data/postgresql.conf
|
cp /tmp/postgresql.conf /var/lib/postgresql/data/postgresql.conf
|
||||||
SHEOF
|
SHEOF
|
||||||
chmod +x Packmate_stuff/update_db_config.sh
|
chmod +x Packmate_stuff/update_db_config.sh
|
||||||
|
# docker-compose.yml (minimal)
|
||||||
# Create docker-compose.yml
|
|
||||||
cat > docker-compose.yml <<'DCEOF'
|
cat > docker-compose.yml <<'DCEOF'
|
||||||
version: '3.8'
|
version: '3.8'
|
||||||
services:
|
services:
|
||||||
@@ -104,7 +103,6 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|
||||||
db:
|
db:
|
||||||
container_name: packmate-db
|
container_name: packmate-db
|
||||||
environment:
|
environment:
|
||||||
@@ -122,28 +120,17 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 15
|
retries: 15
|
||||||
DCEOF
|
DCEOF
|
||||||
|
echo "Starting Packmate containers..."
|
||||||
echo "Packmate setup complete!"
|
docker compose up -d
|
||||||
|
|
||||||
# Register with controller
|
|
||||||
echo "Registering Packmate with controller..."
|
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
|
call_api "/services" "POST" "{\"name\": \"packmate\", \"path\": \"$packmate_dir\", \"git_url\": \"https://gitlab.com/packmate/Packmate.git\"}"
|
||||||
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
|
|
||||||
|
|
||||||
cd "$SCRIPT_DIR"
|
cd "$SCRIPT_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to setup moded_distructive_farm
|
# Function to setup and start moded_distructive_farm
|
||||||
setup_farm() {
|
setup_farm() {
|
||||||
echo ""
|
|
||||||
echo "=== Setting up moded_distructive_farm ==="
|
echo "=== Setting up moded_distructive_farm ==="
|
||||||
|
local farm_dir="$ROOT_DIR/moded_distructive_farm"
|
||||||
local farm_dir="$SERVICES_DIR/moded_distructive_farm"
|
|
||||||
|
|
||||||
if [ -d "$farm_dir" ]; then
|
if [ -d "$farm_dir" ]; then
|
||||||
echo "Farm directory already exists, updating..."
|
echo "Farm directory already exists, updating..."
|
||||||
cd "$farm_dir"
|
cd "$farm_dir"
|
||||||
@@ -153,32 +140,19 @@ setup_farm() {
|
|||||||
git clone https://github.com/ilyastar9999/moded_distructive_farm.git "$farm_dir"
|
git clone https://github.com/ilyastar9999/moded_distructive_farm.git "$farm_dir"
|
||||||
cd "$farm_dir"
|
cd "$farm_dir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create .env file
|
|
||||||
cat > .env <<'ENVEOF'
|
cat > .env <<'ENVEOF'
|
||||||
# Database configuration
|
|
||||||
DB_PORT=5432
|
DB_PORT=5432
|
||||||
DB_HOST=postgres
|
DB_HOST=postgres
|
||||||
DB_USER=farm
|
DB_USER=farm
|
||||||
DB_PASS=${FARM_DB_PASS:-farmpassword123}
|
DB_PASS=farmpassword123
|
||||||
DB_NAME=farm
|
DB_NAME=farm
|
||||||
|
BOARD_URL=http://10.60.0.1
|
||||||
# Scoreboard configuration
|
TEAM_TOKEN=your-team-token
|
||||||
BOARD_URL=${BOARD_URL:-http://10.60.0.1}
|
WEB_PASSWORD=farmadmin
|
||||||
TEAM_TOKEN=${TEAM_TOKEN:-your-team-token}
|
NUM_TEAMS=10
|
||||||
|
IP_TEAM_BASE=10.60.
|
||||||
# Web interface
|
API_TOKEN=farm-api-token-123
|
||||||
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}
|
|
||||||
ENVEOF
|
ENVEOF
|
||||||
|
|
||||||
# Create docker-compose.yml
|
|
||||||
cat > docker-compose.yml <<'DCEOF'
|
cat > docker-compose.yml <<'DCEOF'
|
||||||
version: '3.8'
|
version: '3.8'
|
||||||
services:
|
services:
|
||||||
@@ -205,7 +179,6 @@ services:
|
|||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "3333:8000"
|
- "3333:8000"
|
||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:18
|
image: postgres:18
|
||||||
environment:
|
environment:
|
||||||
@@ -219,32 +192,18 @@ services:
|
|||||||
retries: 3
|
retries: 3
|
||||||
volumes:
|
volumes:
|
||||||
- farm-db:/var/lib/postgresql/data
|
- farm-db:/var/lib/postgresql/data
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
farm-db:
|
farm-db:
|
||||||
DCEOF
|
DCEOF
|
||||||
|
echo "Starting moded_distructive_farm containers..."
|
||||||
echo "moded_distructive_farm setup complete!"
|
docker compose up -d
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
cd "$SCRIPT_DIR"
|
cd "$SCRIPT_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to setup Firegex
|
# Function to setup and start Firegex
|
||||||
setup_firegex() {
|
setup_firegex() {
|
||||||
echo ""
|
|
||||||
echo "=== Setting up Firegex ==="
|
echo "=== Setting up Firegex ==="
|
||||||
|
local firegex_dir="$ROOT_DIR/firegex"
|
||||||
local firegex_dir="$SERVICES_DIR/firegex"
|
|
||||||
|
|
||||||
if [ -d "$firegex_dir" ]; then
|
if [ -d "$firegex_dir" ]; then
|
||||||
echo "Firegex directory already exists, updating..."
|
echo "Firegex directory already exists, updating..."
|
||||||
cd "$firegex_dir"
|
cd "$firegex_dir"
|
||||||
@@ -254,16 +213,11 @@ setup_firegex() {
|
|||||||
git clone https://github.com/Pwnzer0tt1/firegex.git "$firegex_dir"
|
git clone https://github.com/Pwnzer0tt1/firegex.git "$firegex_dir"
|
||||||
cd "$firegex_dir"
|
cd "$firegex_dir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create .env file
|
|
||||||
cat > .env <<'ENVEOF'
|
cat > .env <<'ENVEOF'
|
||||||
# Firegex configuration
|
TEAM_TOKEN=your-team-token
|
||||||
TEAM_TOKEN=${TEAM_TOKEN:-your-team-token}
|
SCOREBOARD_URL=http://10.60.0.1
|
||||||
SCOREBOARD_URL=${BOARD_URL:-http://10.60.0.1}
|
FIREGEX_PORT=5000
|
||||||
FIREGEX_PORT=${FIREGEX_PORT:-5000}
|
|
||||||
ENVEOF
|
ENVEOF
|
||||||
|
|
||||||
# Create docker-compose.yml if not exists
|
|
||||||
if [ ! -f "docker-compose.yml" ]; then
|
if [ ! -f "docker-compose.yml" ]; then
|
||||||
cat > docker-compose.yml <<'DCEOF'
|
cat > docker-compose.yml <<'DCEOF'
|
||||||
version: '3.8'
|
version: '3.8'
|
||||||
@@ -281,57 +235,53 @@ services:
|
|||||||
- "${FIREGEX_PORT:-5000}:5000"
|
- "${FIREGEX_PORT:-5000}:5000"
|
||||||
DCEOF
|
DCEOF
|
||||||
fi
|
fi
|
||||||
|
echo "Starting Firegex containers..."
|
||||||
echo "Firegex setup complete!"
|
docker compose up -d
|
||||||
|
|
||||||
# Register with controller
|
|
||||||
echo "Registering Firegex with controller..."
|
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
|
call_api "/services" "POST" "{\"name\": \"firegex\", \"path\": \"$firegex_dir\", \"git_url\": \"https://github.com/Pwnzer0tt1/firegex.git\"}"
|
||||||
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
|
|
||||||
|
|
||||||
cd "$SCRIPT_DIR"
|
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 setup flow
|
||||||
main() {
|
main() {
|
||||||
echo "Starting setup process..."
|
echo "Starting setup process..."
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Read configuration
|
|
||||||
read -p "Setup Packmate? (y/n): " setup_pm
|
read -p "Setup Packmate? (y/n): " setup_pm
|
||||||
read -p "Setup moded_distructive_farm? (y/n): " setup_fm
|
read -p "Setup moded_distructive_farm? (y/n): " setup_fm
|
||||||
read -p "Setup Firegex? (y/n): " setup_fg
|
read -p "Setup Firegex? (y/n): " setup_fg
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
if [ "$setup_pm" = "y" ]; then
|
if [ "$setup_pm" = "y" ]; then
|
||||||
setup_packmate
|
setup_packmate
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$setup_fm" = "y" ]; then
|
if [ "$setup_fm" = "y" ]; then
|
||||||
setup_farm
|
setup_farm
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$setup_fg" = "y" ]; then
|
if [ "$setup_fg" = "y" ]; then
|
||||||
setup_firegex
|
setup_firegex
|
||||||
fi
|
fi
|
||||||
|
start_game_services
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== Setup Complete! ==="
|
echo "=== Setup Complete! ==="
|
||||||
echo "Services have been configured in: $SERVICES_DIR"
|
echo "Game services have been started from: $SERVICES_DIR"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Next steps:"
|
echo "Next steps:"
|
||||||
echo " 1. Start the infrastructure: docker-compose up -d"
|
echo " 1. Access web dashboard: http://localhost:8000"
|
||||||
echo " 2. Access web dashboard: http://localhost:8000"
|
echo " 2. Register services via the dashboard if auto-registration failed"
|
||||||
echo " 3. Register services via the dashboard if auto-registration failed"
|
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run main if executed directly
|
|
||||||
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
|
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
|
||||||
main
|
main
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user