#!/usr/bin/env bash set -euo pipefail RUNNER_HOST="${RUNNER_HOST:-192.168.178.135}" RUNNER_SSH_USER="${RUNNER_SSH_USER:-root}" RUNNER_SSH_KEY="${RUNNER_SSH_KEY:-/home/worsch/.ssh/id_ops}" RUNNER_SERVICE_SOURCE="${RUNNER_SERVICE_SOURCE:-runner/act-runner-haskelseed.openrc.example}" REMOTE_SERVICE_TMP="/tmp/act_runner.openrc.$$" ssh_args=(-o BatchMode=yes -o ConnectTimeout=8) if [ -n "${RUNNER_SSH_KEY}" ]; then ssh_args+=(-i "${RUNNER_SSH_KEY}") fi target="${RUNNER_SSH_USER}@${RUNNER_HOST}" scp "${ssh_args[@]}" "${RUNNER_SERVICE_SOURCE}" "${target}:${REMOTE_SERVICE_TMP}" ssh "${ssh_args[@]}" "${target}" "REMOTE_SERVICE_TMP='${REMOTE_SERVICE_TMP}' sh -s" <<'REMOTE' set -eu if [ ! -f /root/.runner ]; then echo "missing /root/.runner; register act_runner before activating service" >&2 exit 1 fi backup="/root/.runner.bak-$(date +%Y%m%d%H%M%S)" cp /root/.runner "${backup}" awk ' /"labels": \[/ { print " \"labels\": [" print " \"self-hosted:host\"," print " \"haskelseed:host\"," print " \"linux:host\"," print " \"linux_amd64:host\"," print " \"x86_64:host\"," print " \"container-build:host\"," print " \"registry-publish:host\"" in_labels = 1 next } in_labels && /]/ { print " ]," in_labels = 0 next } !in_labels { print } ' /root/.runner > /root/.runner.tmp mv /root/.runner.tmp /root/.runner chmod 0644 /root/.runner install -m 0755 "${REMOTE_SERVICE_TMP}" /etc/init.d/act_runner rm -f "${REMOTE_SERVICE_TMP}" rc-update add act_runner default >/dev/null 2>&1 || true rc-service act_runner restart echo "runner_backup=${backup}" echo "runner_labels:" sed -n '8,24p' /root/.runner echo "service_status:" rc-service act_runner status || true echo "runner_process:" pgrep -a act_runner || true REMOTE