#!/usr/bin/env bash # Run as the development user, not root. Configuration stays outside the checkout. set -Eeuo pipefail script_dir=$(cd -- "$(dirname -- "$0")" && pwd) runner_dir="$HOME/.local/share/agiledancers-runner" config_dir="$HOME/.config/agiledancers-runner" install -d -m 700 "$runner_dir" "$config_dir" "$HOME/.local/bin" "$HOME/.config/systemd/user" [[ "$(uname -s)/$(uname -m)" == Linux/x86_64 ]] || { echo 'This installer targets the existing Linux x86_64 mini-PC'; exit 1; } for tool in node java mvn docker curl python3 flock timeout; do command -v "$tool" >/dev/null; done : "${JAVA_HOME:?Set JAVA_HOME to your JDK 25 directory}" "$JAVA_HOME/bin/java" -version 2>&1 | grep -Eq 'version "25[.\"]' || { echo 'JDK 25 required'; exit 1; } node -e 'const [a,b,c]=process.versions.node.split(".").map(Number); if (!((a===22&&(b>22||(b===22&&c>=3)))||(a===24&&(b>15||(b===15&&c>=0)))||a>=26)) process.exit(1)' if [[ ! -x "$HOME/.local/bin/act_runner" ]]; then download_dir=$(mktemp -d) trap 'rm -rf -- "$download_dir"' EXIT curl --fail --location --retry 3 \ https://dl.gitea.com/act_runner/0.2.13/act_runner-0.2.13-linux-amd64 -o "$download_dir/act_runner" printf '%s %s\n' 3acac8b506ac8cadc88a55155b5d6378f0fab0b8f62d1e0c0450f4ccd69733e2 "$download_dir/act_runner" | sha256sum --check install -m 755 "$download_dir/act_runner" "$HOME/.local/bin/act_runner" fi "$HOME/.local/bin/act_runner" --version | grep -F 'v0.2.13' install -m 600 "$script_dir/config.yaml" "$runner_dir/config.yaml" install -m 644 "$script_dir/agiledancers-runner.service" "$HOME/.config/systemd/user/agiledancers-runner.service" # Resolve paths now: user services do not inherit an interactive shell's PATH/context. node_dir=$(dirname -- "$(command -v node)") maven_dir=$(dirname -- "$(command -v mvn)") docker_host=${DOCKER_HOST:-$(docker context inspect --format '{{.Endpoints.docker.Host}}')} umask 077 printf 'JAVA_HOME=%s\nPATH=%s/bin:%s:%s:/usr/local/bin:/usr/bin:/bin\nDOCKER_HOST=%s\n' \ "$JAVA_HOME" "$JAVA_HOME" "$node_dir" "$maven_dir" "$docker_host" > "$config_dir/environment" systemctl --user daemon-reload if [[ "${1:-}" == --prepare-only ]]; then echo 'Runner installed; registration and startup still required.' exit 0 fi docker info >/dev/null if [[ ! -f "$runner_dir/.runner" ]]; then token_file=${RUNNER_REGISTRATION_TOKEN_FILE:-$config_dir/registration-token} [[ -f "$token_file" ]] || { echo "Place the repository runner registration token in $token_file (mode 600), then rerun."; exit 1; } registration_token=$(cat "$token_file") [[ -n "$registration_token" ]] || { echo 'Empty registration token'; exit 1; } ( cd "$runner_dir" "$HOME/.local/bin/act_runner" register --no-interactive \ --instance http://192.168.2.28:3000 --name agiledancers-mini-pc \ --labels agiledancers-mini-pc:host --token "$registration_token" chmod 600 .runner ) unset registration_token fi systemctl --user enable --now agiledancers-runner.service echo 'Runner registered and started. The mini-PC and Docker must remain available.'