Created
October 18, 2023 11:53
-
-
Save taggon/d10a50c4ea0800be9669ee14c71640c8 to your computer and use it in GitHub Desktop.
Zig update script - only works when zig is already installed
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 | |
# NOTE: This script requires the 'jq' tool. | |
TMP_DIR=/tmp/zig-update | |
if [ -z "$ZIG_DIR" ]; then | |
ZIG_DIR=`dirname $(which zig)` | |
fi | |
TARGET=$(zig env | jq --raw-output .target | sed 's/^\([a-z0-9_\-]*\).*/\1/g') | |
VERSION=$(zig env | jq --raw-output .version) | |
JSON=$(curl -s https://ziglang.org/download/index.json) | |
TARBALL_URL=$(echo $JSON | jq --raw-output ".master[\"$TARGET\"].tarball") | |
MASTER_VERSION=$(echo $JSON | jq --raw-output .master.version) | |
if [ "$TARBALL_URL" = "null" ]; then | |
echo "Cannot find a tarball for $TARGET" | |
exit 1 | |
fi | |
if [ "$MASETR_VERSION" = "$VERSION" ]; then | |
echo "$VERSION is already installed" | |
exit 1 | |
fi | |
mkdir -p $TMP_DIR | |
echo "Downloading tarball..." | |
if curl "$TARBALL_URL" | tar -xJC $TMP_DIR; then | |
BASENAME=$(basename $TARBALL_URL ".tar.xz") | |
rm -rf $ZIG_DIR | |
mv "$TMP_DIR/$BASENAME" $ZIG_DIR | |
else | |
echo "Failed to update" | |
fi | |
VERSION=$(zig env | jq --raw-output .version) | |
echo "Current version is $VERSION" | |
# Clean up | |
rm -rf $TMP_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment