@@ -53,6 +53,8 @@ readonly PATH_FILE_ETC_KRB5_KEYTAB='/etc/krb5.keytab'
53
53
readonly MOUNT_PATH_NFSD=' /proc/fs/nfsd'
54
54
readonly MOUNT_PATH_RPC_PIPEFS=' /var/lib/nfs/rpc_pipefs'
55
55
56
+ readonly REGEX_EXPORTS_LINES_TO_SKIP=' ^\s*#|^\s*$'
57
+
56
58
57
59
# #####################################################################################
58
60
# ## logging
@@ -291,7 +293,7 @@ assert_nfsd_threads() {
291
293
assert_at_least_one_export () {
292
294
293
295
# ensure /etc/exports has at least one line
294
- grep -Evq ' ^\s*#|^\s*$ ' $PATH_FILE_ETC_EXPORTS
296
+ grep -Evq " $REGEX_EXPORTS_LINES_TO_SKIP " $PATH_FILE_ETC_EXPORTS
295
297
on_failure bail " $PATH_FILE_ETC_EXPORTS has no exports"
296
298
}
297
299
@@ -330,6 +332,7 @@ init_exports() {
330
332
local candidate_export_vars
331
333
local candidate_export_var
332
334
335
+ # collect all candidate environment variable names
333
336
candidate_export_vars=$( compgen -A variable | grep -E ' NFS_EXPORT_[0-9]+' | sort)
334
337
on_failure bail ' failed to detect NFS_EXPORT_* variables'
335
338
@@ -341,18 +344,23 @@ init_exports() {
341
344
342
345
for candidate_export_var in $candidate_export_vars ; do
343
346
344
- local line=${! candidate_export_var}
347
+ local line=" ${! candidate_export_var} "
348
+
349
+ # skip comments and empty lines
350
+ if [[ " $line " =~ $REGEX_EXPORTS_LINES_TO_SKIP ]]; then
351
+ log_warning " skipping $candidate_export_var environment variable since it contains only whitespace or a comment"
352
+ continue ;
353
+ fi
354
+
345
355
local line_as_array
346
356
read -r -a line_as_array <<< " $line"
347
357
local dir=" ${line_as_array[0]} "
348
358
349
359
if [[ ! -d " $dir " ]]; then
350
- log_warning " skipping $candidate_export_var since $dir is not a container directory"
360
+ log_warning " skipping $candidate_export_var environment variable since $dir is not a container directory"
351
361
continue
352
362
fi
353
363
354
- log " will export $line "
355
-
356
364
if [[ $count_valid_exports -gt 0 ]]; then
357
365
exports=$exports $' \n '
358
366
fi
@@ -567,7 +575,15 @@ summarize_exports() {
567
575
log ' list of container exports:'
568
576
569
577
while read -r export ; do
570
- log " $export "
578
+
579
+ # skip comments and empty lines
580
+ if [[ " $export " =~ $REGEX_EXPORTS_LINES_TO_SKIP ]]; then
581
+ continue ;
582
+ fi
583
+
584
+ # log it w/out leading and trailing whitespace
585
+ log " $( echo -e " $export " | sed -e ' s/^[[:space:]]*//' -e ' s/[[:space:]]*$//' ) "
586
+
571
587
done < " $PATH_FILE_ETC_EXPORTS "
572
588
}
573
589
0 commit comments