Skip to content

Instantly share code, notes, and snippets.

@TheWaWaR
Last active October 5, 2022 14:09
Show Gist options
  • Save TheWaWaR/ffaadcc2dd83a1215fab851352c4db7b to your computer and use it in GitHub Desktop.
Save TheWaWaR/ffaadcc2dd83a1215fab851352c4db7b to your computer and use it in GitHub Desktop.
Download zig binary extract it and link the executable file
set -e
DEFAULT_ZIG_DIR="$HOME/local/opt"
DEFAULT_BIN_DIR="$HOME/local/bin"
URL="${1}"
ZIG_DIR="${2:-$DEFAULT_ZIG_DIR}"
BIN_DIR="${3:-$DEFAULT_BIN_DIR}"
function error() {
err_code=$1
err_msg=$2
echo "ERROR: $err_msg"
exit $err_code
}
if [ -z "$URL" ]; then
error 1 "zig download URL is missing!"
fi
FILENAME=`echo $URL | cut -d "/" -f 5`
DIRNAME=`echo $FILENAME | awk -F'.tar' '{print $1}'`
DOWNLOAD_PATH="$ZIG_DIR/$FILENAME"
if [ ! -d "$ZIG_DIR/$DIRNAME" ]; then
echo "download from ${URL} to ${DOWNLOAD_PATH}"
wget -O $DOWNLOAD_PATH $URL
tar -xf $DOWNLOAD_PATH -C $ZIG_DIR
else
echo "zig directory <$ZIG_DIR/$DIRNAME> already exits"
fi
echo -e "link zig-current\n from: <$ZIG_DIR/$DIRNAME>\n to: <$ZIG_DIR/zig-current>"
ln -sf $ZIG_DIR/$DIRNAME $ZIG_DIR/zig-current
echo -e "link zig\n from: <$ZIG_DIR/zig-current/zig>\n to: <$BIN_DIR/zig>"
ln -sf $ZIG_DIR/zig-current/zig $BIN_DIR/zig
echo ">> upgrade success!"
zig version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment