#!/usr/bin/env bash set -euo pipefail usage() { cat <<'EOF' Usage: ./remote-run Environment variables: REMOTE_HOST Default: host.docker.internal REMOTE_PORT Default: 6666 REMOTE_TOKEN Optional shared token EOF } if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then usage exit 0 fi if [[ $# -lt 1 ]]; then usage exit 2 fi cmd="$1" host="${REMOTE_HOST:-host.docker.internal}" port="${REMOTE_PORT:-6666}" token="${REMOTE_TOKEN:-}" url="http://${host}:${port}/run/${cmd}" curl_args=(--silent --show-error --no-buffer "$url") if [[ -n "$token" ]]; then curl_args=(-H "X-Remote-Token: ${token}" "${curl_args[@]}") fi exec curl "${curl_args[@]}"