|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Install and configure a GitHub Actions self-hosted runner on Ubuntu. |
| 3 | +# Repo: https://github.com/wasabi/rustfs |
| 4 | +# Prompts for runner token and runner name; adds labels 'ubicloud-standard-2' and 'ubicloud-standard-4 '; uses default group. |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +RUNNER_VERSION="2.332.0" |
| 9 | +RUNNER_TAR="actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz" |
| 10 | +RUNNER_SHA256="f2094522a6b9afeab07ffb586d1eb3f190b6457074282796c497ce7dce9e0f2a" |
| 11 | +REPO_URL="https://github.com/wasabi/rustfs" |
| 12 | +RUNNER_LABELS="ubicloud-standard-2,ubicloud-standard-4" |
| 13 | +INSTALL_DIR="${INSTALL_DIR:-$HOME/actions-runner}" |
| 14 | + |
| 15 | +echo "GitHub self-hosted runner installer for ${REPO_URL}" |
| 16 | +echo "Runner version: ${RUNNER_VERSION}" |
| 17 | +echo "Install directory: ${INSTALL_DIR}" |
| 18 | +echo "" |
| 19 | + |
| 20 | +# System packages and pipx CLI tools used by CI workflows |
| 21 | +echo "Installing dependencies (apt: unzip, pipx)..." |
| 22 | +export DEBIAN_FRONTEND=noninteractive |
| 23 | +sudo apt-get update -qq |
| 24 | +sudo apt-get install -y unzip pipx |
| 25 | +echo "Installing awscurl via pipx..." |
| 26 | +pipx install awscurl |
| 27 | +pipx ensurepath |
| 28 | + |
| 29 | +# Prompt for token |
| 30 | +read -r -p "Runner token: " RUNNER_TOKEN |
| 31 | +if [ -z "$RUNNER_TOKEN" ]; then |
| 32 | + echo "Error: Runner token is required." |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +# Prompt for runner name |
| 37 | +read -r -p "Runner name: " RUNNER_NAME |
| 38 | +if [ -z "$RUNNER_NAME" ]; then |
| 39 | + echo "Error: Runner name is required." |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +# Create install directory |
| 44 | +mkdir -p "$INSTALL_DIR" |
| 45 | +cd "$INSTALL_DIR" |
| 46 | + |
| 47 | +# Download |
| 48 | +echo "Downloading runner package..." |
| 49 | +curl -o "$RUNNER_TAR" -L "https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/${RUNNER_TAR}" |
| 50 | + |
| 51 | +# Validate hash |
| 52 | +echo "Validating checksum..." |
| 53 | +echo "${RUNNER_SHA256} ${RUNNER_TAR}" | shasum -a 256 -c |
| 54 | + |
| 55 | +# Extract |
| 56 | +echo "Extracting..." |
| 57 | +tar xzf "$RUNNER_TAR" |
| 58 | +rm -f "$RUNNER_TAR" |
| 59 | + |
| 60 | +# Configure: default group (omit --runnergroup), labels x,y |
| 61 | +echo "Configuring runner..." |
| 62 | +./config.sh \ |
| 63 | + --url "$REPO_URL" \ |
| 64 | + --token "$RUNNER_TOKEN" \ |
| 65 | + --name "$RUNNER_NAME" \ |
| 66 | + --labels "$RUNNER_LABELS" \ |
| 67 | + --unattended |
| 68 | + |
| 69 | +# Install and start service (runs in background, survives reboot) |
| 70 | +echo "Installing runner as a systemd service..." |
| 71 | +sudo ./svc.sh install |
| 72 | +sudo ./svc.sh start |
| 73 | + |
| 74 | +echo "" |
| 75 | +echo "Runner installed and running. To use in workflows:" |
| 76 | +echo " runs-on: self-hosted" |
| 77 | +echo "" |
| 78 | +echo "Useful commands (from ${INSTALL_DIR}):" |
| 79 | +echo " sudo ./svc.sh status # check status" |
| 80 | +echo " sudo ./svc.sh stop # stop" |
| 81 | +echo " sudo ./svc.sh start # start" |
| 82 | +echo " sudo ./svc.sh uninstall # remove service (then delete directory to fully remove)" |
0 commit comments