Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·95 lines (79 loc) · 2.77 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·95 lines (79 loc) · 2.77 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
#!/bin/sh
# Universal installer for secfoo (macOS/Linux). Usage:
# curl -fsSL https://raw.githubusercontent.com/rakfortltd/secfoo/main/install.sh | sh
#
# Downloads the correct standalone binary from the latest GitHub Release,
# verifies its checksum, and installs it to $PREFIX/bin (default
# /usr/local/bin, falling back to ~/.local/bin if that isn't writable).
# POSIX sh only -- no bashisms -- since /bin/sh is dash on many systems.
set -e
REPO="rakfortltd/secfoo"
PREFIX="${PREFIX:-/usr/local}"
os_name() {
case "$(uname -s)" in
Darwin) echo "darwin" ;;
Linux) echo "linux" ;;
*)
echo "error: unsupported OS '$(uname -s)' -- see https://github.com/$REPO/releases for manual download options" >&2
exit 1
;;
esac
}
arch_name() {
case "$(uname -m)" in
arm64|aarch64) echo "arm64" ;;
x86_64|amd64) echo "x64" ;;
*)
echo "error: unsupported architecture '$(uname -m)' -- see https://github.com/$REPO/releases for manual download options" >&2
exit 1
;;
esac
}
OS=$(os_name)
ARCH=$(arch_name)
ASSET="secfoo-${OS}-${ARCH}"
echo "Detected platform: ${OS}-${ARCH}"
LATEST_TAG=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" \
| grep '"tag_name"' | head -1 | sed -E 's/.*"tag_name": *"([^"]+)".*/\1/')
if [ -z "$LATEST_TAG" ]; then
echo "error: could not determine the latest release tag from the GitHub API" >&2
exit 1
fi
echo "Latest release: $LATEST_TAG"
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
BASE_URL="https://github.com/$REPO/releases/download/$LATEST_TAG"
curl -fsSL -o "$TMP_DIR/$ASSET" "$BASE_URL/$ASSET"
curl -fsSL -o "$TMP_DIR/SHA256SUMS" "$BASE_URL/SHA256SUMS"
echo "Verifying checksum..."
EXPECTED=$(grep " $ASSET\$" "$TMP_DIR/SHA256SUMS" | awk '{print $1}')
if [ -z "$EXPECTED" ]; then
echo "error: no checksum entry found for $ASSET in SHA256SUMS" >&2
exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
ACTUAL=$(sha256sum "$TMP_DIR/$ASSET" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
ACTUAL=$(shasum -a 256 "$TMP_DIR/$ASSET" | awk '{print $1}')
else
echo "error: neither sha256sum nor shasum is available to verify the download" >&2
exit 1
fi
if [ "$EXPECTED" != "$ACTUAL" ]; then
echo "error: checksum mismatch for $ASSET (expected $EXPECTED, got $ACTUAL) -- aborting install" >&2
exit 1
fi
echo "Checksum OK."
chmod +x "$TMP_DIR/$ASSET"
INSTALL_DIR="$PREFIX/bin"
if [ ! -w "$INSTALL_DIR" ] 2>/dev/null; then
INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
fi
mv "$TMP_DIR/$ASSET" "$INSTALL_DIR/secfoo"
echo "Installed secfoo $LATEST_TAG to $INSTALL_DIR/secfoo"
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*) echo "Note: $INSTALL_DIR is not on your PATH. Add it, e.g.: export PATH=\"$INSTALL_DIR:\$PATH\"" ;;
esac
"$INSTALL_DIR/secfoo" agents || true