Skip to content
This repository was archived by the owner on Oct 6, 2023. It is now read-only.

Commit a2179c3

Browse files
committed
added bail() with minor tweaking
1 parent 7604358 commit a2179c3

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

entrypoint.sh

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ readonly PATH_FILE_ETC_KRB5_KEYTAB='/etc/krb5.keytab'
5353
readonly MOUNT_PATH_NFSD='/proc/fs/nfsd'
5454
readonly MOUNT_PATH_RPC_PIPEFS='/var/lib/nfs/rpc_pipefs'
5555

56+
5657
######################################################################################
5758
### general purpose utilities
5859
######################################################################################
@@ -70,18 +71,25 @@ logHeader() {
7071
echo '=================================================================='
7172
}
7273

74+
bail() {
75+
76+
log "ERROR: $1"
77+
exit 1
78+
}
79+
7380
warn_on_failure() {
7481

82+
# shellcheck disable=SC2181
7583
if [[ $? -ne 0 ]]; then
7684
log "WARNING: $1"
7785
fi
7886
}
7987

8088
exit_on_failure() {
8189

90+
# shellcheck disable=SC2181
8291
if [[ $? -ne 0 ]]; then
83-
log "$1"
84-
exit 1
92+
bail "$1"
8593
fi
8694
}
8795

@@ -153,6 +161,7 @@ stop() {
153161

154162
stop_on_failure() {
155163

164+
# shellcheck disable=SC2181
156165
if [[ $? -ne 0 ]]; then
157166
log "$1"
158167
stop
@@ -220,6 +229,13 @@ is_nfs4_enabled() {
220229
### runtime configuration assertions
221230
######################################################################################
222231

232+
assert_file_provided() {
233+
234+
if [[ ! -f "$1" ]]; then
235+
bail "please provide $1 to the container"
236+
fi
237+
}
238+
223239
assert_kernel_mod() {
224240

225241
local -r moduleName=$1
@@ -237,8 +253,7 @@ assert_port() {
237253
local -r value=${!envName}
238254

239255
if [[ -n "$value" && ( "$value" -lt 1 || "$value" -gt 65535 ) ]]; then
240-
log "Please set $1 to a value between 1 and 65535 inclusive"
241-
exit 1
256+
bail "please set $1 to a value between 1 and 65535 inclusive"
242257
fi
243258
}
244259

@@ -251,8 +266,7 @@ assert_nfs_version() {
251266
assert_disabled_nfs3() {
252267

253268
if [[ -z "$(is_nfs3_enabled)" && "$(get_reqd_nfs_version)" == '3' ]]; then
254-
log 'you cannot simultaneously enable and disable NFS version 3'
255-
exit 1
269+
bail 'you cannot simultaneously enable and disable NFS version 3'
256270
fi
257271
}
258272

@@ -261,33 +275,20 @@ assert_nfsd_threads() {
261275
local -r requested=$(get_reqd_nfsd_threads)
262276

263277
if [[ "$requested" -lt 1 ]]; then
264-
log "Please set $ENV_VAR_NFS_SERVER_THREAD_COUNT to a positive value"
265-
exit 1
278+
bail "please set $ENV_VAR_NFS_SERVER_THREAD_COUNT to a positive value"
266279
fi
267280
}
268281

269282
assert_kerberos_requirements() {
270283

271-
if [[ -z "$(is_kerberos_enabled)" ]]; then
272-
return
273-
fi
274-
275-
if [[ ! -f "$PATH_FILE_ETC_IDMAPD_CONF" ]]; then
276-
log "Please provide $PATH_FILE_ETC_IDMAPD_CONF to the container"
277-
exit 1
278-
fi
284+
if [[ -n "$(is_kerberos_enabled)" ]]; then
279285

280-
if [[ ! -f "$PATH_FILE_ETC_KRB5_KEYTAB" ]]; then
281-
log "Please provide $PATH_FILE_ETC_KRB5_KEYTAB to the container"
282-
exit 1
283-
fi
286+
assert_file_provided "$PATH_FILE_ETC_IDMAPD_CONF"
287+
assert_file_provided "$PATH_FILE_ETC_KRB5_KEYTAB"
288+
assert_file_provided "$PATH_FILE_ETC_KRB5_CONF"
284289

285-
if [[ ! -f "$PATH_FILE_ETC_KRB5_CONF" ]]; then
286-
log "Please provide $PATH_FILE_ETC_KRB5_CONF to the container"
287-
exit 1
290+
assert_kernel_mod rpcsec_gss_krb5
288291
fi
289-
290-
assert_kernel_mod rpcsec_gss_krb5
291292
}
292293

293294

@@ -341,8 +342,7 @@ init_exports() {
341342
done
342343

343344
if [[ $collected -eq 0 ]]; then
344-
log 'no valid exports'
345-
exit 1
345+
bail 'no valid exports'
346346
fi
347347

348348
log "will export $collected filesystem(s)"
@@ -514,6 +514,7 @@ boot_main_print_ready_message() {
514514
cat $PATH_FILE_ETC_EXPORTS
515515
}
516516

517+
517518
######################################################################################
518519
### main routines
519520
######################################################################################

0 commit comments

Comments
 (0)