-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
1974 lines (1716 loc) · 68.2 KB
/
install.sh
File metadata and controls
1974 lines (1716 loc) · 68.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
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
# VoiceMode Universal Installer
# Usage: curl -sSfO https://getvoicemode.com/install.sh && bash install.sh
# Parse command line arguments
NON_INTERACTIVE=false
CI_MODE=false
show_help() {
cat <<EOF
VoiceMode Universal Installer
Usage: $0 [OPTIONS]
Options:
-h, --help Show this help message
-d, --debug Enable debug output
-n, --non-interactive Run without prompts (assumes yes to all)
--ci CI mode (non-interactive + skip audio/API checks)
Environment variables:
VOICEMODE_INSTALL_DEBUG=true Enable debug output
DEBUG=true Enable debug output
CI=true Enables CI mode automatically
Examples:
# Normal installation
curl -O https://getvoicemode.com/install.sh && bash install.sh
# Debug mode
VOICEMODE_INSTALL_DEBUG=true ./install.sh
./install.sh --debug
# Non-interactive mode
./install.sh --non-interactive
# CI mode
./install.sh --ci
EOF
exit 0
}
# Process arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h | --help)
show_help
;;
-d | --debug)
export VOICEMODE_INSTALL_DEBUG=true
shift
;;
-n | --non-interactive)
NON_INTERACTIVE=true
shift
;;
--ci)
CI_MODE=true
NON_INTERACTIVE=true
shift
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Support DEBUG=true as well as VOICEMODE_INSTALL_DEBUG=true
if [[ "${DEBUG:-}" == "true" ]]; then
export VOICEMODE_INSTALL_DEBUG=true
fi
# Detect CI environment
if [[ "${CI:-}" == "true" ]] || [[ "${GITHUB_ACTIONS:-}" == "true" ]]; then
CI_MODE=true
NON_INTERACTIVE=true
fi
# Reattach stdin to terminal for interactive prompts when run via curl | bash
# Only attempt this if /dev/tty exists and is accessible (skip in CI mode)
if [ ! -t 0 ] && [ -e /dev/tty ] && [ -r /dev/tty ] && [ "$CI_MODE" != "true" ]; then
exec </dev/tty 2>/dev/null || true
fi
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
ORANGE='\033[38;5;208m' # Claude Code orange
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m' # No Color
# Global variables
OS=""
ARCH=""
HOMEBREW_INSTALLED=false
XCODE_TOOLS_INSTALLED=false
IS_WSL=false
print_step() {
echo -e "${BLUE}🔧 $1${NC}"
}
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
exit 1
}
detect_os() {
print_step "Detecting operating system..."
# Check if running in WSL
# More robust WSL detection to avoid false positives
# Note: WSLInterop-late is used on newer systems with systemd
if [[ -n "$WSL_DISTRO_NAME" ]] || [[ -n "$WSL_INTEROP" ]] || [[ -f "/proc/sys/fs/binfmt_misc/WSLInterop" ]] || [[ -f "/proc/sys/fs/binfmt_misc/WSLInterop-late" ]]; then
IS_WSL=true
print_warning "Running in WSL2 - additional audio setup may be required"
elif grep -qi "microsoft.*WSL" /proc/version 2>/dev/null; then
# Only match if both "microsoft" AND "WSL" are present (case-insensitive)
IS_WSL=true
print_warning "Running in WSL2 - additional audio setup may be required"
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
ARCH=$(uname -m)
local macos_version=$(sw_vers -productVersion)
print_success "Detected macOS $macos_version on $ARCH"
elif [[ -f /etc/fedora-release ]]; then
OS="fedora"
ARCH=$(uname -m)
local fedora_version=$(cat /etc/fedora-release | grep -oP '\d+' | head -1)
print_success "Detected Fedora $fedora_version on $ARCH$([[ "$IS_WSL" == "true" ]] && echo " (WSL2)" || echo "")"
elif [[ -f /etc/os-release ]]; then
source /etc/os-release
if [[ "$ID" == "ubuntu" ]] || [[ "$ID_LIKE" == *"ubuntu"* ]] || [[ "$ID" == "debian" ]] || [[ "$ID_LIKE" == *"debian"* ]]; then
OS="debian" # Use debian for all Debian-based distros (Ubuntu, Debian, etc - they use apt)
ARCH=$(uname -m)
local distro_name="$NAME"
print_success "Detected $distro_name $VERSION_ID on $ARCH$([[ "$IS_WSL" == "true" ]] && echo " (WSL2)" || echo "")"
elif [[ "$ID" == "fedora" ]]; then
OS="fedora"
ARCH=$(uname -m)
print_success "Detected Fedora $VERSION_ID on $ARCH$([[ "$IS_WSL" == "true" ]] && echo " (WSL2)" || echo "")"
else
print_error "Unsupported Linux distribution: $ID. Currently only Ubuntu, Debian and Fedora are supported."
fi
else
print_error "Unsupported operating system: $OSTYPE"
fi
}
check_xcode_tools() {
print_step "Checking for Xcode Command Line Tools..."
if xcode-select -p >/dev/null 2>&1; then
XCODE_TOOLS_INSTALLED=true
print_success "Xcode Command Line Tools are already installed"
else
print_warning "Xcode Command Line Tools not found"
fi
}
install_xcode_tools() {
if [ "$XCODE_TOOLS_INSTALLED" = false ]; then
print_step "Installing Xcode Command Line Tools..."
echo "This will open a dialog to install Xcode Command Line Tools."
echo "Please follow the prompts and re-run this installer after installation completes."
xcode-select --install
print_warning "Please complete the Xcode Command Line Tools installation and re-run this installer."
exit 0
fi
}
check_homebrew() {
print_step "Checking for Homebrew..."
if command -v brew >/dev/null 2>&1; then
HOMEBREW_INSTALLED=true
print_success "Homebrew is already installed"
else
print_warning "Homebrew not found"
fi
}
collect_system_info() {
print_step "Collecting system information..."
# Initialize global variables for system info
SYSTEM_INFO_OS=""
SYSTEM_INFO_OS_VERSION=""
SYSTEM_INFO_ARCH=""
SYSTEM_INFO_SHELL=""
SYSTEM_INFO_SHELL_VERSION=""
SYSTEM_INFO_SHELL_RC_FILE=""
SYSTEM_INFO_NODE_VERSION=""
SYSTEM_INFO_NPM_VERSION=""
SYSTEM_INFO_PYTHON_VERSION=""
SYSTEM_INFO_PIP_VERSION=""
SYSTEM_INFO_CURL_VERSION=""
SYSTEM_INFO_GIT_VERSION=""
SYSTEM_INFO_FFMPEG_INSTALLED=""
SYSTEM_INFO_DOCKER_INSTALLED=""
SYSTEM_INFO_HOMEBREW_VERSION=""
SYSTEM_INFO_APT_INSTALLED=""
SYSTEM_INFO_TERMINAL_APP=""
SYSTEM_INFO_USER_HOME="$HOME"
SYSTEM_INFO_CURRENT_DIR="$(pwd)"
SYSTEM_INFO_DISK_AVAILABLE=""
# OS and Architecture (already detected)
SYSTEM_INFO_OS="$OS"
SYSTEM_INFO_ARCH="$ARCH"
# OS Version details
if [[ "$OS" == "macos" ]]; then
SYSTEM_INFO_OS_VERSION="$(sw_vers -productVersion 2>/dev/null || echo 'unknown')"
elif [[ "$OS" == "linux" ]]; then
if [ -f /etc/os-release ]; then
. /etc/os-release
SYSTEM_INFO_OS_VERSION="${PRETTY_NAME:-${NAME:-unknown}}"
else
SYSTEM_INFO_OS_VERSION="$(uname -v 2>/dev/null || echo 'unknown')"
fi
else
SYSTEM_INFO_OS_VERSION="$(uname -v 2>/dev/null || echo 'unknown')"
fi
# Default shell and version
SYSTEM_INFO_SHELL="${SHELL:-/bin/bash}"
if command -v "$SYSTEM_INFO_SHELL" >/dev/null 2>&1; then
if [[ "$SYSTEM_INFO_SHELL" == *"zsh"* ]]; then
SYSTEM_INFO_SHELL_VERSION="$($SYSTEM_INFO_SHELL --version 2>/dev/null | head -n1 || echo 'unknown')"
elif [[ "$SYSTEM_INFO_SHELL" == *"bash"* ]]; then
SYSTEM_INFO_SHELL_VERSION="$($SYSTEM_INFO_SHELL --version 2>/dev/null | head -n1 || echo 'unknown')"
elif [[ "$SYSTEM_INFO_SHELL" == *"fish"* ]]; then
SYSTEM_INFO_SHELL_VERSION="$($SYSTEM_INFO_SHELL --version 2>/dev/null || echo 'unknown')"
else
SYSTEM_INFO_SHELL_VERSION="unknown"
fi
fi
# Determine shell RC file
if [[ "$SYSTEM_INFO_SHELL" == *"zsh"* ]]; then
SYSTEM_INFO_SHELL_RC_FILE="$HOME/.zshrc"
elif [[ "$SYSTEM_INFO_SHELL" == *"bash"* ]]; then
if [[ "$OS" == "macos" ]]; then
# macOS uses .bash_profile for login shells
SYSTEM_INFO_SHELL_RC_FILE="$HOME/.bash_profile"
else
SYSTEM_INFO_SHELL_RC_FILE="$HOME/.bashrc"
fi
elif [[ "$SYSTEM_INFO_SHELL" == *"fish"* ]]; then
SYSTEM_INFO_SHELL_RC_FILE="$HOME/.config/fish/config.fish"
else
# Fallback to .profile
SYSTEM_INFO_SHELL_RC_FILE="$HOME/.profile"
fi
# Check if RC file exists, if not try alternatives
if [[ ! -f "$SYSTEM_INFO_SHELL_RC_FILE" ]]; then
if [[ "$SYSTEM_INFO_SHELL" == *"bash"* ]]; then
# Try alternative bash files
for rcfile in "$HOME/.bash_profile" "$HOME/.bashrc" "$HOME/.profile"; do
if [[ -f "$rcfile" ]]; then
SYSTEM_INFO_SHELL_RC_FILE="$rcfile"
break
fi
done
fi
fi
# Node.js and npm versions
if command -v node >/dev/null 2>&1; then
SYSTEM_INFO_NODE_VERSION="$(node --version 2>/dev/null || echo 'not installed')"
else
SYSTEM_INFO_NODE_VERSION="not installed"
fi
if command -v npm >/dev/null 2>&1; then
SYSTEM_INFO_NPM_VERSION="$(npm --version 2>/dev/null || echo 'not installed')"
else
SYSTEM_INFO_NPM_VERSION="not installed"
fi
# Python and pip versions
if command -v python3 >/dev/null 2>&1; then
SYSTEM_INFO_PYTHON_VERSION="$(python3 --version 2>&1 | cut -d' ' -f2 || echo 'not installed')"
elif command -v python >/dev/null 2>&1; then
SYSTEM_INFO_PYTHON_VERSION="$(python --version 2>&1 | cut -d' ' -f2 || echo 'not installed')"
else
SYSTEM_INFO_PYTHON_VERSION="not installed"
fi
if command -v pip3 >/dev/null 2>&1; then
SYSTEM_INFO_PIP_VERSION="$(pip3 --version 2>/dev/null | cut -d' ' -f2 || echo 'not installed')"
elif command -v pip >/dev/null 2>&1; then
SYSTEM_INFO_PIP_VERSION="$(pip --version 2>/dev/null | cut -d' ' -f2 || echo 'not installed')"
else
SYSTEM_INFO_PIP_VERSION="not installed"
fi
# Curl version
if command -v curl >/dev/null 2>&1; then
SYSTEM_INFO_CURL_VERSION="$(curl --version 2>/dev/null | head -n1 | cut -d' ' -f2 || echo 'not installed')"
else
SYSTEM_INFO_CURL_VERSION="not installed"
fi
# Git version
if command -v git >/dev/null 2>&1; then
SYSTEM_INFO_GIT_VERSION="$(git --version 2>/dev/null | cut -d' ' -f3 || echo 'not installed')"
else
SYSTEM_INFO_GIT_VERSION="not installed"
fi
# FFmpeg installed
if command -v ffmpeg >/dev/null 2>&1; then
SYSTEM_INFO_FFMPEG_INSTALLED="yes"
else
SYSTEM_INFO_FFMPEG_INSTALLED="no"
fi
# Docker installed
if command -v docker >/dev/null 2>&1; then
SYSTEM_INFO_DOCKER_INSTALLED="yes"
else
SYSTEM_INFO_DOCKER_INSTALLED="no"
fi
# Package managers
if [[ "$OS" == "macos" ]] && command -v brew >/dev/null 2>&1; then
SYSTEM_INFO_HOMEBREW_VERSION="$(brew --version 2>/dev/null | head -n1 | cut -d' ' -f2 || echo 'not installed')"
else
SYSTEM_INFO_HOMEBREW_VERSION="not installed"
fi
if command -v apt >/dev/null 2>&1; then
SYSTEM_INFO_APT_INSTALLED="yes"
else
SYSTEM_INFO_APT_INSTALLED="no"
fi
# Terminal application (if detectable)
SYSTEM_INFO_TERMINAL_APP="${TERM_PROGRAM:-${TERMINAL_EMULATOR:-unknown}}"
# Available disk space (in GB) on home partition
if [[ "$OS" == "macos" ]]; then
SYSTEM_INFO_DISK_AVAILABLE="$(df -h "$HOME" 2>/dev/null | awk 'NR==2 {print $4}' || echo 'unknown')"
else
SYSTEM_INFO_DISK_AVAILABLE="$(df -h "$HOME" 2>/dev/null | awk 'NR==2 {print $4}' || echo 'unknown')"
fi
if [[ "${VOICEMODE_INSTALL_DEBUG:-}" == "true" ]]; then
echo "System Information:"
echo " OS: $SYSTEM_INFO_OS"
echo " OS Version: $SYSTEM_INFO_OS_VERSION"
echo " Architecture: $SYSTEM_INFO_ARCH"
echo " Shell: $SYSTEM_INFO_SHELL"
echo " Shell Version: $SYSTEM_INFO_SHELL_VERSION"
echo " Shell RC File: $SYSTEM_INFO_SHELL_RC_FILE"
echo " Node Version: $SYSTEM_INFO_NODE_VERSION"
echo " NPM Version: $SYSTEM_INFO_NPM_VERSION"
echo " Python Version: $SYSTEM_INFO_PYTHON_VERSION"
echo " FFmpeg: $SYSTEM_INFO_FFMPEG_INSTALLED"
echo " Terminal: $SYSTEM_INFO_TERMINAL_APP"
echo " Disk Available: $SYSTEM_INFO_DISK_AVAILABLE"
fi
print_success "System information collected"
}
display_dependency_status() {
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " 📋 System Dependency Status"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Required dependencies
echo -e "${BOLD}Required Dependencies:${NC}"
echo ""
# Node.js
if [[ "$SYSTEM_INFO_NODE_VERSION" != "not installed" ]]; then
echo -e " ${GREEN}✅${NC} Node.js ${DIM}$SYSTEM_INFO_NODE_VERSION${NC}"
else
echo -e " ${RED}❌${NC} Node.js ${DIM}(required for Claude Code)${NC}"
fi
# npm
if [[ "$SYSTEM_INFO_NPM_VERSION" != "not installed" ]]; then
echo -e " ${GREEN}✅${NC} npm ${DIM}v$SYSTEM_INFO_NPM_VERSION${NC}"
else
echo -e " ${RED}❌${NC} npm ${DIM}(required for package management)${NC}"
fi
# Python
if [[ "$SYSTEM_INFO_PYTHON_VERSION" != "not installed" ]]; then
echo -e " ${GREEN}✅${NC} Python ${DIM}$SYSTEM_INFO_PYTHON_VERSION${NC}"
else
echo -e " ${RED}❌${NC} Python ${DIM}(required for VoiceMode)${NC}"
fi
# FFmpeg
if [[ "$SYSTEM_INFO_FFMPEG_INSTALLED" == "yes" ]]; then
echo -e " ${GREEN}✅${NC} FFmpeg ${DIM}(audio processing)${NC}"
else
echo -e " ${RED}❌${NC} FFmpeg ${DIM}(required for audio processing)${NC}"
fi
# Git
if [[ "$SYSTEM_INFO_GIT_VERSION" != "not installed" ]]; then
echo -e " ${GREEN}✅${NC} Git ${DIM}v$SYSTEM_INFO_GIT_VERSION${NC}"
else
echo -e " ${YELLOW}⚠️ ${NC} Git ${DIM}(recommended for development)${NC}"
fi
echo ""
echo -e "${BOLD}Package Managers:${NC}"
echo ""
# Platform-specific package managers
if [[ "$OS" == "macos" ]]; then
if [[ "$SYSTEM_INFO_HOMEBREW_VERSION" != "not installed" ]]; then
echo -e " ${GREEN}✅${NC} Homebrew ${DIM}v$SYSTEM_INFO_HOMEBREW_VERSION${NC}"
else
echo -e " ${RED}❌${NC} Homebrew ${DIM}(required for macOS dependencies)${NC}"
fi
elif [[ "$OS" == "linux" ]]; then
if [[ "$SYSTEM_INFO_APT_INSTALLED" == "yes" ]]; then
echo -e " ${GREEN}✅${NC} APT ${DIM}(system package manager)${NC}"
else
echo -e " ${YELLOW}⚠️ ${NC} APT ${DIM}(package manager not detected)${NC}"
fi
fi
echo ""
echo -e "${BOLD}System Information:${NC}"
echo ""
echo " • OS: $SYSTEM_INFO_OS_VERSION"
echo " • Architecture: $SYSTEM_INFO_ARCH"
echo -e " • Shell: ${SYSTEM_INFO_SHELL##*/} ${DIM}(${SYSTEM_INFO_SHELL_RC_FILE})${NC}"
echo " • Terminal: $SYSTEM_INFO_TERMINAL_APP"
echo " • Disk Space: $SYSTEM_INFO_DISK_AVAILABLE available"
if [[ "$IS_WSL" == true ]]; then
echo ""
echo -e " ${YELLOW}⚠️ WSL2 Detected${NC} - Additional audio setup may be required"
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
}
check_missing_dependencies() {
# Returns 0 if all required dependencies are met, 1 if any are missing
local missing=0
if [[ "$SYSTEM_INFO_NODE_VERSION" == "not installed" ]]; then
missing=1
fi
if [[ "$SYSTEM_INFO_NPM_VERSION" == "not installed" ]]; then
missing=1
fi
if [[ "$SYSTEM_INFO_PYTHON_VERSION" == "not installed" ]]; then
missing=1
fi
if [[ "$SYSTEM_INFO_FFMPEG_INSTALLED" != "yes" ]]; then
missing=1
fi
# Platform-specific requirements
if [[ "$OS" == "macos" ]] && [[ "$SYSTEM_INFO_HOMEBREW_VERSION" == "not installed" ]]; then
missing=1
fi
return $missing
}
confirm_action() {
local action="$1"
local default_yes="${2:-true}" # Default to yes unless specified
# In non-interactive mode, always return success
if [[ "$NON_INTERACTIVE" == "true" ]]; then
echo ""
if [[ "$action" == *"?"* ]]; then
echo "$action"
else
echo "About to: $action"
fi
echo "→ Auto-accepting (non-interactive mode)"
return 0
fi
echo ""
# Check if action is already a question (contains "?")
if [[ "$action" == *"?"* ]]; then
echo "$action"
else
echo "About to: $action"
fi
if [[ "$default_yes" == "true" ]]; then
read -p "Continue? [Y/n]: " choice
# Empty response defaults to yes
if [[ -z "$choice" ]]; then
return 0
fi
else
read -p "Continue? [y/N]: " choice
# Empty response defaults to no
if [[ -z "$choice" ]]; then
echo "Skipping: $action"
return 1
fi
fi
case $choice in
[Yy]*) return 0 ;;
*)
echo "Skipping..."
return 1
;;
esac
}
install_homebrew() {
if [ "$HOMEBREW_INSTALLED" = false ]; then
if confirm_action "Install Homebrew (this will also install Xcode Command Line Tools)"; then
print_step "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add Homebrew to PATH for current session
if [[ "$ARCH" == "arm64" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
else
eval "$(/usr/local/bin/brew shellenv)"
fi
print_success "Homebrew installed successfully"
# Update the status variables since Homebrew installs Xcode tools
HOMEBREW_INSTALLED=true
XCODE_TOOLS_INSTALLED=true
else
print_error "Homebrew is required for VoiceMode dependencies. Installation aborted."
fi
fi
}
check_system_dependencies() {
print_step "Checking system dependencies..."
if [[ "$OS" == "macos" ]]; then
local packages=("node" "portaudio" "ffmpeg")
local missing_packages=()
for package in "${packages[@]}"; do
if brew list "$package" >/dev/null 2>&1; then
print_success "$package is already installed"
else
missing_packages+=("$package")
fi
done
if [ ${#missing_packages[@]} -eq 0 ]; then
print_success "All system dependencies are already installed"
return 0
else
echo "Missing packages: ${missing_packages[*]}"
return 1
fi
elif [[ "$OS" == "fedora" ]]; then
local packages=("nodejs" "portaudio-devel" "ffmpeg" "cmake" "python3-devel" "alsa-lib-devel")
local missing_packages=()
for package in "${packages[@]}"; do
# Special handling for ffmpeg which might be installed from RPM Fusion
if [[ "$package" == "ffmpeg" ]]; then
if command -v ffmpeg >/dev/null 2>&1; then
print_success "$package is already installed"
else
missing_packages+=("$package")
fi
elif rpm -q "$package" >/dev/null 2>&1; then
print_success "$package is already installed"
else
missing_packages+=("$package")
fi
done
if [ ${#missing_packages[@]} -eq 0 ]; then
print_success "All system dependencies are already installed"
return 0
else
echo "Missing packages: ${missing_packages[*]}"
return 1
fi
elif [[ "$OS" == "debian" ]]; then
local packages=("nodejs" "npm" "portaudio19-dev" "ffmpeg" "cmake" "python3-dev" "libasound2-dev" "libasound2-plugins")
local missing_packages=()
for package in "${packages[@]}"; do
if dpkg -l "$package" 2>/dev/null | grep -q '^ii'; then
print_success "$package is already installed"
else
missing_packages+=("$package")
fi
done
if [ ${#missing_packages[@]} -eq 0 ]; then
print_success "All system dependencies are already installed"
return 0
else
echo "Missing packages: ${missing_packages[*]}"
return 1
fi
fi
}
install_system_dependencies() {
if ! check_system_dependencies; then
if [[ "$OS" == "macos" ]]; then
# Build list of what needs to be installed
local needs_homebrew=false
local needs_deps=false
local install_message=""
if [ "$HOMEBREW_INSTALLED" = false ]; then
needs_homebrew=true
install_message="• Homebrew (package manager)\n • Xcode Command Line Tools (automatically installed)\n "
fi
# Check for missing audio dependencies
local missing_packages=()
for package in ffmpeg portaudio; do
if ! brew list $package &>/dev/null; then
missing_packages+=($package)
needs_deps=true
fi
done
if [ "$needs_homebrew" = true ] || [ "$needs_deps" = true ]; then
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " 📦 System Dependencies Required"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "VoiceMode needs to install the following:"
if [ "$needs_homebrew" = true ]; then
echo -e "$install_message"
fi
if [ "$needs_deps" = true ]; then
echo "• Audio dependencies: ${missing_packages[*]}"
fi
echo ""
if confirm_action "Install all required dependencies?"; then
# Install Homebrew if needed
if [ "$needs_homebrew" = true ]; then
install_homebrew
if [ "$HOMEBREW_INSTALLED" = false ]; then
print_warning "Failed to install Homebrew. Cannot proceed."
return 1
fi
fi
# Install missing packages
if [ "$needs_deps" = true ]; then
print_step "Installing audio dependencies..."
brew update
for package in "${missing_packages[@]}"; do
print_step "Installing $package..."
brew install "$package"
print_success "$package installed"
done
fi
else
print_warning "Skipping system dependencies. VoiceMode may not work properly without them."
return 1
fi
fi
elif [[ "$OS" == "fedora" ]]; then
if confirm_action "Install missing system dependencies via DNF"; then
print_step "Installing system dependencies..."
# Update package lists (ignore exit code as dnf check-update returns 100 when updates are available)
sudo dnf check-update || true
# Install required packages
local packages=("nodejs" "portaudio-devel" "ffmpeg" "cmake" "python3-devel" "alsa-lib-devel")
print_step "Installing packages: ${packages[*]}"
sudo dnf install -y "${packages[@]}"
print_success "System dependencies installed"
else
print_warning "Skipping system dependencies. VoiceMode may not work properly without them."
fi
elif [[ "$OS" == "debian" ]]; then
if confirm_action "Install missing system dependencies via APT"; then
print_step "Installing system dependencies..."
# Update package lists
sudo apt update
# Install required packages
local packages=("nodejs" "npm" "portaudio19-dev" "ffmpeg" "cmake" "python3-dev" "libasound2-dev" "libasound2-plugins" "pulseaudio" "pulseaudio-utils")
# Add WSL-specific packages if detected
if [[ "$IS_WSL" == true ]]; then
print_warning "WSL2 detected - installing additional audio packages"
packages+=("libasound2-plugins" "pulseaudio")
fi
print_step "Installing packages: ${packages[*]}"
sudo apt install -y "${packages[@]}"
print_success "System dependencies installed"
# WSL-specific audio setup
if [[ "$IS_WSL" == true ]]; then
print_step "Setting up WSL2 audio support..."
# Start PulseAudio if not running
if ! pgrep -x "pulseaudio" >/dev/null; then
pulseaudio --start 2>/dev/null || true
print_success "Started PulseAudio service"
fi
# Check audio devices
if command -v pactl >/dev/null 2>&1; then
if pactl list sources short 2>/dev/null | grep -q .; then
print_success "Audio devices detected in WSL2"
else
print_warning "No audio devices detected. WSL2 audio setup may require:"
echo " 1. Enable Windows microphone permissions for your terminal"
echo " 2. Ensure WSL version is 2.3.26.0 or higher (run 'wsl --version')"
echo " 3. See: https://github.com/mbailey/voicemode/blob/main/docs/troubleshooting/wsl2-microphone-access.md"
fi
fi
fi
else
print_warning "Skipping system dependencies. VoiceMode may not work properly without them."
fi
fi
fi
}
check_python() {
print_step "Checking Python installation..."
if command -v python3 >/dev/null 2>&1; then
local python_version=$(python3 --version | cut -d' ' -f2)
print_success "Python 3 found: $python_version"
else
print_warning "Python 3 not found in PATH"
echo " UV will manage Python installation automatically"
fi
}
install_uv() {
if ! command -v uv >/dev/null 2>&1; then
if confirm_action "Install UV (required for VoiceMode)"; then
print_step "Installing UV..."
# Install UV using the official installer
curl -LsSf https://astral.sh/uv/install.sh | sh
# Add UV to PATH for current session
export PATH="$HOME/.local/bin:$PATH"
# Verify installation immediately
if ! command -v uv >/dev/null 2>&1; then
print_error "UV installation failed - command not found after installation"
return 1
fi
# Test uv actually works
if ! uv --version >/dev/null 2>&1; then
print_error "UV installation failed - command not working"
return 1
fi
# Add to shell profile if not already there
local shell_profile="${SYSTEM_INFO_SHELL_RC_FILE:-$HOME/.bashrc}"
if [ -n "$shell_profile" ] && [ -f "$shell_profile" ]; then
if ! grep -q "\.local/bin" "$shell_profile"; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >>"$shell_profile"
print_success "Added UV to PATH in $shell_profile"
# Source the profile to make UV immediately available
source "$shell_profile"
print_success "Loaded $shell_profile to update PATH"
fi
fi
print_success "UV installed and verified successfully"
else
print_error "UV is required for VoiceMode. Installation aborted."
return 1
fi
else
print_success "UV is already installed"
# Even if already installed, verify it works
if ! uv --version >/dev/null 2>&1; then
print_error "UV is installed but not working properly"
return 1
fi
fi
}
install_voicemode() {
print_step "Installing VoiceMode..."
# Install voice-mode package with uv tool install
if uv tool install --upgrade --force voice-mode; then
print_success "VoiceMode installed successfully"
# Update shell to ensure PATH includes UV tools
print_step "Updating shell PATH configuration..."
if uv tool update-shell; then
print_success "Shell PATH updated"
# Export PATH for current session
export PATH="$HOME/.local/bin:$PATH"
# Source shell profile for immediate availability
if [[ -n "${SYSTEM_INFO_SHELL_RC_FILE}" ]] && [[ -f "${SYSTEM_INFO_SHELL_RC_FILE}" ]]; then
source "${SYSTEM_INFO_SHELL_RC_FILE}" 2>/dev/null || true
fi
else
print_warning "Could not update shell PATH automatically"
fi
# Verify the voicemode command is available
if command -v voicemode >/dev/null 2>&1; then
print_success "VoiceMode command verified: voicemode"
return 0
else
print_warning "VoiceMode installed but command not immediately available"
if [[ -n "${SYSTEM_INFO_SHELL_RC_FILE}" ]]; then
echo " You may need to restart your shell or run: source ${SYSTEM_INFO_SHELL_RC_FILE}"
else
echo " You may need to restart your shell"
fi
return 0
fi
else
print_error "Failed to install VoiceMode"
return 1
fi
}
setup_local_npm() {
print_step "Setting up local npm configuration..."
# Set up npm to use local directory (no sudo required)
mkdir -p "$HOME/.npm-global"
npm config set prefix "$HOME/.npm-global"
# Add to PATH for current session
export PATH="$HOME/.npm-global/bin:$PATH"
# Add to shell profile if not already there
local shell_profile="${SYSTEM_INFO_SHELL_RC_FILE:-$HOME/.bashrc}"
if [ -n "$shell_profile" ] && [ -f "$shell_profile" ]; then
if ! grep -q "\.npm-global/bin" "$shell_profile"; then
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >>"$shell_profile"
print_success "Added npm global bin to PATH in $shell_profile"
# Source the profile to make npm immediately available
source "$shell_profile"
print_success "Loaded $shell_profile to update PATH"
fi
fi
print_success "Local npm configuration complete"
}
setup_shell_completion() {
# Safe shell completion setup that checks command availability at runtime
# This prevents shell startup errors by only enabling completions when the command exists
# Detect current shell
local shell_type=""
local shell_rc=""
if [[ -n "${BASH_VERSION:-}" ]]; then
shell_type="bash"
shell_rc="$HOME/.bashrc"
elif [[ -n "${ZSH_VERSION:-}" ]]; then
shell_type="zsh"
shell_rc="$HOME/.zshrc"
else
# Try to detect from SHELL environment variable
case "${SHELL:-}" in
*/bash)
shell_type="bash"
shell_rc="$HOME/.bashrc"
;;
*/zsh)
shell_type="zsh"
shell_rc="$HOME/.zshrc"
;;
*)
print_warning "Unsupported shell for completion: ${SHELL:-unknown}"
echo " VoiceMode completion supports bash and zsh only"
return 1
;;
esac
fi
if [[ -z "$shell_type" ]]; then
print_debug "Could not detect shell type for completion setup"
return 1
fi
print_step "Setting up shell completion for $shell_type..."
# Set up completion based on shell type
if [[ "$shell_type" == "bash" ]]; then
# Check for existing bash-completion support
local has_bash_completion=false
local user_completions_dir="${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion/completions"
# Check if bash-completion is installed
if [[ -f "/usr/share/bash-completion/bash_completion" ]] ||
[[ -f "/etc/bash_completion" ]] ||
(command -v brew >/dev/null 2>&1 && brew list bash-completion@2 >/dev/null 2>&1); then
has_bash_completion=true
fi
if [[ "$has_bash_completion" == true ]]; then
# Install completion file to user directory
mkdir -p "$user_completions_dir"
# Generate and save completion file with bash version compatibility
if command -v voicemode >/dev/null 2>&1; then
# Check bash version - nosort option is only available in bash 4.4+
local bash_version="${BASH_VERSION%%.*}"
local bash_minor="${BASH_VERSION#*.}"
bash_minor="${bash_minor%%.*}"
if [[ $bash_version -gt 4 ]] || [[ $bash_version -eq 4 && $bash_minor -ge 4 ]]; then
# Bash 4.4+ supports nosort
_VOICEMODE_COMPLETE=bash_source voicemode >"$user_completions_dir/voicemode" 2>/dev/null
else
# Older bash - filter out nosort option to prevent errors
_VOICEMODE_COMPLETE=bash_source voicemode 2>/dev/null | sed 's/complete -o nosort/complete/g' >"$user_completions_dir/voicemode"
fi
if [[ -s "$user_completions_dir/voicemode" ]]; then
print_success "Installed bash completion to $user_completions_dir/"
echo " Tab completion will be available in new bash sessions"
else
rm -f "$user_completions_dir/voicemode"
# Fallback to shell RC method
has_bash_completion=false
fi
fi
fi
if [[ "$has_bash_completion" == false ]]; then
# Fallback: Add to shell RC file with bash version check
local completion_line='# VoiceMode shell completion
if command -v voicemode >/dev/null 2>&1; then
# Check bash version for nosort compatibility
bash_version="${BASH_VERSION%%.*}"
bash_minor="${BASH_VERSION#*.}"
bash_minor="${bash_minor%%.*}"
if [[ $bash_version -gt 4 ]] || [[ $bash_version -eq 4 && $bash_minor -ge 4 ]]; then
eval "$(_VOICEMODE_COMPLETE=bash_source voicemode)"
else
# Filter out nosort for older bash versions