Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·82 lines (72 loc) · 2.42 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·82 lines (72 loc) · 2.42 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
# Install a prebuilt wiff binary from a GitHub release. The release defaults to
# the rolling `continuous` build; set WIFF_VERSION to install from a different
# release. The binary is placed in ~/.local/bin unless WIFF_BIN_DIR is set.
set -eu
repo="wez/wiff"
version="${WIFF_VERSION:-continuous}"
bin_dir="${WIFF_BIN_DIR:-$HOME/.local/bin}"
for tool in curl tar mktemp; do
if ! command -v "$tool" >/dev/null 2>&1; then
echo "wiff: $tool is required" >&2
exit 1
fi
done
os="$(uname -s)"
arch="$(uname -m)"
case "$os" in
Linux)
case "$arch" in
x86_64 | amd64) target="x86_64-unknown-linux-musl" ;;
aarch64 | arm64) target="aarch64-unknown-linux-musl" ;;
*) echo "wiff: unsupported architecture: $arch" >&2; exit 1 ;;
esac
;;
Darwin)
case "$arch" in
x86_64 | amd64) target="x86_64-apple-darwin" ;;
arm64 | aarch64) target="aarch64-apple-darwin" ;;
*) echo "wiff: unsupported architecture: $arch" >&2; exit 1 ;;
esac
;;
*)
echo "wiff: unsupported operating system: $os" >&2
exit 1
;;
esac
archive="wiff-${target}.tar.gz"
# The release's checksum asset is named after the archive minus its .tar.gz
# suffix, e.g. wiff-aarch64-apple-darwin.sha256.
checksum="${archive%.tar.gz}.sha256"
base="https://github.com/${repo}/releases/download/${version}"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
echo "wiff: downloading $base/$archive"
curl -fSL "$base/$archive" -o "$tmp/$archive"
curl -fSL "$base/$checksum" -o "$tmp/$checksum"
# This sha check guards against a corrupted or truncated download only;
# the checksum shares the release channel with the archive and this script
# so it cannot attest provenance. For that you should not be using curl|sh!
if command -v sha256sum >/dev/null 2>&1; then
(cd "$tmp" && sha256sum -c "$checksum")
elif command -v shasum >/dev/null 2>&1; then
(cd "$tmp" && shasum -a 256 -c "$checksum")
else
echo "wiff: no sha256sum or shasum found; skipping checksum verification" >&2
fi
# Find the binary by name rather than assuming its path within the archive, so a
# change to the archive layout cannot silently extract nothing.
tar -xzf "$tmp/$archive" -C "$tmp"
binary="$(find "$tmp" -type f -name wiff | head -n1)"
if [ -z "$binary" ]; then
echo "wiff: no wiff binary found in $archive" >&2
exit 1
fi
mkdir -p "$bin_dir"
cp "$binary" "$bin_dir/wiff"
chmod +x "$bin_dir/wiff"
echo "wiff: installed $bin_dir/wiff"
case ":$PATH:" in
*":$bin_dir:"*) ;;
*) echo "wiff: note: $bin_dir is not on your PATH" >&2 ;;
esac