-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
ยท265 lines (232 loc) ยท 8.84 KB
/
install.sh
File metadata and controls
executable file
ยท265 lines (232 loc) ยท 8.84 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/bin/bash
# =============================================================================
# Bark for Claude Code โ One-line Installer
# =============================================================================
# Install:
# curl -fsSL https://raw.githubusercontent.com/shaominngqing/bark-claude-code-hook/main/install.sh | bash
#
# Uninstall:
# bark uninstall
# =============================================================================
set -euo pipefail
BARK_VERSION="2.1.4"
REPO="shaominngqing/bark-claude-code-hook"
NC='\033[0m'; BOLD='\033[1m'; DIM='\033[2m'
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
C1='\033[38;5;39m'; C2='\033[38;5;45m'
ok() { echo -e " ${GREEN}โ${NC} $1"; }
warn() { echo -e " ${YELLOW}โ ${NC} $1"; }
fail() { echo -e " ${RED}โ${NC} $1"; exit 1; }
step() { echo -e "\n ${C1}${BOLD}โธ${NC} ${BOLD}$1${NC}"; }
# i18n
is_zh() { [[ "${LANG:-}${LC_ALL:-}" =~ zh ]]; }
# Gradient text
_gradient() {
local text="$1" start="${2:-39}" count="${3:-6}"
for ((i=0; i<${#text}; i++)); do
local c=$(( start + (i % count) ))
printf "\033[1;38;5;${c}m%s" "${text:$i:1}"
done
printf "${NC}"
}
# โโ Banner (block pixel art) โโ
echo ""
{
cat << 'BANNER'
โโโโโโโโโโโ โโโโโ
โโโโโโโโโโโโโ โโโโโ
โโโโ โโโโ โโโโโโ โโโโโโโโ โโโโ โโโโโ
โโโโโโโโโโโ โโโโโโโโ โโโโโโโโโโ โโโโโโโโโ
โโโโโโโโโโโโ โโโโโโโ โโโโ โโโ โโโโโโโโ
โโโโ โโโโ โโโโโโโโ โโโโ โโโโโโโโโ
โโโโโโโโโโโ โโโโโโโโโโ โโโโโ โโโโ โโโโโ
โโโโโโโโโโโ โโโโโโโโ โโโโโ โโโโ โโโโโ
BANNER
} | while IFS= read -r line; do
printf " "
_gradient "$line" 39 6
printf "\n"
done
echo ""
printf " ${DIM}๐ AI-Powered Risk Assessment for Claude Code v${BARK_VERSION}${NC}\n"
echo ""
# โโ Detect platform โโ
step "Detect platform"
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$OS" in
darwin) OS_LABEL="macOS" ;;
linux) OS_LABEL="Linux" ;;
mingw*|msys*|cygwin*) OS="windows"; OS_LABEL="Windows" ;;
*) fail "Unsupported OS: $OS" ;;
esac
case "$ARCH" in
x86_64|amd64) ARCH="x86_64" ;;
aarch64|arm64) ARCH="aarch64" ;;
*) fail "Unsupported architecture: $ARCH" ;;
esac
TARGET="${OS}-${ARCH}"
ok "$OS_LABEL $ARCH"
command -v claude >/dev/null 2>&1 && ok "claude CLI" || warn "claude CLI not found (AI assessment will be unavailable)"
# โโ Download binary โโ
step "Download bark binary"
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/v${BARK_VERSION}/bark-${TARGET}"
if [ "$OS" = "windows" ]; then
DOWNLOAD_URL="${DOWNLOAD_URL}.exe"
fi
TMP_DIR=$(mktemp -d)
TMP_BIN="${TMP_DIR}/bark"
trap "rm -rf '$TMP_DIR'" EXIT
# Render a progress bar: _draw_progress <current> <total>
_draw_progress() {
local cur="$1" total="$2" width=32
local pct=0 filled=0 empty="$width"
if [ "$total" -gt 0 ]; then
pct=$(( cur * 100 / total ))
filled=$(( cur * width / total ))
empty=$(( width - filled ))
fi
# Size label
local size_mb
size_mb=$(echo "scale=1; $cur / 1048576" | bc 2>/dev/null || echo "?")
local total_mb
total_mb=$(echo "scale=1; $total / 1048576" | bc 2>/dev/null || echo "?")
# Build bar
local bar=""
local i
for ((i=0; i<filled; i++)); do bar="${bar}\033[38;5;39mโ"; done
for ((i=0; i<empty; i++)); do bar="${bar}\033[2mโ"; done
printf "\r ${bar}${NC} ${DIM}%s/%sMB${NC} %3d%%" "$size_mb" "$total_mb" "$pct" >&2
}
# Download with animated progress bar
DOWNLOADED=false
TOTAL_SIZE=0
if command -v curl >/dev/null 2>&1; then
# Get file size via HEAD request
TOTAL_SIZE=$(curl -fsSLI "$DOWNLOAD_URL" 2>/dev/null \
| grep -i 'content-length' | tail -1 | tr -dc '0-9')
TOTAL_SIZE="${TOTAL_SIZE:-0}"
if [ "$TOTAL_SIZE" -gt 0 ]; then
# Download in background, poll file size for progress
curl -fsSL "$DOWNLOAD_URL" -o "$TMP_BIN" 2>/dev/null &
DL_PID=$!
while kill -0 "$DL_PID" 2>/dev/null; do
if [ -f "$TMP_BIN" ]; then
CUR_SIZE=$(wc -c < "$TMP_BIN" 2>/dev/null | tr -d ' ')
_draw_progress "${CUR_SIZE:-0}" "$TOTAL_SIZE"
fi
sleep 0.15
done
wait "$DL_PID" && DOWNLOADED=true || true
# Final 100% frame
if [ "$DOWNLOADED" = true ] && [ -s "$TMP_BIN" ]; then
_draw_progress "$TOTAL_SIZE" "$TOTAL_SIZE"
fi
printf "\n" >&2
else
# No content-length: silent download
if curl -fsSL "$DOWNLOAD_URL" -o "$TMP_BIN" 2>/dev/null; then
DOWNLOADED=true
fi
fi
elif command -v wget >/dev/null 2>&1; then
if wget -q "$DOWNLOAD_URL" -O "$TMP_BIN" 2>/dev/null; then
DOWNLOADED=true
fi
fi
if [ "$DOWNLOADED" = true ] && [ -s "$TMP_BIN" ]; then
chmod +x "$TMP_BIN"
# Show size in success message
FILESIZE=$(wc -c < "$TMP_BIN" | tr -d ' ')
if [ "$FILESIZE" -ge 1048576 ]; then
SIZE_LABEL="$(echo "scale=1; $FILESIZE / 1048576" | bc)MB"
elif [ "$FILESIZE" -ge 1024 ]; then
SIZE_LABEL="$(echo "scale=0; $FILESIZE / 1024" | bc)KB"
else
SIZE_LABEL="${FILESIZE}B"
fi
ok "bark v${BARK_VERSION} (${SIZE_LABEL})"
else
# No pre-built binary available โ try building from source
warn "No pre-built binary for ${TARGET}, building from source..."
if ! command -v cargo >/dev/null 2>&1; then
fail "Rust toolchain required. Install: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
fi
step "Build from source"
BUILD_DIR="${TMP_DIR}/bark-src"
if command -v git >/dev/null 2>&1; then
git clone --depth 1 "https://github.com/${REPO}.git" "$BUILD_DIR" 2>/dev/null
else
# Fallback: download tarball
curl -fsSL "https://github.com/${REPO}/archive/main.tar.gz" | tar -xz -C "$TMP_DIR"
BUILD_DIR="${TMP_DIR}/bark-claude-code-hook-main"
fi
(cd "$BUILD_DIR" && cargo build --release 2>&1 | tail -3)
cp "$BUILD_DIR/target/release/bark" "$TMP_BIN"
chmod +x "$TMP_BIN"
ok "Built from source"
fi
# โโ Install binary โโ
step "Install binary"
INSTALL_DIR=""
if [ -d /opt/homebrew/bin ] && echo "$PATH" | grep -q "/opt/homebrew/bin"; then
INSTALL_DIR="/opt/homebrew/bin"
elif [ -d /usr/local/bin ] && [ -w /usr/local/bin ]; then
INSTALL_DIR="/usr/local/bin"
elif [ -d "$HOME/.local/bin" ]; then
INSTALL_DIR="$HOME/.local/bin"
else
mkdir -p "$HOME/.local/bin"
INSTALL_DIR="$HOME/.local/bin"
fi
if cp "$TMP_BIN" "$INSTALL_DIR/bark" 2>/dev/null; then
ok "bark โ $INSTALL_DIR/"
elif sudo cp "$TMP_BIN" "$INSTALL_DIR/bark" 2>/dev/null; then
ok "bark โ $INSTALL_DIR/ (sudo)"
else
# Last resort: install to ~/.local/bin
mkdir -p "$HOME/.local/bin"
cp "$TMP_BIN" "$HOME/.local/bin/bark"
INSTALL_DIR="$HOME/.local/bin"
ok "bark โ $INSTALL_DIR/"
if ! echo "$PATH" | grep -q "$HOME/.local/bin"; then
warn "Add to PATH: export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
fi
# โโ Verify installation โโ
if ! command -v bark >/dev/null 2>&1; then
# Try with full path
BARK_CMD="$INSTALL_DIR/bark"
else
BARK_CMD="bark"
fi
# โโ Run bark install (registers hook in settings.json) โโ
"$BARK_CMD" install
# โโ Optional: Install notification helper โโ
if [ "$OS" = "darwin" ]; then
echo ""
if is_zh; then
NOTIFIER_PROMPT=" ${C2}${BOLD}\xF0\x9F\x94\x94${NC} ${BOLD}ๅฎ่ฃ
Bark ้็ฅๅฉๆ๏ผ${NC}"
NOTIFIER_DESC=" ่ชๅฎไนๅพๆ ใๅ
่ฎธ/ๆ็ป/่ทณ่ฟๆ้ฎใ่ชๅจๅ้็ป็ซฏ็กฎ่ฎค"
NOTIFIER_OPT=" ๅฏ้ โ ไธๅฎ่ฃ
ไนๅฏๆญฃๅธธไฝฟ็จ bark"
else
NOTIFIER_PROMPT=" ${C2}${BOLD}\xF0\x9F\x94\x94${NC} ${BOLD}Install Bark Notifier?${NC}"
NOTIFIER_DESC=" Custom icon, Allow/Deny/Skip buttons, auto-fallback to terminal"
NOTIFIER_OPT=" Optional โ bark works fine without it"
fi
echo -e "$NOTIFIER_PROMPT"
echo -e " ${DIM}$NOTIFIER_DESC${NC}"
echo -e " ${DIM}$NOTIFIER_OPT${NC}"
echo ""
read -p " [y/N] " install_notifier < /dev/tty
if [[ "$install_notifier" =~ ^[Yy] ]]; then
"$BARK_CMD" install-notifier
fi
elif [ "$OS" = "linux" ]; then
echo ""
if is_zh; then
echo -e " ${DIM}\xF0\x9F\x92\xA1 Linux ไธ Bark ไฝฟ็จ D-Bus ้็ฅ๏ผๆ ้้ขๅคๅฎ่ฃ
${NC}"
else
echo -e " ${DIM}\xF0\x9F\x92\xA1 On Linux, Bark uses D-Bus notifications natively โ no extra install needed${NC}"
fi
fi