-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·4698 lines (4136 loc) · 190 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·4698 lines (4136 loc) · 190 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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Vocalinux Installer
# This script installs the Vocalinux application and its dependencies
# -E: ERR trap propagates into functions/subshells
# -e: exit on unhandled command failure -u: error on unset variables
# -o pipefail: a pipeline fails if any stage fails
set -Eeuo pipefail
# Exit codes (see --help). 1 remains the generic/unclassified failure.
EXIT_OK=0
EXIT_MISSING_DEPS=2 # required system tools/packages could not be installed
EXIT_NETWORK=3 # connectivity failure or download/clone failure
EXIT_USER_ABORT=4 # user declined a prompt
# Keep the venv isolated from ~/.local site packages while still allowing
# --system-site-packages to expose distro-provided GTK/PyGObject bindings.
export PYTHONNOUSERSITE=1
# Function to display colored output
print_info() {
echo -e "\e[1;34m[INFO]\e[0m $1"
}
print_success() {
echo -e "\e[1;32m[SUCCESS]\e[0m $1"
}
# Diagnostics go to stderr, not stdout: `exec > >(tee ...) 2>&1` keeps them in the
# log and on screen either way, but stdout is what every $( ) captures. Writing
# them there let the ERR trap's own message land inside a captured value.
print_error() {
echo -e "\e[1;31m[ERROR]\e[0m $1" >&2
}
print_warning() {
echo -e "\e[1;33m[WARNING]\e[0m $1" >&2
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# The installer must build its venv from the *system* Python: distro PyGObject
# (python3-gi / python3-gobject) is compiled for that interpreter only. When the
# script starts inside an activated virtualenv — a shell left in uv's .venv
# after `just deps`, for instance — a bare `python3` resolves to that venv's
# interpreter instead, and a venv created from it cannot import gi even with
# --system-site-packages. Undo the activation for the installer's own process
# before anything looks up an interpreter.
deactivate_inherited_virtualenv() {
local venv_bin cleaned entry
[ -z "${VIRTUAL_ENV:-}" ] && return 0
print_warning "Running inside an activated virtualenv ($VIRTUAL_ENV)."
print_info "Ignoring it so the installation uses the system Python."
venv_bin="${VIRTUAL_ENV%/}/bin"
cleaned=""
while IFS= read -r entry; do
[ "$entry" = "$venv_bin" ] && continue
cleaned="${cleaned:+$cleaned:}$entry"
done < <(printf '%s\n' "${PATH//:/$'\n'}")
PATH="$cleaned"
export PATH
unset VIRTUAL_ENV
unset PYTHONHOME
}
deactivate_inherited_virtualenv
# HTTP-level connectivity check. ICMP ping is blocked on many networks
# (corporate firewalls, public Wi-Fi, CI runners), so probe the actual
# endpoints the installer depends on. Returns 0 if any probe succeeds.
check_connectivity() {
local url
for url in https://pypi.org/simple/ https://api.github.com/ https://huggingface.co/; do
if command_exists curl; then
if curl -fsI --connect-timeout 5 --max-time 10 -o /dev/null "$url" 2>/dev/null; then
return 0
fi
elif command_exists wget; then
if wget -q --spider --timeout=10 "$url" 2>/dev/null; then
return 0
fi
else
return 1
fi
done
return 1
}
is_kde_plasma_session() {
local desktop="${XDG_CURRENT_DESKTOP:-} ${DESKTOP_SESSION:-} ${GDMSESSION:-}"
local kde_session="${KDE_FULL_SESSION:-}"
local desktop_lower="${desktop,,}"
local kde_session_lower="${kde_session,,}"
[[ "$desktop_lower" == *kde* || "$desktop_lower" == *plasma* || "$kde_session_lower" == "true" ]]
}
print_kde_wayland_ibus_hint() {
print_warning "KDE Plasma Wayland detected."
print_info "For direct dictation into apps, open System Settings -> Keyboard -> Virtual Keyboard and select 'IBus Wayland'."
print_info "After changing it, restart Vocalinux or log out and back in."
}
# Read a numeric PID from a file (instance.lock / engine.pid). Empty if missing/invalid.
read_pid_file() {
local file="$1"
local pid=""
[ -f "$file" ] || return 0
pid=$(tr -d '[:space:]' < "$file" 2>/dev/null || true)
if [[ "$pid" =~ ^[0-9]+$ ]]; then
echo "$pid"
fi
}
# True only for the Vocalinux app / IBus engine — not editors, shells, or tests
# whose argv merely contains the string "vocalinux" (e.g. cwd under the repo).
is_vocalinux_process() {
local pid="$1"
if [ "$pid" = "$$" ] || [ "$pid" = "$PPID" ]; then
return 1
fi
[ -r "/proc/$pid/cmdline" ] || return 1
local stat
stat=$(ps -o stat= -p "$pid" 2>/dev/null | awk '{print $1}')
if [[ "$stat" == Z* ]]; then
return 1
fi
local cmdline
cmdline=$(tr '\0' ' ' < "/proc/$pid/cmdline" 2>/dev/null)
[ -n "$cmdline" ] || return 1
# Never target the installer/uninstaller themselves
if [[ "$cmdline" == *"install.sh"* || "$cmdline" == *"uninstall.sh"* ]]; then
return 1
fi
# python -m vocalinux.main [--flags]
if [[ "$cmdline" == *"-m vocalinux.main"* ]]; then
return 0
fi
# IBus engine: .../vocalinux/.../ibus_engine.py
if [[ "$cmdline" == *"ibus_engine.py"* && "$cmdline" == *"vocalinux"* ]]; then
return 0
fi
# Console-script entrypoints. Setuptools scripts are executed as
# `python …/bin/vocalinux`, so argv0 is python — scan every arg for the
# script path (require …/bin/vocalinux to avoid matching a repo directory).
local arg
while IFS= read -r -d '' arg; do
case "$arg" in
vocalinux|vocalinux-gui|*/bin/vocalinux|*/bin/vocalinux-gui)
return 0
;;
esac
done < "/proc/$pid/cmdline"
return 1
}
# Prefer the PIDs the app writes; fall back to narrow entrypoint patterns only.
# Deliberately does NOT use `pgrep -f vocalinux` (matches editors/shells/cwd paths).
get_vocalinux_pids() {
local data_home="${XDG_DATA_HOME:-$HOME/.local/share}"
local -A seen=()
local pid candidate
local -a candidates=()
for candidate in \
"$(read_pid_file "$data_home/vocalinux/instance.lock")" \
"$(read_pid_file "$data_home/vocalinux-ibus/engine.pid")"
do
[ -n "$candidate" ] && candidates+=("$candidate")
done
# Fallback when PID files are missing/stale: exact process name or known argv.
while read -r candidate; do
[ -n "$candidate" ] && candidates+=("$candidate")
done < <(
pgrep -u "$(id -u)" -x vocalinux 2>/dev/null || true
pgrep -u "$(id -u)" -x vocalinux-gui 2>/dev/null || true
pgrep -u "$(id -u)" -f -- '-m vocalinux\.main' 2>/dev/null || true
pgrep -u "$(id -u)" -f -- 'vocalinux/.*/ibus_engine\.py' 2>/dev/null || true
)
for pid in "${candidates[@]}"; do
[ -n "${seen[$pid]:-}" ] && continue
seen[$pid]=1
if is_vocalinux_process "$pid"; then
echo "$pid"
fi
done
}
check_running_processes() {
local PIDS
PIDS=$(get_vocalinux_pids || true)
if [ -n "$PIDS" ]; then
print_warning "Found running Vocalinux process(es):"
local pid
for pid in $PIDS; do
local cmd
cmd=$(tr '\0' ' ' < "/proc/$pid/cmdline" 2>/dev/null || echo "?")
print_warning " PID $pid: $cmd"
done
echo ""
if [[ "$NON_INTERACTIVE" == "yes" ]]; then
print_info "Non-interactive mode: stopping Vocalinux automatically..."
else
read -p "Vocalinux must be stopped before installation. Kill running process(es)? (Y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Nn]$ ]]; then
print_error "Cannot proceed with installation while Vocalinux is running."
print_info "Please stop Vocalinux manually and run the installer again."
exit "$EXIT_USER_ABORT"
fi
fi
print_info "Stopping Vocalinux..."
# shellcheck disable=SC2086
echo $PIDS | xargs -r kill -TERM 2>/dev/null || true
sleep 2
local REMAINING_PIDS
REMAINING_PIDS=$(get_vocalinux_pids || true)
if [ -n "$REMAINING_PIDS" ]; then
print_warning "Some processes still running, forcing termination..."
# shellcheck disable=SC2086
echo $REMAINING_PIDS | xargs -r kill -KILL 2>/dev/null || true
sleep 1
fi
local FINAL_PIDS
FINAL_PIDS=$(get_vocalinux_pids || true)
if [ -n "$FINAL_PIDS" ]; then
print_error "Could not terminate all Vocalinux processes: $FINAL_PIDS"
print_error "Please manually kill these processes and run the installer again."
exit "$EXIT_USER_ABORT"
else
print_success "All Vocalinux processes stopped"
fi
fi
}
# Parse command line arguments
INSTALL_MODE="user"
RUN_TESTS="no"
DEV_MODE="no"
VENV_DIR="venv"
SKIP_MODELS="no"
SKIP_SYSTEM_DEPS="no"
NON_INTERACTIVE="no"
INTERACTIVE_MODE="yes" # Default to interactive mode
AUTO_MODE="no"
REBUILD_WHISPERCPP="ask"
# Pinned pywhispercpp release (sdist, built from source). Keep in sync with
# uv.lock and the requirements/ exports.
PYWHISPERCPP_VERSION="1.5.0"
HAS_NVIDIA_GPU="unknown"
GPU_NAME=""
GPU_MEMORY=""
HAS_VULKAN="no"
VULKAN_DEVICE=""
VULKAN_SOFTWARE_DEVICE=""
# Initialize mode/state variables that are set later by flags or prompts so
# that every read under `set -u` is well-defined in every code path.
INSTALL_TAG=""
SELECTED_ENGINE=""
WHISPERCPP_BACKEND=""
WHISPERCPP_ALREADY_INSTALLED="false"
REMOTE_API_URL=""
# Detect if running non-interactively (e.g., via curl | bash)
# If stdin is a pipe but /dev/tty exists, redirect stdin so user input works normally.
# If no terminal is available at all (headless/CI), fall back to automatic mode.
if [ ! -t 0 ]; then
if [ -e /dev/tty ] && [ -r /dev/tty ]; then
if { true < /dev/tty; } 2>/dev/null; then
exec < /dev/tty
INTERACTIVE_MODE="ask"
else
AUTO_MODE="yes"
INTERACTIVE_MODE="no"
NON_INTERACTIVE="yes"
fi
else
AUTO_MODE="yes"
INTERACTIVE_MODE="no"
NON_INTERACTIVE="yes"
fi
fi
while [[ $# -gt 0 ]]; do
case $1 in
--dev)
DEV_MODE="yes"
shift
;;
--test)
RUN_TESTS="yes"
shift
;;
--venv-dir=*)
VENV_DIR="${1#*=}"
shift
;;
--skip-models)
SKIP_MODELS="yes"
shift
;;
--skip-system-deps)
SKIP_SYSTEM_DEPS="yes"
shift
;;
--rebuild-whispercpp)
REBUILD_WHISPERCPP="yes"
shift
;;
--no-rebuild-whispercpp)
REBUILD_WHISPERCPP="no"
shift
;;
--engine=*)
SELECTED_ENGINE="${1#*=}"
shift
;;
--interactive|-i)
INTERACTIVE_MODE="yes"
shift
;;
--tag=*)
INSTALL_TAG="${1#*=}"
shift
;;
--auto)
AUTO_MODE="yes"
INTERACTIVE_MODE="no"
NON_INTERACTIVE="yes"
shift
;;
--help)
echo "Vocalinux Installer"
echo ""
echo "Usage: $0 [options]"
echo ""
echo "Installation Modes:"
echo " (no flags) Interactive mode - guided setup with recommendations"
echo " --auto Automatic mode - install with defaults (whisper.cpp)"
echo " --auto --engine=whisper Auto mode with specific engine"
echo ""
echo "Options:"
echo " --interactive, -i Force interactive mode (default)"
echo " --auto Non-interactive automatic installation"
echo " --engine=NAME Speech engine: whisper_cpp (default), whisper, vosk, remote_api"
echo " --dev Install in development mode with all dev dependencies"
echo " --test Run tests after installation"
echo " --venv-dir=PATH Specify custom virtual environment directory"
echo " --skip-models Skip downloading speech models during installation"
echo " --skip-system-deps"
echo " Skip package-manager dependency installation (advanced)"
echo " --rebuild-whispercpp Rebuild/reinstall pywhispercpp even if already installed"
echo " --no-rebuild-whispercpp Reuse existing pywhispercpp when present (auto-mode default)"
echo " --tag=TAG Install specific release tag (default: latest release)"
echo " --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Interactive mode (recommended)"
echo " $0 --auto # Auto-install with whisper.cpp"
echo " $0 --auto --engine=vosk # Auto-install VOSK only"
echo " $0 --dev --test # Dev mode with tests"
echo ""
echo "During installation a full transcript is saved to"
echo " ~/.local/state/vocalinux/install-<timestamp>.log"
echo ""
echo "Exit codes:"
echo " 0 success"
echo " 1 generic failure"
echo " 2 required system dependencies could not be installed"
echo " 3 network / download failure"
echo " 4 user aborted at a prompt"
exit 0
;;
*)
print_error "Unknown option: $1"
echo "Use --help to see available options"
exit 1
;;
esac
done
# If dev mode is enabled, automatically run tests
if [[ "$DEV_MODE" == "yes" ]]; then
RUN_TESTS="yes"
fi
# ---------------------------------------------------------------------------
# Global install log: everything (stdout + stderr) is teed to this file so
# failures can be debugged after the fact. The path is printed at exit.
# ---------------------------------------------------------------------------
INSTALL_LOG_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/vocalinux"
if ! mkdir -p "$INSTALL_LOG_DIR" 2>/dev/null; then
INSTALL_LOG_DIR="${TMPDIR:-/tmp}"
fi
INSTALL_LOG_FILE="$INSTALL_LOG_DIR/install-$(date +%Y%m%d-%H%M%S).log"
exec > >(tee -a "$INSTALL_LOG_FILE") 2>&1
# Scratch directory for pip logs, model downloads, and other temps.
# Removed on success; kept for inspection (with a notice) when the install fails.
# Exporting TMPDIR routes pip/wget/curl scratch files into this directory.
VOCALINUX_TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/vocalinux-install.XXXXXXXX")"
export TMPDIR="$VOCALINUX_TMP_DIR"
cleanup_on_exit() {
local rc=$?
if [ "$rc" -eq "$EXIT_OK" ]; then
rm -rf "$VOCALINUX_TMP_DIR"
else
print_error ""
print_error "Installation did not complete (exit code $rc)."
print_error "Full install log: $INSTALL_LOG_FILE"
print_error "Scratch files kept for inspection: $VOCALINUX_TMP_DIR"
fi
}
trap cleanup_on_exit EXIT
trap 'print_error "Unexpected error near line $LINENO (exit code $?); see $INSTALL_LOG_FILE"' ERR
trap 'print_warning "Interrupted by user"; exit 130' INT
trap 'print_warning "Terminated by signal"; exit 143' TERM
# Display ASCII art banner
cat << "EOF"
▗▖ ▗▖ ▗▄▖ ▗▄▄▖ ▗▄▖ ▗▖ ▗▄▄▄▖▗▖ ▗▖▗▖ ▗▖▗▖ ▗▖
▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌ ▐▌▐▌ █ ▐▛▚▖▐▌▐▌ ▐▌ ▝▚▞▘
▐▌ ▐▌▐▌ ▐▌▐▌ ▐▛▀▜▌▐▌ █ ▐▌ ▝▜▌▐▌ ▐▌ ▐▌
▝▚▞▘ ▝▚▄▞▘▝▚▄▄▖▐▌ ▐▌▐▙▄▄▖▗▄█▄▖▐▌ ▐▌▝▚▄▞▘▗▞▘▝▚▖
Voice Dictation for Linux
EOF
print_info "Vocalinux Installer"
print_info "=============================="
echo ""
check_running_processes
resolve_install_tag() {
if [ -n "$INSTALL_TAG" ]; then
return 0
fi
if command_exists curl; then
local latest
# (|| true: pipefail would otherwise abort when head closes the pipe
# early or the API is unreachable; empty means "not resolved")
latest=$(curl -fsSL --connect-timeout 5 --retry 2 \
"https://api.github.com/repos/VocaHQ/vocalinux/releases/latest" \
2>/dev/null | grep '"tag_name"' | head -1 | cut -d'"' -f4 || true)
if [ -n "$latest" ]; then
INSTALL_TAG="$latest"
return 0
fi
fi
# No hardcoded fallback tag: silently installing a stale release is worse
# than failing. The remote-install path below aborts with a --tag hint if
# INSTALL_TAG is still empty; in-repo installs do not need a tag at all.
print_warning "Could not determine the latest release tag (GitHub API unreachable?)."
return 0
}
resolve_install_tag
# Check if running from within the vocalinux repo or remotely (via curl)
REPO_URL="https://github.com/VocaHQ/vocalinux.git"
INSTALL_DIR=""
CLEANUP_ON_EXIT="no"
# Function to check and install git if needed
ensure_git_installed() {
if command -v git >/dev/null 2>&1; then
return 0
fi
print_warning "git is not installed. Attempting to install git..."
# Detect distribution for package manager selection
local DISTRO_FAMILY="unknown"
if [ -f /etc/os-release ]; then
. /etc/os-release
if [[ "$ID" == "ubuntu" || "${ID_LIKE:-}" == *"ubuntu"* || "$ID" == "pop" || "$ID" == "linuxmint" || "$ID" == "elementary" || "$ID" == "zorin" ]]; then
DISTRO_FAMILY="ubuntu"
elif [[ "$ID" == "debian" || "${ID_LIKE:-}" == *"debian"* ]]; then
DISTRO_FAMILY="debian"
elif [[ "$ID" == "fedora" || "${ID_LIKE:-}" == *"fedora"* || "$ID" == "rhel" || "$ID" == "centos" || "$ID" == "rocky" || "$ID" == "almalinux" ]]; then
DISTRO_FAMILY="fedora"
elif [[ "$ID" == "arch" || "${ID_LIKE:-}" == *"arch"* || "$ID" == "manjaro" || "$ID" == "endeavouros" ]]; then
DISTRO_FAMILY="arch"
elif [[ "$ID" == "opensuse" || "${ID_LIKE:-}" == *"suse"* ]]; then
DISTRO_FAMILY="suse"
elif [[ "$ID" == "gentoo" ]]; then
DISTRO_FAMILY="gentoo"
elif [[ "$ID" == "alpine" ]]; then
DISTRO_FAMILY="alpine"
elif [[ "$ID" == "void" ]]; then
DISTRO_FAMILY="void"
elif [[ "$ID" == "solus" ]]; then
DISTRO_FAMILY="solus"
elif [[ "$ID" == "mageia" ]]; then
DISTRO_FAMILY="mageia"
fi
fi
case "$DISTRO_FAMILY" in
ubuntu|debian)
sudo apt update && sudo apt install -y git || {
print_error "Failed to install git. Please install git manually and run the installer again."
print_error " Ubuntu/Debian: sudo apt install git"
exit "$EXIT_MISSING_DEPS"
}
;;
fedora)
sudo dnf install -y git || {
print_error "Failed to install git. Please install git manually and run the installer again."
print_error " Fedora: sudo dnf install git"
exit "$EXIT_MISSING_DEPS"
}
;;
arch)
sudo pacman -S --noconfirm git || {
print_error "Failed to install git. Please install git manually and run the installer again."
print_error " Arch: sudo pacman -S git"
exit "$EXIT_MISSING_DEPS"
}
;;
suse)
sudo zypper install -y git || {
print_error "Failed to install git. Please install git manually and run the installer again."
print_error " openSUSE: sudo zypper install git"
exit "$EXIT_MISSING_DEPS"
}
;;
gentoo)
sudo emerge git || {
print_error "Failed to install git. Please install git manually and run the installer again."
print_error " Gentoo: sudo emerge git"
exit "$EXIT_MISSING_DEPS"
}
;;
alpine)
sudo apk add git || {
print_error "Failed to install git. Please install git manually and run the installer again."
print_error " Alpine: sudo apk add git"
exit "$EXIT_MISSING_DEPS"
}
;;
void)
sudo xbps-install -Sy git || {
print_error "Failed to install git. Please install git manually and run the installer again."
print_error " Void: sudo xbps-install -Sy git"
exit "$EXIT_MISSING_DEPS"
}
;;
solus)
sudo eopkg install git || {
print_error "Failed to install git. Please install git manually and run the installer again."
print_error " Solus: sudo eopkg install git"
exit "$EXIT_MISSING_DEPS"
}
;;
mageia)
if command -v dnf >/dev/null 2>&1; then
sudo dnf install -y git || {
print_error "Failed to install git. Please install git manually and run the installer again."
exit "$EXIT_MISSING_DEPS"
}
else
sudo urpmi --force git || {
print_error "Failed to install git. Please install git manually and run the installer again."
exit "$EXIT_MISSING_DEPS"
}
fi
;;
*)
print_error "git is not installed and could not auto-detect your distribution."
print_error "Please install git manually and run the installer again:"
print_error " Ubuntu/Debian: sudo apt install git"
print_error " Fedora/RHEL: sudo dnf install git"
print_error " Arch: sudo pacman -S git"
print_error " openSUSE: sudo zypper install git"
exit "$EXIT_MISSING_DEPS"
;;
esac
print_success "git installed successfully!"
}
# Check if running from within the vocalinux repository
# Validate that pyproject.toml/setup.py actually belongs to vocalinux before entering local repo mode
IS_VOCALINUX_LOCAL=false
if [ -f "pyproject.toml" ] && grep -q 'name = "vocalinux"' "pyproject.toml" 2>/dev/null; then
IS_VOCALINUX_LOCAL=true
elif [ -f "setup.py" ] && grep -q "vocalinux" "setup.py" 2>/dev/null; then
IS_VOCALINUX_LOCAL=true
fi
if [ "$IS_VOCALINUX_LOCAL" = true ]; then
# Running from within the vocalinux repo
INSTALL_DIR="$(pwd)"
print_info "Running from local repository: $INSTALL_DIR"
# Convert relative VENV_DIR to absolute for wrapper scripts.
# Absolute --venv-dir= paths must not be re-prefixed with INSTALL_DIR.
case "$VENV_DIR" in
/*) ;;
*) VENV_DIR="$INSTALL_DIR/$VENV_DIR" ;;
esac
else
# Running remotely (e.g., via curl | bash)
if [ -z "$INSTALL_TAG" ]; then
print_error "No release tag available: the GitHub API was unreachable and no --tag was given."
print_error "Re-run with an explicit release tag, e.g.: --tag=<release>"
exit "$EXIT_NETWORK"
fi
print_info "Installing Vocalinux version: ${INSTALL_TAG}"
# Ensure git is installed before attempting to clone
ensure_git_installed
INSTALL_DIR="$HOME/.local/share/vocalinux-install"
mkdir -p "$INSTALL_DIR"
if [ -d "$INSTALL_DIR/.git" ]; then
print_info "Updating existing clone..."
cd "$INSTALL_DIR"
if ! git fetch origin tag "$INSTALL_TAG" || ! git reset --hard "$INSTALL_TAG"; then
print_error "Failed to update the Vocalinux clone to $INSTALL_TAG."
print_error "Check the install log and your network connection: $INSTALL_LOG_FILE"
exit "$EXIT_NETWORK"
fi
else
rm -rf "$INSTALL_DIR"
git clone --depth 1 --branch "$INSTALL_TAG" "$REPO_URL" "$INSTALL_DIR" || {
print_error "Failed to clone Vocalinux repository"
exit "$EXIT_NETWORK"
}
cd "$INSTALL_DIR"
fi
CLEANUP_ON_EXIT="yes"
print_info "Repository cloned to: $INSTALL_DIR"
# When running remotely, install venv to user's home directory
VENV_DIR="$HOME/.local/share/vocalinux/venv"
fi
# Change to install directory
cd "$INSTALL_DIR"
print_info "Using virtual environment: $VENV_DIR"
[[ "$DEV_MODE" == "yes" ]] && print_info "Installing in development mode"
[[ "$RUN_TESTS" == "yes" ]] && print_info "Tests will be run after installation"
echo ""
# Check if running as root
if [ "$EUID" -eq 0 ]; then
print_error "Please do not run this script as root or with sudo."
exit 1
fi
# Detect Linux distribution and version
detect_distro() {
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO_NAME="${NAME:-unknown}"
DISTRO_ID="${ID:-unknown}"
DISTRO_VERSION="${VERSION_ID:-}"
DISTRO_FAMILY="unknown"
# Determine distribution family
if [[ "$ID" == "ubuntu" || "${ID_LIKE:-}" == *"ubuntu"* || "$ID" == "pop" || "$ID" == "linuxmint" || "$ID" == "elementary" || "$ID" == "zorin" ]]; then
DISTRO_FAMILY="ubuntu"
elif [[ "$ID" == "debian" || "${ID_LIKE:-}" == *"debian"* ]]; then
DISTRO_FAMILY="debian"
elif [[ "$ID" == "fedora" || "${ID_LIKE:-}" == *"fedora"* || "$ID" == "rhel" || "$ID" == "centos" || "$ID" == "rocky" || "$ID" == "almalinux" ]]; then
DISTRO_FAMILY="fedora"
elif [[ "$ID" == "arch" || "${ID_LIKE:-}" == *"arch"* || "$ID" == "manjaro" || "$ID" == "endeavouros" ]]; then
DISTRO_FAMILY="arch"
elif [[ "$ID" == "opensuse" || "${ID_LIKE:-}" == *"suse"* ]]; then
DISTRO_FAMILY="suse"
elif [[ "$ID" == "gentoo" ]]; then
DISTRO_FAMILY="gentoo"
elif [[ "$ID" == "alpine" ]]; then
DISTRO_FAMILY="alpine"
elif [[ "$ID" == "void" ]]; then
DISTRO_FAMILY="void"
elif [[ "$ID" == "solus" ]]; then
DISTRO_FAMILY="solus"
elif [[ "$ID" == "mageia" ]]; then
DISTRO_FAMILY="mageia"
fi
print_info "Detected: $DISTRO_NAME $DISTRO_VERSION ($DISTRO_FAMILY family)"
return 0
else
print_error "Could not detect Linux distribution (missing /etc/os-release)"
return 1
fi
}
# Detect NVIDIA GPU presence
detect_nvidia_gpu() {
# Check if nvidia-smi command exists and can successfully query GPU
if command -v nvidia-smi >/dev/null 2>&1 && nvidia-smi >/dev/null 2>&1; then
# Extract GPU information for user feedback
# (|| true: nvidia-smi may fail mid-pipeline; pipefail must not abort)
GPU_NAME=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -n1 || true)
GPU_MEMORY=$(nvidia-smi --query-gpu=memory.total --format=csv,noheader 2>/dev/null | head -n1 || true)
HAS_NVIDIA_GPU="yes"
return 0
else
HAS_NVIDIA_GPU="no"
return 1
fi
}
cuda_toolkit_root_has_runtime_library() {
local CUDA_ROOT="$1"
compgen -G "$CUDA_ROOT/lib64/libcudart.so*" >/dev/null && return 0
compgen -G "$CUDA_ROOT/lib/libcudart.so*" >/dev/null && return 0
compgen -G "$CUDA_ROOT/lib/x86_64-linux-gnu/libcudart.so*" >/dev/null && return 0
compgen -G "$CUDA_ROOT/targets/x86_64-linux/lib/libcudart.so*" >/dev/null && return 0
compgen -G "$CUDA_ROOT/targets/aarch64-linux/lib/libcudart.so*" >/dev/null && return 0
compgen -G "$CUDA_ROOT/targets/sbsa-linux/lib/libcudart.so*" >/dev/null && return 0
return 1
}
validate_cuda_toolkit_root() {
local CUDA_ROOT="$1"
[ -n "$CUDA_ROOT" ] || return 1
[ -x "$CUDA_ROOT/bin/nvcc" ] || return 1
[ -f "$CUDA_ROOT/include/cuda_runtime.h" ] || return 1
cuda_toolkit_root_has_runtime_library "$CUDA_ROOT" || return 1
}
candidate_cuda_toolkit_roots() {
local CUDA_VAR
for CUDA_VAR in CUDAToolkit_ROOT CUDA_HOME CUDA_PATH; do
local CUDA_ROOT="${!CUDA_VAR:-}"
[ -n "$CUDA_ROOT" ] && printf '%s\n' "$CUDA_ROOT"
done
if command -v nvcc >/dev/null 2>&1; then
local NVCC_PATH
local NVCC_ROOT
NVCC_PATH=$(readlink -f "$(command -v nvcc)" 2>/dev/null || command -v nvcc)
NVCC_ROOT=$(cd "$(dirname "$NVCC_PATH")/.." 2>/dev/null && pwd -P)
[ -n "$NVCC_ROOT" ] && printf '%s\n' "$NVCC_ROOT"
fi
local CUDA_ROOT
for CUDA_ROOT in /usr/local/cuda /usr/local/cuda-* /opt/cuda; do
[ -d "$CUDA_ROOT" ] && printf '%s\n' "$CUDA_ROOT"
done
}
find_valid_cuda_toolkit_root() {
local QUIET="${1:-no}"
local SEEN_ROOTS=""
local CUDA_ROOT
while IFS= read -r CUDA_ROOT; do
[ -n "$CUDA_ROOT" ] || continue
local NORMALIZED_ROOT
NORMALIZED_ROOT=$(cd "$CUDA_ROOT" 2>/dev/null && pwd -P) || NORMALIZED_ROOT="$CUDA_ROOT"
if [[ ":$SEEN_ROOTS:" == *":$NORMALIZED_ROOT:"* ]]; then
continue
fi
SEEN_ROOTS="${SEEN_ROOTS:+$SEEN_ROOTS:}$NORMALIZED_ROOT"
if validate_cuda_toolkit_root "$NORMALIZED_ROOT"; then
printf '%s\n' "$NORMALIZED_ROOT"
return 0
fi
if [[ "$QUIET" != "quiet" ]]; then
print_warning "Ignoring incomplete CUDA toolkit root: $NORMALIZED_ROOT" >&2
print_warning " Required: bin/nvcc, include/cuda_runtime.h, and libcudart.so*" >&2
fi
done < <(candidate_cuda_toolkit_roots)
return 1
}
detect_nvidia_compute_architectures() {
command -v nvidia-smi >/dev/null 2>&1 || return 1
local COMPUTE_CAPS
COMPUTE_CAPS=$(nvidia-smi --query-gpu=compute_cap --format=csv,noheader 2>/dev/null || true)
[ -n "$COMPUTE_CAPS" ] || return 1
printf '%s\n' "$COMPUTE_CAPS" | awk '
{
gsub(/[[:space:]]/, "", $1)
if ($1 ~ /^[0-9]+(\.[0-9]+)?$/) {
split($1, parts, ".")
minor = parts[2]
if (minor == "") {
minor = "0"
}
print parts[1] minor "-real"
}
}
' | sort -u | paste -sd ';' -
}
cuda_toolkit_supports_architectures() {
local CUDA_ROOT="$1"
local CUDA_ARCHS="$2"
[ -n "$CUDA_ARCHS" ] || return 0
local NVCC_ARCHS
NVCC_ARCHS=$("$CUDA_ROOT/bin/nvcc" --list-gpu-arch 2>/dev/null || true)
if [ -z "$NVCC_ARCHS" ]; then
print_warning "Could not query supported CUDA architectures from $CUDA_ROOT/bin/nvcc" >&2
print_warning "Continuing with detected CMAKE_CUDA_ARCHITECTURES=$CUDA_ARCHS" >&2
return 0
fi
local IFS=';'
local CUDA_ARCH
for CUDA_ARCH in $CUDA_ARCHS; do
local ARCH_DIGITS="${CUDA_ARCH%%-*}"
if ! printf '%s\n' "$NVCC_ARCHS" | grep -q "compute_$ARCH_DIGITS"; then
print_warning "CUDA toolkit at $CUDA_ROOT cannot target compute capability $ARCH_DIGITS." >&2
print_warning "Install a newer CUDA toolkit, such as CUDA 11.8+ for RTX 40/Ada GPUs." >&2
return 1
fi
done
return 0
}
get_cuda_cmake_args() {
local CUDA_ROOT="$1"
local CUDA_ARGS="-DCUDAToolkit_ROOT=$CUDA_ROOT -DCMAKE_CUDA_COMPILER=$CUDA_ROOT/bin/nvcc"
local CUDA_ARCHS
CUDA_ARCHS=$(detect_nvidia_compute_architectures || true)
if [ -n "$CUDA_ARCHS" ]; then
cuda_toolkit_supports_architectures "$CUDA_ROOT" "$CUDA_ARCHS" || return 1
CUDA_ARGS="$CUDA_ARGS -DCMAKE_CUDA_ARCHITECTURES=$CUDA_ARCHS"
fi
printf '%s\n' "$CUDA_ARGS"
}
# CPU implementations of Vulkan. whisper.cpp on these is slower than its own CPU
# backend, so they must never be reported as a GPU. One list, read by both
# detect_vulkan and check_vulkan_gpu_compatibility.
VULKAN_SOFTWARE_PATTERNS=(llvmpipe swiftshader lavapipe zink virtio venus)
is_software_renderer() {
local name="$1" pattern
for pattern in "${VULKAN_SOFTWARE_PATTERNS[@]}"; do
if printf '%s' "$name" | grep -iq "$pattern"; then
return 0
fi
done
return 1
}
# List the Vulkan devices vulkaninfo reports, one per line.
vulkan_device_names() {
command -v vulkaninfo >/dev/null 2>&1 || return 1
# (|| true: no match must not abort pipefail.)
vulkaninfo --summary 2>/dev/null | awk -F'=' '/deviceName/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); if ($2 != "") print $2}' || true
}
# Detect Vulkan support for whisper.cpp
detect_vulkan() {
# Only a hardware deviceName counts. The loader prints a header even when no
# ICD resolves, and a software renderer is not a GPU -- reporting either as
# one is what made Step 1 promise Vulkan performance the machine cannot give.
HAS_VULKAN="no"
VULKAN_DEVICE=""
VULKAN_SOFTWARE_DEVICE=""
local devices name
devices=$(vulkan_device_names) || return 1
[ -n "$devices" ] || return 1
while IFS= read -r name; do
[ -z "$name" ] && continue
if is_software_renderer "$name"; then
[ -n "$VULKAN_SOFTWARE_DEVICE" ] || VULKAN_SOFTWARE_DEVICE="$name"
continue
fi
HAS_VULKAN="yes"
VULKAN_DEVICE="$name"
return 0
done <<< "$devices"
return 1
}
# Check for incompatible Intel GPUs that don't support VK_KHR_16bit_storage
# These GPUs will fail with "device does not support 16-bit storage" error
# Affected: Intel Gen7 and older (Ivy Bridge, Haswell, Sandy Bridge)
# See: https://github.com/VocaHQ/vocalinux/issues/238
#
# IMPORTANT: This check filters out software renderers (llvmpipe, etc.) and only
# evaluates real hardware GPUs. Modern AMD, Intel (Gen8+), and NVIDIA GPUs all
# support VK_KHR_16bit_storage, so this mainly catches very old Intel Gen7 GPUs.
check_vulkan_gpu_compatibility() {
# List of known incompatible GPU patterns (old Intel Gen7 and older)
local INCOMPATIBLE_PATTERNS=(
"Ivy Bridge"
"Haswell"
"Sandy Bridge"
"HD Graphics 2500"
"HD Graphics 4000"
"HD Graphics 4400"
"HD Graphics 4600"
"HD Graphics P4600"
"HD Graphics P4700"
"IVB"
"HSW"
"SNB"
)
# Check if vulkaninfo is available
if ! command -v vulkaninfo >/dev/null 2>&1; then
echo "unknown:vulkaninfo not available"
return 1
fi
# Get all device names from vulkaninfo
local DEVICE_NAMES_RAW
DEVICE_NAMES_RAW=$(vulkan_device_names || true)
# Separate hardware GPUs from software renderers
local HARDWARE_GPUS=""
while IFS= read -r device_name; do
[ -z "$device_name" ] && continue
if is_software_renderer "$device_name"; then
continue
fi
if [ -n "$HARDWARE_GPUS" ]; then
HARDWARE_GPUS="${HARDWARE_GPUS}, ${device_name}"
else
HARDWARE_GPUS="$device_name"
fi
done <<< "$DEVICE_NAMES_RAW"
# If no hardware GPUs found, we can't determine compatibility
if [ -z "$HARDWARE_GPUS" ]; then
echo "unknown:No hardware GPU found (only software renderers)"
return 1
fi
# Get Vulkan features and check for VK_KHR_16bit_storage
# Modern GPUs (AMD, Intel Gen8+, NVIDIA) all support this extension
local FEATURES_OUTPUT
# Exits non-zero on drivers that still print usable output; the text is what matters.
FEATURES_OUTPUT=$(vulkaninfo --features 2>/dev/null) || true
if [ -n "$FEATURES_OUTPUT" ]; then
# Check for VK_KHR_16bit_storage extension or equivalent features
if echo "$FEATURES_OUTPUT" | grep -q "VK_KHR_16bit_storage"; then
echo "compatible:${HARDWARE_GPUS}"
return 0
fi
# Alternative: check for 16-bit storage features directly
if echo "$FEATURES_OUTPUT" | grep -Eq "storageBuffer16BitAccess[[:space:]]*=[[:space:]]*true|uniformAndStorageBuffer16BitAccess[[:space:]]*=[[:space:]]*true"; then
echo "compatible:${HARDWARE_GPUS}"
return 0
fi
fi
# If Vulkan features check didn't confirm support, check against known incompatible patterns
# This handles systems where vulkaninfo --features doesn't show the extension
local INCOMPATIBLE_GPUS=""
local HAS_COMPATIBLE_GPU=false