forked from kercre123/wire-pod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·1059 lines (1031 loc) · 42.8 KB
/
setup.sh
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
echo
UNAME=$(uname -a)
if [[ ${UNAME} == *"Darwin"* ]]; then
if [[ -f /usr/local/Homebrew/bin/brew ]]; then
TARGET="darwin"
echo "macOS confirmed."
if [[ ! -f /usr/local/go/bin/go ]]; then
echo "Go was not found. You must download it from https://go.dev/dl/ for your macOS."
exit 1
fi
else
echo "macOS detected, but 'brew' was not found. Install it with the following command and try running setup.sh again:"
echo '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
exit 1
fi
elif [[ -f /usr/bin/apt ]]; then
TARGET="debian"
echo "Debian-based Linux confirmed."
elif [[ -f /usr/bin/pacman ]]; then
TARGET="arch"
echo "Arch Linux confirmed."
elif [[ -f /usr/bin/dnf ]]; then
TARGET="fedora"
echo "Fedora/openSUSE detected."
else
echo "This OS is not supported. This script currently supports Linux with either apt, pacman, or dnf."
if [[ ! "$1" == *"--bypass-target-check"* ]]; then
echo "If you would like to get the required packages yourself, you may bypass this by running setup.sh with the --bypass-target-check flag"
echo "The following packages are required (debian apt in this case): wget openssl net-tools libsox-dev libopus-dev make iproute2 xz-utils libopusfile-dev pkg-config gcc curl g++ unzip avahi-daemon git"
exit 1
fi
fi
if [[ "${UNAME}" == *"x86_64"* ]]; then
ARCH="x86_64"
echo "amd64 architecture confirmed."
elif [[ "${UNAME}" == *"aarch64"* ]]; then
ARCH="aarch64"
echo "aarch64 architecture confirmed."
elif [[ "${UNAME}" == *"armv7l"* ]]; then
ARCH="armv7l"
echo "armv7l WARN: The Coqui and VOSK bindings are broken for this platform at the moment, so please choose Picovoice when the script asks."
exit 1
else
echo "Your CPU architecture not supported. This script currently supports x86_64, aarch64, and armv7l."
exit 1
fi
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. sudo ./setup.sh"
exit 1
fi
if [[ ! -d ./chipper ]]; then
echo "Script is not running in the wire-pod/ directory or chipper folder is missing. Exiting."
exit 1
fi
if [[ $1 != "-f" ]]; then
if [[ ${ARCH} == "x86_64" ]] && [[ ${TARGET} != "darwin" ]]; then
CPUINFO=$(cat /proc/cpuinfo)
if [[ "${CPUINFO}" == *"avx"* ]]; then
echo "AVX support confirmed."
else
echo "This CPU does not support AVX. Text to speech performance will not be optimal."
AVXSUPPORT="noavx"
#echo "If you would like to bypass this, run the script like this: './setup.sh -f'"
#exit 1
fi
fi
fi
echo "Checks have passed!"
echo
function getPackages() {
echo "Installing required packages"
if [[ ${TARGET} == "debian" ]]; then
apt update -y
apt install -y wget openssl net-tools libsox-dev libopus-dev make iproute2 xz-utils libopusfile-dev pkg-config gcc curl g++ unzip avahi-daemon git libasound2-dev
elif [[ ${TARGET} == "arch" ]]; then
pacman -Sy --noconfirm
sudo pacman -S --noconfirm wget openssl net-tools sox opus make iproute2 opusfile curl unzip avahi git
elif [[ ${TARGET} == "fedora" ]]; then
dnf update
dnf install -y wget openssl net-tools sox opus make opusfile curl unzip avahi git
elif [[ ${TARGET} == "darwin" ]]; then
echo "macOS target, assuming packages already installed (opus opusfile pkg-config)"
fi
touch ./vector-cloud/packagesGotten
echo
echo "Installing golang binary package"
mkdir golang
cd golang
if [[ ${TARGET} != "darwin" ]]; then
if [[ ! -f /usr/local/go/bin/go ]]; then
if [[ ${ARCH} == "x86_64" ]]; then
wget -q --show-progress --no-check-certificate https://go.dev/dl/go1.19.4.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.19.4.linux-amd64.tar.gz
elif [[ ${ARCH} == "aarch64" ]]; then
wget -q --show-progress --no-check-certificate https://go.dev/dl/go1.19.4.linux-arm64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.19.4.linux-arm64.tar.gz
elif [[ ${ARCH} == "armv7l" ]]; then
wget -q --show-progress --no-check-certificate https://go.dev/dl/go1.19.4.linux-armv6l.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.19.4.linux-armv6l.tar.gz
fi
ln -s /usr/local/go/bin/go /usr/bin/go
fi
else
echo "This is a macOS target, assuming Go is installed already"
fi
cd ..
rm -rf golang
echo
}
function buildCloud() {
echo
echo "Installing docker"
if [[ ${TARGET} == "debian" ]]; then
apt update -y
apt install -y docker.io
elif [[ ${TARGET} == "arch" ]]; then
pacman -Sy --noconfirm
sudo pacman -S --noconfirm docker
fi
systemctl start docker
echo
cd vector-cloud
./build.sh
cd ..
echo
echo "./vector-cloud/build/vic-cloud built!"
echo
}
function buildChipper() {
echo
cd chipper
echo
cd ..
}
function getLanguage() {
if [[ ${sttService} == "vosk" ]]; then
origDir=$(pwd)
echo
echo "Which STT language would you like to use?"
echo "1: English (US)"
echo "2: Italian (IT)"
echo "3: Spanish (ES)"
echo "4: French (FR)"
echo "5: German (DE)"
echo
read -p "Enter a number (1): " languageNum
if [[ ! -n ${languageNum} ]]; then
languageNum="en-US"
if [[ ! -d vosk/models/en-US ]]; then
cd ${origDir}
echo "Downloading English (US) model"
mkdir -p vosk/models/en-US
cd vosk/models/en-US
wget -q --show-progress --no-check-certificate https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip
unzip vosk-model-small-en-us-0.15.zip
mv vosk-model-small-en-us-0.15 model
rm vosk-model-small-en-us-0.15.zip
fi
elif [[ ${languageNum} == "1" ]]; then
languageNum="en-US"
if [[ ! -d vosk/models/en-US ]]; then
cd ${origDir}
echo "Downloading English (US) model"
mkdir -p vosk/models/en-US
cd vosk/models/en-US
wget -q --show-progress --no-check-certificate https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip
unzip vosk-model-small-en-us-0.15.zip
mv vosk-model-small-en-us-0.15 model
rm vosk-model-small-en-us-0.15.zip
fi
elif [[ ${languageNum} == "2" ]]; then
languageNum="it-IT"
if [[ ! -d vosk/models/it-IT ]]; then
cd ${origDir}
echo "Downloading Italian (IT) model"
mkdir -p vosk/models/it-IT
cd vosk/models/it-IT
wget -q --show-progress --no-check-certificate https://alphacephei.com/vosk/models/vosk-model-small-it-0.22.zip
unzip vosk-model-small-it-0.22.zip
mv vosk-model-small-it-0.22 model
rm vosk-model-small-it-0.22.zip
fi
elif [[ ${languageNum} == "3" ]]; then
languageNum="es-ES"
if [[ ! -d vosk/models/es-ES ]]; then
cd ${origDir}
echo "Downloading Spanish (ES) model"
mkdir -p vosk/models/es-ES
cd vosk/models/es-ES
wget -q --show-progress --no-check-certificate https://alphacephei.com/vosk/models/vosk-model-small-es-0.42.zip
unzip vosk-model-small-es-0.42.zip
mv vosk-model-small-es-0.42 model
rm vosk-model-small-es-0.42.zip
fi
elif [[ ${languageNum} == "4" ]]; then
languageNum="fr-FR"
if [[ ! -d vosk/models/fr-FR ]]; then
cd ${origDir}
echo "Downloading French (FR) model"
mkdir -p vosk/models/fr-FR
cd vosk/models/fr-FR
wget -q --show-progress --no-check-certificate https://alphacephei.com/vosk/models/vosk-model-small-fr-0.22.zip
unzip vosk-model-small-fr-0.22.zip
mv vosk-model-small-fr-0.22 model
rm vosk-model-small-fr-0.22.zip
fi
elif [[ ${languageNum} == "5" ]]; then
languageNum="de-DE"
if [[ ! -d vosk/models/de-DE ]]; then
cd ${origDir}
echo "Downloading German (DE) model"
mkdir -p vosk/models/de-DE
cd vosk/models/de-DE
wget -q --show-progress --no-check-certificate https://alphacephei.com/vosk/models/vosk-model-small-de-0.15.zip
unzip vosk-model-small-de-0.15.zip
mv vosk-model-small-de-0.15 model
rm vosk-model-small-de-0.15.zip
fi
else
echo
echo "Choose a valid number, or just press enter to use the default number."
getLanguage
fi
cd ${origDir}
fi
}
function getSTT() {
rm -f ./chipper/pico.key
function sttServicePrompt() {
if [[ ${TARGET} == "darwin" ]]; then
sttService="leopard"
echo "Using Picovoice Leopard because that is the only speech-to-text service supported for macOS."
else
echo
echo "Which speech-to-text service would you like to use?"
echo "1: Coqui (local, no usage collection, less accurate, a little slower)"
echo "2: Picovoice Leopard (local, usage collected, accurate, account signup required)"
echo "3: VOSK (local, accurate, multilanguage, fast, recommended)"
echo
read -p "Enter a number (3): " sttServiceNum
if [[ ! -n ${sttServiceNum} ]]; then
sttService="vosk"
elif [[ ${sttServiceNum} == "1" ]]; then
sttService="coqui"
elif [[ ${sttServiceNum} == "2" ]]; then
sttService="leopard"
elif [[ ${sttServiceNum} == "3" ]]; then
sttService="vosk"
else
echo
echo "Choose a valid number, or just press enter to use the default number."
sttServicePrompt
fi
fi
}
sttServicePrompt
if [[ ${sttService} == "leopard" ]]; then
function picoApiPrompt() {
echo
echo "Create an account at https://console.picovoice.ai/ and enter the Access Key it gives you."
echo
read -p "Enter your Access Key: " picoKey
if [[ ! -n ${picoKey} ]]; then
echo
echo "You must enter a key."
picoApiPrompt
fi
}
picoApiPrompt
echo ${picoKey} > ./chipper/pico.key
elif [[ ${sttService} == "vosk" ]]; then
origDir=$(pwd)
if [[ ! -f ./vosk/completed ]]; then
echo "Getting VOSK assets"
rm -fr /root/.vosk
mkdir /root/.vosk
cd /root/.vosk
if [[ ${ARCH} == "x86_64" ]]; then
VOSK_DIR="vosk-linux-x86_64-0.3.43"
elif [[ ${ARCH} == "aarch64" ]]; then
VOSK_DIR="vosk-linux-aarch64-0.3.43"
elif [[ ${ARCH} == "armv7l" ]]; then
VOSK_DIR="vosk-linux-armv7l-0.3.43"
fi
VOSK_ARCHIVE="$VOSK_DIR.zip"
wget -q --show-progress --no-check-certificate "https://github.com/alphacep/vosk-api/releases/download/v0.3.43/$VOSK_ARCHIVE"
unzip "$VOSK_ARCHIVE"
mv "$VOSK_DIR" libvosk
rm -fr "$VOSK_ARCHIVE"
cd ${origDir}/chipper
export CGO_ENABLED=1
export CGO_CFLAGS="-I/root/.vosk/libvosk"
export CGO_LDFLAGS="-L /root/.vosk/libvosk -lvosk -ldl -lpthread"
export LD_LIBRARY_PATH="$HOME/.vosk/libvosk:$LD_LIBRARY_PATH"
/usr/local/go/bin/go get -u github.com/alphacep/vosk-api/go/...
/usr/local/go/bin/go get github.com/alphacep/vosk-api
/usr/local/go/bin/go install github.com/alphacep/vosk-api/go
cd ${origDir}
fi
else
if [[ ! -f ./stt/completed ]]; then
echo "Getting STT assets"
if [[ -d /root/.coqui ]]; then
rm -rf /root/.coqui
fi
origDir=$(pwd)
mkdir /root/.coqui
cd /root/.coqui
if [[ ${ARCH} == "x86_64" ]]; then
if [[ ${AVXSUPPORT} == "noavx" ]]; then
wget -q --show-progress --no-check-certificate https://wire.my.to/noavx-coqui/native_client.tflite.Linux.tar.xz
else
wget -q --show-progress --no-check-certificate https://github.com/coqui-ai/STT/releases/download/v1.3.0/native_client.tflite.Linux.tar.xz
fi
tar -xf native_client.tflite.Linux.tar.xz
rm -f ./native_client.tflite.Linux.tar.xz
elif [[ ${ARCH} == "aarch64" ]]; then
wget -q --show-progress --no-check-certificate https://github.com/coqui-ai/STT/releases/download/v1.3.0/native_client.tflite.linux.aarch64.tar.xz
tar -xf native_client.tflite.linux.aarch64.tar.xz
rm -f ./native_client.tflite.linux.aarch64.tar.xz
elif [[ ${ARCH} == "armv7l" ]]; then
wget -q --show-progress --no-check-certificate https://github.com/coqui-ai/STT/releases/download/v1.3.0/native_client.tflite.linux.armv7.tar.xz
tar -xf native_client.tflite.linux.armv7.tar.xz
rm -f ./native_client.tflite.linux.armv7.tar.xz
fi
cd ${origDir}/chipper
export CGO_LDFLAGS="-L$HOME/.coqui/"
export CGO_CXXFLAGS="-I$HOME/.coqui/"
export LD_LIBRARY_PATH="$HOME/.coqui/:$LD_LIBRARY_PATH"
/usr/local/go/bin/go get -u github.com/asticode/go-asticoqui/...
/usr/local/go/bin/go get github.com/asticode/go-asticoqui
/usr/local/go/bin/go install github.com/asticode/go-asticoqui
cd ${origDir}
mkdir -p stt
cd stt
function sttModelPrompt() {
echo
echo "Which voice model would you like to use?"
echo "1: large_vocabulary (faster, less accurate, ~100MB)"
echo "2: huge_vocabulary (slower, more accurate, handles faster speech better, ~900MB)"
echo
read -p "Enter a number (1): " sttModelNum
if [[ ! -n ${sttModelNum} ]]; then
sttModel="large_vocabulary"
elif [[ ${sttModelNum} == "1" ]]; then
sttModel="large_vocabulary"
elif [[ ${sttModelNum} == "2" ]]; then
sttModel="huge_vocabulary"
else
echo
echo "Choose a valid number, or just press enter to use the default number."
sttModelPrompt
fi
}
sttModelPrompt
if [[ -f model.scorer ]]; then
rm -rf ./*
fi
if [[ ${sttModel} == "large_vocabulary" ]]; then
echo "Getting STT model..."
wget -O model.tflite -q --show-progress --no-check-certificate https://coqui.gateway.scarf.sh/english/coqui/v1.0.0-large-vocab/model.tflite
echo "Getting STT scorer..."
wget -O model.scorer -q --show-progress --no-check-certificate https://coqui.gateway.scarf.sh/english/coqui/v1.0.0-large-vocab/large_vocabulary.scorer
elif [[ ${sttModel} == "huge_vocabulary" ]]; then
echo "Getting STT model..."
wget -O model.tflite -q --show-progress --no-check-certificate https://coqui.gateway.scarf.sh/english/coqui/v1.0.0-huge-vocab/model.tflite
echo "Getting STT scorer..."
wget -O model.scorer -q --show-progress --no-check-certificate https://coqui.gateway.scarf.sh/english/coqui/v1.0.0-huge-vocab/huge-vocabulary.scorer
else
echo "Invalid model specified"
exit 0
fi
echo
touch completed
echo "STT assets successfully downloaded!"
cd ..
else
echo "STT assets already there! If you want to redownload, use the 4th option in setup.sh."
fi
fi
}
function IPDNSPrompt() {
read -p "Enter a number (3): " yn
case $yn in
"1") SANPrefix="IP" ;;
"2") SANPrefix="DNS" ;;
"3") isEscapePod="epod" ;;
"4") noCerts="true" ;;
"") isEscapePod="epod" ;;
*)
echo "Please answer with 1, 2, 3, or 4."
IPDNSPrompt
;;
esac
}
function IPPrompt() {
if [[ ${TARGET} == "darwin" ]]; then
IPADDRESS=$(ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2)
else
IPADDRESS=$(ip -4 addr | grep $(ip addr | awk '/state UP/ {print $2}' | sed 's/://g') | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
fi
read -p "Enter the IP address of the machine you are running this script on (${IPADDRESS}): " ipaddress
if [[ ! -n ${ipaddress} ]]; then
address=${IPADDRESS}
else
address=${ipaddress}
fi
}
function DNSPrompt() {
read -p "Enter the domain you would like to use: " dnsurl
if [[ ! -n ${dnsurl} ]]; then
echo "You must enter a domain."
DNSPrompt
fi
address=${dnsurl}
}
function generateCerts() {
echo
echo "Creating certificates"
echo
echo "Would you like to use your IP address or a domain for the Subject Alt Name?"
echo "Or would you like to use the escapepod.local certs?"
echo
echo "1: IP address (recommended for OSKR Vectors)"
echo "2: Domain"
echo "3: escapepod.local (required for regular production Vectors)"
if [[ -d ./certs ]]; then
echo "4: Keep certificates as is"
fi
IPDNSPrompt
if [[ ${noCerts} != "true" ]]; then
if [[ ${isEscapePod} != "epod" ]]; then
if [[ ${SANPrefix} == "IP" ]]; then
IPPrompt
else
DNSPrompt
fi
rm -f ./chipper/useepod
rm -rf ./certs
mkdir certs
cd certs
echo ${address} >address
echo "Creating san config"
echo "[req]" >san.conf
echo "default_bits = 4096" >>san.conf
echo "default_md = sha256" >>san.conf
echo "distinguished_name = req_distinguished_name" >>san.conf
echo "x509_extensions = v3_req" >>san.conf
echo "prompt = no" >>san.conf
echo "[req_distinguished_name]" >>san.conf
echo "C = US" >>san.conf
echo "ST = VA" >>san.conf
echo "L = SomeCity" >>san.conf
echo "O = MyCompany" >>san.conf
echo "OU = MyDivision" >>san.conf
echo "CN = ${address}" >>san.conf
echo "[v3_req]" >>san.conf
echo "keyUsage = nonRepudiation, digitalSignature, keyEncipherment" >>san.conf
echo "extendedKeyUsage = serverAuth" >>san.conf
echo "subjectAltName = @alt_names" >>san.conf
echo "[alt_names]" >>san.conf
echo "${SANPrefix}.1 = ${address}" >>san.conf
echo "Generating key and cert"
openssl req -x509 -nodes -days 730 -newkey rsa:2048 -keyout cert.key -out cert.crt -config san.conf
echo
echo "Certificates generated!"
echo
cd ..
else
echo
echo "escapepod.local chosen."
touch chipper/useepod
fi
fi
}
function makeSource() {
if [[ -f ./chipper/source.sh ]]; then
echo "Found an existing source.sh, exporting"
cd chipper
source source.sh
cd ..
SOURCEEXPORTED="true"
fi
if [[ ! -f ./certs/address ]] && [[ ! -f ./chipper/useepod ]]; then
echo "You need to generate certs first!"
exit 0
fi
cd chipper
if [[ ! -f ./useepod ]]; then
read -p "What port would you like to use? (443): " portPrompt
if [[ -n ${portPrompt} ]]; then
port=${portPrompt}
else
port="443"
fi
if netstat -pln | grep :${port}; then
echo
netstat -pln | grep :${port}
echo
echo "Something may be using port ${port}. Make sure that port is free before you start chipper."
fi
else
echo
echo "Using port 443 for chipper because escapepod.local is being used."
port="443"
echo
fi
read -p "What port would you like to use for the HTTP webserver used for custom intents, bot configuration, etc? (8080): " webportPrompt
if [[ -n ${webportPrompt} ]]; then
webport=${webportPrompt}
else
webport="8080"
fi
echo
function weatherPrompt() {
echo "Would you like to setup weather commands? This involves creating a free account at one of the weather providers' websites and putting in your API key."
echo "Otherwise, placeholder values will be used."
echo
echo "1: Yes, and I want to use weatherapi.com"
echo "2: Yes, and I want to use openweathermap.org (with forecast support)"
echo "3: No"
if [[ ${SOURCEEXPORTED} == "true" ]]; then
echo "4: Do not change weather configuration"
fi
read -p "Enter a number (3): " yn
case $yn in
"1") weatherSetup="true" weatherProvider="weatherapi.com" ;;
"2") weatherSetup="true" weatherProvider="openweathermap.org" ;;
"3") weatherSetup="false" ;;
"4") weatherSetup="true" noChangeWeather="true" ;;
"") weatherSetup="false" ;;
*)
echo "Please answer with 1 or 2."
weatherPrompt
;;
esac
}
weatherPrompt
if [[ ${weatherSetup} == "true" ]]; then
if [[ ! ${noChangeWeather} == "true" ]]; then
function weatherKeyPrompt() {
echo
echo "Create an account at https://$weatherProvider and enter the API key it gives you."
echo "If you have changed your mind, enter Q to continue without weather commands."
echo
read -p "Enter your API key: " weatherAPI
if [[ ! -n ${weatherAPI} ]]; then
echo "You must enter an API key. If you have changed your mind, you may also enter Q to continue without weather commands."
weatherKeyPrompt
fi
if [[ ${weatherAPI} == "Q" ]]; then
weatherSetup="false"
fi
}
weatherKeyPrompt
function weatherUnitPrompt() {
echo "What temperature unit would you like to use?"
echo
echo "1: Fahrenheit"
echo "2: Celsius"
read -p "Enter a number (1): " yn
case $yn in
"1") weatherUnit="F" ;;
"2") weatherUnit="C" ;;
"") weatherUnit="F" ;;
*)
echo "Please answer with 1 or 2."
weatherUnitPrompt
;;
esac
}
weatherUnitPrompt
else
if [[ $WEATHERAPI_ENABLED == "true" ]]; then
weatherUnit="$WEATHERAPI_UNIT"
weatherProvider="$WEATHERAPI_PROVIDER"
weatherAPI="$WEATHERAPI_KEY"
else
weatherSetup="false"
fi
fi
fi
function knowledgePrompt() {
echo
echo "Would you like to setup knowledge graph (I have a question) commands?"
echo "Houndify: Same service the official server uses. You must create a free account at https://www.houndify.com/signup and putting in your Client Key and Client ID."
echo "OpenAI: May not provide accurate results, but may be faster and more interesting. You must create a free account at https://beta.openai.com/signup and enter an API key. You only have a trial."
echo "This is not required, and if you choose 3 then placeholder values will be used. And if you change your mind later, just run ./setup.sh again with the 6th option."
echo
echo "1: Yes, with Houndify"
echo "2: Yes, with OpenAI"
echo "3: No"
if [[ ${SOURCEEXPORTED} == "true" ]]; then
echo "4: Do not change knowledgegraph configuration"
fi
read -p "Enter a number (3): " yn
case $yn in
"1") knowledgeSetup="true" knowledgeProvider="houndify" ;;
"2") knowledgeSetup="true" knowledgeProvider="openai" ;;
"3") knowledgeSetup="false" ;;
"4") knowledgeSetup="true" noChangeKnowledge="true" ;;
"") knowledgeSetup="false" ;;
*)
echo "Please answer with 1 or 2."
knowledgePrompt
;;
esac
}
knowledgePrompt
if [[ ${knowledgeSetup} == "true" ]]; then
if [[ ! ${noChangeKnowledge} == "true" ]]; then
function houndifyIDPrompt() {
knowledgeIntent="false"
echo
echo "Create an account at https://www.houndify.com/signup and enter the Client ID (not Key) it gives you."
echo "If you have changed your mind, enter Q to continue without knowledge graph commands."
echo
read -p "Enter your Client ID: " knowledgeID
if [[ ! -n ${knowledgeID} ]]; then
echo "You must enter a Houndify Client ID. If you have changed your mind, you may also enter Q to continue without knowledgegraph commands."
houndifyIDPrompt
fi
if [[ ${knowledgeID} == "Q" ]]; then
knowledgeSetup="false"
fi
}
function openAIPrompt() {
echo
echo "Create an account at https://beta.openai.com/signup, generate an API key, and enter it here."
echo "If you have changed your mind, enter Q to continue without knowledge graph commands."
if [[ $SOURCEEXPORTED == "true" ]] && ! [[ $KNOWLEDGE_KEY == "" ]]; then
echo "Press enter to use the key you entered the last time you set this up."
fi
echo
read -p "Enter your API key: " knowledgeKey
if [[ ! -n ${knowledgeKey} ]]; then
if [[ $KNOWLEDGE_KEY == "" ]]; then
echo "You must enter an OpenAI API key. If you have changed your mind, you may also enter Q to continue without knowledgegraph commands."
openAIPrompt
else
knowledgeKey="$KNOWLEDGE_KEY"
fi
fi
if [[ ${knowledgeKey} == "Q" ]]; then
knowledgeSetup="false"
fi
echo
echo "Would you like to use the intent graph feature? This is a feature which was introduced by DDL in firmware 1.8. If the speech does not match an intent, it will feed the information to OpenAI and the bot will respond with that response instead."
echo
echo "1: Yes"
echo "2: No"
echo
read -p "Enter a number (1): " yn
case $yn in
"1") knowledgeIntent="true" ;;
"2") knowledgeIntent="false" ;;
"") knowledgeIntent="true" ;;
*) knowledgeIntent="true" ;;
esac
echo
}
function houndifyKeyPrompt() {
echo
echo "Now enter the Houndify Client Key (not ID)."
echo
read -p "Enter your Client Key: " knowledgeKey
if [[ ! -n ${knowledgeKey} ]]; then
echo "You must enter a Houndify Client Key."
houndifyKeyPrompt
fi
if [[ ${knowledgeKey} == "Q" ]]; then
knowledgeSetup="false"
fi
}
if [[ ${knowledgeProvider} == "houndify" ]]; then
houndifyIDPrompt
else
openAIPrompt
fi
if [[ ${knowledgeSetup} == "true" ]] && [[ ${knowledgeProvider} == "houndify" ]]; then
houndifyKeyPrompt
fi
else
if [[ "$KNOWLEDGE_ENABLED" == "true" ]]; then
knowledgeKey="$KNOWLEDGE_KEY"
knowledgeID="$KNOWLEDGE_ID"
knowledgeProvider="$KNOWLEDGE_PROVIDER"
knowledgeIntent="$KNOWLEDGE_INTENT_GRAPH"
else
if [[ "$HOUNDIFY_ENABLED" == "true" ]]; then
knowledgeKey="$HOUNDIFY_CLIENT_KEY"
knowledgeID="$HOUNDIFY_CLIENT_ID"
knowledgeProvider="houndify"
else
knowledgeSetup="false"
fi
fi
fi
fi
echo "export DDL_RPC_PORT=${port}" >source.sh
if [[ ! -f ./useepod ]]; then
echo 'export DDL_RPC_TLS_CERTIFICATE=$(cat ../certs/cert.crt)' >>source.sh
echo 'export DDL_RPC_TLS_KEY=$(cat ../certs/cert.key)' >>source.sh
else
echo 'export DDL_RPC_TLS_CERTIFICATE=$(cat ./epod/ep.crt)' >>source.sh
echo 'export DDL_RPC_TLS_KEY=$(cat ./epod/ep.key)' >>source.sh
fi
echo "export DDL_RPC_CLIENT_AUTHENTICATION=NoClientCert" >>source.sh
if [[ ${weatherSetup} == "true" ]]; then
echo "export WEATHERAPI_ENABLED=true" >>source.sh
echo "export WEATHERAPI_PROVIDER=$weatherProvider" >>source.sh
echo "export WEATHERAPI_KEY=${weatherAPI}" >>source.sh
echo "export WEATHERAPI_UNIT=${weatherUnit}" >>source.sh
else
echo "export WEATHERAPI_ENABLED=false" >>source.sh
fi
if [[ ${knowledgeSetup} == "true" ]]; then
echo "export KNOWLEDGE_ENABLED=true" >>source.sh
echo "export KNOWLEDGE_INTENT_GRAPH=${knowledgeIntent}" >> source.sh
if [[ ${knowledgeProvider} == "houndify" ]]; then
echo "export KNOWLEDGE_PROVIDER=houndify" >> source.sh
echo "export KNOWLEDGE_KEY=${knowledgeKey}" >>source.sh
echo "export KNOWLEDGE_ID=${knowledgeID}" >>source.sh
else
echo "export KNOWLEDGE_PROVIDER=openai" >> source.sh
echo "export KNOWLEDGE_KEY=${knowledgeKey}" >> source.sh
fi
else
echo "export KNOWLEDGE_ENABLED=false" >>source.sh
fi
echo "export WEBSERVER_PORT=${webport}" >>source.sh
if [[ -f ./pico.key ]]; then
picoKey=$(cat ./pico.key)
echo "export STT_SERVICE=leopard" >>source.sh
echo "export PICOVOICE_APIKEY=${picoKey}" >> source.sh
elif [[ ${sttService} == "vosk" ]]; then
echo "export STT_SERVICE=vosk" >>source.sh
echo "export STT_LANGUAGE=${languageNum}" >>source.sh
else
echo "export STT_SERVICE=coqui" >>source.sh
fi
echo "export DEBUG_LOGGING=true" >>source.sh
echo "export WIREPOD_EX_TMP_PATH=/tmp" >>source.sh
echo "export WIREPOD_EX_DATA_PATH=./data" >>source.sh
echo "export WIREPOD_EX_NVM_PATH=./nvm" >>source.sh
cd ..
echo
echo "Created source.sh file!"
echo
if [[ ! -f ./chipper/useepod ]]; then
cd certs
echo "Creating server_config.json for robot"
echo '{"jdocs": "REPLACEME", "tms": "REPLACEME", "chipper": "REPLACEME", "check": "REPLACECONN/ok:80", "logfiles": "s3://anki-device-logs-prod/victor", "appkey": "oDoa0quieSeir6goowai7f"}' >server_config.json
address=$(cat address)
if [[ ${TARGET} == "darwin" ]]; then
perl -i -pe"s/REPLACEME/${address}:${port}/g" server_config.json
perl -i -pe"s/REPLACECONN/${address}/g" server_config.json
else
sed -i "s/REPLACEME/${address}:${port}/g" server_config.json
sed -i "s/REPLACECONN/${address}/g" server_config.json
fi
cd ..
else
mkdir -p certs
cd certs
echo "Creating server_config.json for robot"
echo '{"jdocs": "escapepod.local:443", "tms": "escapepod.local:443", "chipper": "escapepod.local:443", "check": "escapepod.local/ok:80", "logfiles": "s3://anki-device-logs-prod/victor", "appkey": "oDoa0quieSeir6goowai7f"}' >server_config.json
cd ..
fi
echo "Created!"
echo
}
function scpToBot() {
if [[ ! -n ${botAddress} ]]; then
echo "To copy vic-cloud and server_config.json to your OSKR robot, run this script like this:"
echo "Usage: sudo ./setup.sh scp <vector's ip> <path/to/ssh-key>"
echo "Example: sudo ./setup.sh scp 192.168.1.150 /home/wire/id_rsa_Vector-R2D2"
echo
echo "If your Vector is on Wire's custom software or you have an old dev build, you can run this command without an SSH key:"
echo "Example: sudo ./setup.sh scp 192.168.1.150"
echo
exit 0
fi
if [[ ! -f ./certs/server_config.json ]]; then
echo "server_config.json file missing. You need to generate this file with ./setup.sh's 6th option."
exit 0
fi
if [[ ! -n ${keyPath} ]]; then
echo
if [[ ! -f ./ssh_root_key ]]; then
echo "Key not provided, downloading ssh_root_key..."
wget http://wire.my.to:81/ssh_root_key
else
echo "Key not provided, using ./ssh_root_key (already there)..."
fi
chmod 600 ./ssh_root_key
keyPath="./ssh_root_key"
fi
if [[ ! -f ${keyPath} ]]; then
echo "The key that was provided was not found. Exiting."
exit 0
fi
ssh -i ${keyPath} root@${botAddress} "cat /build.prop" >/tmp/sshTest 2>>/tmp/sshTest
botBuildProp=$(cat /tmp/sshTest)
if [[ "${botBuildProp}" == *"no mutual signature"* ]]; then
echo
echo "An entry must be made to the ssh config for this to work. Would you like the script to do this?"
echo "1: Yes"
echo "2: No (exit)"
echo
function rsaAddPrompt() {
read -p "Enter a number (1): " yn
case $yn in
"1") echo ;;
"2") exit 0 ;;
"") echo ;;
*)
echo "Please answer with 1 or 2."
rsaAddPrompt
;;
esac
}
rsaAddPrompt
echo "PubkeyAcceptedKeyTypes +ssh-rsa" >>/etc/ssh/ssh_config
botBuildProp=$(ssh -i ${keyPath} root@${botAddress} "cat /build.prop")
fi
if [[ ! "${botBuildProp}" == *"ro.build"* ]]; then
echo "Unable to communicate with robot. The key may be invalid, the bot may not be unlocked, or this device and the robot are not on the same network."
exit 0
fi
scp -v -i ${keyPath} root@${botAddress}:/build.prop /tmp/scpTest >/tmp/scpTest 2>>/tmp/scpTest
scpTest=$(cat /tmp/scpTest)
if [[ "${scpTest}" == *"sftp"* ]]; then
oldVar="-O"
else
oldVar=""
fi
if [[ ! "${botBuildProp}" == *"ro.build"* ]]; then
echo "Unable to communicate with robot. The key may be invalid, the bot may not be unlocked, or this device and the robot are not on the same network."
exit 0
fi
ssh -oStrictHostKeyChecking=no -i ${keyPath} root@${botAddress} "mount -o rw,remount / && mount -o rw,remount,exec /data && systemctl stop anki-robot.target && mv /anki/data/assets/cozmo_resources/config/server_config.json /anki/data/assets/cozmo_resources/config/server_config.json.bak"
scp -oStrictHostKeyChecking=no ${oldVar} -i ${keyPath} ./vector-cloud/build/vic-cloud root@${botAddress}:/anki/bin/
scp -oStrictHostKeyChecking=no ${oldVar} -i ${keyPath} ./certs/server_config.json root@${botAddress}:/anki/data/assets/cozmo_resources/config/
scp -oStrictHostKeyChecking=no ${oldVar} -i ${keyPath} ./vector-cloud/pod-bot-install.sh root@${botAddress}:/data/
if [[ -f ./chipper/useepod ]]; then
scp -oStrictHostKeyChecking=no ${oldVar} -i ${keyPath} ./chipper/epod/ep.crt root@${botAddress}:/anki/etc/wirepod-cert.crt
scp -oStrictHostKeyChecking=no ${oldVar} -i ${keyPath} ./chipper/epod/ep.crt root@${botAddress}:/data/data/wirepod-cert.crt
else
scp -oStrictHostKeyChecking=no ${oldVar} -i ${keyPath} ./certs/cert.crt root@${botAddress}:/anki/etc/wirepod-cert.crt
scp -oStrictHostKeyChecking=no ${oldVar} -i ${keyPath} ./certs/cert.crt root@${botAddress}:/data/data/wirepod-cert.crt
fi
ssh -oStrictHostKeyChecking=no -i ${keyPath} root@${botAddress} "chmod +rwx /anki/data/assets/cozmo_resources/config/server_config.json /anki/bin/vic-cloud /data/data/wirepod-cert.crt /anki/etc/wirepod-cert.crt /data/pod-bot-install.sh && /data/pod-bot-install.sh"
rm -f /tmp/sshTest
rm -f /tmp/scpTest
echo "Vector has been reset to Onboarding mode, but no user data has actually been erased."
echo
echo "Everything has been copied to the bot! Use https://keriganc.com/vector-epod-setup on any device with Bluetooth to finish setting up your Vector!"
echo
echo "Everything is now setup! You should be ready to run chipper. sudo ./chipper/start.sh"
echo
}
function setupSystemd() {
if [[ ${TARGET} == "macos" ]]; then
echo "This cannot be done on macOS."
exit 1
fi
if [[ ! -f ./chipper/source.sh ]]; then
echo "You need to make a source.sh file. This can be done with the setup.sh script, option 6."
exit 1
fi
source ./chipper/source.sh
echo "[Unit]" >wire-pod.service
echo "Description=Wire Escape Pod (coqui)" >>wire-pod.service
echo >>wire-pod.service
echo "[Service]" >>wire-pod.service
echo "Type=simple" >>wire-pod.service
echo "WorkingDirectory=$(readlink -f ./chipper)" >>wire-pod.service
echo "ExecStart=$(readlink -f ./chipper/start.sh)" >>wire-pod.service
echo >>wire-pod.service
echo "[Install]" >>wire-pod.service
echo "WantedBy=multi-user.target" >>wire-pod.service
cat wire-pod.service
echo
cd chipper
if [[ ${STT_SERVICE} == "leopard" ]]; then
echo "wire-pod.service created, building chipper with Picovoice STT service..."
/usr/local/go/bin/go build cmd/leopard/main.go
elif [[ ${STT_SERVICE} == "vosk" ]]; then
echo "wire-pod.service created, building chipper with VOSK STT service..."
export CGO_ENABLED=1
export CGO_CFLAGS="-I$HOME/.vosk/libvosk"
export CGO_LDFLAGS="-L $HOME/.vosk/libvosk -lvosk -ldl -lpthread"
export LD_LIBRARY_PATH="$HOME/.vosk/libvosk:$LD_LIBRARY_PATH"
/usr/local/go/bin/go build cmd/vosk/main.go
else
echo "wire-pod.service created, building chipper with Coqui STT service..."
export CGO_LDFLAGS="-L$HOME/.coqui/"
export CGO_CXXFLAGS="-I$HOME/.coqui/"
export LD_LIBRARY_PATH="$HOME/.coqui/:$LD_LIBRARY_PATH"
/usr/local/go/bin/go build cmd/coqui/main.go
fi
mv main chipper
echo
echo "./chipper/chipper has been built!"
cd ..
mv wire-pod.service /lib/systemd/system/
systemctl daemon-reload
systemctl enable wire-pod
echo
echo "systemd service has been installed and enabled! The service is called wire-pod.service"
echo
echo "To start the service, run: 'systemctl start wire-pod'"
echo "Then, to see logs, run 'journalctl -fe | grep start.sh'"
}
function disableSystemd() {
if [[ ${TARGET} == "macos" ]]; then
echo "This cannot be done on macOS."
exit 1
fi
echo
echo "Disabling wire-pod.service"
systemctl stop wire-pod.service
systemctl disable wire-pod.service
rm ./chipper/chipper
rm -f /lib/systemd/system/wire-pod.service
systemctl daemon-reload
echo
echo "wire-pod.service has been removed and disabled."
}
function firstPrompt() {
read -p "Enter a number (1): " yn
case $yn in
"1")
echo
getPackages
getSTT
getLanguage
generateCerts
buildChipper
makeSource
echo -e "\033[33m\033[1mEverything is set up! wire-pod is ready to start!\033[0m"
echo
if [[ -f ./chipper/useepod ]]; then
echo "You chose to use escapepod.local, so you do not need to run any SCP commands for a prod bot to use this. You just need to put on an official escape pod OTA. The instructions can be found in the root of this repo."
echo
fi
;;
"2")
echo
getPackages
buildCloud
;;
"3")
echo
getPackages
buildChipper
;;
"4")
echo
rm -f ./stt/completed
getSTT
getLanguage
;;
"5")
echo
getPackages
generateCerts
;;
"6")
echo
makeSource
;;
"")
echo
getPackages