-
Notifications
You must be signed in to change notification settings - Fork 2
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
switch to using --check #4
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
#!/bin/bash | ||
|
||
function checksum() { | ||
local s | ||
s=$(curl -fsSL "$1") | ||
if ! command -v shasum >/dev/null | ||
then | ||
shasum() { sha1sum "$@"; } | ||
fi | ||
c=$(printf %s\\n "$s" | shasum | awk '{print $1}') | ||
if [ "$c" = "$2" ] | ||
then | ||
printf %s\\n "$s" | ||
local h | ||
if command -v shasum >/dev/null ; then | ||
h=shasum | ||
else | ||
echo "invalid checksum $c != $2" 1>&2; | ||
h=sha1sum | ||
fi | ||
if [ ! "$2" ] ; then | ||
printf %s\\n "$s" | "$h" | awk '{print $1}' | ||
return 1; | ||
fi | ||
unset s | ||
unset c | ||
printf %s\\n "$s" | "$h" --check --status <(printf '%s -\n' "$2") || { | ||
echo "checksum failed" >&2; | ||
return 1; | ||
} | ||
printf %s\\n "$s" | ||
} |
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.
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.
Note that shell truncates trailing newlines from variables, so if a script ends with several newlines, it'll only keep the last one. Example exhibiting the problem:
So
printf %s\\n "$f" | shasum -a 256
does not give the same ascurl -fsSL http://localhost:8980/f | shasum -a 256
, it gives the same result ascurl -fsSL http://localhost:8980/t | shasum -a 256
andprintf %s\\n "$t" | shasum -a 256
.It's quite likely there exist scripts in the wild that have trailing newlines, so the shell variable capture is probably non-viable.
(I ran this experiment in msys zsh on windows, but ran it based on knowledge of the newline chomping of POSIX sh -- I just double-checked and ran it on bash on linux and it was the same result, only difference being the weird "*" in the shasum output is now another space as expected)
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.
@dundarious given that, downloading the script to a tmp file may be the best solution
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.
#6