Skip to content

Commit

Permalink
add check sum check
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Apr 4, 2024
1 parent 5187697 commit a5ad5c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,39 @@ install_zig() {
esac

local json
json=$(curl --fail --silent --location https://ziglang.org/download/index.json)
json=$(curl --fail --progress-bar --location https://ziglang.org/download/index.json)

local download_url
download_url=$(
json_parse "$json" |
grep "\[\"$version\",\"${architecture}-${platform}\",\"tarball\"\]" |
awk 'NR==1 { print $2 }' |
tr -d '"'
)
)
local expected_shasum
expected_shasum=$(
json_parse "$json_replace" |
grep "\[\"$version\",\"${architecture}-${platform}\",\"shasum\"\]" |
awk '{print $2}' |
tr -d '"'
)

local source_path="${install_path}/zig-${platform}-${architecture}-${version}.tar.xz"

echo "∗ Downloading and installing Zig..."
curl --fail --silent --location --create-dirs --output "$source_path" "$download_url"
curl --fail --progress-bar --location --create-dirs --output "$source_path" "$download_url"

local actual_shasum
actual_shasum="$(shasum -a 256 "$source_path" | awk '{print $1}')"

if [[ "${expected_shasum}" != "${actual_shasum}" ]];then
fail "Checksum not same, expected: ${expected_shasum}, actual: ${actual_shasum}, file: ${source_path}"
fi

tar -xf "$source_path" -C "$install_path" --strip-components=1
mkdir -p "${install_path}/bin"
ln -s "${install_path}/zig" "${install_path}/bin/zig"
echo "The installation was successful!"
echo "${version} was installed successful!"
}

install_zig "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
2 changes: 1 addition & 1 deletion bin/list-all
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -Eo pipefail
# shellcheck disable=SC1091
source "$(dirname "$0")/../lib/json.bash"

json=$(curl --fail --silent --location https://ziglang.org/download/index.json)
json=$(curl --fail --progress-bar --location https://ziglang.org/download/index.json)

sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
Expand Down

0 comments on commit a5ad5c7

Please sign in to comment.