install.sh: Fix ShellCheck warnings#239
Conversation
|
Thanks for your pull request, @CyberShadow! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
script/install.sh
Outdated
| fi | ||
| log "Removing $path/$1" | ||
| rm -rf "$path/$1" | ||
| rm -rf "${path:-.}/$1" |
There was a problem hiding this comment.
This one is particularly scary - it doesn't look like it can expand to rm -rf /, but it gets too close for comfort, e.g. with --path /.
PetarKirov
left a comment
There was a problem hiding this comment.
Overall LGTM. It would have been nice if each category of warnings fixed was in its own commit and the commit message included the warning text itself.
script/install.sh
Outdated
| check_tools egrep | ||
| if [ -d "$path" ]; then | ||
| ls "$path" | egrep -v '^dub|^install\.sh|^d-keyring\.gpg' | ||
| find "$path" -maxdepth 1 -printf "%f\n" 1 | grep -Ev '^dub|^install\.sh|^d-keyring\.gpg' |
There was a problem hiding this comment.
Why the change from ls to find -maxdepth 1?
There was a problem hiding this comment.
As I understand, ls's output is not meant to be parseable, it's meant for humans. The particular warning here is SC2012, but there are some other related warnings related to piping ls.
Note that this fix was incorrect and suboptimal; in the latest version it is all one find invocation, which also allows us to drop grep/egrep.
script/install.sh
Outdated
| fi | ||
| log "Removing $path/$1" | ||
| rm -rf "$path/$1" | ||
| rm -rf "${path:-.}/$1" |
"> is for string comparisons. Use -gt instead." https://github.com/koalaman/shellcheck/wiki/SC2071
"Quote this to prevent word splitting." https://github.com/koalaman/shellcheck/wiki/SC2046
"Use "${var:?}" to ensure this never expands to / ."
https://github.com/koalaman/shellcheck/wiki/SC2115
"Declare and assign separately to avoid masking return values." https://github.com/koalaman/shellcheck/wiki/SC2155
"$/${} is unnecessary on arithmetic variables."
https://github.com/koalaman/shellcheck/wiki/SC2004
595b514 to
9b5a2c7
Compare
Good idea, done. I also improved some of the fixes slightly. |
07ea81c to
deb1eea
Compare
SC2012: "Use find instead of ls to better handle non-alphanumeric filenames." https://github.com/koalaman/shellcheck/wiki/SC2012 SC2196: "egrep is non-standard and deprecated. Use grep -E instead." https://github.com/koalaman/shellcheck/wiki/SC2196
"Note that A && B || C is not if-then-else. C may run when A is true." https://github.com/koalaman/shellcheck/wiki/SC2015
"Double quote to prevent globbing and word splitting." https://github.com/koalaman/shellcheck/wiki/SC2086
deb1eea to
c0763b8
Compare
PetarKirov
left a comment
There was a problem hiding this comment.
Thanks @CyberShadow for splitting the PR into separate commits and linking to the respective Shell Check wiki entry, much appreciated!
By re-reviewing the commits one-by-one and reading the respective SC explanations, I feel much more comfortable signing off on this PR.
wilzbach
left a comment
There was a problem hiding this comment.
Thanks @CyberShadow for splitting the PR into separate commits and linking to the respective Shell Check wiki entry, much appreciated!
Same here :)
|
Btw how about adding a check to Travis, s.t. it future additions are checked as well? -> https://github.com/koalaman/shellcheck/wiki/TravisCI |
| fi | ||
| log "Removing $path/$1" | ||
| rm -rf "$path/$1" | ||
| rm -rf "${path:?}/$1" |
There was a problem hiding this comment.
Well that's why we're using set -u, but anyhow.
There was a problem hiding this comment.
With set -u, $var will error only if it's unset, not empty. ${var:?} will always error if var is empty (or unset).
| local path=$(mktemp "$TMP_ROOT/XXXXXX") | ||
| local url path | ||
| url=$1 | ||
| path=$(mktemp "$TMP_ROOT/XXXXXX") |
1a0eccb to
9f549b9
Compare
No description provided.