Add spin-up-runner.sh
This commit is contained in:
parent
cbf76bc8fb
commit
15bd87b11a
1 changed files with 71 additions and 0 deletions
71
spin-up-runner.sh
Normal file
71
spin-up-runner.sh
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Check if the script is run with sudo
|
||||||
|
if [[ $EUID -ne 0 ]]; then
|
||||||
|
echo "Please run this script with sudo."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Change directory to /var/lib/forgejo-runner
|
||||||
|
cd /var/lib/forgejo-runner
|
||||||
|
|
||||||
|
# Request runner directory name from the user
|
||||||
|
read -p "Enter the runner directory name: " RUNNER_DIR_NAME
|
||||||
|
|
||||||
|
# Create the directory with the user's input
|
||||||
|
mkdir "$RUNNER_DIR_NAME"
|
||||||
|
|
||||||
|
# Copy the ./forgejo-runner file into the created directory
|
||||||
|
cp ./forgejo-runner "$RUNNER_DIR_NAME/"
|
||||||
|
|
||||||
|
# Change directory to the created directory
|
||||||
|
cd "$RUNNER_DIR_NAME"
|
||||||
|
|
||||||
|
# Request runner name from the user
|
||||||
|
read -p "Enter the runner name: " RUNNER_NAME
|
||||||
|
|
||||||
|
# Request runner target domain from the user
|
||||||
|
while true; do
|
||||||
|
read -p "Enter the URL of the Forgejo instance you're registering this runner to: " URL
|
||||||
|
if [ -n "$URL" ]; then
|
||||||
|
# Check if the URL includes the http(s) scheme
|
||||||
|
if [[ ! "$URL" =~ ^https?:// ]]; then
|
||||||
|
# Prepend https:// to the entered URL
|
||||||
|
URL="https://$URL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Append /api/v1/forgejo/version to the entered URL
|
||||||
|
CHECK_URL="${URL%/}/api/v1/version"
|
||||||
|
|
||||||
|
# Use curl to check if the URL is valid
|
||||||
|
if curl -s -o /dev/null -w "%{http_code}" "$CHECK_URL" > /dev/null 2>&1; then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
echo "Invalid URL or unable to reach the version endpoint. Please try again."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "URL cannot be empty. Please try again."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Request runner registration token from the user
|
||||||
|
while true; do
|
||||||
|
read -p "Enter the runner registration token: " TOKEN
|
||||||
|
if [ -n "$TOKEN" ]; then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
echo "Token cannot be empty. Please try again."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Register the runner with the provided information
|
||||||
|
./forgejo-runner register --no-interactive --token "$TOKEN" --name "$RUNNER_NAME" --instance "$URL" --labels docker:docker://node:16-bullseye,self-hosted
|
||||||
|
|
||||||
|
# Enable and start the systemd service with the runner directory name
|
||||||
|
sudo systemctl enable --now "forgejo-runner@$RUNNER_DIR_NAME"
|
||||||
|
|
||||||
|
# Completion message
|
||||||
|
echo "Runner setup for $RUNNER_NAME in $RUNNER_DIR_NAME completed."
|
||||||
|
|
||||||
|
# Exit the script
|
||||||
|
exit 0
|
Loading…
Reference in a new issue