2025-06-01 16:57:00 +12:00

50 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
# shellcheck disable=SC1091
source "${AGENT_PATH}/common.sh"
_check_required_env_vars "SERVER" "SERVICE" "TEMP_DIR" \
"GITEA_RUNNER_DIRECTORY" "ACT_RUNNER_VERSION" \
"GITEA_URL" "GITEA_TOKEN" "GITEA_RUNNER_NAME" "GITEA_RUNNER_LABELS"
echo "Downloading act_runner ${ACT_RUNNER_VERSION}..."
wget https://gitea.com/gitea/act_runner/releases/download/v${ACT_RUNNER_VERSION}/act_runner-${ACT_RUNNER_VERSION}-linux-amd64 -O "${TEMP_DIR}/act_runner"
chmod +x "${TEMP_DIR}/act_runner" || _die "Failed to download ${TEMP_DIR}/act_runner"
ACT_RUNNER="${GITEA_RUNNER_DIRECTORY}/act_runner"
CONFIG_FILE="${GITEA_RUNNER_DIRECTORY}/config.yaml"
echo "Checking version..."
mkdir -p "${GITEA_RUNNER_DIRECTORY}" || _die "Failed to create ${GITEA_RUNNER_DIRECTORY}"
cp "${TEMP_DIR}/act_runner" "$ACT_RUNNER" || _die "Failed to copy ${TEMP_DIR}/act_runner to ${GITEA_RUNNER_DIRECTORY}/act_runner"
${ACT_RUNNER} --version || _die "Failed to run ${ACT_RUNNER}"
# only register once!
if [ ! -f "${CONFIG_FILE}" ]; then
echo "Generating config.yaml..."
${ACT_RUNNER} generate-config > "${CONFIG_FILE}" || _die "Failed to generate config.yaml"
# replace the " file: .runner" line with " file: ${GITEA_RUNNER_DIRECTORY}/registration" in config.yaml
sed -i "s|[[:space:]]*file:[[:space:]]*\.runner| file: ${GITEA_RUNNER_DIRECTORY}/registration|" "${CONFIG_FILE}"
echo "Registering runner..."
${ACT_RUNNER} --config "${CONFIG_FILE}" \
register --no-interactive \
--instance "${GITEA_URL}" \
--token "${GITEA_TOKEN}" \
--name "${GITEA_RUNNER_NAME}" \
--labels "${GITEA_RUNNER_LABELS}"
else
echo "Runner already registered."
fi
[ -f "${CONFIG_FILE}" ] || _die "Failed to create ${CONFIG_FILE}"
[ -f "${ACT_RUNNER}" ] || _die "Failed to create ${ACT_RUNNER}"
echo "CONFIG_FILE: ${CONFIG_FILE}"
echo "ACT_RUNNER: ${ACT_RUNNER}"
./start.sh || _die "Failed to start"
echo "Installation complete for service ${SERVICE}."