Skip to content

Commit

Permalink
fix: sha256 command (#1987)
Browse files Browse the repository at this point in the history
* fix: sha256 command

* chore: name variables
  • Loading branch information
aiell0 authored Mar 17, 2023
1 parent 5fe9ac6 commit 0d33b36
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions scripts/install_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,33 @@ arch=$(get_machine_arch)

echo "arch=$arch"

remote_filename="tfsec"
local_filename="tfsec"
case "$(uname -s)" in
Darwin*)
remote_filename+="-darwin-${arch}"
remote_filename="$local_filename-darwin-${arch}"
checkgen_filename="$local_filename-checkgen-darwin-${arch}"
;;
MINGW64*)
remote_filename+="-windows-${arch}"
remote_filename="$local_filename-windows-${arch}"
checkgen_filename+="$local_filename-checkgen-windows-${arch}"
local_filename+=".exe"
;;
MSYS_NT*)
remote_filename+="-windows-${arch}"
remote_filename+="$local_filename-windows-${arch}"
checkgen_filename+="$local_filename-checkgen-windows-${arch}"
local_filename+=".exe"
;;
*)
remote_filename+="-linux-${arch}"
remote_filename+="$local_filename-linux-${arch}"
checkgen_filename+="$local_filename-checkgen-linux-${arch}"
;;
esac
checksum_file="tfsec_checksums.txt"
download_path=$(mktemp -d -t tfsec.XXXXXXXXXX)

echo "remote_filename=$remote_filename"
echo "local_filename=$local_filename"
echo "checkgen_filename=$checkgen_filename"

mkdir -p $download_path

Expand All @@ -58,25 +62,28 @@ fi

echo "Downloading tfsec $version"

curl --fail --silent -L -o "${download_path}/${remote_filename}" "https://github.com/aquasecurity/tfsec/releases/download/${version}/${remote_filename}"
tfsec_dl_status=$?
if [ $tfsec_dl_status -ne 0 ]; then
echo "Failed to download ${remote_filename}"
exit $tfsec_dl_status
fi
echo "Downloaded successfully"

echo "Validate checksum"
curl --fail --silent -L -o "${download_path}/${checksum_file}" "https://github.com/aquasecurity/tfsec/releases/download/${version}/${checksum_file}"
checksum_dl_val=$?
if [ $checksum_dl_val -ne 0 ]; then
echo "Failed to download checksum file ${checksum_file}"
exit $checksum_dl_val
fi
download_file() {
echo "Downloading $3..."
local download_path=${1:?Download path no supplied}
local version=${2:?No version supplied}
local file=${3:?File to download not supplied}
curl --fail --silent -L -o "${download_path}/${file}" "https://github.com/aquasecurity/tfsec/releases/download/${version}/${file}"
dl_status=$?
if [ $dl_status -ne 0 ]; then
echo "Failed to download ${file}"
exit $dl_status
fi
echo "Downloaded file \"${file}\" successfully"
}

download_file ${download_path} ${version} ${remote_filename}
download_file ${download_path} ${version} ${checkgen_filename}
download_file ${download_path} ${version} ${checksum_file}

pushd $PWD > /dev/null
cd $download_path
sha256sum -c $checksum_file --quiet --ignore-missing
cat ${checksum_file} | grep ${checkgen_filename} > checksum.txt
sha256sum -c checksum.txt --quiet
shasum_val=$?
popd > /dev/null

Expand Down

0 comments on commit 0d33b36

Please sign in to comment.