-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·76 lines (66 loc) · 2.27 KB
/
start.sh
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
#!/bin/bash
set -euo pipefail
build_image() {
image="$1"
docker pull ghcr.io/actions/actions-runner:latest
docker build -t "$image" .
}
image_name() {
scope="$1"
echo "$scope/github-runner"
}
service_name() {
scope="$1"
if [[ "$scope" == */* ]]; then
owner="${scope%%/*}"
repo="${scope##*/}"
echo "github-runner.$owner.$repo"
else
echo "github-runner.$scope"
fi
}
main() {
# Parse command line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-s|--scope)
scope="$2"
shift
;;
*)
echo "Unknown option: $key"
exit 1
;;
esac
shift
done
if [ -z "${scope+x}" ]; then
echo "Scope is required (e.g. 'org' or 'owner/repo')"
exit 1
fi
service=$(service_name "$scope")
image=$(image_name "$scope")
build_image "$image"
# Enable the service if it is not already enabled
if ! systemctl is-enabled --quiet "$service"; then
sudo systemctl enable "$service"
echo "Service $service has been enabled."
else
echo "Service $service is already enabled."
fi
# Check if the service is active
if systemctl is-active --quiet "$service"; then
# Restart the service if it's already running
sudo systemctl restart "$service"
echo "Service $service has been restarted."
else
# Start the service if it's not running
sudo systemctl start "$service"
echo "Service $service has been started."
fi
}
# Execute the main function only if the script is called directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi