-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·154 lines (143 loc) · 7 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·154 lines (143 loc) · 7 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bash
#
# honey/setup.sh — one-command setup.
#
# 1. Verify the toolchain (bash, git, jq, Go 1.25+).
# 2. Clone the bumblebee repo (for threat_intel catalogs) if absent.
# 3. go install the bumblebee binary.
# 4. Offer the optional Go-based vuln lenses (osv-scanner, govulncheck).
# 5. Run doctor.sh to confirm everything is ready.
#
# Idempotent: safe to re-run. Installs nothing it can install for you that
# needs a package manager (jq, Go) — it tells you the command instead. The
# Python-based skillspector lens is pointed to, not auto-installed.
# HONEY_SETUP_INSTALL_LENSES=0 skips the optional-lens step entirely.
set -uo pipefail
HONEY_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Did the user pin BUMBLEBEE_REPO explicitly (env or honey.conf) BEFORE we apply
# the default in preflight? If so, we respect it and skip the discovery prompt.
[ -n "${BUMBLEBEE_REPO:-}" ] && BUMBLEBEE_REPO_EXPLICIT=1 || BUMBLEBEE_REPO_EXPLICIT=""
. "$HONEY_DIR/lib/preflight.sh"
echo "honey setup"
echo
# --- 1. Toolchain we can't auto-install (tell the user, don't guess pkg mgr) -
need_tool=0
check_cmd git "install git: https://git-scm.com" || need_tool=1
check_cmd jq "macOS: brew install jq · Debian/Ubuntu: sudo apt-get install jq" || need_tool=1
check_go_version || need_tool=1
if [ "$need_tool" -ne 0 ]; then
echo
printf '%sInstall the tool(s) above, then re-run ./setup.sh%s\n' "$C_BAD" "$C_OFF"
exit 1
fi
# Persist a setting to honey.conf so it survives across shells AND bare-env
# Local-routine / cron runs (which don't inherit your interactive environment).
# Written as `export VAR="${VAR:-value}"` to preserve env-var > conf > default.
CONF="$HONEY_DIR/honey.conf"
persist() { # persist VAR VALUE
local var="$1" val="$2"
[ -f "$CONF" ] || { printf '# honey.conf — machine-specific config (gitignored). Written by setup.sh.\n' >"$CONF"; }
# Drop any prior line for this var, then append the new one.
grep -v "^export $var=" "$CONF" >"$CONF.tmp" 2>/dev/null || :
mv "$CONF.tmp" "$CONF"
# shellcheck disable=SC2016 # the ${VAR:-...} is literal text written to honey.conf, not for expansion here
printf 'export %s="${%s:-%s}"\n' "$var" "$var" "$val" >>"$CONF"
ok "persisted $var=$val to honey.conf"
}
# --- 2. bumblebee checkout (for threat_intel catalogs) ----------------------
# If BUMBLEBEE_REPO was already set (env or honey.conf), respect it. Otherwise,
# if an existing clone is found at a non-default path, offer to use it rather
# than cloning a duplicate; fall back to the default location.
bb_has_catalogs() { [ -d "$1/threat_intel" ] && ls "$1"/threat_intel/*.json >/dev/null 2>&1; }
if [ -z "${BUMBLEBEE_REPO_EXPLICIT:-}" ] && [ ! -f "$CONF" ] && ! bb_has_catalogs "$BUMBLEBEE_REPO"; then
# No persisted/explicit choice yet, and nothing at the default. Look for an
# existing clone elsewhere so we don't silently create a second copy.
echo " looking for an existing bumblebee checkout ..."
FOUND=""
while IFS= read -r cand; do
d="$(dirname "$cand")"; bb_has_catalogs "$d" && { FOUND="$d"; break; }
done < <(find "$HOME" -maxdepth 6 -type d -name threat_intel -path '*/bumblebee/*' 2>/dev/null)
if [ -n "$FOUND" ] && [ "$FOUND" != "$BUMBLEBEE_REPO" ]; then
echo
echo " Found an existing bumblebee clone at:"
echo " $FOUND"
echo " honey's default is: $BUMBLEBEE_REPO"
if [ -t 0 ]; then
printf " Use the existing clone instead of cloning a new one? [Y/n] "
read -r ans
case "$ans" in [Nn]*) : ;; *) BUMBLEBEE_REPO="$FOUND"; persist BUMBLEBEE_REPO "$FOUND" ;; esac
else
# Non-interactive (CI, piped): prefer the found clone, persist it.
BUMBLEBEE_REPO="$FOUND"; persist BUMBLEBEE_REPO "$FOUND"
echo " (non-interactive: using the existing clone)"
fi
fi
fi
CAT="$BUMBLEBEE_REPO/threat_intel"
CAT_JSONS=("$CAT"/*.json)
if [ -d "$CAT" ] && [ -e "${CAT_JSONS[0]}" ]; then
ok "bumblebee checkout present ($BUMBLEBEE_REPO)"
elif [ -d "$BUMBLEBEE_REPO/.git" ]; then
echo " updating bumblebee checkout ($BUMBLEBEE_REPO) ..."
if git -C "$BUMBLEBEE_REPO" pull --ff-only --quiet; then ok "checkout updated"; else bad "pull failed (continuing)"; fi
else
echo " cloning bumblebee into $BUMBLEBEE_REPO ..."
if git clone --quiet https://github.com/perplexityai/bumblebee "$BUMBLEBEE_REPO"; then
ok "cloned bumblebee"
else
bad "clone failed"
hint "clone manually, or set BUMBLEBEE_REPO to an existing clone and re-run"
exit 1
fi
fi
# --- 3. bumblebee binary ----------------------------------------------------
echo " installing bumblebee binary (go install $GO_PKG) ..."
if go install "$GO_PKG"; then
ok "binary installed"
else
bad "go install failed"; exit 1
fi
# Warn if the freshly-installed binary isn't reachable yet (PATH not updated).
check_gobin_on_path >/dev/null || {
gobin="$(go env GOBIN 2>/dev/null)"; [ -z "$gobin" ] && gobin="$(go env GOPATH)/bin"
echo
printf '%sNote:%s %s is not on your PATH. Add this to your shell profile:\n' "$C_BAD" "$C_OFF" "$gobin"
# shellcheck disable=SC2016 # $PATH and `source` are literal text shown to the user, not for expansion
printf ' export PATH="%s:$PATH"\n' "$gobin"
# shellcheck disable=SC2016
printf 'then open a new shell (or `source` it) before scanning.\n'
}
# --- 4. Optional lenses -----------------------------------------------------
# honey can run additional scanners as "lenses" (see README). They are OPT-IN
# and never required. We offer to install the two lightweight Go-based ones
# here (you already have Go); SkillSpector has a Python stack so we only point
# to it rather than installing it. Set HONEY_SETUP_INSTALL_LENSES=0 to skip.
if [ "${HONEY_SETUP_INSTALL_LENSES:-1}" = "1" ]; then
echo
echo "optional vuln-scanning lenses (Go-based — safe to install now):"
if command -v osv-scanner >/dev/null 2>&1; then
ok "osv-scanner already installed"
else
echo " installing osv-scanner (multi-ecosystem lockfile vuln scan) ..."
if go install github.com/google/osv-scanner/cmd/osv-scanner@latest; then ok "osv-scanner installed"; else bad "osv-scanner install failed (optional — continuing)"; fi
fi
if command -v govulncheck >/dev/null 2>&1; then
ok "govulncheck already installed"
else
echo " installing govulncheck (Go reachability-aware vuln scan) ..."
if go install golang.org/x/vuln/cmd/govulncheck@latest; then ok "govulncheck installed"; else bad "govulncheck install failed (optional — continuing)"; fi
fi
echo
echo "optional agent-skill lens (separate Python install — NOT installed automatically):"
if command -v skillspector >/dev/null 2>&1; then
ok "skillspector already installed"
else
hint "skillspector scans AI agent skills; install per https://github.com/NVIDIA/skillspector"
hint "then it activates automatically on the next run."
fi
fi
# --- 5. Verify --------------------------------------------------------------
echo
echo "running doctor to verify ..."
echo
exec "$HONEY_DIR/doctor.sh"