#!/bin/bash # This script is used to install gitea act_runner . ./env.sh set -e ARCH=$(uname -m) echo "Architecture $ARCH" DOWNLOAD_VARIANT="" ACT_RUNNER_VERSION="0.2.11" RUNNER="$INSTALL_DIR/act_runner" if [[ "$ARCH" == "amd64" ]]; then DOWNLOAD_VARIANT="amd64" elif [[ "$ARCH" == "aarch64" ]]; then DOWNLOAD_VARIANT="arm64" else echo "Unsupported architecture: $ARCH" exit 1 fi DOWNLOAD_URL="https://dl.gitea.com/act_runner/$ACT_RUNNER_VERSION/act_runner-$ACT_RUNNER_VERSION-linux-$DOWNLOAD_VARIANT" mkdir -p "$INSTALL_DIR" wget -q "$DOWNLOAD_URL" -O "$RUNNER" || { echo "Failed to download act_runner from $DOWNLOAD_URL" exit 1 } chmod +x "$INSTALL_DIR/act_runner" echo "act_runner downloaded and made executable." DEFAULT_LABELS=( "ubuntu-latest:docker://gitea/runner-images:ubuntu-latest" "ubuntu-22.04:docker://gitea/runner-images:ubuntu-22.04" "ubuntu-20.04:docker://gitea/runner-images:ubuntu-20.04" ) LABELS=("${DEFAULT_LABELS[@]}" "${ADDITIONAL_LABLES[@]}") LABLES_STRING=$(IFS=','; echo "${LABELS[*]}") pushd "$INSTALL_DIR" || exit 1 $RUNNER register \ --no-interactive \ --instance $GITEA_URL \ --token $GITEA_TOKEN \ --name $RUNNER_NAME \ --labels $LABLES_STRING popd || exit 1 # $RUNNER generate-config > "$INSTALL_DIR/config.yaml" # echo "act_runner config generated." # echo "act_runner config file created at $INSTALL_DIR/config.yaml" # echo "manually add additional labels to the config file - $INSTALL_DIR/config.yaml" # echo "add the following labels to the config file - $INSTALL_DIR/config.yaml" # for label in "${ADDITIONAL_LABLES[@]}"; do # echo " - $label" # done # echo "manually add docker socket to the config file - $INSTALL_DIR/config.yaml" # echo "add the following docker socket to the config file - $INSTALL_DIR/config.yaml" # echo " - $CONTAINER_HOST" # Create systemd service file SERVICE_FILE="${SERVICE_NAME}.service" cp "$SERVICE_FILE.template" "$SERVICE_FILE" ESC_RUNNER=$(printf '%s' "$RUNNER" | sed 's:/:\\/:g') ESC_INSTALL_DIR=$(printf '%s' "$INSTALL_DIR" | sed 's:/:\\/:g') sed -i "s|^ExecStart=.*$|ExecStart=${ESC_RUNNER} daemon|" "$SERVICE_FILE" sed -i "s|^WorkingDirectory=.*$|WorkingDirectory=${ESC_INSTALL_DIR}|" "$SERVICE_FILE" mv "$SERVICE_FILE" "$USER_SYSTEMD/$SERVICE_FILE" systemctl --user daemon-reload systemctl --user enable --now "${SERVICE_NAME}.service" echo "Gitea act_runner installed and systemd service created."