#!/bin/bash # Crea (se manca) e avvia il runner delle Gitea Actions su questo PC: `make runner`. # Rifarlo da zero: `docker compose -f tools/gitea-runner/docker-compose.yml down`, cancellare $RUNNER_DATA e il runner # vecchio da Gitea (repo → Impostazioni → Actions → Runner), poi di nuovo `make runner`. # Il token di registrazione si chiede all'API di Gitea con le credenziali di git (serve lo scope write:repository). set -euo pipefail ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd) COMPOSE="$ROOT/tools/gitea-runner/docker-compose.yml" REPO=${RUNNER_REPO:-manzolo/leggenda-del-regolo} export RUNNER_DATA=${RUNNER_DATA:-$HOME/.local/share/gitea-runner} export GITEA_RUNNER_NAME=${GITEA_RUNNER_NAME:-pc-$(hostname | tr '[:upper:]' '[:lower:]')} mkdir -p "$RUNNER_DATA" if [[ ! -s $RUNNER_DATA/.runner ]]; then pass=$(printf 'protocol=https\nhost=git.manzolo.it\n\n' | git credential fill | sed -n 's/^password=//p') user=$(printf 'protocol=https\nhost=git.manzolo.it\n\n' | git credential fill | sed -n 's/^username=//p') [[ -n $pass ]] || { echo "nessuna credenziale git per git.manzolo.it"; exit 1; } tok=$(curl -sf -X POST -u "$user:$pass" "https://git.manzolo.it/api/v1/repos/$REPO/actions/runners/registration-token" | python3 -c 'import json,sys; print(json.load(sys.stdin)["token"])') || { echo "Gitea non ha dato il token di registrazione (scope write:repository?)"; exit 1; } echo "registro il runner $GITEA_RUNNER_NAME su $REPO" GITEA_RUNNER_REGISTRATION_TOKEN=$tok docker compose -f "$COMPOSE" up -d for _ in $(seq 30); do [[ -s $RUNNER_DATA/.runner ]] && break; sleep 1; done [[ -s $RUNNER_DATA/.runner ]] || { docker logs --tail 20 gitea-runner; echo "registrazione non riuscita"; exit 1; } chmod 600 "$RUNNER_DATA/.runner" 2>/dev/null || true fi # Senza token nell'ambiente del container: da qui in poi si autentica con .runner. docker compose -f "$COMPOSE" up -d sleep 2; docker logs --tail 1 gitea-runner