Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New 'etcupdate' sub command #660
base: master
Are you sure you want to change the base?
New 'etcupdate' sub command #660
Changes from 1 commit
c3b20ed
7031fb3
98866dc
2dcb30c
98706c0
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, the
C1
-C8
naming convention makes it difficult to read what is going on, which might make for maintenance difficulty. Perhaps prefer functions and variables that actually describe the operation, rather than the opaque, e.g.user_added
(I think that'sC1
),upgrade_added
(C2
?), for readability.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern of
for X in $(find...)
is risky if filenames contain whitespace or control chars, but the "usual" mechanisms to sanely deal with arbitrary filenames are typicallybash
-specific (e.g.find ... -print0 | while IFS= read -r -d''; do ... done
).Generally, in POSIX shells, the only supported way (I know of) is to
find -exec sh -c '...' +
orfind -print0 | xargs -0 sh -c '...'
, which would introduce a subshell and affect availability/scope of your variables.Perhaps, this may be better written as...
This should ensure that filenames are properly quoted, so even if they contain garbage, they will still be handled correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even considering the readability of
C1
(as above), the suffixct
does not make sense. I believe this is a file list, built up for display purposes, butct
could easily be taken to mean count.Perhaps
$user_added_list
and$user_added_count
would make it more explicit?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the output of
diff -u
is important, consider using temp files to capture it rather than variables. Variables can have whitespace folding and length issues, which might lead to unexpected corruption.Also, if
diff3
is available (i.e.if command -v diff3 >/dev/null 1>&2; then ... fi
), perhaps use a threeway diff to generate auto-updated files, e.g.diff3 -A "${newbasefile}" "${currentbasefile}" "${jailfile}"
(I think that's the right way around for those file args; it may also/alternatively need-m
). This should be able to better differentiate between changes that were made by the end-user and changes that were introduced by the update. I think this is whatfreebsd-update
does for the "normal" install/upgrade procedure, and it might be good to do something similar here.Perhaps use
diffdir="$(mktemp -d -t "${TMPDIR:-/tmp}/etcupdate.XXXXXX")"
to make a temporary directory, then write your diffs into the temp dir. Let the end-user decide whether to use your version or the existing version, then move the desired version out of the directory into the correct place. Usetrap "[ -d '${diffdir}' ] && rm -rf -- '${diffdir}'" EXIT INT TERM
to clean up all unused temp files at the end of the run.Also, perhaps allow end-user to invoke
vi
(or"${VISUAL:-${EDITOR:-vi}}"
for style points) on the updated file, so they can make manual edits to each file prior to acceptance. Especially, if doing in-place diffs withdiff3
, you can use the exit code to determine if a diff conflict has happened ([ "$?" -eq 1 ]
), and prompt them to manually resolve.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend
--
between switches and file list; if someone happens to place a file called-x
into /etc,rm
would see this as an argument, not a file. e.g.rm -f -- ${jailfile}
If
$jailfile
is always a file (constrained byfind -type f
in L56), does it need to be recursive-r
?Possible issue with whitespace in filename, if filename is folded into
eval
'd command string? Since you are usingeval "$@"
inexecuteconditional
, couldn't this simply beexecuteconditional rm -f -- "${jailfile}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with above, could this be
executeconditional cp -p -- "${newbasefile}" "${jailfile}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, there have been changes to the jail's
/etc
files compared to thecurrentbasefile
, so there will be a diff for C5 or C6. Rather than have a list of diffs to revisit later (the conservative approach is to leave them alone), it would be great to have the option enter an interactive mode to approve/modify the diff here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with above, could this be
executeconditional mkdir -p -- "${jailpath}"
(the
-p
would make any missing intermediate parent dirs; omit it if you don't want this)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with above, could this be
executeconditional chmod "${dirperm}" -- "${jailpath}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest changing
bastille_jail_base
to something likebastille_thin_jail
because the former makes it sound like a "base" jail, which is what the release jails are in this context. The thin jail is the jail to be operated on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I agree with you, I named this variable following the same convention found in the codebase, for consistency. Perhaps best left as is until it (if) is reviewed as a whole? I can see pros and cons of both approaches. So.. umm.. I'm not sure.
bastille/usr/local/share/bastille/create.sh
Line 274 in 3a4ebc6
bastille/usr/local/share/bastille/destroy.sh
Line 40 in 3a4ebc6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with above, could this be
executeconditional cp -p -- "${sourcefile}" "${jailfile}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are trying to loop over the passed function arguments here, i.e.
$1
,$2
, etc...Consider refactoring into a
while [ -n "$1" ]; do ... shift; done
-- then you can always use$1
and have no limitation on the number of arguments passed:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest changing
bastille_jail_base
to something likebastille_thin_jail
because the former makes it sound like a "base" jail, which is what the release jails are in this context. The thin jail is the jail to be operated on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#660 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest changing
bastille_jail_base
to something likebastille_thin_jail
because the former makes it sound like a "base" jail, which is what the release jails are in this context. The thin jail is the jail to be operated on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#660 (comment)