-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzig-manager
57 lines (47 loc) · 1.25 KB
/
zig-manager
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
55
56
57
#!/bin/sh
set -eux
TARGET_DIR="/usr/local/bin/zig"
usage() {
echo "Usage: $0 COMMAND"
echo
echo "Manage Zig binary packages"
echo
echo "Commands:"
echo " fetch URL SHA256 Fetch a Zig binary package from the given URL with the given SHA256 hash"
echo " extract Extract the Zig binary package into the directory $TARGET_DIR if not already extracted"
}
fetch() {
local url="$1"
local sha256="$2"
apk add --no-cache --virtual .fetch-deps curl \
&& curl -s -o /usr/src/zig.tar.xz "$url" \
&& echo "$sha256 *zig.tar.xz" | sha256sum -c - \
&& apk del .fetch-deps
}
extract() {
apk add --no-cache --virtual .extract-deps tar xz
mkdir -p "$TARGET_DIR"
if [ ! -f "$TARGET_DIR/.extracted" ]; then
tar -Jxf /usr/src/zig.tar.xz -C "$TARGET_DIR" --strip-components=1
touch "$TARGET_DIR/.extracted"
fi
rm /usr/src/zig.tar.xz
apk del .extract-deps
}
case "$1" in
fetch)
if [ -z "$2" ] || [ -z "$3" ]; then
echo "Error: URL and SHA256 are required for fetch."
usage
exit 1
fi
fetch "$2" "$3"
;;
extract)
extract
;;
*)
usage
exit 1
;;
esac