forked from euantorano/docker-zig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-zig-manager
executable file
·50 lines (42 loc) · 972 Bytes
/
docker-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
#!/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 sha hash"
echo " extract Extract Zig binary package into directory $TARGET_DIRECTORY if not already extracted"
}
fetch() {
apk add --no-cache --virtual .fetch-deps curl \
&& curl -s -o zig.tar.xz "$1" ; \
if [[ -n "$2" ]]; then
echo "$2 *zig.tar.xz" | sha256sum -c - ;
fi \
&& 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)
fetch $2 $3
;;
extract)
extract
;;
*)
usage
exit 1
;;
esac