-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdate-zig.sh
More file actions
executable file
·46 lines (40 loc) · 1.13 KB
/
update-zig.sh
File metadata and controls
executable file
·46 lines (40 loc) · 1.13 KB
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
#!/bin/bash
set -Eeufo pipefail
trap 'echo >&2 "$0:$LINENO [$?]: $BASH_COMMAND"' ERR
die() {
echo >&2 "$@"
exit 1
}
run() {
echo >&2 "$@"
"$@"
}
install() {
name=$1
key=${2#key=}
dir=${3#dir=}
index_url=$4
run cd ~/Documents/"$name"
fd -q -d 1 -e tar -e xz && die "There is already a .tar or .xz file"
read -r url shasum < <(
run curl -sL "$index_url" \
| run jq -r $key'."aarch64-macos" | "\(.tarball) \(.shasum)"')
id=${url##*/}
id=${id%.tar.xz}
[[ -z "$id" ]] && die "Failed to extract id"
[[ -n "$dir" ]] && mkdir "$id"
run curl -LO "$url"
run shasum --check -a 256 <<< "$shasum $id.tar.xz"
run xz -d "$id.tar.xz"
run tar ${dir:+-C "$id"} -xf "$id.tar"
run rm "$id.tar"
run sim i -f "$id/$name"
}
if [[ ${1-zig} == zig ]]; then
install zig key=.master dir= https://ziglang.org/download/index.json
fi
if [[ ${1-zls} == zls ]]; then
zig_version=$(run zig version)
zig_version=${zig_version//+/%2B}
install zls key= dir=yes "https://releases.zigtools.org/v1/zls/select-version?zig_version=$zig_version&compatibility=only-runtime"
fi