-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·241 lines (197 loc) · 5.54 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·241 lines (197 loc) · 5.54 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/bin/sh
# bench installer
# Installs bench binary and optionally Claude Code skill + agent
set -e
VERSION="3.0.0"
REPO_URL="https://raw.githubusercontent.com/KakkoiDev/bench/main"
# Detect local vs remote (curl | sh) mode
SCRIPT_DIR="$(cd "$(dirname "$0")" 2>/dev/null && pwd)" || SCRIPT_DIR=""
if [ -n "$SCRIPT_DIR" ] && [ -f "$SCRIPT_DIR/bench" ]; then
LOCAL_MODE=1
BENCH_SOURCE="$SCRIPT_DIR/bench"
else
LOCAL_MODE=0
BENCH_SOURCE=""
fi
# Defaults
INSTALL_DIR=""
INSTALL_CLAUDE=0
SKIP_DEPS=0
UNINSTALL=0
# Colors (disabled if not a terminal)
if [ -t 1 ]; then
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
RESET='\033[0m'
else
GREEN="" RED="" YELLOW="" RESET=""
fi
info() { printf "${GREEN}[+]${RESET} %s\n" "$1"; }
warn() { printf "${YELLOW}[!]${RESET} %s\n" "$1"; }
error() { printf "${RED}[x]${RESET} %s\n" "$1" >&2; }
die() { error "$1"; exit 1; }
usage() {
cat <<EOF
bench installer v${VERSION}
Usage: ./install.sh [OPTIONS]
Options:
--dir PATH Install directory (default: ~/.local/bin or /usr/local/bin)
--with-claude Also install Claude Code skill and agent
--skip-deps Skip dependency checks
--uninstall Remove bench and optional Claude Code files
--help Show this help
Examples:
./install.sh # Install bench only
./install.sh --with-claude # Install bench + Claude Code integration
./install.sh --dir ~/bin # Install to custom directory
./install.sh --uninstall # Remove everything
./install.sh --uninstall --with-claude # Remove bench + Claude Code files
EOF
exit 0
}
# --- Argument parsing ---
while [ $# -gt 0 ]; do
case "$1" in
--dir) INSTALL_DIR="$2"; shift 2 ;;
--with-claude) INSTALL_CLAUDE=1; shift ;;
--skip-deps) SKIP_DEPS=1; shift ;;
--uninstall) UNINSTALL=1; shift ;;
--help) usage ;;
*) die "Unknown option: $1" ;;
esac
done
# --- Resolve install directory ---
resolve_install_dir() {
if [ -n "$INSTALL_DIR" ]; then
return
fi
# Prefer ~/.local/bin (no sudo needed)
if [ -d "$HOME/.local/bin" ]; then
INSTALL_DIR="$HOME/.local/bin"
elif [ -w /usr/local/bin ]; then
INSTALL_DIR="/usr/local/bin"
else
INSTALL_DIR="$HOME/.local/bin"
fi
}
# --- Dependency checks ---
check_deps() {
if [ "$SKIP_DEPS" = 1 ]; then
warn "Skipping dependency checks"
return
fi
missing=""
# Required
command -v perl >/dev/null 2>&1 || missing="$missing perl"
command -v bc >/dev/null 2>&1 || missing="$missing bc"
command -v ps >/dev/null 2>&1 || missing="$missing ps"
# Perl Time::HiRes
if command -v perl >/dev/null 2>&1; then
perl -MTime::HiRes -e '1' 2>/dev/null || missing="$missing perl-Time::HiRes"
fi
if [ -n "$missing" ]; then
die "Missing dependencies:$missing"
fi
# Optional (warn only)
if ! command -v lsof >/dev/null 2>&1 && ! command -v ss >/dev/null 2>&1; then
warn "Neither lsof nor ss found. --port flag will not work."
fi
if ! command -v jq >/dev/null 2>&1; then
warn "jq not found. Recommended for analyzing benchmark results."
fi
}
# --- Download helper (remote mode) ---
download() {
_dl_url="$1" _dl_dest="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$_dl_url" -o "$_dl_dest"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$_dl_dest" "$_dl_url"
else
die "curl or wget required for remote install"
fi
}
# --- Install bench ---
install_bench() {
mkdir -p "$INSTALL_DIR"
if [ "$LOCAL_MODE" = 1 ]; then
cp "$BENCH_SOURCE" "$INSTALL_DIR/bench"
else
info "Downloading bench from GitHub..."
download "$REPO_URL/bench" "$INSTALL_DIR/bench"
fi
chmod +x "$INSTALL_DIR/bench"
info "Installed bench to $INSTALL_DIR/bench"
# Check PATH
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*)
warn "$INSTALL_DIR is not in your PATH"
warn "Add to your shell profile: export PATH=\"$INSTALL_DIR:\$PATH\""
;;
esac
}
# --- Claude Code integration ---
CLAUDE_DIR="$HOME/.claude"
AGENT_FILE="$CLAUDE_DIR/agents/bench.md"
SKILL_DIR="$CLAUDE_DIR/skills/bench"
SKILL_FILE="$SKILL_DIR/SKILL.md"
install_claude() {
if [ "$INSTALL_CLAUDE" != 1 ]; then
return
fi
if [ ! -d "$CLAUDE_DIR" ]; then
die "$HOME/.claude directory not found. Is Claude Code installed?"
fi
# Install agent
mkdir -p "$CLAUDE_DIR/agents"
if [ "$LOCAL_MODE" = 1 ]; then
cp "$SCRIPT_DIR/.claude/agents/bench.md" "$AGENT_FILE"
else
download "$REPO_URL/.claude/agents/bench.md" "$AGENT_FILE"
fi
info "Installed agent to $AGENT_FILE"
# Install skill
mkdir -p "$SKILL_DIR"
if [ "$LOCAL_MODE" = 1 ]; then
cp "$SCRIPT_DIR/.claude/skills/bench/SKILL.md" "$SKILL_FILE"
else
download "$REPO_URL/.claude/skills/bench/SKILL.md" "$SKILL_FILE"
fi
info "Installed skill to $SKILL_FILE"
}
# --- Uninstall ---
uninstall() {
resolve_install_dir
if [ -f "$INSTALL_DIR/bench" ]; then
rm "$INSTALL_DIR/bench"
info "Removed $INSTALL_DIR/bench"
else
warn "bench not found at $INSTALL_DIR/bench"
fi
if [ "$INSTALL_CLAUDE" = 1 ]; then
if [ -f "$AGENT_FILE" ]; then
rm "$AGENT_FILE"
info "Removed $AGENT_FILE"
fi
if [ -d "$SKILL_DIR" ]; then
rm -rf "$SKILL_DIR"
info "Removed $SKILL_DIR"
fi
fi
info "Uninstall complete"
exit 0
}
# --- Main ---
if [ "$UNINSTALL" = 1 ]; then
uninstall
fi
resolve_install_dir
check_deps
install_bench
install_claude
info "bench v${VERSION} installed successfully"
if [ "$INSTALL_CLAUDE" = 1 ]; then
info "Claude Code skill and agent installed"
fi