Skip to content

Instantly share code, notes, and snippets.

@kiriappeee
Last active September 5, 2018 06:47
Show Gist options
  • Save kiriappeee/07a477607ae7391778e7a9899ea166b7 to your computer and use it in GitHub Desktop.
Save kiriappeee/07a477607ae7391778e7a9899ea166b7 to your computer and use it in GitHub Desktop.
Compare local file sha 256 with sha256 through stdin or through remote file
#!/bin/bash
# Usage: ./comparesha256.sh /path/to/local/file sha-copied-from-website
#
# Example: ./comparesha256.sh /usr/local/bin/go de874549d9a8d8d8062be05808509c09a88a248e77ec14eb77453530829ac02b
# Expected output will look like this:
#
# Files checksums match
#
#
# Remote sha - 287b08291e14f1fae8ba44374b26a2b12eb941af3497ed0ca649253e21ba2f83
# Local file sha - 287b08291e14f1fae8ba44374b26a2b12eb941af3497ed0ca649253e21ba2f83
localFile=$1
remoteSha=$2
if [ "$(uname)" == "Darwin" ]
then
localSha=$(gsha256sum $localFile | awk '{print $1')
else
localSha=$(sha256sum $localFile | awk '{print $1}')
fi
if [ "$localSha" == "$remoteSha" ]
then
echo "Files checksums match"
else
echo "MATCH ERROR in file checksums"
fi
printf "\n\nRemote sha - $remoteSha\nLocal file sha - $localSha\n"
#!/bin/bash
# Usage: ./comparesha256.sh /path/to/local/file https://somesite.com/path-to-remote-sha-256-text-file
#
# Example: ./comparesha256.sh /usr/local/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64.sha256
# Expected output will look like this:
#
# Files checksums match
#
#
# Remote sha - 287b08291e14f1fae8ba44374b26a2b12eb941af3497ed0ca649253e21ba2f83
# Local file sha - 287b08291e14f1fae8ba44374b26a2b12eb941af3497ed0ca649253e21ba2f83
localFile=$1
remoteSha256Location=$2
remoteSha=$(curl -sL $remoteSha256Location | awk '{print $1}')
if [ "$(uname)" == "Darwin" ]
then
localSha=$(gsha256sum $localFile | awk '{print $1')
else
localSha=$(sha256sum $localFile | awk '{print $1}')
fi
if [ "$localSha" == "$remoteSha" ]
then
echo "Files checksums match"
else
echo "MATCH ERROR in file checksums"
fi
printf "\n\nRemote sha - $remoteSha\nLocal file sha - $localSha\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment