Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·62 lines (52 loc) · 1.69 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·62 lines (52 loc) · 1.69 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
#!/bin/sh
set -e
REPO="museslabs/stochos"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
BINARY="stochos"
get_latest_tag() {
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' \
| cut -d '"' -f 4
}
main() {
tag="${1:-$(get_latest_tag)}"
if [ -z "$tag" ]; then
echo "error: could not determine latest release" >&2
exit 1
fi
os="$(uname -s)"
arch="$(uname -m)"
case "$os" in
Linux)
os_name="linux"
case "$arch" in
x86_64) arch_name="x86_64" ;;
*) echo "error: unsupported architecture for Linux: $arch" >&2; exit 1 ;;
esac
;;
Darwin)
os_name="darwin"
case "$arch" in
arm64|aarch64) arch_name="aarch64" ;;
*) echo "error: unsupported architecture for macOS: $arch (Apple Silicon only)" >&2; exit 1 ;;
esac
;;
*) echo "error: unsupported OS: $os" >&2; exit 1 ;;
esac
tarball="${BINARY}-${os_name}-${arch_name}.tar.gz"
url="https://github.com/${REPO}/releases/download/${tag}/${tarball}"
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
echo "downloading ${BINARY} ${tag}..."
curl -fsSL "$url" -o "${tmpdir}/${tarball}"
tar xzf "${tmpdir}/${tarball}" -C "$tmpdir"
if [ -w "$INSTALL_DIR" ]; then
mv "${tmpdir}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
else
echo "installing to ${INSTALL_DIR} (requires sudo)..."
sudo mv "${tmpdir}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
fi
chmod +x "${INSTALL_DIR}/${BINARY}"
echo "installed ${BINARY} to ${INSTALL_DIR}/${BINARY}"
}
main "$@"