Skip to content

add check_shasum #44

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

Merged
merged 3 commits into from
Jan 4, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add check_sum
  • Loading branch information
aniaan committed Dec 26, 2020
commit 61d422e652d4e1aefb0be44f9f797150f4ca0529
26 changes: 26 additions & 0 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ my_mktemp () {
echo -n $tempdir
}

check_shasum() {
local archive_file_name=$1
local authentic_checksum_file=$2
local authentic_checksum=$(cat $authentic_checksum_file)

if $(command -v sha256sum >/dev/null 2>&1); then
sha256sum \
-c <<<"$authentic_checksum $archive_file_name"
elif $(command -v shasum >/dev/null 2>&1); then
shasum \
-a 256 \
-c <<<"$authentic_checksum $archive_file_name"
else
echo "sha256sum or shasum is not available for use" >&2
return 1
fi
}

install_golang () {
local install_type=$1
local version=$2
Expand All @@ -55,6 +73,14 @@ install_golang () {
local tempdir=$(my_mktemp $platform)

curl "https://dl.google.com/go/go${version}.${platform}-${arch}.tar.gz" -o "${tempdir}/archive.tar.gz"
curl "https://dl.google.com/go/go${version}.${platform}-${arch}.tar.gz.sha256" -o "${tempdir}/archive.tar.gz.sha256"

echo 'start check sha256sum'
if ! check_shasum "${tempdir}/archive.tar.gz" "${tempdir}/archive.tar.gz.sha256"; then
echo "Authenticity of package archive can not be assured. Exiting." >&2
rm -rf "${tempdir}"
exit 1
fi

tar -C "$install_path" -xzf "${tempdir}/archive.tar.gz"

Expand Down