Skip to content

Comments

install.sh: Fix ShellCheck warnings#239

Merged
MartinNowak merged 9 commits intodlang:masterfrom
CyberShadow:pull-20170717-123612
Aug 14, 2017
Merged

install.sh: Fix ShellCheck warnings#239
MartinNowak merged 9 commits intodlang:masterfrom
CyberShadow:pull-20170717-123612

Conversation

@CyberShadow
Copy link
Member

No description provided.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @CyberShadow!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

fi
log "Removing $path/$1"
rm -rf "$path/$1"
rm -rf "${path:-.}/$1"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 /.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed.

@CyberShadow CyberShadow requested a review from MartinNowak July 17, 2017 12:42
Copy link
Member

@PetarKirov PetarKirov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change from ls to find -maxdepth 1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

fi
log "Removing $path/$1"
rm -rf "$path/$1"
rm -rf "${path:-.}/$1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed.

@CyberShadow CyberShadow force-pushed the pull-20170717-123612 branch from 595b514 to 9b5a2c7 Compare July 18, 2017 02:42
@CyberShadow
Copy link
Member Author

CyberShadow commented Jul 18, 2017

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.

Good idea, done. I also improved some of the fixes slightly.

@CyberShadow CyberShadow force-pushed the pull-20170717-123612 branch 2 times, most recently from 07ea81c to deb1eea Compare July 18, 2017 02:50
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
@CyberShadow CyberShadow force-pushed the pull-20170717-123612 branch from deb1eea to c0763b8 Compare July 18, 2017 02:58
Copy link
Member

@PetarKirov PetarKirov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @CyberShadow for splitting the PR into separate commits and linking to the respective Shell Check wiki entry, much appreciated!

Same here :)

@wilzbach
Copy link
Contributor

Btw how about adding a check to Travis, s.t. it future additions are checked as well?

-> https://github.com/koalaman/shellcheck/wiki/TravisCI

Copy link
Member

@MartinNowak MartinNowak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks a lot.

fi
log "Removing $path/$1"
rm -rf "$path/$1"
rm -rf "${path:?}/$1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that's why we're using set -u, but anyhow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat

@MartinNowak MartinNowak force-pushed the pull-20170717-123612 branch from 1a0eccb to 9f549b9 Compare August 14, 2017 14:13
@MartinNowak MartinNowak merged commit 2eabc00 into dlang:master Aug 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants