yq/scripts/extract-checksum.sh

60 lines
1.8 KiB
Bash
Raw Permalink Normal View History

2021-12-10 04:02:59 +00:00
#!/bin/bash
# This script works with checksums_hashes_order and checksums to extract the relevant
# sha of the various yq downloads. You can then use your favourite checksum tool to validate.
# <CHECKSUM> must match an entry in checksums_hashes_order.
#
# Usage: ./extract-checksum.sh <CHECKSUM> <FILE>
2021-12-10 05:48:10 +00:00
# E.g: ./extract-checksum.sh SHA-256 yq_linux_amd64.tar.gz
2021-12-10 04:02:59 +00:00
# Outputs:
# yq_linux_amd64.tar.gz acebc9d07aa2d0e482969b2c080ee306e8f58efbd6f2d857eefbce6469da1473
#
# Usage with rhash:
2021-12-10 05:48:10 +00:00
# ./extract-checksum.sh SHA-256 yq_linux_amd64.tar.gz | rhash -c -
2021-12-10 04:02:59 +00:00
#
# Tip, if you want the checksum first then the filename (e.g. for the md5sum command)
# then you can pipe the output of this script into awk to switch the fields around:
#
2021-12-10 05:48:10 +00:00
# ./extract-checksum.sh MD5 yq_linux_amd64.tar.gz | awk '{ print $2 " " $1}' | md5sum -c -
2021-12-10 04:02:59 +00:00
#
#
if [ "$1" == "" ]; then
echo "Please specify at a hash algorithm from the checksum_hashes_order"
echo "Usage: $0 <HASH-ALG> <FILE>"
exit 1
fi
2021-12-10 05:48:10 +00:00
if [ "$2" != "" ]; then
2023-09-18 23:52:36 +00:00
# so we don't match x.tar.gz when 'x' is given
2021-12-10 05:48:10 +00:00
file="$2\s"
else
file=""
fi
if [ ! -f "checksums_hashes_order" ]; then
2021-12-10 04:02:59 +00:00
echo "This script requires checksums_hashes_order to run"
2021-12-10 05:48:10 +00:00
echo "Download the file from https://github.com/mikefarah/yq/releases/ for the version of yq you are trying to validate"
2021-12-10 04:02:59 +00:00
exit 1
fi
2021-12-10 05:48:10 +00:00
if [ ! -f "checksums" ]; then
echo "This script requires the checksums file to run"
echo "Download the file from https://github.com/mikefarah/yq/releases/ for the version of yq you are trying to validate"
2021-12-10 04:02:59 +00:00
exit 1
fi
grepMatch=$(grep -m 1 -n "$1" checksums_hashes_order)
if [ "$grepMatch" == "" ]; then
2023-09-18 23:52:36 +00:00
echo "Could not find hash algorithm '$1' in checksums_hashes_order"
2021-12-10 04:02:59 +00:00
exit 1
fi
set -e
lineNumber=$(echo "$grepMatch" | cut -f1 -d:)
realLineNumber="$(($lineNumber + 1))"
2021-12-10 05:48:10 +00:00
grep "$file" checksums | sed 's/ /\t/g' | cut -f1,$realLineNumber