Skip to content

Instantly share code, notes, and snippets.

@scottzach1
Last active May 9, 2024 23:59
Show Gist options
  • Save scottzach1/e311654b7fe7115ba077016a5dc7b35d to your computer and use it in GitHub Desktop.
Save scottzach1/e311654b7fe7115ba077016a5dc7b35d to your computer and use it in GitHub Desktop.
Bash script to configure multiple Self-hosted GitHub Runners
#!/bin/bash
# _ _ _ _
# ___ ___ ___ | |_| |_ ______ _ ___| |__ / |
# / __|/ __/ _ \| __| __|_ / _` |/ __| '_ \| |
# \__ \ (_| (_) | |_| |_ / / (_| | (__| | | | |
# |___/\___\___/ \__|\__/___\__,_|\___|_| |_|_|
#
# Zac Scott (github.com/scottzach1)
#
# A quick and hacky script to configure n self-hosted GitHub runners.
# * Gist https://gist.github.com/scottzach1/e311654b7fe7115ba077016a5dc7b35d
# * Adapted from https://github.com/orgs/community/discussions/26769#discussioncomment-3539575
if [ "$EUID" -ne 0 ]
then
echo "Please run as root"
exit 1;
fi
set -e
export NAME=__fill_me_in__
export TOKEN=__fill_me_in__
export REPOSITORY=__fill_me_in__
export COUNT=5
export VERSION=2.316.1
for i in $(seq 1 5);
do
export user="runner-$NAME-$i"
echo "Adding $user";
useradd -m -G sudo "$user";
cd "/home/$user" || exit 1;
mkdir actions-runner;
cd actions-runner || exit 1;
curl -o "actions-runner-linux-x64-$VERSION.tar.gz" -L "https://github.com/actions/runner/releases/download/v$VERSION/actions-runner-linux-x64-$VERSION.tar.gz";
tar xzf "./actions-runner-linux-x64-$VERSION.tar.gz";
chown -R "$user" ./
sudo -u "$user" bash -c "./config.sh --url '$REPOSITORY' --token '$TOKEN' --name '$NAME-$i' --unattended";
./svc.sh install "$user";
./svc.sh start "$user";
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment