-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathInstall.sh
More file actions
executable file
·1336 lines (1123 loc) · 51.2 KB
/
Install.sh
File metadata and controls
executable file
·1336 lines (1123 loc) · 51.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
# TARS System Installation Protocol
# Atomikspace / Pyrater / TeknikL
set -e
if [ -n "$SUDO_USER" ]; then
ACTUAL_USER="$SUDO_USER"
ACTUAL_HOME="/home/$SUDO_USER"
echo ""
echo "+================================================================+"
echo "| NOTICE: Script run with sudo - will set ownership to: $SUDO_USER"
echo "+================================================================+"
echo ""
sleep 2
else
ACTUAL_USER="$(whoami)"
ACTUAL_HOME="$HOME"
fi
DELAY=0.02
PI_VERSION=""
INSTALL_RETROPIE=false
INSTALL_RASPOTIFY=false
show_tars_boot() {
clear
cat << "EOF"
+=============================================+
| |
| ████████╗ █████╗ ██████╗ ███████╗ |
| ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝ |
| ██║ ███████║██████╔╝███████╗ |
| ██║ ██╔══██║██╔══██╗╚════██║ |
| ██║ ██║ ██║██║ ██║███████║ |
| ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ |
| |
+=============================================+
EOF
sleep 2
}
tars_say() {
local message=$1
local type=${2:-"info"}
case $type in
"info")
echo "+=== TARS ====================================================+"
echo "| ${message}"
echo "+=============================================================+"
;;
"success")
echo "+=== TARS ====================================================+"
echo "| [OK] ${message}"
echo "+=============================================================+"
;;
"warning")
echo "+=== TARS ====================================================+"
echo "| [!] ${message}"
echo "+=============================================================+"
;;
"error")
echo "+=== TARS ====================================================+"
echo "| [X] ${message}"
echo "+=============================================================+"
;;
esac
echo ""
}
# Download a model to stt/ — auto-installs on Pi5, prompts otherwise
# Usage: download_model "name" "prompt text" "url" "local_path" [pi_versions]
# local_path: filename (saves with -O) or empty string (extracts tar archive)
# pi_versions: space-separated list of profiles, default "pi5 pi4"
download_model() {
local name=$1 prompt_msg=$2 url=$3 local_path=$4
local versions=${5:-"pi5 pi4"}
# Check if this profile should get this model
local dominated=false
for v in $versions; do [[ "$PI_VERSION" == "$v" ]] && dominated=true; done
$dominated || return 0
# Skip if already installed
if [[ -n "$local_path" ]]; then
[[ -f "stt/$local_path" ]] && return 0
else
# For tar archives, check if extracted dir exists (dirname from tarball)
local dirname="${url##*/}"
dirname="${dirname%.tar.bz2}"
[[ -d "stt/$dirname" ]] && return 0
fi
# Confirm (auto-yes on Pi5)
if [[ "$PI_VERSION" != "pi5" ]]; then
echo ""
read -p "| ${prompt_msg} [y/N] " -n 1 -r
echo
[[ $REPLY =~ ^[Yy]$ ]] || return 0
fi
tars_say "Downloading ${name}..." "info"
mkdir -p stt
if [[ -n "$local_path" ]]; then
# Direct file download
if wget -q --show-progress -O "stt/$local_path" "$url"; then
echo "| [OK] ${name} installed"
else
echo "| [!] Failed to download ${name}"
fi
else
# Tar archive: download, extract, cleanup
local archive="${url##*/}"
cd stt
if wget -q --show-progress "$url"; then
tar xjf "$archive"
rm "$archive"
echo "| [OK] ${name} installed"
else
echo "| [!] Failed to download ${name}"
fi
cd ..
fi
}
select_pi_version() {
local tars_data_dir="src/memory"
local pi_version_file="$tars_data_dir/pi_version"
# Check for saved pi_version file from a previous install
if [ -f "$pi_version_file" ]; then
local saved_version
saved_version=$(cat "$pi_version_file" | tr -d '[:space:]')
if [ -n "$saved_version" ]; then
tars_say "Device profile: ${saved_version^^}" "info"
PI_VERSION="$saved_version"
_display_profile_summary
return
fi
fi
echo ""
echo "+===============================================================+"
echo "| RASPBERRY PI VERSION SELECTION |"
echo "+===============================================================+"
echo "| |"
echo "| Select your Raspberry Pi model: |"
echo "| |"
echo "| 1) Raspberry Pi 5 - Full features, all local processing |"
echo "| 2) Raspberry Pi 4 - Most features, some cloud fallbacks |"
echo "| 3) Raspberry Pi 3 - Lite mode, Piper TTS, cloud STT |"
echo "| 4) Raspberry Pi Zero 2 - Minimal, Piper TTS, cloud STT |"
echo "| |"
echo "+===============================================================+"
echo ""
while true; do
read -p "Enter your choice [1-4]: " choice
case $choice in
1)
PI_VERSION="pi5"
tars_say "Selected: Raspberry Pi 5 (Full Installation)" "success"
break
;;
2)
PI_VERSION="pi4"
tars_say "Selected: Raspberry Pi 4 (Standard Installation)" "success"
break
;;
3)
PI_VERSION="pi3"
tars_say "Selected: Raspberry Pi 3 (Lite Installation)" "success"
break
;;
4)
PI_VERSION="pizero2"
tars_say "Selected: Raspberry Pi Zero 2 (Minimal Installation)" "success"
break
;;
*)
echo "Invalid selection. Please enter 1, 2, 3, or 4."
;;
esac
done
mkdir -p "$tars_data_dir"
echo "$PI_VERSION" > "$pi_version_file"
_display_profile_summary
read -p "Continue with this profile? [y/n]: " -r CONFIRM
if [[ ! $CONFIRM =~ ^[Yy]$ ]]; then
tars_say "Installation cancelled by user." "warning"
exit 0
fi
}
_display_profile_summary() {
echo ""
echo "+===============================================================+"
echo "| INSTALLATION PROFILE: ${PI_VERSION^^}"
echo "+===============================================================+"
case $PI_VERSION in
"pi5")
echo "| Features: Full local STT, TTS, embeddings, UI, vision"
echo "| Memory: Full embedding-based memory"
echo "| Size: ~2.5GB+ dependencies"
;;
"pi4")
echo "| Features: Vosk STT, Piper/eSpeak TTS, embeddings, UI"
echo "| Memory: Full embedding-based memory"
echo "| Size: ~1.5GB+ dependencies"
;;
"pi3")
echo "| Features: Cloud STT, Piper/eSpeak TTS, keyword memory, no UI"
echo "| Memory: Lite keyword-based memory"
echo "| Size: ~500MB dependencies"
;;
"pizero2")
echo "| Features: OpenAI STT, Piper/eSpeak TTS, keyword memory, no UI"
echo "| Memory: Lite keyword-based memory"
echo "| Size: ~300MB dependencies"
;;
esac
echo "+===============================================================+"
echo ""
}
select_thirdparty_apps() {
echo ""
echo "+===============================================================+"
echo "| 3RD PARTY APPLICATIONS |"
echo "+===============================================================+"
echo "| |"
echo "| Would you like to install optional 3rd party applications? |"
echo "| |"
echo "| NOTE: You can skip this now and run the installer again |"
echo "| later once you are satisfied with the main installation. |"
echo "| |"
echo "+===============================================================+"
echo ""
read -p "Install 3rd party applications? [y/n]: " -r THIRDPARTY_REPLY
echo ""
if [[ ! $THIRDPARTY_REPLY =~ ^[Yy]$ ]]; then
tars_say "Skipping 3rd party applications. Run this installer again when ready." "info"
return
fi
echo "+===============================================================+"
echo "| 3RD PARTY APPLICATION SELECTION |"
echo "+===============================================================+"
echo "| |"
echo "| Select applications to install (toggle with number): |"
echo "| |"
echo "| 1) RetroPie - Retro gaming emulation platform |"
echo "| [!] WARNING: Installation takes approximately 60 minutes |"
echo "| depending on your Pi model and network speed. |"
echo "| |"
echo "| 2) Raspotify - Spotify Connect client for Raspberry Pi |"
echo "| Turns your Pi into a Spotify speaker (requires Premium) |"
echo "| |"
echo "+===============================================================+"
echo ""
local retropie_selected=false
local raspotify_selected=false
while true; do
local retropie_mark="[ ]"
local raspotify_mark="[ ]"
if [ "$retropie_selected" = true ]; then
retropie_mark="[X]"
fi
if [ "$raspotify_selected" = true ]; then
raspotify_mark="[X]"
fi
echo " ${retropie_mark} 1) RetroPie (~60 min install)"
echo " ${raspotify_mark} 2) Raspotify (~2 min install)"
echo ""
echo " Enter a number to toggle, or 'done' to confirm: "
read -p " > " toggle_choice
case $toggle_choice in
1)
if [ "$retropie_selected" = true ]; then
retropie_selected=false
else
retropie_selected=true
fi
;;
2)
if [ "$raspotify_selected" = true ]; then
raspotify_selected=false
else
raspotify_selected=true
fi
;;
done|DONE|Done|d|D)
break
;;
*)
echo " Invalid selection. Enter 1-2 to toggle or 'done' to confirm."
;;
esac
echo ""
done
local selected_apps=""
if [ "$retropie_selected" = true ]; then
INSTALL_RETROPIE=true
selected_apps="${selected_apps} - RetroPie (estimated ~60 minutes)\n"
fi
if [ "$raspotify_selected" = true ]; then
INSTALL_RASPOTIFY=true
selected_apps="${selected_apps} - Raspotify (estimated ~2 minutes)\n"
fi
if [ -n "$selected_apps" ]; then
echo ""
echo "+===============================================================+"
echo "| PLEASE CONFIRM |"
echo "+===============================================================+"
echo "| |"
echo "| You have selected: |"
echo -e "| ${selected_apps}|"
echo "| |"
echo "| Make sure you have a stable power supply and network |"
echo "| connection before proceeding. |"
echo "| |"
echo "| You can always skip this and run the installer again later. |"
echo "| |"
echo "+===============================================================+"
echo ""
read -p "Are you sure you want to proceed? [y/n]: " -r CONFIRM1
echo ""
if [[ ! $CONFIRM1 =~ ^[Yy]$ ]]; then
INSTALL_RETROPIE=false
INSTALL_RASPOTIFY=false
tars_say "3rd party installation cancelled. Run this installer again when ready." "info"
return
fi
local queued=""
[ "$INSTALL_RETROPIE" = true ] && queued="${queued} RetroPie"
[ "$INSTALL_RASPOTIFY" = true ] && queued="${queued} Raspotify"
tars_say "Queued for installation:${queued}" "success"
else
tars_say "No 3rd party applications selected." "info"
fi
}
install_retropie() {
if [ "$INSTALL_RETROPIE" != true ]; then
return 0
fi
echo ""
echo "+===============================================================+"
echo "| RETROPIE INSTALLATION |"
echo "+===============================================================+"
echo "| Target device: ${PI_VERSION^^}"
echo "+===============================================================+"
echo ""
tars_say "Installing RetroPie dependencies..." "info"
sudo apt install -y git dialog xmlstarlet lsb-release 2>&1 | tail -10
local retropie_dir="$HOME/RetroPie-Setup"
if [ -d "$retropie_dir" ]; then
echo "+===============================================================+"
echo "| EXISTING RETROPIE-SETUP DETECTED"
echo "+===============================================================+"
echo "| Location: $retropie_dir"
echo "+===============================================================+"
echo ""
read -p "Re-clone RetroPie-Setup? (overwrites existing) [y/n]: " -r RECLONE_REPLY
echo ""
if [[ $RECLONE_REPLY =~ ^[Yy]$ ]]; then
tars_say "Removing existing RetroPie-Setup..." "info"
sudo rm -rf "$retropie_dir"
else
tars_say "Keeping existing RetroPie-Setup directory." "info"
fi
fi
if [ ! -d "$retropie_dir" ]; then
tars_say "Cloning RetroPie-Setup repository..." "info"
git clone --depth=1 https://github.com/RetroPie/RetroPie-Setup.git "$retropie_dir"
tars_say "RetroPie-Setup cloned successfully." "success"
fi
sudo chown -R $ACTUAL_USER:$ACTUAL_USER "$retropie_dir"
echo ""
echo "+===============================================================+"
echo "| RETROPIE SETUP READY"
echo "+===============================================================+"
echo "| |"
echo "| RetroPie-Setup has been downloaded to: |"
echo "| $retropie_dir"
echo "| |"
case $PI_VERSION in
"pi5")
echo "| NOTE (Pi5): No official prebuilt image exists yet. |"
echo "| RetroPie will be installed on top of your current Pi OS. |"
echo "| The Pi 5 can handle Dreamcast, Saturn, PSP and more. |"
;;
"pi4")
echo "| NOTE (Pi4): Full RetroPie support. Most emulators will |"
echo "| run smoothly including N64, PSX, and Dreamcast. |"
;;
"pi3")
echo "| NOTE (Pi3): RetroPie Lite. Best for 8/16-bit consoles |"
echo "| (NES, SNES, Genesis, Game Boy). N64/PSX may struggle. |"
;;
"pizero2")
echo "| NOTE (Zero2): Minimal RetroPie. Works well for 8/16-bit |"
echo "| consoles. Heavier emulators will likely not perform well. |"
;;
esac
echo "| |"
echo "+===============================================================+"
echo ""
read -p "Run RetroPie basic install now? (this can take a while) [y/n]: " -r RUN_SETUP_REPLY
echo ""
if [[ $RUN_SETUP_REPLY =~ ^[Yy]$ ]]; then
tars_say "Running RetroPie basic install (non-interactive)..." "info"
tars_say "This may take 30-60+ minutes depending on your Pi and network." "warning"
echo ""
cd "$retropie_dir"
sudo ./retropie_packages.sh setup basic_install
cd - > /dev/null
tars_say "RetroPie basic install complete!" "success"
tars_say "Configuring RetroPie for manual launch only..." "info"
local autostart_file="/opt/retropie/configs/all/autostart.sh"
if [ -f "$autostart_file" ]; then
echo "# disabled - use launch_retropie.sh to start" | sudo tee "$autostart_file" > /dev/null
tars_say "EmulationStation autostart disabled." "success"
fi
sudo systemctl stop asplashscreen 2>/dev/null
sudo systemctl disable asplashscreen 2>/dev/null
sudo systemctl mask asplashscreen 2>/dev/null
tars_say "RetroPie splash screen disabled." "success"
sudo systemctl set-default graphical.target 2>/dev/null
sudo systemctl enable display-manager 2>/dev/null
tars_say "Desktop boot target preserved." "success"
echo ""
echo "+===============================================================+"
echo "| RetroPie is installed but will NOT start on boot. |"
echo "| To play, run: ./launch_retropie.sh |"
echo "| |"
echo "| To configure further or install optional packages, run: |"
echo "| cd $retropie_dir"
echo "| sudo ./retropie_setup.sh |"
echo "+===============================================================+"
else
tars_say "RetroPie setup skipped. You can run it later with:" "info"
echo "| cd $retropie_dir"
echo "| sudo ./retropie_setup.sh"
echo "|"
echo "| Then select 'Basic Install' from the menu."
echo "+===============================================================+"
fi
echo ""
}
install_raspotify() {
if [ "$INSTALL_RASPOTIFY" != true ]; then
return 0
fi
echo ""
echo "+===============================================================+"
echo "| RASPOTIFY INSTALLATION |"
echo "+===============================================================+"
echo "| Spotify Connect client for Raspberry Pi |"
echo "| Target device: ${PI_VERSION^^}"
echo "+===============================================================+"
echo ""
tars_say "Installing Raspotify (Spotify Connect)..." "info"
if ! command -v curl &> /dev/null; then
sudo apt-get -y install curl 2>&1 | tail -5
fi
if curl -sL https://dtcooper.github.io/raspotify/install.sh | sh; then
tars_say "Raspotify installed successfully!" "success"
tars_say "Configuring device name as 'SpotiTars'..." "info"
local raspotify_conf="/etc/raspotify/conf"
if [ -f "$raspotify_conf" ]; then
sudo sed -i 's/^#\?DEVICE_NAME=.*/DEVICE_NAME="SpotiTars"/' "$raspotify_conf"
sudo sed -i 's/^#\?LIBRESPOT_BACKEND=.*/LIBRESPOT_BACKEND=alsa/' "$raspotify_conf"
if ! grep -q '^LIBRESPOT_BACKEND=' "$raspotify_conf"; then
echo 'LIBRESPOT_BACKEND=alsa' | sudo tee -a "$raspotify_conf" > /dev/null
fi
if grep -q '^#\?LIBRESPOT_DEVICE=' "$raspotify_conf"; then
sudo sed -i 's/^#\?LIBRESPOT_DEVICE=.*/LIBRESPOT_DEVICE=hw:2,0/' "$raspotify_conf"
else
echo 'LIBRESPOT_DEVICE=hw:2,0' | sudo tee -a "$raspotify_conf" > /dev/null
fi
sudo systemctl restart raspotify
tars_say "Device name set to 'SpotiTars'." "success"
tars_say "Audio output set to USB PnP Audio Device (hw:2,0)." "success"
else
tars_say "Config file not found. Set name manually in /etc/raspotify/conf" "warning"
fi
else
tars_say "Raspotify installation failed. You can try manually later:" "error"
echo "| curl -sL https://dtcooper.github.io/raspotify/install.sh | sh"
echo "+===============================================================+"
echo ""
return 1
fi
echo ""
echo "+===============================================================+"
echo "| RASPOTIFY SETUP COMPLETE |"
echo "+===============================================================+"
echo "| |"
echo "| Raspotify is now running as a system service. |"
echo "| |"
echo "| Your Pi will appear as 'SpotiTars' in Spotify Connect. |"
echo "| Open Spotify on your phone/computer and look for it |"
echo "| in the 'Connect to a device' menu. |"
echo "| |"
echo "| NOTE: A Spotify Premium account is required. |"
echo "| |"
echo "| To customize settings (device name, bitrate, etc): |"
echo "| sudo nano /etc/raspotify/conf |"
echo "| sudo systemctl restart raspotify |"
echo "| |"
echo "| Useful commands: |"
echo "| sudo systemctl status raspotify - Check status |"
echo "| sudo systemctl restart raspotify - Restart service |"
echo "| sudo systemctl stop raspotify - Stop service |"
echo "| |"
echo "+===============================================================+"
echo ""
}
generate_requirements() {
local req_dir="$HOME/.local/share/tars_a"
mkdir -p "$req_dir"
local req_file="$req_dir/requirements_${PI_VERSION}.txt"
tars_say "Generating requirements for ${PI_VERSION^^}..." "info"
cat > "$req_file" << 'COMMON'
# === COMMON REQUIREMENTS (All Pi versions) ===
# LLM Tools
openai # External LLM API
tiktoken # Token counting for OpenAI models
# Sound Processing Tools
pydub # Audio processing for TTS modifications
soundfile # Read & write sound files
sounddevice # Audio I/O for playing and capturing sound
# Chat UI & Web Frameworks
flask # Web framework for ChatUI
flask-cors # Cross-Origin Resource Sharing (CORS) for Flask
flask-socketio # WebSockets support for Flask
eventlet # Async support for Flask-SocketIO
Pillow # Image processing for ChatUI face animation
# Miscellaneous Utilities
configobj # Maintain comments in config.ini during updates
python-dotenv # Load environment variables from a .env file
requests # HTTP library for API interactions
joblib # Efficient serialization of Python objects
ddgs # web search parsing
qrcode[pil] # QR code generation for remote access
# Servo Control
adafruit-circuitpython-pca9685 # PCA9685 servo controller libraries
adafruit-blinka
adafruit-circuitpython-busdevice
adafruit-circuitpython-servokit # Servo libraries (high-level servo control)
# Battery
adafruit-circuitpython-ina260 # INA260 sensor
# Discord
discord.py # Discord bot API
# Wake Word (Atomik)
scipy # Signal processing for wake word detection
# Multimedia
pygame # Game development & multimedia support
COMMON
if [[ "$PI_VERSION" == "pi5" ]]; then
cat >> "$req_file" << 'LGPIO'
# === GPIO (Pi5 only) ===
lgpio # Required for Raspberry Pi 5 GPIO
LGPIO
fi
if [[ "$PI_VERSION" == "pi5" || "$PI_VERSION" == "pi4" ]]; then
cat >> "$req_file" << 'EMBEDDINGS'
# === EMBEDDING & MEMORY (Pi4/Pi5) ===
sentence-transformers # Sentence embeddings and semantic search
# Memory & Search Tools
bm25s # BM25 ranking for information retrieval
pystemmer # Stem words for text processing
hyperdb-python # High-performance database library
scikit-learn # Predictive data analysis tools
flashrank # Lightweight re-ranker
EMBEDDINGS
fi
if [[ "$PI_VERSION" == "pi5" || "$PI_VERSION" == "pi4" ]]; then
cat >> "$req_file" << 'SHERPA'
# === SHERPA-ONNX STT (Pi4/Pi5) ===
sherpa-onnx # Offline speech recognition (SenseVoiceTiny)
# === ONNX RUNTIME FOR EMOTION DETECTION (Pi4/Pi5) ===
optimum[onnxruntime] # ONNX Runtime inference for emotion classifier
SHERPA
fi
cat >> "$req_file" << 'LOCALTTS'
# === LOCAL TTS (All Pi versions) ===
piper-tts # Local TTS with voice cloning support
LOCALTTS
if [[ "$PI_VERSION" == "pi5" ]]; then
cat >> "$req_file" << 'HEAVY'
# === HEAVY PROCESSING (Pi5 only) ===
sherpa-onnx # Local STT using sherpa-onnx
silero-vad # Voice Activity Detection (VAD) using Silero
omegaconf # Required for silero speech
fastrtc[vad, stt, tts] # FastRTC for real-time communication
librosa # Audio analysis and feature extraction
# Emotion Detection (Pi5 only)
optimum[onnxruntime] # ONNX model optimization
HEAVY
fi
if [[ "$PI_VERSION" == "pi5" || "$PI_VERSION" == "pi4" ]]; then
cat >> "$req_file" << 'UI'
# === UI & CAMERA (Pi4/Pi5) ===
PyOpenGL # OpenGL support
PyOpenGL-accelerate # OpenGL acceleration
picamera2 # PI camera module
opencv-python # Video classes and modifiers
simplejpeg # Camera Requirement
numpy==2.1 # Needed for image rotations
moviepy # Video editing and playback support
evdev # Handle Linux input devices
UI
fi
if [[ "$PI_VERSION" == "pi5" || "$PI_VERSION" == "pi4" ]]; then
cat >> "$req_file" << 'CLOUDTTS'
# === CLOUD TTS OPTIONS (Pi4/Pi5) ===
elevenlabs # External TTS using 11Labs API
CLOUDTTS
fi
if [[ "$PI_VERSION" == "pi3" || "$PI_VERSION" == "pizero2" ]]; then
cat >> "$req_file" << 'CLOUDONLY'
# === CLOUD TTS (Pi3/Zero2) ===
elevenlabs # External TTS using 11Labs API
CLOUDONLY
fi
if [[ "$PI_VERSION" == "pi5" || "$PI_VERSION" == "pi4" ]]; then
cat >> "$req_file" << 'DISCORD'
DISCORD
fi
if [[ "$PI_VERSION" == "pi5" ]]; then
cat >> "$req_file" << 'YOUTUBE'
# === MEDIA (Pi5) ===
yt-dlp # Youtube downloading
pandas # Data analysis
YOUTUBE
fi
tars_say "Requirements file generated: $req_file" "success"
echo "+===============================================================+"
echo "| PACKAGES TO BE INSTALLED:"
echo "+===============================================================+"
grep -v "^#" "$req_file" | grep -v "^$" | while read line; do
echo "| - $line"
done
echo "+===============================================================+"
echo ""
}
show_system_diagnostic() {
echo "+===============================================================+"
echo "| SYSTEM DIAGNOSTIC INITIATED |"
echo "+===============================================================+"
echo "| CPU Architecture: $(uname -m)"
echo "| Kernel Version: $(uname -r)"
echo "| Hostname: $(hostname)"
echo "| Pi Version: ${PI_VERSION^^}"
echo "+===============================================================+"
echo ""
}
spin_loader() {
local pid=$1
local message=$2
local timeout=${3:-300}
local spin='|/-\'
local i=0
local elapsed=0
echo -ne "| "
while kill -0 $pid 2>/dev/null; do
i=$(( (i+1) %4 ))
echo -ne "\r| ${spin:$i:1} ${message} (${elapsed}s)"
sleep 1
elapsed=$((elapsed + 1))
if [ $elapsed -ge $timeout ]; then
kill -9 $pid 2>/dev/null || true
echo -ne "\r| [X] ${message} - TIMEOUT after ${timeout}s\n"
return 1
fi
done
wait $pid
local exit_code=$?
if [ $exit_code -eq 0 ]; then
echo -ne "\r| [OK] ${message} (${elapsed}s)\n"
return 0
else
echo -ne "\r| [X] ${message} - FAILED with exit code $exit_code\n"
return 1
fi
}
_ensure_swap() {
# Pi Zero 2 (512MB) and Pi 3 (1GB) need extra swap for pip/builds
local min_swap_mb=1024
local swap_file="/var/tars_swap"
local current_swap_kb=$(free | awk '/^Swap:/{print $2}')
local current_swap_mb=$((current_swap_kb / 1024))
if [[ $current_swap_mb -ge $min_swap_mb ]]; then
echo "| [OK] Swap: ${current_swap_mb}MB (sufficient)"
return 0
fi
tars_say "Low swap detected (${current_swap_mb}MB). Adding temporary swap for install..." "info"
# Expand dphys-swapfile if available (preferred on Raspberry Pi OS)
if [ -f /etc/dphys-swapfile ]; then
sudo sed -i "s/^CONF_SWAPSIZE=.*/CONF_SWAPSIZE=${min_swap_mb}/" /etc/dphys-swapfile
sudo systemctl restart dphys-swapfile 2>/dev/null || sudo dphys-swapfile setup && sudo dphys-swapfile swapon
local new_swap_kb=$(free | awk '/^Swap:/{print $2}')
local new_swap_mb=$((new_swap_kb / 1024))
echo "| [OK] Swap expanded to ${new_swap_mb}MB via dphys-swapfile"
return 0
fi
# Fallback: create a swap file manually
if [ ! -f "$swap_file" ]; then
sudo dd if=/dev/zero of="$swap_file" bs=1M count=$min_swap_mb status=none
sudo chmod 600 "$swap_file"
sudo mkswap "$swap_file" >/dev/null
fi
sudo swapon "$swap_file" 2>/dev/null || true
local new_swap_kb=$(free | awk '/^Swap:/{print $2}')
local new_swap_mb=$((new_swap_kb / 1024))
echo "| [OK] Swap expanded to ${new_swap_mb}MB via swap file"
}
retry_pip_install() {
local n=1
local max=5
local delay=5
local req_file="$HOME/.local/share/tars_a/requirements_${PI_VERSION}.txt"
tars_say "Initiating Python dependency installation for ${PI_VERSION^^}..." "info"
# Ensure enough swap for low-memory devices
if [[ "$PI_VERSION" == "pizero2" || "$PI_VERSION" == "pi3" ]]; then
_ensure_swap
fi
while true; do
echo "+===============================================================+"
echo "| Attempt: $n/$max"
echo "+===============================================================+"
if [[ "$PI_VERSION" == "pizero2" || "$PI_VERSION" == "pi3" ]]; then
# Install one package at a time to limit peak memory usage
local failed=0
local total=$(grep -v "^#" "$req_file" | grep -v "^$" | wc -l)
local count=0
while IFS= read -r line; do
# Strip inline comments and trim whitespace
local pkg=$(echo "$line" | sed 's/#.*//' | xargs)
[[ -z "$pkg" ]] && continue
count=$((count + 1))
echo -ne "\r| [$count/$total] Installing: $pkg "
if ! pip install --no-cache-dir "$pkg" >/dev/null 2>&1; then
echo -e "\r| [!] Failed: $pkg "
failed=$((failed + 1))
fi
done < "$req_file"
echo ""
if [[ $failed -eq 0 ]]; then
tars_say "Python dependencies synchronized successfully." "success"
break
else
tars_say "$failed package(s) failed to install." "warning"
if [[ $n -ge $max ]]; then
tars_say "Some packages could not be installed after $max attempts." "error"
break
fi
fi
else
if pip install -r "$req_file"; then
tars_say "Python dependencies synchronized successfully." "success"
break
fi
fi
if [[ $n -lt $max ]]; then
tars_say "Connection interference detected. Retrying in $delay seconds..." "warning"
for ((i=delay; i>0; i--)); do
echo -ne "\r| >>> Retry countdown: $i seconds... "
sleep 1
done
echo ""
((n++))
else
tars_say "Critical failure. Unable to establish connection after $max attempts." "error"
exit 1
fi
done
}
detect_os_version() {
tars_say "Analyzing operating system parameters..." "info"
if [ -f /etc/os-release ]; then
. /etc/os-release
OS_VERSION_ID=$VERSION_ID
OS_VERSION_CODENAME=$VERSION_CODENAME
echo "+===============================================================+"
echo "| OPERATING SYSTEM DETECTED"
echo "+===============================================================+"
echo "| System: $PRETTY_NAME"
echo "| Codename: $VERSION_CODENAME"
echo "| Version: $VERSION_ID"
echo "+===============================================================+"
echo ""
sleep 1
else
tars_say "Unable to determine OS version. Proceeding with adaptive protocol." "warning"
OS_VERSION_CODENAME="unknown"
fi
}
install_chromium() {
if [[ "$PI_VERSION" == "pi3" || "$PI_VERSION" == "pizero2" ]]; then
tars_say "Skipping Chromium installation (UI disabled for ${PI_VERSION^^})" "info"
return 0
fi
tars_say "Initiating chromium installation sequence..." "info"
echo "+===============================================================+"
echo "| CHROMIUM INSTALLATION PROTOCOL"
echo "+===============================================================+"
if apt-cache show chromium &>/dev/null; then
echo "| Package detected: chromium (Latest variant)"
if ! sudo apt install -y chromium sox libsox-fmt-all portaudio19-dev espeak-ng libcap-dev --fix-missing 2>&1 | tee /tmp/chromium-install.log | grep -v "^Setting up\|^Preparing\|^Unpacking" | head -20; then
tars_say "Chromium installation encountered issues. Check /tmp/chromium-install.log" "warning"
fi
CHROMIUM_CMD="chromium"
elif apt-cache show chromium-browser &>/dev/null; then
echo "| Package detected: chromium-browser (Legacy variant)"
if ! sudo apt install -y chromium-browser sox libsox-fmt-all portaudio19-dev espeak-ng libcap-dev --fix-missing 2>&1 | tee /tmp/chromium-install.log | grep -v "^Setting up\|^Preparing\|^Unpacking" | head -20; then
tars_say "Chromium-browser installation encountered issues. Check /tmp/chromium-install.log" "warning"
fi
CHROMIUM_CMD="chromium-browser"
else
tars_say "Chromium package not found in repositories. Manual intervention required." "error"
exit 1
fi
install_chromedriver
echo ""
}
install_chromedriver() {
tars_say "ChromeDriver installation protocol engaged..." "info"
echo "+===============================================================+"
echo "| CHROMEDRIVER CONFIGURATION"
echo "+===============================================================+"
if command -v chromedriver &>/dev/null; then
echo "| Status: Already present in system"
VERSION=$(chromedriver --version 2>/dev/null | head -1)
echo "| Version: $VERSION"
echo "+===============================================================+"
return 0
fi
if apt-cache show chromium-driver &>/dev/null; then
echo "| Method: Package Manager (chromium-driver)"
echo "+===============================================================+"
if ! sudo apt install -y chromium-driver 2>&1 | tee /tmp/chromedriver-install.log | grep -v "^Setting up\|^Preparing\|^Unpacking" | head -20; then
tars_say "ChromeDriver installation encountered issues. Check /tmp/chromedriver-install.log" "warning"
fi
else
tars_say "ChromeDriver not found in repositories" "warning"
fi
}
create_desktop_shortcut() {
tars_say "Creating desktop shortcut..." "info"
local install_dir
install_dir="$(cd .. && pwd)"
local desktop_dir
if [ -n "$SUDO_USER" ]; then
desktop_dir="$(eval echo ~$SUDO_USER)/Desktop"
else
desktop_dir="$HOME/Desktop"
fi
mkdir -p "$desktop_dir"
local desktop_file="${desktop_dir}/TARS"
cat > "$desktop_file" << LAUNCHER
#!/bin/bash
cd "${install_dir}" || { echo "ERROR: Could not cd to ${install_dir}"; read -p "Press Enter to close..."; exit 1; }
./tars-launcher.sh
echo ""