From b1d8fcc31067307a3b402e13562d61ee76fbf8c5 Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Thu, 9 Jan 2025 12:08:24 +0100 Subject: [PATCH] core: use native shasum binary on macOS for download verification (#1245) Signed-off-by: Abiola Ibrahim --- util/downloader/sha.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/downloader/sha.go b/util/downloader/sha.go index c1292f86..0ce970fb 100644 --- a/util/downloader/sha.go +++ b/util/downloader/sha.go @@ -5,6 +5,8 @@ import ( "path/filepath" "strconv" "strings" + + "github.com/abiosoft/colima/util" ) // SHA is the shasum of a file. @@ -18,14 +20,19 @@ type SHA struct { func (s SHA) ValidateFile(host hostActions, file string) error { dir, filename := filepath.Split(file) digest := strings.TrimPrefix(s.Digest, fmt.Sprintf("sha%d:", s.Size)) + shasumBinary := "shasum" + if util.MacOS() { + shasumBinary = "/usr/bin/shasum" + } script := strings.NewReplacer( "{dir}", dir, "{digest}", digest, "{size}", strconv.Itoa(s.Size), "{filename}", filename, + "{shasum_bin}", shasumBinary, ).Replace( - `cd {dir} && echo "{digest} {filename}" | shasum -a {size} --check --status`, + `cd {dir} && echo "{digest} {filename}" | {shasum_bin} -a {size} --check --status`, ) return host.Run("sh", "-c", script)