-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsetup-opentranscribe.sh
More file actions
executable file
·2149 lines (1891 loc) · 88.9 KB
/
setup-opentranscribe.sh
File metadata and controls
executable file
·2149 lines (1891 loc) · 88.9 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
# OpenTranscribe Cross-Platform Setup Script
#
# Environment variables:
# OPENTRANSCRIBE_BRANCH Git branch to download files from (default: master)
# OPENTRANSCRIBE_UNATTENDED When non-empty, skip all interactive prompts and
# use safe defaults or pre-set environment variables
# (used by CI and release-test harnesses)
#
# Env vars honored in unattended mode (all optional; any can be pre-set):
# PROJECT_DIR Where to install (default: ./opentranscribe)
# HUGGINGFACE_TOKEN PyAnnote HuggingFace token
# WHISPER_MODEL Whisper model id (e.g. large-v3-turbo)
# OPENSEARCH_MODELS OpenSearch embedding model id
# GPU_DEVICE_ID CUDA device index to pin (default: 0)
# LLM_PROVIDER vllm|openai|ollama|anthropic|openrouter (default: vllm, no-op)
# NGINX_SERVER_NAME If set, enables HTTPS/NGINX setup; else skipped
# VLLM_BASE_URL, VLLM_API_KEY, VLLM_MODEL_NAME
# OPENAI_API_KEY, OPENAI_MODEL_NAME
# OLLAMA_BASE_URL, OLLAMA_MODEL_NAME
# ANTHROPIC_API_KEY, ANTHROPIC_MODEL_NAME
# OPENROUTER_API_KEY, OPENROUTER_MODEL_NAME
set -e
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# ─── Unattended-mode helpers ─────────────────────────────────────────────────
# When OPENTRANSCRIBE_UNATTENDED is set, interactive prompts are skipped and
# pre-set environment variables (or safe defaults) are used instead.
is_unattended() {
[[ -n "${OPENTRANSCRIBE_UNATTENDED:-}" ]]
}
# ot_log_unattended: emit a log line when a prompt is skipped in unattended mode
ot_log_unattended() {
echo -e "${BLUE}[unattended]${NC} $*"
}
# Helper functions for colored output
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
print_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
print_header() {
echo ""
echo -e "${BLUE}═══════════════════════════════════════════${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}═══════════════════════════════════════════${NC}"
echo ""
}
echo -e "${YELLOW}OpenTranscribe Cross-Platform Setup Script${NC}"
echo "Automatic hardware detection and configuration for CUDA, MPS, and CPU"
echo ""
# Global variables
PROJECT_DIR="opentranscribe"
DETECTED_PLATFORM=""
DETECTED_DEVICE=""
COMPUTE_TYPE=""
BATCH_SIZE=""
DOCKER_RUNTIME=""
USE_GPU_RUNTIME="false"
#######################
# HARDWARE DETECTION
#######################
detect_platform() {
echo -e "${BLUE}🔍 Detecting platform and hardware...${NC}"
# Detect OS and Architecture
DETECTED_PLATFORM=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$DETECTED_PLATFORM" in
"linux")
echo "✓ Detected: Linux ($ARCH)"
;;
"darwin")
DETECTED_PLATFORM="macos"
echo "✓ Detected: macOS ($ARCH)"
;;
"mingw"*|"msys"*|"cygwin"*)
DETECTED_PLATFORM="windows"
echo "✓ Detected: Windows ($ARCH)"
;;
*)
echo "⚠️ Unknown platform: $DETECTED_PLATFORM ($ARCH)"
;;
esac
# Detect hardware acceleration
detect_hardware_acceleration
}
detect_hardware_acceleration() {
DETECTED_DEVICE="cpu" # Default fallback
# Check for NVIDIA GPU (CUDA)
if command -v nvidia-smi &> /dev/null; then
if nvidia-smi &> /dev/null; then
echo "✓ NVIDIA GPU detected"
nvidia-smi --query-gpu=index,name,memory.total --format=csv,noheader
DETECTED_DEVICE="cuda"
COMPUTE_TYPE="float16"
BATCH_SIZE="16"
USE_GPU_RUNTIME="true"
# Get count of available GPUs
GPU_COUNT=$(nvidia-smi --query-gpu=index --format=csv,noheader,nounits | wc -l)
# Get default GPU (first available)
DEFAULT_GPU=$(nvidia-smi --query-gpu=index --format=csv,noheader,nounits | head -n1)
GPU_DEVICE_ID=${DEFAULT_GPU:-0}
return
fi
fi
# Check for Apple Silicon (MPS)
if [[ "$DETECTED_PLATFORM" == "macos" ]]; then
# Check for Apple Silicon
if [[ $(uname -m) == "arm64" ]]; then
echo "✓ Apple Silicon detected (M1/M2)"
DETECTED_DEVICE="mps"
COMPUTE_TYPE="float32"
BATCH_SIZE="8"
# Check macOS version for MPS support (requires macOS 12.3+)
macos_version=$(sw_vers -productVersion)
if [[ $(echo "$macos_version" | cut -d. -f1) -ge 12 ]] && [[ $(echo "$macos_version" | cut -d. -f2) -ge 3 ]]; then
echo "✓ macOS $macos_version supports MPS acceleration"
else
echo "⚠️ macOS $macos_version detected, MPS requires 12.3+, falling back to CPU"
DETECTED_DEVICE="cpu"
fi
return
else
echo "✓ Intel Mac detected"
fi
fi
# CPU fallback
echo "ℹ️ Using CPU processing (no GPU acceleration detected)"
DETECTED_DEVICE="cpu"
COMPUTE_TYPE="int8"
BATCH_SIZE="4"
# Detect CPU cores for optimization
if command -v nproc &> /dev/null; then
CPU_CORES=$(nproc)
elif command -v sysctl &> /dev/null; then
CPU_CORES=$(sysctl -n hw.ncpu)
else
CPU_CORES=4
fi
echo "✓ Detected $CPU_CORES CPU cores"
}
#######################
# DOCKER CONFIGURATION
#######################
check_gpu_support() {
# Check for NVIDIA GPUs
if command -v nvidia-smi &> /dev/null; then
echo "✅ NVIDIA GPU detected:"
nvidia-smi --query-gpu=name --format=csv,noheader
else
echo "❌ No NVIDIA GPU detected or nvidia-smi not found"
return 1
fi
# Check for NVIDIA container runtime
if docker info 2>/dev/null | grep -q "nvidia"; then
echo "✅ NVIDIA Container Runtime is properly configured"
return 0
else
echo "❌ NVIDIA Container Runtime is not properly configured"
return 1
fi
}
configure_docker_runtime() {
echo -e "${BLUE}🐳 Configuring Docker runtime...${NC}"
if [[ "$USE_GPU_RUNTIME" == "true" && "$DETECTED_DEVICE" == "cuda" ]]; then
echo "🧪 Testing NVIDIA Container Toolkit..."
if check_gpu_support; then
echo -e "${GREEN}✅ NVIDIA Container Toolkit fully functional${NC}"
DOCKER_RUNTIME="nvidia"
else
echo -e "${RED}❌ NVIDIA Container Toolkit tests failed${NC}"
echo ""
echo "Possible solutions:"
echo "1. Install NVIDIA Container Toolkit:"
echo " https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html"
echo "2. Restart Docker daemon after installation"
echo "3. Check NVIDIA driver installation with: nvidia-smi"
echo ""
echo -e "${YELLOW}⚠️ Automatically falling back to CPU mode...${NC}"
fallback_to_cpu
fi
else
DOCKER_RUNTIME="default"
echo "✓ Using default Docker runtime"
fi
}
fallback_to_cpu() {
DETECTED_DEVICE="cpu"
COMPUTE_TYPE="int8"
BATCH_SIZE="4"
USE_GPU_RUNTIME="false"
DOCKER_RUNTIME="default"
}
#######################
# NETWORK AND DEPENDENCY CHECKS
#######################
check_network_connectivity() {
echo -e "${BLUE}🌐 Checking network connectivity...${NC}"
# Test GitHub connectivity
if ! curl -s --connect-timeout 5 --max-time 10 https://raw.githubusercontent.com > /dev/null 2>&1; then
echo -e "${YELLOW}⚠️ GitHub may not be accessible for downloading files${NC}"
echo "This could affect the setup process. Please check your internet connection."
echo ""
if is_unattended; then
ot_log_unattended "Aborting on network check failure (unattended mode cannot continue without GitHub)."
exit 1
fi
read -p "Do you want to continue anyway? (y/N) " -n 1 -r </dev/tty
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Setup cancelled by user."
exit 1
fi
else
echo "✓ Network connectivity verified"
fi
}
validate_downloaded_files() {
echo -e "${BLUE}🔍 Validating downloaded files...${NC}"
# Note: Database schema is managed by Alembic migrations on backend startup.
# No init_db.sql validation needed.
# Validate docker-compose files exist
if [ ! -f "docker-compose.yml" ]; then
echo -e "${RED}❌ docker-compose.yml file not found${NC}"
return 1
fi
if [ ! -f "docker-compose.prod.yml" ]; then
echo -e "${RED}❌ docker-compose.prod.yml file not found${NC}"
return 1
fi
# Check for essential services in base file
if ! grep -q "services:" docker-compose.yml; then
echo -e "${RED}❌ docker-compose.yml appears invalid (no 'services:' section)${NC}"
return 1
fi
if ! grep -q "backend:" docker-compose.yml || ! grep -q "frontend:" docker-compose.yml; then
echo -e "${RED}❌ docker-compose.yml missing essential services${NC}"
return 1
fi
echo "✓ docker-compose.yml and docker-compose.prod.yml validated"
echo " (Full configuration validation will occur after .env file creation)"
echo "✓ All downloaded files validated successfully"
return 0
}
check_dependencies() {
echo -e "${BLUE}📋 Checking dependencies...${NC}"
# Check for curl
if ! command -v curl &> /dev/null; then
echo -e "${RED}❌ curl is not installed${NC}"
echo "curl is required to download configuration files."
echo "Please install curl and try again."
exit 1
else
echo "✓ curl detected"
fi
# Check for Docker
if ! command -v docker &> /dev/null; then
echo -e "${RED}❌ Docker is not installed${NC}"
echo "Visit https://docs.docker.com/get-docker/ for installation instructions."
exit 1
else
docker_version=$(docker --version | cut -d' ' -f3 | cut -d',' -f1)
echo "✓ Docker $docker_version detected"
fi
# Check for Docker Compose
if ! docker compose version &> /dev/null; then
echo -e "${RED}❌ Docker Compose is not installed or not in PATH${NC}"
echo "Visit https://docs.docker.com/compose/install/ for installation instructions."
exit 1
else
compose_version=$(docker compose version --short)
echo "✓ Docker Compose $compose_version detected"
fi
# Check if Docker daemon is running
local docker_check_output
docker_check_output=$(docker info 2>&1)
if [ $? -ne 0 ]; then
if echo "$docker_check_output" | grep -qi "permission denied"; then
echo -e "${RED}❌ Permission denied accessing Docker.${NC}"
echo ""
echo "Your user ($USER) is not in the 'docker' group."
echo "Run: sudo usermod -aG docker \$USER then log out and back in."
echo "Or re-run this script with sudo."
elif echo "$docker_check_output" | grep -qi "cannot connect\|is the docker daemon running\|no such file"; then
echo -e "${RED}❌ Docker daemon is not running.${NC}"
echo "Run: sudo systemctl start docker"
echo "To start on boot: sudo systemctl enable docker"
else
echo -e "${RED}❌ Failed to connect to Docker.${NC}"
echo "$docker_check_output"
fi
exit 1
else
echo "✓ Docker daemon is running"
fi
# Check network connectivity
check_network_connectivity
}
#######################
# CONFIGURATION SETUP
#######################
setup_project_directory() {
echo -e "${BLUE}📁 Setting up project directory...${NC}"
# Create and enter project directory
mkdir -p "$PROJECT_DIR"
cd "$PROJECT_DIR"
# Resolve to absolute path so later cd calls work regardless of cwd changes
PROJECT_DIR="$(pwd)"
echo "✓ Created project directory: $PROJECT_DIR"
}
create_database_files() {
echo "✓ Downloading database initialization files..."
# Create database directory
mkdir -p database
# Note: Database schema is managed by Alembic migrations - no init_db.sql download needed
}
create_configuration_files() {
echo -e "${BLUE}📄 Creating configuration files...${NC}"
# Create database initialization files
create_database_files
# Create comprehensive docker-compose.yml directly
create_production_compose
# Validate all downloaded files
if ! validate_downloaded_files; then
echo -e "${RED}❌ File validation failed${NC}"
exit 1
fi
# Download opentranscribe.sh management script
download_management_script
# Download NGINX/SSL configuration files
download_nginx_files
# Download model downloader scripts
download_model_downloader_scripts
# Create .env.example
create_production_env_example
}
create_production_compose() {
echo "✓ Downloading production docker-compose configuration..."
local max_retries=3
local branch="${OPENTRANSCRIBE_BRANCH:-master}"
# URL-encode the branch name (replace / with %2F)
local encoded_branch
encoded_branch=$(echo "$branch" | sed 's|/|%2F|g')
# Download base docker-compose.yml
echo " Downloading base docker-compose.yml..."
local retry_count=0
local base_url="https://raw.githubusercontent.com/davidamacey/OpenTranscribe/${encoded_branch}/docker-compose.yml"
while [ $retry_count -lt $max_retries ]; do
if curl -fsSL --connect-timeout 10 --max-time 30 "$base_url" -o docker-compose.yml; then
if [ -s docker-compose.yml ] && grep -q "services:" docker-compose.yml; then
echo " ✓ Downloaded base docker-compose.yml"
break
else
echo " ⚠️ Downloaded base file appears invalid, retrying..."
rm -f docker-compose.yml
fi
else
echo " ⚠️ Download attempt $((retry_count + 1)) failed"
fi
retry_count=$((retry_count + 1))
if [ $retry_count -lt $max_retries ]; then
sleep 2
fi
done
if [ $retry_count -ge $max_retries ]; then
echo -e "${RED}❌ Failed to download base docker-compose.yml${NC}"
echo "Please check your internet connection and try again."
echo "Alternative: You can manually download from: $base_url"
exit 1
fi
# Download production overrides docker-compose.prod.yml
echo " Downloading production overrides docker-compose.prod.yml..."
retry_count=0
local prod_url="https://raw.githubusercontent.com/davidamacey/OpenTranscribe/${encoded_branch}/docker-compose.prod.yml"
while [ $retry_count -lt $max_retries ]; do
if curl -fsSL --connect-timeout 10 --max-time 30 "$prod_url" -o docker-compose.prod.yml; then
if [ -s docker-compose.prod.yml ] && grep -q "services:" docker-compose.prod.yml; then
echo " ✓ Downloaded production docker-compose.prod.yml"
# Download GPU overlay for NVIDIA acceleration (non-fatal)
download_gpu_overlay
# Download optional gpu-scale overlay (non-fatal)
download_gpu_scale_overlay
echo "✓ Production docker-compose configuration complete"
return 0
else
echo " ⚠️ Downloaded prod file appears invalid, retrying..."
rm -f docker-compose.prod.yml
fi
else
echo " ⚠️ Download attempt $((retry_count + 1)) failed"
fi
retry_count=$((retry_count + 1))
if [ $retry_count -lt $max_retries ]; then
sleep 2
fi
done
echo -e "${RED}❌ Failed to download docker-compose.prod.yml${NC}"
echo "Please check your internet connection and try again."
echo "Alternative: You can manually download from: $prod_url"
exit 1
}
download_gpu_overlay() {
# Download docker-compose.gpu.yml for NVIDIA GPU support
# This enables GPU acceleration when NVIDIA Container Toolkit is detected
echo " Downloading docker-compose.gpu.yml (GPU acceleration support)..."
local branch="${OPENTRANSCRIBE_BRANCH:-master}"
local encoded_branch
encoded_branch=$(echo "$branch" | sed 's|/|%2F|g')
local gpu_url="https://raw.githubusercontent.com/davidamacey/OpenTranscribe/${encoded_branch}/docker-compose.gpu.yml"
if curl -fsSL --connect-timeout 10 --max-time 30 "$gpu_url" -o docker-compose.gpu.yml 2>/dev/null; then
if [ -s docker-compose.gpu.yml ] && grep -q "celery-worker:" docker-compose.gpu.yml; then
echo " ✓ Downloaded docker-compose.gpu.yml (GPU acceleration)"
else
echo " ⚠️ Downloaded gpu file appears invalid, removing..."
rm -f docker-compose.gpu.yml
fi
else
echo " ℹ️ docker-compose.gpu.yml not available (GPU support optional)"
fi
}
download_gpu_scale_overlay() {
# Optional: Download docker-compose.gpu-scale.yml for multi-GPU support
# This is non-fatal - users can skip if they don't have multi-GPU setups
echo " Downloading optional docker-compose.gpu-scale.yml (multi-GPU support)..."
local branch="${OPENTRANSCRIBE_BRANCH:-master}"
local encoded_branch
encoded_branch=$(echo "$branch" | sed 's|/|%2F|g')
local gpu_scale_url="https://raw.githubusercontent.com/davidamacey/OpenTranscribe/${encoded_branch}/docker-compose.gpu-scale.yml"
if curl -fsSL --connect-timeout 10 --max-time 30 "$gpu_scale_url" -o docker-compose.gpu-scale.yml 2>/dev/null; then
if [ -s docker-compose.gpu-scale.yml ] && grep -q "celery-worker-gpu-scaled:" docker-compose.gpu-scale.yml; then
echo " ✓ Downloaded docker-compose.gpu-scale.yml (optional multi-GPU scaling)"
else
echo " ⚠️ Downloaded gpu-scale file appears invalid, removing..."
rm -f docker-compose.gpu-scale.yml
fi
else
echo " ℹ️ docker-compose.gpu-scale.yml not available (optional feature)"
fi
}
download_management_script() {
echo "✓ Downloading OpenTranscribe management script..."
# Download the opentranscribe.sh script from the repository
local max_retries=3
local retry_count=0
local branch="${OPENTRANSCRIBE_BRANCH:-master}"
# URL-encode the branch name (replace / with %2F)
local encoded_branch
encoded_branch=$(echo "$branch" | sed 's|/|%2F|g')
local download_url="https://raw.githubusercontent.com/davidamacey/OpenTranscribe/${encoded_branch}/opentranscribe.sh"
while [ $retry_count -lt $max_retries ]; do
if curl -fsSL --connect-timeout 10 --max-time 30 "$download_url" -o opentranscribe.sh; then
# Validate downloaded file
if [ -s opentranscribe.sh ] && grep -q "OpenTranscribe Management Script" opentranscribe.sh; then
chmod +x opentranscribe.sh
echo "✓ Downloaded and validated opentranscribe.sh"
return 0
else
echo "⚠️ Downloaded opentranscribe.sh appears invalid, retrying..."
rm -f opentranscribe.sh
fi
else
echo "⚠️ Download attempt $((retry_count + 1)) failed"
fi
retry_count=$((retry_count + 1))
if [ $retry_count -lt $max_retries ]; then
echo "⏳ Retrying in 2 seconds..."
sleep 2
fi
done
echo -e "${YELLOW}⚠️ Failed to download opentranscribe.sh after $max_retries attempts${NC}"
echo "You can manually download from: $download_url"
}
download_nginx_files() {
echo "✓ Downloading NGINX/SSL configuration files..."
local max_retries=3
local branch="${OPENTRANSCRIBE_BRANCH:-master}"
local encoded_branch
encoded_branch=$(echo "$branch" | sed 's|/|%2F|g')
# Create nginx and scripts directory structure
mkdir -p nginx/ssl
mkdir -p scripts
touch nginx/ssl/.gitkeep
# Download docker-compose.nginx.yml
echo " Downloading docker-compose.nginx.yml..."
local retry_count=0
local nginx_compose_url="https://raw.githubusercontent.com/davidamacey/OpenTranscribe/${encoded_branch}/docker-compose.nginx.yml"
while [ $retry_count -lt $max_retries ]; do
if curl -fsSL --connect-timeout 10 --max-time 30 "$nginx_compose_url" -o docker-compose.nginx.yml; then
if [ -s docker-compose.nginx.yml ] && grep -q "nginx:" docker-compose.nginx.yml; then
echo " ✓ Downloaded docker-compose.nginx.yml"
break
else
echo " ⚠️ Downloaded nginx compose file appears invalid, retrying..."
rm -f docker-compose.nginx.yml
fi
else
echo " ⚠️ Download attempt $((retry_count + 1)) failed"
fi
retry_count=$((retry_count + 1))
if [ $retry_count -lt $max_retries ]; then
sleep 2
fi
done
if [ $retry_count -ge $max_retries ]; then
echo " ⚠️ Could not download docker-compose.nginx.yml (HTTPS support optional)"
fi
# Download nginx/site.conf.template
echo " Downloading nginx/site.conf.template..."
retry_count=0
local nginx_conf_url="https://raw.githubusercontent.com/davidamacey/OpenTranscribe/${encoded_branch}/nginx/site.conf.template"
while [ $retry_count -lt $max_retries ]; do
if curl -fsSL --connect-timeout 10 --max-time 30 "$nginx_conf_url" -o nginx/site.conf.template; then
if [ -s nginx/site.conf.template ] && grep -q "server" nginx/site.conf.template; then
echo " ✓ Downloaded nginx/site.conf.template"
break
else
echo " ⚠️ Downloaded nginx config appears invalid, retrying..."
rm -f nginx/site.conf.template
fi
else
echo " ⚠️ Download attempt $((retry_count + 1)) failed"
fi
retry_count=$((retry_count + 1))
if [ $retry_count -lt $max_retries ]; then
sleep 2
fi
done
if [ $retry_count -ge $max_retries ]; then
echo " ⚠️ Could not download nginx/site.conf.template (HTTPS support optional)"
fi
# Download scripts/generate-ssl-cert.sh
echo " Downloading scripts/generate-ssl-cert.sh..."
retry_count=0
local ssl_script_url="https://raw.githubusercontent.com/davidamacey/OpenTranscribe/${encoded_branch}/scripts/generate-ssl-cert.sh"
while [ $retry_count -lt $max_retries ]; do
if curl -fsSL --connect-timeout 10 --max-time 30 "$ssl_script_url" -o scripts/generate-ssl-cert.sh; then
if [ -s scripts/generate-ssl-cert.sh ] && grep -q "SSL Certificate" scripts/generate-ssl-cert.sh; then
chmod +x scripts/generate-ssl-cert.sh
echo " ✓ Downloaded scripts/generate-ssl-cert.sh"
break
else
echo " ⚠️ Downloaded SSL script appears invalid, retrying..."
rm -f scripts/generate-ssl-cert.sh
fi
else
echo " ⚠️ Download attempt $((retry_count + 1)) failed"
fi
retry_count=$((retry_count + 1))
if [ $retry_count -lt $max_retries ]; then
sleep 2
fi
done
if [ $retry_count -ge $max_retries ]; then
echo " ⚠️ Could not download scripts/generate-ssl-cert.sh (HTTPS support optional)"
fi
# Download scripts/fix-model-permissions.sh
echo " Downloading scripts/fix-model-permissions.sh..."
retry_count=0
local fix_perms_url="https://raw.githubusercontent.com/davidamacey/OpenTranscribe/${encoded_branch}/scripts/fix-model-permissions.sh"
while [ $retry_count -lt $max_retries ]; do
if curl -fsSL --connect-timeout 10 --max-time 30 "$fix_perms_url" -o scripts/fix-model-permissions.sh; then
if [ -s scripts/fix-model-permissions.sh ] && grep -q "Permission" scripts/fix-model-permissions.sh; then
chmod +x scripts/fix-model-permissions.sh
echo " ✓ Downloaded scripts/fix-model-permissions.sh"
break
else
echo " ⚠️ Downloaded fix-permissions script appears invalid, retrying..."
rm -f scripts/fix-model-permissions.sh
fi
else
echo " ⚠️ Download attempt $((retry_count + 1)) failed"
fi
retry_count=$((retry_count + 1))
if [ $retry_count -lt $max_retries ]; then
sleep 2
fi
done
if [ $retry_count -ge $max_retries ]; then
echo " ⚠️ Could not download scripts/fix-model-permissions.sh"
fi
echo "✓ NGINX/SSL files download complete"
}
download_model_downloader_scripts() {
echo "✓ Downloading model downloader scripts..."
# Create scripts directory
mkdir -p scripts
# Download download-models.sh
local max_retries=3
local retry_count=0
local branch="${OPENTRANSCRIBE_BRANCH:-master}"
local encoded_branch
encoded_branch=$(echo "$branch" | sed 's|/|%2F|g')
local download_url="https://raw.githubusercontent.com/davidamacey/OpenTranscribe/${encoded_branch}/scripts/download-models.sh"
while [ $retry_count -lt $max_retries ]; do
if curl -fsSL --connect-timeout 10 --max-time 30 "$download_url" -o scripts/download-models.sh; then
if [ -s scripts/download-models.sh ] && grep -q "OpenTranscribe Model Downloader" scripts/download-models.sh; then
chmod +x scripts/download-models.sh
echo "✓ Downloaded and validated download-models.sh"
break
else
echo "⚠️ Downloaded download-models.sh appears invalid, retrying..."
rm -f scripts/download-models.sh
fi
else
echo "⚠️ Download attempt $((retry_count + 1)) failed"
fi
retry_count=$((retry_count + 1))
if [ $retry_count -lt $max_retries ]; then
echo "⏳ Retrying in 2 seconds..."
sleep 2
fi
done
# Download download-models.py
retry_count=0
download_url="https://raw.githubusercontent.com/davidamacey/OpenTranscribe/${encoded_branch}/scripts/download-models.py"
while [ $retry_count -lt $max_retries ]; do
if curl -fsSL --connect-timeout 10 --max-time 30 "$download_url" -o scripts/download-models.py; then
if [ -s scripts/download-models.py ] && grep -q "Download all required AI models" scripts/download-models.py; then
echo "✓ Downloaded and validated download-models.py"
break
else
echo "⚠️ Downloaded download-models.py appears invalid, retrying..."
rm -f scripts/download-models.py
fi
else
echo "⚠️ Download attempt $((retry_count + 1)) failed"
fi
retry_count=$((retry_count + 1))
if [ $retry_count -lt $max_retries ]; then
echo "⏳ Retrying in 2 seconds..."
sleep 2
fi
done
# Download common.sh (utility functions used by opentr.sh)
retry_count=0
download_url="https://raw.githubusercontent.com/davidamacey/OpenTranscribe/${encoded_branch}/scripts/common.sh"
while [ $retry_count -lt $max_retries ]; do
if curl -fsSL --connect-timeout 10 --max-time 30 "$download_url" -o scripts/common.sh; then
if [ -s scripts/common.sh ] && grep -q "check_docker" scripts/common.sh; then
echo "✓ Downloaded and validated common.sh"
return 0
else
echo "⚠️ Downloaded common.sh appears invalid, retrying..."
rm -f scripts/common.sh
fi
else
echo "⚠️ Download attempt $((retry_count + 1)) failed"
fi
retry_count=$((retry_count + 1))
if [ $retry_count -lt $max_retries ]; then
echo "⏳ Retrying in 2 seconds..."
sleep 2
fi
done
echo -e "${YELLOW}⚠️ Failed to download model downloader scripts${NC}"
echo "Models will be downloaded on first application run instead."
}
create_production_env_example() {
echo "✓ Downloading environment configuration template..."
# Download the official .env.example from the repository
local max_retries=3
local retry_count=0
local branch="${OPENTRANSCRIBE_BRANCH:-master}"
# URL-encode the branch name (replace / with %2F)
local encoded_branch
encoded_branch=$(echo "$branch" | sed 's|/|%2F|g')
local download_url="https://raw.githubusercontent.com/davidamacey/OpenTranscribe/${encoded_branch}/.env.example"
while [ $retry_count -lt $max_retries ]; do
if curl -fsSL --connect-timeout 10 --max-time 30 "$download_url" -o .env.example; then
# Validate downloaded file
if [ -s .env.example ] && grep -q "POSTGRES_HOST" .env.example && grep -q "HUGGINGFACE_TOKEN" .env.example; then
echo "✓ Downloaded and validated .env.example"
return 0
else
echo "⚠️ Downloaded env file appears invalid, retrying..."
rm -f .env.example
fi
else
echo "⚠️ Download attempt $((retry_count + 1)) failed"
fi
retry_count=$((retry_count + 1))
if [ $retry_count -lt $max_retries ]; then
echo "⏳ Retrying in 2 seconds..."
sleep 2
fi
done
echo -e "${RED}❌ Failed to download .env.example file after $max_retries attempts${NC}"
echo "Please check your internet connection and try again."
echo "Alternative: You can manually download from:"
echo "$download_url"
exit 1
}
prompt_huggingface_token() {
# Unattended mode: use HUGGINGFACE_TOKEN from environment (or leave empty)
if is_unattended; then
if [[ -n "${HUGGINGFACE_TOKEN:-}" ]]; then
ot_log_unattended "Using HUGGINGFACE_TOKEN from environment"
else
ot_log_unattended "HUGGINGFACE_TOKEN not set; continuing without it"
HUGGINGFACE_TOKEN=""
fi
return 0
fi
echo ""
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${YELLOW}🤗 HuggingFace Token Configuration${NC}"
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo -e "${RED}⚠️ IMPORTANT: Token + Model Agreements REQUIRED!${NC}"
echo ""
echo "Without this token:"
echo " • Transcription will work normally"
echo " • Speaker diarization (who said what) will NOT work"
echo " • Models cannot be pre-downloaded (will download on first use)"
echo ""
echo -e "${CYAN}Step 1: Get your FREE HuggingFace token${NC}"
echo " 1. Visit: https://huggingface.co/settings/tokens"
echo " 2. Click 'New token'"
echo " 3. Give it a name (e.g., 'OpenTranscribe')"
echo " 4. Select 'Read' permissions"
echo " 5. Copy the token"
echo ""
echo -e "${CYAN}Step 2: Accept BOTH gated model agreements (CRITICAL!)${NC}"
echo -e " ${RED}You MUST accept BOTH models or downloads will fail!${NC}"
echo ""
echo " 1. Segmentation Model:"
echo " https://huggingface.co/pyannote/segmentation-3.0"
echo -e " ${GREEN}→ Click 'Agree and access repository'${NC}"
echo ""
echo " 2. Speaker Diarization Model:"
echo " https://huggingface.co/pyannote/speaker-diarization-3.1"
echo -e " ${GREEN}→ Click 'Agree and access repository'${NC}"
echo ""
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
# Ask if they want to enter token now
read -p "Do you have a HuggingFace token to enter now? (Y/n) " -n 1 -r </dev/tty
echo
echo
if [[ $REPLY =~ ^[Nn]$ ]]; then
print_warning "Skipping HuggingFace token - you can add it later"
echo "To add later:"
echo " 1. Edit: $PROJECT_DIR/.env"
echo " 2. Set: HUGGINGFACE_TOKEN=your_token_here"
echo " 3. Restart: cd $PROJECT_DIR && ./opentranscribe.sh restart"
echo ""
HUGGINGFACE_TOKEN=""
return 0
fi
# Prompt for token
echo "Please enter your HuggingFace token:"
echo "(Token will be hidden for security)"
read -s HUGGINGFACE_TOKEN </dev/tty
echo
# Strip any 'HUGGINGFACE_TOKEN=' prefix if user pasted it
HUGGINGFACE_TOKEN="${HUGGINGFACE_TOKEN#HUGGINGFACE_TOKEN=}"
# Validate token format (basic check - should start with hf_)
if [[ -z "$HUGGINGFACE_TOKEN" ]]; then
print_warning "No token entered - you can add it later in .env file"
HUGGINGFACE_TOKEN=""
elif [[ ! "$HUGGINGFACE_TOKEN" =~ ^hf_ ]]; then
print_warning "Token doesn't start with 'hf_' - this may not be valid"
echo "Using it anyway, but verify it's correct."
echo ""
else
print_success "HuggingFace token configured!"
echo ""
fi
}
configure_environment() {
echo -e "${BLUE}⚙️ Configuring environment...${NC}"
if [ -f .env ]; then
echo "ℹ️ Using existing .env file"
return
fi
# Generate all secure secrets using openssl or python3 fallback
echo "🔒 Generating secure credentials..."
if command -v openssl &> /dev/null; then
# Use openssl for cryptographically secure random generation
POSTGRES_PASSWORD=$(openssl rand -hex 32)
MINIO_ROOT_PASSWORD=$(openssl rand -hex 32)
JWT_SECRET=$(openssl rand -hex 64)
# ENCRYPTION_KEY: Add prefix to make it invalid base64, forcing backend exception handler path
# This ensures backend uses the working derive-from-string logic
ENCRYPTION_KEY="opentranscribe_$(openssl rand -base64 48)"
REDIS_PASSWORD=$(openssl rand -hex 32)
OPENSEARCH_PASSWORD=$(openssl rand -hex 32)
FLOWER_PASSWORD=$(openssl rand -hex 16)
# MinIO server-side encryption key (AES-256-GCM)
MINIO_KMS_KEY="opentranscribe-key:$(openssl rand -base64 32)"
elif command -v python3 &> /dev/null; then
# Fallback to Python's secrets module
POSTGRES_PASSWORD=$(python3 -c "import secrets; print(secrets.token_hex(32))")
MINIO_ROOT_PASSWORD=$(python3 -c "import secrets; print(secrets.token_hex(32))")
JWT_SECRET=$(python3 -c "import secrets; print(secrets.token_hex(64))")
# ENCRYPTION_KEY: Add prefix to force backend exception handler path
ENCRYPTION_KEY=$(python3 -c "import secrets, base64; print('opentranscribe_' + base64.b64encode(secrets.token_bytes(48)).decode())")
REDIS_PASSWORD=$(python3 -c "import secrets; print(secrets.token_hex(32))")
OPENSEARCH_PASSWORD=$(python3 -c "import secrets; print(secrets.token_hex(32))")
FLOWER_PASSWORD=$(python3 -c "import secrets; print(secrets.token_hex(16))")
# MinIO server-side encryption key (AES-256-GCM)
MINIO_KMS_KEY=$(python3 -c "import secrets, base64; print('opentranscribe-key:' + base64.b64encode(secrets.token_bytes(32)).decode())")
else
# Basic fallback (not recommended for production)
POSTGRES_PASSWORD="postgres_$(date +%s)_$(shuf -i 10000-99999 -n 1 2>/dev/null || echo $RANDOM)"
MINIO_ROOT_PASSWORD="minio_$(date +%s)_$(shuf -i 10000-99999 -n 1 2>/dev/null || echo $RANDOM)"
JWT_SECRET="jwt_secret_$(date +%s)_$(shuf -i 10000-99999 -n 1 2>/dev/null || echo $RANDOM)"
ENCRYPTION_KEY="encryption_key_$(date +%s)_$(shuf -i 10000-99999 -n 1 2>/dev/null || echo $RANDOM)"
REDIS_PASSWORD="redis_$(date +%s)_$(shuf -i 10000-99999 -n 1 2>/dev/null || echo $RANDOM)"
OPENSEARCH_PASSWORD="opensearch_$(date +%s)_$(shuf -i 10000-99999 -n 1 2>/dev/null || echo $RANDOM)"
FLOWER_PASSWORD="flower_$(date +%s)_$(shuf -i 10000-99999 -n 1 2>/dev/null || echo $RANDOM)"
# MinIO KMS key (basic fallback)
MINIO_KMS_KEY="opentranscribe-key:$(date +%s | md5sum | head -c 32 | base64)"
echo "⚠️ Using basic secrets - install openssl or python3 for cryptographically secure generation"
fi
print_success "Secure credentials generated (64-char JWT/encryption, 32-char passwords)"
# Prompt for HuggingFace token
prompt_huggingface_token
# Model selection based on hardware
select_whisper_model
# OpenSearch neural search model selection
select_opensearch_models
# GPU selection for multi-GPU systems
select_gpu_device
# LLM configuration for AI features
configure_llm_settings
# Create .env file
create_env_file
}
select_whisper_model() {
echo -e "${YELLOW}🎤 Selecting Whisper Model based on hardware...${NC}"
echo ""
# Auto-select optimal model based on hardware with GPU memory detection
local RECOMMENDED_MODEL=""
local RECOMMENDATION_REASON=""
case "$DETECTED_DEVICE" in
"cuda")
# Try to detect GPU memory for better model selection
if command -v nvidia-smi &> /dev/null; then
GPU_MEMORY=$(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits -i "${GPU_DEVICE_ID:-0}")
if [[ $GPU_MEMORY -gt 16000 ]]; then
RECOMMENDED_MODEL="large-v3-turbo"
RECOMMENDATION_REASON="High-end GPU detected (${GPU_MEMORY}MB VRAM) - 6x faster than large-v3, excellent accuracy"
elif [[ $GPU_MEMORY -gt 8000 ]]; then