forgejo-runner-services/install

47 lines
1.7 KiB
Text
Raw Normal View History

#!/bin/bash
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" # Retrieves script directory
source "${SCRIPT_DIR}/pretty_print" # Includes our nice print function
CONTAINERS_SYSTEMD_DIR="/var/lib/forgejo-runner/.config/containers/systemd"
FORGEJO_INSTANCE="https://git.archive.hostux.fr"
if [ "$1" = "--skip-init" ]; then
pretty_print "Skipping the initial configuration." yellow bold
elif [ -z "$1" ]; then
pretty_print --no-newline "Enter the registration token from the Forgejo instance: " blue bold
read FORGEJO_REGISTRATION_TOKEN
pretty_print "Generating the configuration..." blue bold
podman run --rm -it \
-v forgejo-runner_data:/data \
-e FORGEJO_INSTANCE="$FORGEJO_INSTANCE" \
-e FORGEJO_REGISTRATION_TOKEN="$FORGEJO_REGISTRATION_TOKEN" \
code.forgejo.org/forgejo/runner:3.3.0 \
sh -c '
forgejo-runner register --no-interactive --token "$FORGEJO_REGISTRATION_TOKEN" --name forgejo-runner-on-norrsken --instance "$FORGEJO_INSTANCE" &&
forgejo-runner generate-config > config.yml &&
sed -i -e "s|network: .*|network: host|" config.yml &&
sed -i -e "s|labels: \[\]|labels: \[\"docker:docker://alpine:3.19\"\]|" config.yml &&
chown -R 1000:1000 /data
'
else
echo "Usage: $0 [--skip-init]"
fi
if [ ! -d "$CONTAINERS_SYSTEMD_DIR" ]; then
pretty_print "Creating the containers units folder" blue bold
mkdir -p "$CONTAINERS_SYSTEMD_DIR"
fi
filename="forgejo-runner.container"
destination_filename="$filename"
pretty_print "\nInstalling $filename..." blue bold
cp -v $cp_do_not_overwrite_option "${SCRIPT_DIR}/$filename" "${CONTAINERS_SYSTEMD_DIR}/$destination_filename"
systemctl --user daemon-reload
pretty_print "\nReloaded systemctl daemon. Done!" green bold