-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall-actions-runner
executable file
·113 lines (94 loc) · 2.65 KB
/
install-actions-runner
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
# Installs github actions runner as a service on newer ubuntu hosts
set -ex
if (( $# < 1 )); then
echo "Usage: $0 <github repourl>"
echo "Example $0 https://github.com/jeremybusk/demobox"
exit 1
fi
github_repo_url=$1
runner_version="2.277.1"
[[ -f /etc/os-release ]] && . /etc/os-release
if [[ "$NAME" == "Ubuntu" ]] && [[ $VERSION_ID > 20 ]]; then
echo "I: Installing on $NAME $VERSION_ID."
else
echo "E: Unsupported Operating System!"
exit 1
fi
function user_add() {
username=$1
if ! [[ $(getent passwd $username) ]]; then
echo "Adding user $username"
sudo adduser \
--system \
--shell /bin/bash \
--gecos "Github actions runner user" \
--group \
--disabled-password \
--home /home/actions-runner \
$username
fi
}
function sudo_allow_user() {
username=$1
sudo_file=/etc/sudoers.d/custom
sudo_text="$username ALL = (ALL) NOPASSWD:ALL"
# if ! [[ $(grep actions-runner $sudo_file) ]]; then
if ! [[ $(grep "$sudo_text" $sudo_file) ]]; then
echo "adduing $sudo_text to $sudo_file"
echo $sudo_text | sudo tee -a $sudo_file
fi
}
remove_service(){
servicename=$1
set +e
systemctl stop $servicename
systemctl disable $servicename
rm -f /etc/systemd/system/$servicename
rm -f /etc/systemd/system/$servicename
rm -f /usr/lib/systemd/system/$servicename
rm -f /usr/lib/systemd/system/$servicename
userdel -r $servicename
rm -rf /home/$servicename
systemctl daemon-reload
systemctl reset-failed
systemctl list-unit-files | grep $servicename
set -e
}
add_service() {
username=$1
if [[ $(systemctl status $username) ]]; then
echo "E: $username service already exits"
return 1
fi
homedir="/home/$username"
cd $homedir
sudo -u $username curl -O -L https://github.com/actions/runner/releases/download/v${runner_version}/actions-runner-linux-x64-${runner_version}.tar.gz
sudo -u $username tar xzf ./actions-runner-linux-x64-${runner_version}.tar.gz
sudo -u $username ./config.sh --url ${github_repo_url}
# chown -R $username $homedir
sudo bash -c "cat <<EOT > /etc/systemd/system/$username.service
[Unit]
Description=Github Actions Systems Runner
After=$username.service
[Service]
User=actions-runner
WorkingDirectory=/home/actions-runner
ExecStart=/$homedir/run.sh
ExecReload=/bin/kill -SIGUSR1 \$MAINPID
[Install]
WantedBy=multi-user.target
EOT"
sudo systemctl enable $username.service
sudo systemctl start $username.service
systemctl is-active $username
systemctl is-enabled $username
}
main(){
username=actions-runner
remove_service $username
user_add $username
sudo_allow_user $username
add_service $username
}
main "$@"