#!/bin/sh
set -e

# Register once (state stored in /data/.runner, which is a mounted volume so it
# survives restarts). On later starts it just runs the daemon.
if [ ! -f /data/.runner ]; then
  echo "Registering runner with ${GITEA_INSTANCE_URL} ..."
  act_runner register --no-interactive \
    --instance "${GITEA_INSTANCE_URL}" \
    --token "${GITEA_RUNNER_REGISTRATION_TOKEN}" \
    --name "${GITEA_RUNNER_NAME:-vm-runner}" \
    --labels "${GITEA_RUNNER_LABELS:-ubuntu:host}"
fi

exec act_runner daemon
