Skip to content

Instantly share code, notes, and snippets.

@maxkratz
Created March 14, 2026 14:52
Show Gist options
  • Select an option

  • Save maxkratz/0282f1ddd035b3770a2c9d011089e1a8 to your computer and use it in GitHub Desktop.

Select an option

Save maxkratz/0282f1ddd035b3770a2c9d011089e1a8 to your computer and use it in GitHub Desktop.
forgejo-actions-runner-setup.sh
#!/bin/bash
set -e
#
# This script installs the latest version of the Forgejo Actions runner.
# Based on: https://forgejo.org/docs/next/admin/actions/runner-installation/
#
# author: Max Kratz <github@maxkratz.com>
# date: 2026-03-14
#
# Function to check command availability
check_if_installed () {
echo "=> Checking availability of $1"
if command -v $1 &> /dev/null; then
echo -e "\t$1 installation found."
else
echo -e "\t$1 installation not found. Please install $1 first."
exit 1
fi
}
# Check utilities before continuing
NECESSARY_COMMANDS=("sed" "curl" "jq" "cut" "wget" "docker" "gpg")
for c in ${NECESSARY_COMMANDS[@]}; do
check_if_installed "$c"
done
# Download latest Forgejo Actions runner version
export ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
export RUNNER_VERSION=$(curl -X 'GET' https://data.forgejo.org/api/v1/repos/forgejo/runner/releases/latest | jq .name -r | cut -c 2-)
export FORGEJO_URL="https://code.forgejo.org/forgejo/runner/releases/download/v${RUNNER_VERSION}/forgejo-runner-${RUNNER_VERSION}-linux-${ARCH}"
wget -O forgejo-runner ${FORGEJO_URL} || curl -o forgejo-runner ${FORGEJO_URL}
chmod +x forgejo-runner
wget -O forgejo-runner.asc ${FORGEJO_URL}.asc || curl -o forgejo-runner.asc ${FORGEJO_URL}.asc
gpg --keyserver hkps://keys.openpgp.org --recv EB114F5E6C0DC2BCDD183550A4B61A2DC5923710
gpg --verify forgejo-runner.asc forgejo-runner && echo "✓ Verified" || echo "✗ Failed"
# Copy binary to destination path
cp forgejo-runner /usr/local/bin/forgejo-runner
# Create user if necessary
# Based on: https://stackoverflow.com/a/53391998
exists=$(grep -c "^runner:" /etc/passwd)
if [ $exists -eq 0 ]; then
echo "=> The user runner does not exist, creating it."
useradd --create-home runner
# Add user to Docker group
usermod -aG docker runner
else
echo "=> The user runner already exists."
fi
# Install systemd service
wget -O /etc/systemd/system/forgejo-runner.service https://code.forgejo.org/forgejo/runner/raw/branch/main/contrib/forgejo-runner.service
systemctl daemon-reload
systemctl start forgejo-runner.service
systemctl enable forgejo-runner.service
echo "=> Installation finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment