-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
90 lines (75 loc) · 2.21 KB
/
install.sh
File metadata and controls
90 lines (75 loc) · 2.21 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
#!/bin/sh
# Snare install script
# Usage: curl -fsSL https://snare.sh/install | sh
set -e
REPO="peg/snare"
BINARY="snare"
INSTALL_DIR="${SNARE_INSTALL_DIR:-/usr/local/bin}"
# Detect OS and architecture
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
arm64) ARCH="arm64" ;;
*)
echo "Unsupported architecture: $ARCH" >&2
exit 1
;;
esac
case "$OS" in
linux|darwin) ;;
*)
echo "Unsupported OS: $OS" >&2
exit 1
;;
esac
# Fetch latest release version
LATEST=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' \
| sed 's/.*"tag_name": "\(.*\)".*/\1/')
if [ -z "$LATEST" ]; then
echo "Failed to fetch latest release" >&2
exit 1
fi
TARBALL="${BINARY}_${OS}_${ARCH}.tar.gz"
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${LATEST}/${TARBALL}"
CHECKSUM_URL="https://github.com/${REPO}/releases/download/${LATEST}/checksums.txt"
echo "Installing snare ${LATEST} (${OS}/${ARCH})..."
# Create temp dir
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
# Download binary
curl -fsSL "$DOWNLOAD_URL" -o "${TMP}/${TARBALL}"
# Verify checksum
curl -fsSL "$CHECKSUM_URL" -o "${TMP}/checksums.txt"
EXPECTED=$(grep "$TARBALL" "${TMP}/checksums.txt" | awk '{print $1}')
if [ -z "$EXPECTED" ]; then
echo "Failed to find checksum for ${TARBALL} in checksums.txt" >&2
exit 1
fi
ACTUAL=$(sha256sum "${TMP}/${TARBALL}" 2>/dev/null | awk '{print $1}' \
|| shasum -a 256 "${TMP}/${TARBALL}" | awk '{print $1}')
if [ "$EXPECTED" != "$ACTUAL" ]; then
echo "Checksum mismatch — download may be corrupt or tampered" >&2
echo " expected: $EXPECTED" >&2
echo " actual: $ACTUAL" >&2
exit 1
fi
echo "✓ Checksum verified"
# Extract
tar -xzf "${TMP}/${TARBALL}" -C "$TMP"
# Install
if [ -w "$INSTALL_DIR" ]; then
mv "${TMP}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
else
echo "Installing to ${INSTALL_DIR} (requires sudo)..."
sudo mv "${TMP}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
fi
chmod +x "${INSTALL_DIR}/${BINARY}"
echo "✓ Installed to ${INSTALL_DIR}/${BINARY}"
echo ""
echo "Get started:"
echo " snare arm --webhook <discord-or-slack-url>"
echo ""
echo "Docs: https://snare.sh"