#!/bin/sh # Installs or updates a Loopgate runner on this box (ADR 0137). The portal's Devices page gives the line: # curl -fsSL https://loopgate.dev/runner/install.sh | sh -s -- lgr_… [--url https://…] [--dir ~/loopgate] # The runner gets a temporary address by itself; --url names a permanent one. Run again to take a # newer compose.yaml or a fresh token; the rest of runner.env is kept. set -eu token="" url="" dir="$HOME/loopgate" plane="https://app.loopgate.dev" site="https://loopgate.dev" while [ $# -gt 0 ]; do case "$1" in --url) url="$2"; shift 2 ;; --dir) dir="$2"; shift 2 ;; --control-plane) plane="$2"; shift 2 ;; lgr_*) token="$1"; shift ;; *) echo "Unknown argument: $1" >&2; exit 2 ;; esac done if ! docker compose version >/dev/null 2>&1; then echo "Docker with Compose is needed. Install it with: curl -fsSL https://get.docker.com | sh" >&2 exit 1 fi mkdir -p "$dir" cd "$dir" curl -fsSL "$site/runner/compose.yaml?$(date +%s)" -o compose.yaml # A missing key is added, a given one replaced; everything else in runner.env stays as written. set_env() { grep -v "^$1=" runner.env > runner.env.new || true echo "$1=$2" >> runner.env.new mv runner.env.new runner.env } umask 077 # The box's own name on the portal's Devices page; inside the container the hostname is the container's. [ -f runner.env ] || { touch runner.env && set_env LOOPGATE_CONTROL_PLANE "$plane" && set_env LOOPGATE_RUNNER_NAME "$(hostname)"; } [ -n "$token" ] && set_env LOOPGATE_INSTALL_TOKEN "$token" [ -n "$url" ] && set_env LOOPGATE_RUNNER_URL "$url" chmod 600 runner.env plane=$(sed -n 's/^LOOPGATE_CONTROL_PLANE=//p' runner.env) docker compose up -d echo "Waiting for the runner to start and register…" i=0 while [ $i -lt 60 ]; do if curl -fsS http://127.0.0.1:4311/health >/dev/null 2>&1 && docker compose logs runner 2>/dev/null | grep -Eq "Registered as|Runner ready at"; then echo "Runner connected. Open the portal's Devices page: $plane/#/devices" exit 0 fi i=$((i + 1)) sleep 2 done echo "The runner did not register within two minutes. Its last lines:" >&2 docker compose logs --tail 20 runner >&2 exit 1