-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·101 lines (81 loc) · 2.64 KB
/
install.sh
File metadata and controls
executable file
·101 lines (81 loc) · 2.64 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh
# Install the neaps CLI.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/openwatersio/neaps/main/install.sh | sh
#
# Environment variables:
# NEAPS_VERSION - version to install (default: latest)
# NEAPS_INSTALL_DIR - installation directory (default: /usr/local/bin)
set -e
REPO="openwatersio/neaps"
INSTALL_DIR="${NEAPS_INSTALL_DIR:-/usr/local/bin}"
# Detect OS
OS="$(uname -s)"
case "$OS" in
Linux) os="linux" ;;
Darwin) os="darwin" ;;
*) echo "Error: unsupported OS: $OS" >&2; exit 1 ;;
esac
# Detect architecture
ARCH="$(uname -m)"
case "$ARCH" in
x86_64) arch="x64" ;;
aarch64|arm64) arch="arm64" ;;
*) echo "Error: unsupported architecture: $ARCH" >&2; exit 1 ;;
esac
TARGET="${os}-${arch}"
# Only linux-x64 and darwin-arm64 binaries are available
if [ "$TARGET" != "linux-x64" ] && [ "$TARGET" != "darwin-arm64" ]; then
echo "Error: no pre-built binary for ${TARGET}." >&2
echo "Install via npm instead: npm install -g @neaps/cli" >&2
exit 1
fi
# Resolve version
if [ -z "$NEAPS_VERSION" ]; then
NEAPS_VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
fi
if [ -z "$NEAPS_VERSION" ]; then
echo "Error: could not determine latest version." >&2
exit 1
fi
ARCHIVE="neaps-${TARGET}.tar.gz"
BASE_URL="https://github.com/${REPO}/releases/download/${NEAPS_VERSION}"
echo "Installing neaps ${NEAPS_VERSION} (${TARGET})..."
# Download archive and checksums
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
curl -fsSL "${BASE_URL}/${ARCHIVE}" -o "${TMPDIR}/${ARCHIVE}"
curl -fsSL "${BASE_URL}/checksums.txt" -o "${TMPDIR}/checksums.txt"
# Verify checksum
EXPECTED=$(grep "${ARCHIVE}" "${TMPDIR}/checksums.txt" | cut -d' ' -f1)
if [ -z "$EXPECTED" ]; then
echo "Error: no checksum found for ${ARCHIVE}" >&2
exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
ACTUAL=$(sha256sum "${TMPDIR}/${ARCHIVE}" | cut -d' ' -f1)
elif command -v shasum >/dev/null 2>&1; then
ACTUAL=$(shasum -a 256 "${TMPDIR}/${ARCHIVE}" | cut -d' ' -f1)
else
echo "Error: no sha256sum or shasum command found" >&2
exit 1
fi
if [ "$ACTUAL" != "$EXPECTED" ]; then
echo "Error: checksum verification failed" >&2
echo " expected: ${EXPECTED}" >&2
echo " got: ${ACTUAL}" >&2
exit 1
fi
# Extract
tar xzf "${TMPDIR}/${ARCHIVE}" -C "$TMPDIR"
# Install
if [ -w "$INSTALL_DIR" ]; then
mv "${TMPDIR}/neaps" "${INSTALL_DIR}/neaps"
else
echo "Writing to ${INSTALL_DIR} requires elevated permissions."
sudo mv "${TMPDIR}/neaps" "${INSTALL_DIR}/neaps"
fi
chmod +x "${INSTALL_DIR}/neaps"
echo "Installed neaps to ${INSTALL_DIR}/neaps"