#!/bin/bash set -ex function dependencies() { if ! which go > /dev/null ; then apt-get update apt-get install -y -qq wget tar wget https://go.dev/dl/go1.20.2.linux-amd64.tar.gz tar zxf go1.20.2.linux-amd64.tar.gz export PATH=$PATH:$(pwd)/go/bin fi if ! which make > /dev/null ; then apt-get install -y -qq make fi } function checkout() { local git="$1" if ! test -d forgejo-runner ; then git clone $git forgejo-runner fi } function build() { local version="$1" ( cd forgejo-runner git checkout $version make build ) } function register() { local forgejo="$1" docker exec --user 1000 forgejo forgejo actions --registration-token-admin > forgejo-runner-token timeout --signal=KILL 30 ./forgejo-runner/forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat forgejo-runner-token) } function run() { ./forgejo-runner/forgejo-runner daemon >& forgejo-runner.log & echo $! > forgejo-runner-pid } function setup() { local git="${1:-https://codeberg.org/forgejo/runner}" local version="${1:-v1.4.1}" local forgejo="${1:-http://$(cat forgejo-ip):3000/}" dependencies checkout $git build $version register $forgejo run } function teardown() { if test -f forgejo-runner-pid ; then kill -9 $(cat forgejo-runner-pid) rm -f forgejo-runner-pid fi } "$@"