Skip to content

Instantly share code, notes, and snippets.

@nektro
Created February 13, 2025 11:58
Show Gist options
  • Save nektro/a53ac708ffa775ba6d69ed3b3c9fb580 to your computer and use it in GitHub Desktop.
Save nektro/a53ac708ffa775ba6d69ed3b3c9fb580 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
download-zig() {
arch=$(uname -m)
os=$(uname -s | tr '[:upper:]' '[:lower:]')
double="$arch-$os"
if [ -z "$1" ]
then
echo missing version argument
return
fi
saveversion="$1"
echo saving $saveversion
savepath="$HOME/.local/share/zig/$saveversion"
filename=zig-$os-$arch-$saveversion.tar.xz
if [ -d $savepath ]
then
echo local folder already exists
echo $savepath
else
echo local folder does not exist, downloading
wget -q --show-progress http://mirrors.nektro.net/zig/$saveversion/$filename
wget -q --show-progress http://mirrors.nektro.net/zig/$saveversion/$filename.minisig
echo verifying
minisign -Vm $filename -P 'RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U' || return
echo extracting
tar -xf $filename
folder=$filename
folder=${folder%.*}
folder=${folder%.*}
rm $filename
rm $filename.minisig
mkdir -p $HOME/.local/share/zig
mv $folder $savepath
fi
}
update-zig() {
arch=$(uname -m)
os=$(uname -s | tr '[:upper:]' '[:lower:]')
double="$arch-$os"
old=$(zig version)
if [[ $1 == "master" ]]
then
new=$(curl -s https://ziglang.org/download/index.json | jq -r '.master.version')
else
new=$1
fi
download-zig $new
savepath="$HOME/.local/share/zig/$new"
ln -s -T -f $savepath/zig ~/.local/bin/zig
ln -s -T -f $savepath/zig ~/.local/bin/zig-$new
echo
echo "Updated Zig from ${old} to $(zig version)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment