#!/bin/bash set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PORT="${PORT:-7250}" IMAGE="towercore:final-mips64le" TAR="$ROOT/images/towercore-mips64le.tar" if [ ! -f "$TAR" ] && [ -f "$ROOT/towercore-mips64le.tar" ]; then TAR="$ROOT/towercore-mips64le.tar" fi echo "loading MIPS image..." docker load -i "$TAR" >/dev/null mips_can_exec() { local out out="$(docker run --rm --platform linux/mips64le \ --entrypoint /towerctl "$IMAGE" 2>&1 || true)" ! grep -qi 'exec format error' <<<"$out" } if ! mips_can_exec; then echo "registering linux/mips64le binfmt..." docker run --privileged --rm tonistiigi/binfmt --install mips64le || true if ! mips_can_exec; then echo "MIPS emulation is not available on this host." >&2 echo "Linux: enable binfmt_misc; Docker Desktop/macOS may forbid it." >&2 exit 1 fi fi mkdir -p "$ROOT/state-mips" docker rm -f towercore-mips >/dev/null 2>&1 || true ARGS=(--rm --name towercore-mips --platform linux/mips64le --user "$(id -u):$(id -g)" -p "$PORT:7250" -v "$ROOT/state-mips:/var/lib/towercore") if [ -f "$ROOT/config.env" ]; then ARGS+=(--env-file "$ROOT/config.env") fi echo "TowerCore MIPS: 127.0.0.1:$PORT (state: $ROOT/state-mips)" exec docker run "${ARGS[@]}" "$IMAGE"