Last active 1732827192

forgejo-runner-install.bash Raw
1#!/usr/bin/bash
2set -x
3
4# Description:
5# This script is for installing forgejo-runner. To use it, you need to execute it with a version as an argument
6#
7# For example:
8#
9# forgejo-runner-install 5.0.3
10
11# functions
12# example: rm / || die 'It didn't work!' 2
13die() {
14 local message=$1
15 local code=$2
16
17 echo -e "Error: $1"
18 exit $2
19}
20
21
22version=$1
23url="https://code.forgejo.org/forgejo/runner/releases/download/v$version/forgejo-runner-$version-linux-amd64"
24binary="forgejo-runner-$version-linux-amd64"
25
26# check if version was provided
27if [[ -z $version ]]; then
28 die "You didn't provide a version to install. Please, provide one similar to: a.b.c" 1
29fi
30
31if ! command -v podman &> /dev/null; then
32 die "Podman is not installed. Please, install it and reboot before proceeding." 2
33fi
34
35# download and symlink
36cd /usr/local/bin
37curl -LO "$url"
38ln -fs $binary forgejo-runner
39cd -
40
41# fix perms
42chmod 755 /usr/local/bin/$binary
43
44# create user
45if ! id -u forgejo-runner; then
46 useradd -mr -d /var/lib/forgejo-runner forgejo-runner
47
48 # enable podman
49 systemctl --user -M forgejo-runner@ enable --now podman.socket
50
51 # enable linger
52 loginctl enable-linger forgejo-runner
53
54 # create systemd service
55 user_home=$( sudo -iu forgejo-runner pwd )
56 user_service_path=$user_home/.config/systemd/user
57 sudo -u forgejo-runner mkdir -p $user_service_path
58
59 if [[ ! -f $user_service_path/forgejo-runner.service ]]; then
60 cat <<- 'EOF' | sudo -u forgejo-runner tee $user_service_path/forgejo-runner.service
61 [Unit]
62 Description=Forgejo Runner
63 Documentation=https://forgejo.org/docs/latest/admin/actions/
64
65 [Service]
66 ExecStart=forgejo-runner daemon
67 ExecReload=/bin/kill -s HUP $MAINPID
68 WorkingDirectory=/var/lib/forgejo-runner
69 Restart=on-failure
70 TimeoutSec=0
71 RestartSec=10
72
73 [Install]
74 WantedBy=multi-user.target
75 EOF
76
77 # activate service
78 systemctl --user -M forgejo-runner@ daemon-reload
79 systemctl --user -M forgejo-runner@ enable --now forgejo-runner.service
80 else
81 # reload
82 systemctl --user -M forgejo-runner@ reload forgejo-runner.service
83 fi
84fi
85
86# fix perms
87chmod -R o-rwx /var/lib/forgejo-runner
88
89# registration
90echo 'Now, you need to proceed registering forgejo-runner'.