Skip to content
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

fix: sha256 command #1987

Merged
merged 2 commits into from
Mar 17, 2023
Merged
Changes from all commits
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
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