asd
This commit is contained in:
137
setuper/setup.sh
137
setuper/setup.sh
@@ -66,6 +66,8 @@ setup_packmate() {
|
||||
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)
|
||||
PACKMATE_WEB_LOGIN=$(grep '^PACKMATE_WEB_LOGIN=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
||||
PACKMATE_WEB_PASSWORD=$(grep '^PACKMATE_WEB_PASSWORD=' "$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"
|
||||
@@ -73,14 +75,20 @@ setup_packmate() {
|
||||
if [ -z "$NET_INTERFACE" ]; then
|
||||
NET_INTERFACE="eth0"
|
||||
fi
|
||||
if [ -z "$PACKMATE_WEB_LOGIN" ]; then
|
||||
PACKMATE_WEB_LOGIN="admin"
|
||||
fi
|
||||
if [ -z "$PACKMATE_WEB_PASSWORD" ]; then
|
||||
PACKMATE_WEB_PASSWORD="admin123"
|
||||
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
|
||||
WEB_LOGIN=$PACKMATE_WEB_LOGIN
|
||||
WEB_PASSWORD=$PACKMATE_WEB_PASSWORD
|
||||
POSTGRES_USER=packmate
|
||||
POSTGRES_PASSWORD=K604YnL3G1hp2RDkCZNjGpxbyNpNHTRb
|
||||
POSTGRES_DB=packmate
|
||||
@@ -134,6 +142,8 @@ services:
|
||||
DCEOF
|
||||
echo "Starting Packmate containers..."
|
||||
docker compose up -d --no-build
|
||||
echo "Waiting for Packmate to be ready..."
|
||||
sleep 5
|
||||
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"
|
||||
@@ -182,38 +192,23 @@ ENVEOF
|
||||
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
|
||||
|
||||
# Export environment variables for installer
|
||||
export SCOREBOARD_URL="$BOARD_URL"
|
||||
export TEAM_TOKEN="$TEAM_TOKEN"
|
||||
export FIREGEX_PORT="5000"
|
||||
export DOCKER_MODE="true"
|
||||
|
||||
mkdir -p "$firegex_dir"
|
||||
cd "$firegex_dir"
|
||||
|
||||
echo "Installing Firegex using official installer..."
|
||||
sh -c "$(curl -sLf https://pwnzer0tt1.it/firegex.sh)"
|
||||
|
||||
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"
|
||||
@@ -222,13 +217,75 @@ DCEOF
|
||||
# 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."
|
||||
|
||||
# Read Packmate config from .env
|
||||
PACKMATE_LOCAL_IP=$(grep '^PACKMATE_LOCAL_IP=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
||||
PACKMATE_WEB_LOGIN=$(grep '^PACKMATE_WEB_LOGIN=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
||||
PACKMATE_WEB_PASSWORD=$(grep '^PACKMATE_WEB_PASSWORD=' "$ENV_FILE" | cut -d'=' -f2- | tr -d '"' | xargs)
|
||||
if [ -z "$PACKMATE_LOCAL_IP" ]; then
|
||||
PACKMATE_LOCAL_IP="10.60.1.2"
|
||||
fi
|
||||
if [ -z "$PACKMATE_WEB_LOGIN" ]; then
|
||||
PACKMATE_WEB_LOGIN="admin"
|
||||
fi
|
||||
if [ -z "$PACKMATE_WEB_PASSWORD" ]; then
|
||||
PACKMATE_WEB_PASSWORD="admin123"
|
||||
fi
|
||||
# Create base64 auth string
|
||||
PACKMATE_AUTH=$(echo -n "$PACKMATE_WEB_LOGIN:$PACKMATE_WEB_PASSWORD" | base64)
|
||||
|
||||
# Resolve SERVICES_DIR to absolute path
|
||||
if [ "${SERVICES_DIR:0:1}" != "/" ]; then
|
||||
SERVICES_DIR="$ROOT_DIR/$SERVICES_DIR"
|
||||
fi
|
||||
|
||||
if [ ! -d "$SERVICES_DIR" ]; then
|
||||
echo "Services directory $SERVICES_DIR does not exist, skipping game services startup."
|
||||
return
|
||||
fi
|
||||
|
||||
# Find all subdirectories with docker-compose.yml
|
||||
echo "Scanning for services in $SERVICES_DIR..."
|
||||
local service_count=0
|
||||
|
||||
for service_dir in "$SERVICES_DIR"/*/ ; do
|
||||
if [ -f "$service_dir/docker-compose.yml" ]; then
|
||||
service_name=$(basename "$service_dir")
|
||||
echo "Starting service: $service_name"
|
||||
cd "$service_dir"
|
||||
docker compose up -d --no-build
|
||||
|
||||
# Extract ports from docker-compose.yml
|
||||
local service_ports=$(grep -E '^\s*-\s*"?[0-9]+:[0-9]+' "$service_dir/docker-compose.yml" | sed 's/.*"\?\([0-9]*\):[0-9]*.*/\1/' | tr '\n' ',' | sed 's/,$//')
|
||||
|
||||
# Register service with controller and send ports
|
||||
echo "Registering $service_name with controller..."
|
||||
local ports_json="[$service_ports]"
|
||||
ports_json=$(echo "$ports_json" | sed 's/,/,/g')
|
||||
call_api "/services" "POST" "{\"name\": \"$service_name\", \"path\": \"$service_dir\", \"ports\": $ports_json}"
|
||||
|
||||
# Add service to Packmate if Packmate is running
|
||||
if [ -n "$service_ports" ]; then
|
||||
echo "Adding $service_name to Packmate..."
|
||||
PACKMATE_URL="http://${PACKMATE_LOCAL_IP}:65000"
|
||||
# Try to add each port to Packmate
|
||||
IFS=',' read -ra PORTS <<< "$service_ports"
|
||||
for port in "${PORTS[@]}"; do
|
||||
curl -s -X POST "${PACKMATE_URL}/api/service/" \
|
||||
-H "Accept: application/json" \
|
||||
-H "Authorization: Basic $PACKMATE_AUTH" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"name\": \"$service_name\", \"port\": $port}" || true
|
||||
done
|
||||
fi
|
||||
|
||||
service_count=$((service_count + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Started and registered $service_count game service(s)"
|
||||
|
||||
cd "$SCRIPT_DIR"
|
||||
}
|
||||
|
||||
# Main setup flow
|
||||
@@ -239,13 +296,13 @@ main() {
|
||||
read -p "Setup moded_distructive_farm? (y/n): " setup_fm
|
||||
read -p "Setup Firegex? (y/n): " setup_fg
|
||||
echo ""
|
||||
if [ "$setup_pm" = "y" ]; then
|
||||
if [ "$setup_pm" != "n" ]; then
|
||||
setup_packmate
|
||||
fi
|
||||
if [ "$setup_fm" = "y" ]; then
|
||||
if [ "$setup_fm" != "n" ]; then
|
||||
setup_farm
|
||||
fi
|
||||
if [ "$setup_fg" = "y" ]; then
|
||||
if [ "$setup_fg" != "n" ]; then
|
||||
setup_firegex
|
||||
fi
|
||||
start_game_services
|
||||
|
||||
Reference in New Issue
Block a user