Update spin-up-runner.sh
This commit is contained in:
parent
f9fdad44c4
commit
391444a3d4
1 changed files with 101 additions and 30 deletions
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Check if the script is run with sudo
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
|
@ -15,8 +15,79 @@ 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/"
|
||||
# Symlink the ./forgejo-runner binary into the created directory
|
||||
ln ./forgejo-runner "$RUNNER_DIR_NAME/forgejo-runner"
|
||||
|
||||
# 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
|
||||
#!/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"
|
||||
|
||||
# Symlink the ./forgejo-runner binary into the created directory
|
||||
ln ./forgejo-runner "$RUNNER_DIR_NAME/forgejo-runner"
|
||||
|
||||
# Change directory to the created directory
|
||||
cd "$RUNNER_DIR_NAME"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue