Simple zig update scripts

These are two simple zig update scripts, which I use on Alpine Linux and OpenBSD to get the latest zig binary. I you only need the latest zig version, this is maybe helpful.

#!/bin/sh

# dependencies: wget, tar, minisign, posix stuff, doas (grep, mkdir, rm)

save_zig="$XDG_CONFIG_HOME/zig"
target="zig-x86_64-linux"
mirror="zig.linus.dev/zig/"

rm -rf "$save_zig"
mkdir "$save_zig"

build="/tmp/build-zig"

rm -rf "$build"
mkdir "$build"

version=$(wget -qO- "https://ziglang.org/download/index.json" | grep -A 1 '"master":' | grep -o '"version": "[^"]*' | grep -o '[^"]*$')

name="${target}-${version}"

wget -O "${build}/zig.tar.xz" "https://${mirror}${name}.tar.xz" 
wget -O "${build}/zig.tar.xz.minisig" "https://ziglang.org/builds/${name}.tar.xz.minisig"
printf "untrusted comment:\nRWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U" > "${build}/minisign.pub"

(cd "$build" && minisign -Vm "${build}/zig.tar.xz")

tar -xJf "${build}/zig.tar.xz" -C "$save_zig" --strip-components=1

doas ln -sf "${save_zig}/zig" /usr/local/bin/zig
#!/bin/sh

# dependencies: ftp, tar, minisign, posix stuff, doas (grep, mkdir, rm)

save_zig="$XDG_CONFIG_HOME/zig/"
target="zig-x86_64-openbsd"
mirror="zig.linus.dev/zig/"

rm -rf "$save_zig"
mkdir -p "$save_zig"

build="/tmp/build-zig"

rm -rf "$build"
mkdir -p "$build"

version=$(ftp -o- "https://ziglang.org/download/index.json" | grep -A 1 '"master":' | grep -o '"version": "[^"]*' | grep -o '[^"]*$')

name="${target}-${version}"

ftp -o "${build}/zig.tar.xz" "https://${mirror}${name}.tar.xz" 

ftp -o "${build}/zig.tar.xz.minisig" "https://ziglang.org/builds/${name}.tar.xz.minisig"

printf "untrusted comment:\nRWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U" > "${build}/minisign.pub"

(cd "$build" && minisign -Vm "zig.tar.xz")

xz -dc "${build}/zig.tar.xz" | tar -xf - -C "$save_zig" -s "/^${name}\///"

rm -rf "${save_zig}${name}"

doas ln -sf "${save_zig}/zig" /usr/local/bin/zig

zig docs say you should also check the trusted comment to see if the file names match.

But im not sure what the point of that is, minisig is already file specific so its not possible for it to verify the wrong file?

Also if you find your self installing versions often, even if periods where you do that is uncommon, you should be using community mirrors to remove burden from zigs servers, since they are intentionally low budget and therefore have limited bandwidth.

about the minisig thing idk, I am using community mirror, just as far as I know the version I need to get from ziglang.org

Ah sorry, I missed the mirror part.

Still, hard-coding a specific mirror is not the best, mirrors are likely to also be low budget since they tend to be riding on personal servers.

unless the version is master, which is currently hardcoded, you dont need to fetch the index since the version string should map directly to a download url.

doesnt really matter if your not using it often.