-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-judgehost.sh
executable file
·218 lines (195 loc) · 6.65 KB
/
start-judgehost.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
# ARG_HELP([Start a judgehost container on a certain core])
# ARG_POSITIONAL_SINGLE([cpu-core],[Which cpu core to run the judgehost container on])
# ARG_TYPE_GROUP([nnint],[N],[cpu-core])
# ARG_OPTIONAL_SINGLE([domserver-baseurl],[u],[Baseurl of the DOMserver],[https://dj.chipcie.ch.tudelft.nl/])
# ARG_OPTIONAL_SINGLE([password],[p],[Password of the judgehosts in the domserver (leave empty for prompt)])
# ARG_OPTIONAL_SINGLE([hostname],[n],[Hostname used to register on DOMserver],[judgedaemon])
# ARG_OPTIONAL_SINGLE([container],[c],[Docker container to use as judgehost],[ghcr.io/wisvch/domjudge-packaging/judgehost])
# ARG_OPTIONAL_SINGLE([version],[v],[Version of the container],[8.2.0])
# ARG_OPTIONAL_BOOLEAN([detach],[d],[Run container in background and print container ID],[off])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.10.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
die()
{
local _ret="${2:-1}"
test "${_PRINT_HELP:-no}" = yes && print_help >&2
echo "$1" >&2
exit "${_ret}"
}
# validators
nnint()
{
printf "%s" "$1" | grep -q '^\s*+\?[0-9]\+\s*$' || die "The value of argument '$2' is '$1', which is not a non-negative integer."
printf "%d" "$1"
}
begins_with_short_option()
{
local first_option all_short_options='hupncvd'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}
# THE DEFAULTS INITIALIZATION - POSITIONALS
_positionals=()
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_domserver_baseurl="https://dj.chipcie.ch.tudelft.nl/"
_arg_password=
_arg_hostname="judgedaemon"
_arg_container="ghcr.io/wisvch/domjudge-packaging/judgehost"
_arg_version="8.3"
_arg_detach="off"
print_help()
{
printf '%s\n' "Start a judgehost container on a certain core"
printf 'Usage: %s [-h|--help] [-u|--domserver-baseurl <arg>] [-p|--password <arg>] [-n|--hostname <arg>] [-c|--container <arg>] [-v|--version <arg>] [-d|--(no-)detach] <cpu-core>\n' "$0"
printf '\t%s\n' "<cpu-core>: Which cpu core to run the judgehost container on"
printf '\t%s\n' "-h, --help: Prints help"
printf '\t%s\n' "-u, --domserver-baseurl: Baseurl of the DOMserver (default: 'https://dj.chipcie.ch.tudelft.nl/')"
printf '\t%s\n' "-p, --password: Password of the judgehosts in the domserver (leave empty for prompt) (no default)"
printf '\t%s\n' "-n, --hostname: Hostname used to register on DOMserver (default: 'judgedaemon')"
printf '\t%s\n' "-c, --container: Docker container to use as judgehost (default: 'ghcr.io/wisvch/domjudge-packaging/judgehost')"
printf '\t%s\n' "-v, --version: Version of the container (default: '8.3')"
printf '\t%s\n' "-d, --detach, --no-detach: Run container in background and print container ID (off by default)"
}
parse_commandline()
{
_positionals_count=0
while test $# -gt 0
do
_key="$1"
case "$_key" in
-h|--help)
print_help
exit 0
;;
-h*)
print_help
exit 0
;;
-u|--domserver-baseurl)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_domserver_baseurl="$2"
shift
;;
--domserver-baseurl=*)
_arg_domserver_baseurl="${_key##--domserver-baseurl=}"
;;
-u*)
_arg_domserver_baseurl="${_key##-u}"
;;
-p|--password)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_password="$2"
shift
;;
--password=*)
_arg_password="${_key##--password=}"
;;
-p*)
_arg_password="${_key##-p}"
;;
-n|--hostname)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_hostname="$2"
shift
;;
--hostname=*)
_arg_hostname="${_key##--hostname=}"
;;
-n*)
_arg_hostname="${_key##-n}"
;;
-c|--container)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_container="$2"
shift
;;
--container=*)
_arg_container="${_key##--container=}"
;;
-c*)
_arg_container="${_key##-c}"
;;
-v|--version)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_version="$2"
shift
;;
--version=*)
_arg_version="${_key##--version=}"
;;
-v*)
_arg_version="${_key##-v}"
;;
-d|--no-detach|--detach)
_arg_detach="on"
test "${1:0:5}" = "--no-" && _arg_detach="off"
;;
-d*)
_arg_detach="on"
_next="${_key##-d}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-d" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
*)
_last_positional="$1"
_positionals+=("$_last_positional")
_positionals_count=$((_positionals_count + 1))
;;
esac
shift
done
}
handle_passed_args_count()
{
local _required_args_string="'cpu-core'"
test "${_positionals_count}" -ge 1 || _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require exactly 1 (namely: $_required_args_string), but got only ${_positionals_count}." 1
test "${_positionals_count}" -le 1 || _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect exactly 1 (namely: $_required_args_string), but got ${_positionals_count} (the last one was: '${_last_positional}')." 1
}
assign_positional_args()
{
local _positional_name _shift_for=$1
_positional_names="_arg_cpu_core "
shift "$_shift_for"
for _positional_name in ${_positional_names}
do
test $# -gt 0 || break
eval "$_positional_name=\${1}" || die "Error during argument parsing, possibly an Argbash bug." 1
shift
done
}
parse_commandline "$@"
handle_passed_args_count
assign_positional_args 1 "${_positionals[@]}"
# OTHER STUFF GENERATED BY Argbash
# Validation of values
_arg_cpu_core="$(nnint "$_arg_cpu_core" "cpu-core")" || exit 1
### END OF CODE GENERATED BY Argbash (sortof) ### ])
# [ <-- needed because of Argbash
if [ -z "$JUDGEDAEMON_PASSWORD" ]; then
if [ -z "$_arg_password" ]; then
echo -n Password:
read -s JUDGEDAEMON_PASSWORD
echo
else
JUDGEDAEMON_PASSWORD=$_arg_password
fi
fi
docker run \
--rm \
$( [ "$_arg_detach" = on ] && printf %s '-d' ) \
--privileged \
-v /sys/fs/cgroup:/sys/fs/cgroup \
-e DOMSERVER_BASEURL=$_arg_domserver_baseurl \
-e JUDGEDAEMON_PASSWORD=$JUDGEDAEMON_PASSWORD \
--name judgehost-$_arg_cpu_core \
--hostname "$_arg_hostname" \
--add-host dj.chipcie.ch.tudelft.nl:34.141.175.184 \
-e DAEMON_ID=$_arg_cpu_core \
$_arg_container:$_arg_version
# ] <-- needed because of Argbash