Skip to content

Commit 26956c6

Browse files
committed
add
1 parent dbdaee5 commit 26956c6

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

Linux/install_zig.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
3+
#-------------------------------------------------------#
4+
## <DO NOT RUN STANDALONE, meant for CI Only>
5+
## Meant to Install & Setup Zig
6+
###-----------------------------------------------------###
7+
8+
#-------------------------------------------------------#
9+
##ENV
10+
set -euo pipefail
11+
ZIG_DIR="/usr/local/zig"
12+
TEMP_DIR="$(mktemp -d)"
13+
trap 'rm -rf "$TEMP_DIR"' EXIT
14+
#-------------------------------------------------------#
15+
16+
#-------------------------------------------------------#
17+
##Architecture
18+
case "$(uname -m)" in
19+
aarch64) ARCH="aarch64" ;;
20+
armv7l) ARCH="armv7a" ;;
21+
i?86) ARCH="i386" ;;
22+
riscv64) ARCH="riscv64" ;;
23+
x86_64) ARCH="x86_64" ;;
24+
*) echo "[-] Unsupported architecture: $(uname -m)" && exit 1 ;;
25+
esac
26+
echo "[+] Installing Zig for linux-${ARCH}..."
27+
#-------------------------------------------------------#
28+
29+
#-------------------------------------------------------#
30+
##Deps
31+
for cmd in curl jq tar; do
32+
command -v "${cmd}" >/dev/null || { echo "[-] Missing: ${cmd}" && exit 1; }
33+
done
34+
#-------------------------------------------------------#
35+
36+
#-------------------------------------------------------#
37+
##Install
38+
#Clean Existing
39+
[[ -d "${ZIG_DIR}" ]] && sudo rm -rf "${ZIG_DIR}"
40+
#Get URL
41+
cd "${TEMP_DIR}"
42+
DOWNLOAD_URL="$(curl -qfsSL "https://ziglang.org/download/index.json" | \
43+
jq -r ".master.\"${ARCH}-linux\".tarball // empty")"
44+
[[ -z "${DOWNLOAD_URL}" || "${DOWNLOAD_URL}" == "null" ]] && {
45+
echo "[-] No release found for $ARCH-linux" && exit 1;
46+
}
47+
#Download
48+
for i in {1..3}; do
49+
curl -w "(DL) <== %{url}\n" -fSL "${DOWNLOAD_URL}" -o "zig.tar.xz" && break
50+
[[ $i -eq 3 ]] && { echo "[-] Download failed" && exit 1; }
51+
echo "[!] Retry $i/3..."
52+
done
53+
#Extract and install
54+
tar -xf "zig.tar.xz"
55+
ZIG_SRC="$(find . -maxdepth 1 -type d -name "*zig*" | head -1)"
56+
[[ -z "${ZIG_SRC}" ]] && { echo "[-] Extract failed" && exit 1; }
57+
sudo mkdir -p "${ZIG_DIR}"
58+
sudo cp -r "${ZIG_SRC}"/* "${ZIG_DIR}"/
59+
#-------------------------------------------------------#
60+
61+
#-------------------------------------------------------#
62+
##Check
63+
export PATH="${ZIG_DIR}:${PATH}"
64+
hash -r &>/dev/null
65+
command -v zig >/dev/null || { echo "[-] Installation failed" && exit 1; }
66+
echo "[+] Success! Zig version: $(zig version)"
67+
sudo ldconfig 2>/dev/null || true
68+
#-------------------------------------------------------#

0 commit comments

Comments
 (0)