-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinstall_zig.sh
executable file
·55 lines (43 loc) · 1.32 KB
/
install_zig.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
set -eux
# Thanks to https://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux
unames=$(uname -s)
arch=$(uname -m)
case "$unames" in
Linux*) OS="linux";;
Darwin*) OS="macos";;
*) echo "Unknown HOST_ARCH=$(uname -s)"; exit 1;;
esac
case "$arch" in
x86_64*) ARCH="x86_64";;
arm64*) ARCH="aarch64";;
*) echo "Unknown $arch"; exit 1;;
esac
HOST_ARCH="$ARCH-$OS"
ZIG_VERSION=0.13.0
ZIG_VERSIONS=$(curl https://ziglang.org/download/index.json)
ZIG_MASTER_TAR=$(echo $ZIG_VERSIONS | jq -r ".\"$ZIG_VERSION\".\"$HOST_ARCH\".tarball")
ZIG_MASTER_SHA256=$(echo $ZIG_VERSIONS | jq -r ".\"$ZIG_VERSION\".\"$HOST_ARCH\".shasum")
ZIG_TAR_NAME="zig-$ZIG_VERSION.tar.xz"
if [ -e $ZIG_TAR_NAME ]; then
rm $ZIG_TAR_NAME
fi
curl $ZIG_MASTER_TAR -o $ZIG_TAR_NAME
TAR_SHA256=$(shasum -a 256 $ZIG_TAR_NAME | awk '{print $1}')
if [ "$TAR_SHA256" != "$ZIG_MASTER_SHA256" ]; then
echo "Invalid SHASUM!"
exit 1
fi
INSTALL_DIR="$HOME/.local/zig-master"
if [ -e $INSTALL_DIR ]; then
rm -rf $INSTALL_DIR
fi
mkdir -p $INSTALL_DIR
tar -xvf $ZIG_TAR_NAME -C $INSTALL_DIR --strip-components 1
rm $ZIG_TAR_NAME
set +e
cat ~/.bashrc | grep "PATH=\$PATH:$HOME/.local/zig-master"
if [ $? -ne 0 ]; then
echo "PATH=\$PATH:$HOME/.local/zig-master" >> ~/.bashrc
fi
set -e