Last active
July 5, 2023 09:42
-
-
Save qtfkwk/8c0a92aa319687e45d16a5bee0ff10fb to your computer and use it in GitHub Desktop.
Install or update Zig on Debian
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Install or update Zig on Debian | |
set -xeo pipefail | |
dst="$HOME/zig" | |
minisign_pub="RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U" | |
json_url="https://ziglang.org/download/index.json" | |
version="master" | |
arch="x86_64" | |
os="linux" | |
json_file="$(basename "$json_url")" | |
need=() | |
for i in jq minisign wget; do which "$i" || need+=("$i"); done | |
if [ ${#need[@]} -gt 0 ]; then sudo apt update; sudo apt install -y ${need[@]}; fi | |
cd "$dst" | |
wget -N "$json_url" | |
tar_url=$(jq -r ".$version.\"$arch-$os\".tarball" "$json_file") | |
tar_sha=$(jq -r ".$version.\"$arch-$os\".shasum" "$json_file") | |
tar_file=$(echo "$tar_url" |cut -d/ -f5) | |
tar_sha_file="$tar_file.sha256" | |
dir=$(echo "$tar_file" |sed 's/\.tar\.xz$//') | |
echo "$tar_url" "$tar_url.minisig" |xargs -P0 wget -N | |
echo "$tar_sha $tar_file" >"$tar_sha_file" | |
sha256sum -c "$tar_sha_file" | |
minisign -V -P "$minisign_pub" -m "$tar_file" | |
if [ ! -e "$dir" ]; then tar xf "$tar_file"; fi | |
rm -f latest | |
ln -s "$dir" latest | |
ls -l | |
t="hello"; if [ ! -e "$t" ]; then mkdir "$t"; cd "$t"; zig init-exe; cd -; fi | |
cd "$t"; zig build run; cd - | |
ls |grep "^zig-$os-$arch-" |grep -v "^$dir" |xargs rm -rf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment