-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·425 lines (357 loc) · 14.2 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·425 lines (357 loc) · 14.2 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#!/bin/bash
# Vocord - One-line installer
# Usage: curl -sSL https://raw.githubusercontent.com/jolehuit/vocord/main/install.sh | bash
# Override Vencord path: VENCORD_DIR=~/my/vencord curl -sSL ... | bash
set -eo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
echo ""
echo -e "${CYAN}${BOLD} Vocord${NC}"
echo -e "${CYAN} Cross-platform voice message transcription for Vencord${NC}"
echo -e "${CYAN} https://github.com/jolehuit/vocord${NC}"
echo ""
REPO="https://github.com/jolehuit/vocord.git"
OS="$(uname -s)"
ARCH="$(uname -m)"
TMPDIR_VOCORD="$(mktemp -d)"
VOCORD_DATA="$HOME/.local/share/vocord"
cleanup() { rm -rf "$TMPDIR_VOCORD"; }
trap cleanup EXIT
# ── Detect platform ───────────────────────────────────────────────
BACKEND="transcribe-rs"
mkdir -p "$VOCORD_DATA"
if [[ "$OS" == "Darwin" && "$ARCH" == "arm64" ]]; then
echo -e " ${GREEN}Platform:${NC} macOS Apple Silicon"
echo ""
echo -e " ${BOLD}Choose transcription backend:${NC}"
echo -e " ${CYAN}1)${NC} mlx-whisper — fast, uses Apple GPU (recommended)"
echo -e " ${CYAN}2)${NC} whisper-onnx — Rust/GGML, CPU-based"
echo ""
printf " Choice [1]: " >/dev/tty
read -r BACKEND_CHOICE </dev/tty || BACKEND_CHOICE=""
case "$BACKEND_CHOICE" in
2) BACKEND="transcribe-rs" ;;
*) BACKEND="mlx-whisper" ;;
esac
elif [[ "$OS" == "Darwin" ]]; then
echo -e " ${GREEN}Platform:${NC} macOS Intel"
else
echo -e " ${GREEN}Platform:${NC} $OS ($ARCH)"
fi
echo -e " ${GREEN}Backend:${NC} $BACKEND"
echo "$BACKEND" > "$VOCORD_DATA/backend"
echo ""
VESKTOP_DATA=""
DISCORD_APP=""
# ── Helper: detect Vesktop data directory ─────────────────────────
detect_vesktop() {
if [[ "$OS" == "Darwin" ]]; then
for d in "$HOME/Library/Application Support/vesktop" "$HOME/Library/Application Support/Vesktop"; do
[[ -d "$d" ]] && VESKTOP_DATA="$d" && return 0
done
elif [[ "$OS" == "Linux" ]]; then
local xdg="${XDG_CONFIG_HOME:-$HOME/.config}"
for d in "$xdg/vesktop" "$xdg/Vesktop"; do
[[ -d "$d" ]] && VESKTOP_DATA="$d" && return 0
done
fi
return 1
}
# ── Helper: configure Vesktop to use a custom Vencord build ──────
configure_vesktop() {
local dist_dir="$1"
[[ -z "$VESKTOP_DATA" ]] && return 1
echo -e " ${GREEN}Vesktop detected:${NC} $VESKTOP_DATA"
# Try state.json first (newer Vesktop), fall back to settings.json
local target_file="$VESKTOP_DATA/state.json"
if [[ -f "$VESKTOP_DATA/settings.json" && ! -f "$VESKTOP_DATA/state.json" ]]; then
target_file="$VESKTOP_DATA/settings.json"
elif [[ ! -f "$target_file" ]]; then
echo '{}' > "$target_file"
fi
# Use python3 for reliable JSON manipulation
if command -v python3 &> /dev/null; then
python3 -c "
import json, sys
path, dist = sys.argv[1], sys.argv[2]
try:
with open(path) as f:
data = json.load(f)
except (json.JSONDecodeError, ValueError):
data = {}
data['vencordDir'] = dist
with open(path, 'w') as f:
json.dump(data, f, indent=4)
f.write('\n')
" "$target_file" "$dist_dir"
echo -e " ${GREEN}Vesktop configured:${NC} vencordDir → $dist_dir"
return 0
else
echo -e " ${YELLOW}python3 not found -- set Vencord location manually in Vesktop:${NC}"
echo " Settings > Developer Options > Vencord Location → $dist_dir"
return 1
fi
}
# ── Helper: check if Discord Desktop has Vencord injected ────────
check_discord_desktop() {
if [[ "$OS" == "Darwin" ]]; then
for app in "/Applications/Discord.app" "/Applications/Discord Canary.app" "$HOME/Applications/Discord.app"; do
if [[ -d "$app" ]]; then
DISCORD_APP="$app"
echo ""
echo -e " ${CYAN}Discord Desktop detected:${NC} $app"
break
fi
done
elif [[ "$OS" == "Linux" ]]; then
if command -v discord &> /dev/null; then
DISCORD_APP="discord"
echo ""
echo -e " ${CYAN}Discord Desktop detected.${NC}"
fi
fi
}
# ── Find Vencord source ──────────────────────────────────────────
if [[ -z "$VENCORD_DIR" ]]; then
# Search common locations (Vencord, Equicord, and common dev dirs)
for dir in \
"$HOME/Vencord" \
"$HOME/VencordDev" \
"$HOME/vencord" \
"$HOME/Equicord" \
"$HOME/equicord" \
"$HOME/.local/share/Vencord" \
"$HOME/Documents/Vencord" \
"$HOME/Projects/Vencord" \
"$HOME/Dev/Vencord" \
"$HOME/dev/Vencord" \
"$HOME/Code/Vencord" \
"$HOME/code/Vencord" \
"$HOME/src/Vencord"; do
if [[ -d "$dir/src/userplugins" ]]; then
VENCORD_DIR="$dir"
break
fi
done
# Wildcard search in home directory
if [[ -z "$VENCORD_DIR" ]]; then
for dir in "$HOME"/*/src/userplugins; do
if [[ -d "$dir" ]]; then
VENCORD_DIR="$(dirname "$(dirname "$dir")")"
break
fi
done
fi
fi
if [[ -n "$VENCORD_DIR" && -d "$VENCORD_DIR/src/userplugins" ]]; then
echo -e " ${GREEN}Vencord source:${NC} $VENCORD_DIR"
else
echo -e " ${YELLOW}No Vencord source tree found.${NC}"
echo ""
# Check prerequisites for cloning
if ! command -v git &> /dev/null; then
echo -e "${RED} Error: git is required. Install git and try again.${NC}"
exit 1
fi
if ! command -v node &> /dev/null; then
echo -e "${RED} Error: Node.js is required to build Vencord.${NC}"
echo ""
if [[ "$OS" == "Darwin" ]]; then
echo " Install it: brew install node"
elif [[ "$OS" == "Linux" ]]; then
echo " Install it: https://nodejs.org or use your package manager"
fi
exit 1
fi
# Install pnpm if needed
if ! command -v pnpm &> /dev/null; then
echo " Installing pnpm..."
if command -v corepack &> /dev/null; then
corepack enable 2>/dev/null || true
corepack prepare pnpm@latest --activate 2>/dev/null || npm install -g pnpm
else
npm install -g pnpm
fi
fi
if ! command -v pnpm &> /dev/null; then
echo -e "${RED} Error: Failed to install pnpm.${NC}"
exit 1
fi
# Clone Vencord
VENCORD_DIR="$HOME/Vencord"
echo -e " ${BOLD}Cloning Vencord to $VENCORD_DIR...${NC}"
git clone --depth 1 --quiet "https://github.com/Vendicated/Vencord.git" "$VENCORD_DIR"
echo " Installing Vencord dependencies..."
cd "$VENCORD_DIR"
pnpm install --frozen-lockfile 2>&1 | tail -3
mkdir -p "$VENCORD_DIR/src/userplugins"
echo -e " ${GREEN}Vencord source:${NC} $VENCORD_DIR"
fi
DEST="$VENCORD_DIR/src/userplugins/vocord"
echo ""
# ── Clean up existing installation if present ─────────────────────
if [[ -d "$DEST" ]]; then
echo -e " ${YELLOW}Existing Vocord installation detected. Removing...${NC}"
rm -rf "$DEST"
echo -e " ${GREEN}Old plugin files removed${NC}"
fi
if [[ -d "$VOCORD_DATA/venv" ]]; then
echo -e " ${YELLOW}Existing venv detected. Removing...${NC}"
rm -rf "$VOCORD_DATA/venv"
echo -e " ${GREEN}Old venv removed${NC}"
fi
echo ""
# ── Step 1: Clone Vocord repo ────────────────────────────────────
echo -e "${BOLD}[1/4]${NC} Downloading Vocord..."
git clone --depth 1 --quiet "$REPO" "$TMPDIR_VOCORD/vocord"
echo -e " ${GREEN}Done${NC}"
# ── Step 2: Install backend ──────────────────────────────────────
echo ""
if [[ "$BACKEND" == "mlx-whisper" ]]; then
echo -e "${BOLD}[2/4]${NC} Installing mlx-whisper..."
# Install uv if not present
if ! command -v uv &> /dev/null; then
echo " Installing uv..."
curl -LsSf https://astral.sh/uv/install.sh | sh 2>&1 | tail -1
source "$HOME/.local/bin/env" 2>/dev/null || export PATH="$HOME/.local/bin:$PATH"
fi
echo -e " uv $(uv --version | cut -d' ' -f2)"
# Create isolated venv and install mlx-whisper
VOCORD_VENV="$VOCORD_DATA/venv"
echo " Creating venv at $VOCORD_VENV..."
uv venv "$VOCORD_VENV" --quiet --allow-existing
echo " Installing mlx-whisper (this may take a moment)..."
uv pip install --python "$VOCORD_VENV/bin/python" mlx-whisper --quiet
if "$VOCORD_VENV/bin/python" -c "import mlx_whisper" 2>/dev/null; then
echo -e " ${GREEN}mlx-whisper installed in isolated venv${NC}"
else
echo -e "${RED}Error: Failed to install mlx-whisper${NC}"
exit 1
fi
else
echo -e "${BOLD}[2/4]${NC} Setting up transcribe-rs..."
# Check Rust
if ! command -v cargo &> /dev/null; then
echo -e "${YELLOW} Rust not found. Installing via rustup...${NC}"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --quiet
source "$HOME/.cargo/env"
fi
echo -e " Rust $(cargo --version | cut -d' ' -f2)"
# Check ffmpeg
if ! command -v ffmpeg &> /dev/null; then
echo -e "${YELLOW} Warning: ffmpeg not found.${NC}"
if [[ "$OS" == "Darwin" ]]; then
echo " Install it: brew install ffmpeg"
elif [[ "$OS" == "Linux" ]]; then
echo " Install it: sudo apt install ffmpeg"
fi
else
echo -e " ffmpeg found"
fi
# Build transcribe-cli
echo " Building transcribe-cli (this may take a few minutes)..."
cd "$TMPDIR_VOCORD/vocord/transcribe-cli"
if ! cargo build --release 2>&1; then
echo -e "${RED}Error: cargo build failed (see output above)${NC}"
exit 1
fi
if [[ -f "target/release/transcribe-cli" ]]; then
cp "target/release/transcribe-cli" "$VOCORD_DATA/transcribe-cli"
echo -e " ${GREEN}transcribe-cli built and installed to $VOCORD_DATA${NC}"
else
echo -e "${RED}Error: Build failed${NC}"
exit 1
fi
# Download Whisper GGML model
MODEL_PATH="$VOCORD_DATA/ggml-large-v3-turbo.bin"
if [[ ! -f "$MODEL_PATH" ]]; then
echo " Downloading Whisper large-v3-turbo model (~800 MB)..."
# NOTE: This model is served from a third-party host. No checksum is
# verified. If you prefer, download it manually from Hugging Face:
# https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large-v3-turbo.bin
# and place it at: $MODEL_PATH
if ! curl -L --fail --progress-bar -o "$MODEL_PATH" \
"https://blob.handy.computer/ggml-large-v3-turbo.bin"; then
rm -f "$MODEL_PATH"
echo -e "${RED} Error: Model download failed.${NC}"
exit 1
fi
echo -e " ${GREEN}Model saved to: $MODEL_PATH${NC}"
else
echo -e " Model already at: $MODEL_PATH"
fi
fi
# ── Close Vesktop before making any changes ───────────────────────
detect_vesktop
if [[ -n "$VESKTOP_DATA" ]]; then
echo ""
echo -e "${YELLOW}Closing Vesktop to apply changes...${NC}"
if [[ "$OS" == "Darwin" ]]; then
osascript -e 'quit app "Vesktop"' 2>/dev/null || pkill -ix vesktop 2>/dev/null || true
else
pkill -ix vesktop 2>/dev/null || true
fi
sleep 2
fi
# ── Step 3: Install plugin ────────────────────────────────────────
echo ""
echo -e "${BOLD}[3/4]${NC} Installing plugin..."
mkdir -p "$DEST"
cp "$TMPDIR_VOCORD/vocord/index.tsx" "$DEST/"
cp "$TMPDIR_VOCORD/vocord/native.ts" "$DEST/"
echo -e " ${GREEN}Installed to: $DEST${NC}"
# ── Step 4: Build and configure ───────────────────────────────────
echo ""
echo -e "${BOLD}[4/4]${NC} Building Vencord..."
cd "$VENCORD_DIR"
if command -v pnpm &> /dev/null; then
# Run pnpm build without piping so the exit code is captured directly.
if pnpm build 2>&1; then
# Verify the plugin is actually in the build output
if grep -q "Vocord" "$VENCORD_DIR/dist/renderer.js" 2>/dev/null; then
echo -e " ${GREEN}Build complete (Vocord verified in output)${NC}"
else
echo -e "${RED} Build succeeded but Vocord not found in output!${NC}"
echo -e "${RED} Check that $DEST/index.tsx exists and retry: cd $VENCORD_DIR && pnpm build${NC}"
exit 1
fi
else
echo -e "${RED} Build failed! Retry manually: cd $VENCORD_DIR && pnpm build${NC}"
exit 1
fi
else
echo -e "${YELLOW} pnpm not found -- rebuild manually: cd $VENCORD_DIR && pnpm build${NC}"
fi
# Auto-configure Vesktop if detected
echo ""
configure_vesktop "$VENCORD_DIR/dist" || true
# Check for Discord Desktop and inject if detected and not using Vesktop
check_discord_desktop
[[ -z "$VESKTOP_DATA" && -n "$DISCORD_APP" ]] && {
echo -e " ${GREEN}Injecting Vencord into Discord Desktop...${NC}"
if ! (cd "$VENCORD_DIR" && pnpm inject 2>&1); then
echo -e "${YELLOW} Warning: Vencord injection failed. Try manually: cd $VENCORD_DIR && pnpm inject${NC}"
fi
}
# ── Done ──────────────────────────────────────────────────────────
echo ""
echo -e "${GREEN}${BOLD} Vocord installed successfully!${NC}"
echo ""
# Restart Vesktop if detected
if [[ -n "$VESKTOP_DATA" ]]; then
echo -e " ${GREEN}Restarting Vesktop...${NC}"
if [[ "$OS" == "Darwin" ]]; then
open -a "$(ls -d /Applications/[Vv]esktop.app 2>/dev/null | head -1)" 2>/dev/null || open -a Vesktop 2>/dev/null || true
elif [[ "$OS" == "Linux" ]]; then
vesktop &>/dev/null &
fi
echo ""
fi
echo " Next steps:"
echo " 1. Enable: Settings > Vencord > Plugins > Vocord"
echo " 2. Click the mic icon next to any voice message"
echo ""