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

Commit 4c932b9

Browse files
committed
ignore comments and empty lines for /etc/exports
1 parent 2ba982a commit 4c932b9

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

entrypoint.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ 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+
readonly REGEX_EXPORTS_LINES_TO_SKIP='^\s*#|^\s*$'
57+
5658

5759
######################################################################################
5860
### logging
@@ -291,7 +293,7 @@ assert_nfsd_threads() {
291293
assert_at_least_one_export() {
292294

293295
# 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
295297
on_failure bail "$PATH_FILE_ETC_EXPORTS has no exports"
296298
}
297299

@@ -330,6 +332,7 @@ init_exports() {
330332
local candidate_export_vars
331333
local candidate_export_var
332334

335+
# collect all candidate environment variable names
333336
candidate_export_vars=$(compgen -A variable | grep -E 'NFS_EXPORT_[0-9]+' | sort)
334337
on_failure bail 'failed to detect NFS_EXPORT_* variables'
335338

@@ -341,18 +344,23 @@ init_exports() {
341344

342345
for candidate_export_var in $candidate_export_vars; do
343346

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+
345355
local line_as_array
346356
read -r -a line_as_array <<< "$line"
347357
local dir="${line_as_array[0]}"
348358

349359
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"
351361
continue
352362
fi
353363

354-
log "will export $line"
355-
356364
if [[ $count_valid_exports -gt 0 ]]; then
357365
exports=$exports$'\n'
358366
fi
@@ -567,7 +575,15 @@ summarize_exports() {
567575
log 'list of container exports:'
568576

569577
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+
571587
done < "$PATH_FILE_ETC_EXPORTS"
572588
}
573589

0 commit comments

Comments
 (0)