-
Notifications
You must be signed in to change notification settings - Fork 317
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
feat: add script to verify parameter checksums in parameters.json #1251
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/sh | ||
|
||
# This script verifies that a given `.params` file (and the corresponding | ||
# `.vk` file) is part of `parameters.json` as has the correct digest. | ||
# | ||
# This script runs on POSIX compatible shells. You need to have standard | ||
# utilities (`basename`, `head`, `grep`) as well as have `jq` and `b2sum` | ||
# installed. | ||
# | ||
# The input a `parameter.json` file and a `.params' file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wording is weird ('The input a') |
||
|
||
if [ "${#}" -ne 1 ]; then | ||
echo "Verify that a given .params file (and the corresponding .vk file)" | ||
echo "is part of parameters.json as has the correct digest." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
echo "" | ||
echo "Usage: $(basename "${0}") parameters.json parameter-file.params" | ||
exit 1 | ||
fi | ||
|
||
if ! command -v b2sum >/dev/null 2>&1 | ||
then | ||
echo "ERROR: 'b2sum' needs to be installed." | ||
exit 1 | ||
fi | ||
|
||
if ! command -v jq >/dev/null 2>&1 | ||
then | ||
echo "ERROR: 'jq' needs to be installed." | ||
exit 1 | ||
fi | ||
|
||
PARAMS_JSON=${1} | ||
PARAMS_ID="${2%.*}" | ||
|
||
PARAMS_FILE="${PARAMS_ID}.params" | ||
VK_FILE="${PARAMS_ID}.vk" | ||
|
||
# Transforms the `parameters.json` into a string that consists of digest and | ||
# filename pairs. | ||
PARAMS_JSON_DATA=$(jq -r 'to_entries[] | "\(.value.digest) \(.key)"' "${PARAMS_JSON}") | ||
|
||
VK_HASH_SHORT=$(b2sum "${VK_FILE}"|head --bytes 32) | ||
if echo "${PARAMS_JSON_DATA}"|grep --silent "${VK_HASH_SHORT} ${VK_FILE}"; then | ||
echo "ok Correct digest of VK file was found in ${PARAMS_JSON}." | ||
else | ||
echo "not ok ERROR: Digest of VK file was *not* found/correct in ${PARAMS_JSON}." | ||
exit 1 | ||
fi | ||
|
||
PARAMS_HASH_SHORT=$(b2sum "${PARAMS_FILE}"|head --bytes 32) | ||
if echo "${PARAMS_JSON_DATA}"|grep --silent "${PARAMS_HASH_SHORT} ${PARAMS_FILE}"; then | ||
echo "ok Correct digest of params file was found in ${PARAMS_JSON}." | ||
else | ||
echo "not ok ERROR: Digest of params file was *not* found/correct in ${PARAMS_JSON}." | ||
exit 1 | ||
fi | ||
|
||
echo "# Verification successfully completed." |
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.
Minor typo 'as has the' = 'and has the'