-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·63 lines (48 loc) · 1.61 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·63 lines (48 loc) · 1.61 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
#!/bin/sh
set -eu
REPO="plumenetwork/nest-cli"
INSTALL_DIR="/usr/local/bin"
BINARY_NAME="nest"
main() {
os="$(uname -s)"
arch="$(uname -m)"
case "$os" in
Linux) target_os="unknown-linux-gnu" ;;
Darwin) target_os="apple-darwin" ;;
*) err "Unsupported OS: $os" ;;
esac
case "$arch" in
x86_64|amd64) target_arch="x86_64" ;;
aarch64|arm64) target_arch="aarch64" ;;
*) err "Unsupported architecture: $arch" ;;
esac
target="${target_arch}-${target_os}"
archive="nest-cli-${target}.tar.gz"
# Get latest release tag
tag="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' | head -1 | cut -d '"' -f 4)"
if [ -z "$tag" ]; then
err "Failed to fetch latest release"
fi
url="https://github.com/${REPO}/releases/download/${tag}/${archive}"
printf "Installing %s %s (%s)...\n" "$BINARY_NAME" "$tag" "$target"
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
curl -fsSL "$url" -o "${tmpdir}/${archive}"
tar xzf "${tmpdir}/${archive}" -C "$tmpdir"
# Install binary
if [ -w "$INSTALL_DIR" ]; then
mv "${tmpdir}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
else
printf "Need sudo to install to %s\n" "$INSTALL_DIR"
sudo mv "${tmpdir}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
fi
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
printf "Installed %s to %s/%s\n" "$tag" "$INSTALL_DIR" "$BINARY_NAME"
printf "Run 'nest --help' to get started.\n"
}
err() {
printf "Error: %s\n" "$1" >&2
exit 1
}
main