diff --git a/.env.example b/.env.example index eba550a..ec84ff7 100644 --- a/.env.example +++ b/.env.example @@ -28,3 +28,9 @@ BOARD_URL=http://10.60.0.1 TEAM_TOKEN=your_team_token NUM_TEAMS=10 IP_TEAM_BASE=10.60. + +# Packmate Configuration +PACKMATE_LOCAL_IP=10.60.1.2 +NET_INTERFACE=eth0 +PACKMATE_WEB_LOGIN=admin +PACKMATE_WEB_PASSWORD=admin123 \ No newline at end of file diff --git a/setuper/setup.sh b/setuper/setup.sh index 8455bc1..31e73c9 100644 --- a/setuper/setup.sh +++ b/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 < .env < 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