#!/usr/bin/env bash set -euo pipefail : "${NS2_GAME_PORT:=27015}" : "${NS2_WEB_PORT:=8080}" : "${NS2_WEB_INTERNAL_PORT:=8081}" : "${NS2_IP:=0.0.0.0}" if [[ "${NS2_DEBUG:-0}" == "1" ]]; then set -x fi ARGS=() ARGS+=("-ip" "${NS2_IP}") ARGS+=("-port" "${NS2_GAME_PORT}") if [[ "${NS2_INSECURE:-0}" == "1" ]]; then ARGS+=("-insecure") fi if [[ "${NS2_WEBADMIN:-0}" == "1" ]]; then ARGS+=("-webadmin" "-webport" "${NS2_WEB_INTERNAL_PORT}") fi if [[ -n "${NS2_NAME:-}" ]]; then ARGS+=("-name" "${NS2_NAME}") fi if [[ -n "${NS2_MAP:-}" ]]; then ARGS+=("-map" "${NS2_MAP}") fi if [[ -n "${NS2_LIMIT:-}" ]]; then ARGS+=("-limit" "${NS2_LIMIT}") fi if [[ -n "${NS2_PASSWORD:-}" ]]; then ARGS+=("-password" "${NS2_PASSWORD}") fi if [[ -n "${NS2_WEBUSER:-}" ]]; then ARGS+=("-webuser" "${NS2_WEBUSER}") fi if [[ -n "${NS2_WEBPASSWORD:-}" ]]; then ARGS+=("-webpassword" "${NS2_WEBPASSWORD}") fi if [[ -n "${NS2_WEBDOMAIN:-}" ]]; then ARGS+=("-webdomain" "${NS2_WEBDOMAIN}") fi if [[ -n "${NS2_WEBUSERS_FILE:-}" ]]; then ARGS+=("-webusers" "${NS2_WEBUSERS_FILE}") fi if [[ -n "${NS2_MODSTORAGE:-}" ]]; then ARGS+=("-modstorage" "${NS2_MODSTORAGE}") fi if [[ -n "${NS2_CONFIG_PATH:-}" ]]; then ARGS+=("-config_path" "${NS2_CONFIG_PATH}") fi if [[ -n "${NS2_LOGDIR:-}" ]]; then ARGS+=("-logdir" "${NS2_LOGDIR}") fi cd /opt/ns2 if [[ "${NS2_WEBADMIN:-0}" == "1" ]] && [[ "${NS2_WEB_PROXY:-1}" == "1" ]]; then if command -v socat >/dev/null 2>&1; then echo "[ns2] starting web proxy: 0.0.0.0:${NS2_WEB_PORT} -> 127.0.0.1:${NS2_WEB_INTERNAL_PORT}" >&2 socat TCP-LISTEN:"${NS2_WEB_PORT}",fork,reuseaddr,bind=0.0.0.0 TCP:127.0.0.1:"${NS2_WEB_INTERNAL_PORT}" & else echo "[ns2] warning: socat not installed; cannot start web proxy" >&2 fi fi WINE_BIN="" if command -v wine64 >/dev/null 2>&1; then WINE_BIN="wine64" elif command -v wine >/dev/null 2>&1; then WINE_BIN="wine" else echo "[ns2] error: wine executable not found in PATH" >&2 exit 127 fi if [[ $# -gt 0 ]]; then echo "[ns2] launching: ${WINE_BIN} x64/Server.exe $*" >&2 exec "${WINE_BIN}" x64/Server.exe "$@" fi echo "[ns2] launching: ${WINE_BIN} x64/Server.exe ${ARGS[*]}" >&2 exec "${WINE_BIN}" x64/Server.exe "${ARGS[@]}"