diff --git a/setuper/setup.sh b/setuper/setup.sh index 66dcb17..062b402 100644 --- a/setuper/setup.sh +++ b/setuper/setup.sh @@ -230,6 +230,16 @@ start_game_services() { fi # Create base64 auth string PACKMATE_AUTH=$(echo -n "$PACKMATE_WEB_LOGIN:$PACKMATE_WEB_PASSWORD" | base64) + PACKMATE_URL="http://${PACKMATE_LOCAL_IP}:65000" + # Try to obtain Packmate session cookie (JSESSIONID) using Basic auth + PACKMATE_COOKIE=$(curl -s -k -D - "$PACKMATE_URL/" \ + -H "Authorization: Basic $PACKMATE_AUTH" \ + -H "Accept: application/json" | grep -i 'Set-Cookie' | grep -i 'JSESSIONID' | head -n1 | sed 's/.*JSESSIONID=\([^;]*\).*/\1/') + if [ -n "$PACKMATE_COOKIE" ]; then + PACKMATE_COOKIE_HEADER="Cookie: JSESSIONID=$PACKMATE_COOKIE" + else + PACKMATE_COOKIE_HEADER="" + fi # Resolve SERVICES_DIR to absolute path case "$SERVICES_DIR" in @@ -288,15 +298,28 @@ start_game_services() { # 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 + # Try to add each exposed host port to Packmate echo "$service_ports" | tr ',' '\n' | while read port; do if [ -n "$port" ]; then - curl -s -X POST "${PACKMATE_URL}/api/service/" \ + # Primary attempt (with trailing slash) + status=$(curl -s -k -o /dev/null -w "%{http_code}" -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 + ${PACKMATE_COOKIE_HEADER:+-H "$PACKMATE_COOKIE_HEADER"} \ + -d "{\"name\": \"$service_name\", \"port\": $port}" ) + if [ "$status" -ge 200 ] && [ "$status" -lt 300 ]; then + echo "Packmate: registered $service_name port $port (status $status)" + else + # Fallback attempt without trailing slash + status2=$(curl -s -k -o /dev/null -w "%{http_code}" -X POST "${PACKMATE_URL}/api/service" \ + -H "Accept: application/json" \ + -H "Authorization: Basic $PACKMATE_AUTH" \ + -H "Content-Type: application/json" \ + ${PACKMATE_COOKIE_HEADER:+-H "$PACKMATE_COOKIE_HEADER"} \ + -d "{\"name\": \"$service_name\", \"port\": $port}" ) + echo "Packmate: register $service_name port $port -> status $status (fallback $status2)" + fi fi done fi