This repository has been archived by the owner on Aug 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsetup.sh
executable file
·790 lines (762 loc) · 29.3 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
#!/bin/bash
echo
UNAME=$(uname -a)
CPUINFO=$(cat /proc/cpuinfo)
if [[ -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."
exit 1
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 bindings may be broken for this platform."
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" ]]; then
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() {
if [[ ! -f ./vector-cloud/packagesGotten ]]; then
echo "Installing required packages (ffmpeg, golang, wget, openssl, net-tools, iproute2, sox, opus)"
if [[ ${TARGET} == "debian" ]]; then
apt update -y
apt install -y wget openssl net-tools libsox-dev libasound2-dev libopus-dev make iproute2 xz-utils libopusfile-dev pkg-config gcc curl g++ unzip avahi-daemon git
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
fi
touch ./vector-cloud/packagesGotten
echo
echo "Installing golang binary package"
mkdir golang
cd golang
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.18.2.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.2.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
elif [[ ${ARCH} == "aarch64" ]]; then
wget -q --show-progress --no-check-certificate https://go.dev/dl/go1.18.2.linux-arm64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.2.linux-arm64.tar.gz
export PATH=$PATH:/usr/local/go/bin
elif [[ ${ARCH} == "armv7l" ]]; then
wget -q --show-progress --no-check-certificate https://go.dev/dl/go1.18.2.linux-armv6l.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.2.linux-armv6l.tar.gz
export PATH=$PATH:/usr/local/go/bin
fi
fi
cd ..
rm -rf golang
else
echo "Required packages already gotten."
fi
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 getSTT() {
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
if [[ ! -f completed ]]; then
if [[ -f model.scorer ]]; then
rm -rf ./*
fi
echo $1
if [[ ! -f completed ]]; 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
fi
fi
echo
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="/root/.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}
rm -fr vosk
mkdir -p vosk
mkdir -p vosk/models
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
cd ${origDir}
cd ${origDir}/vosk
touch completed
echo
cd ..
echo "STT assets successfully downloaded!"
}
function IPDNSPrompt() {
read -p "Enter a number (1): " yn
case $yn in
"1") SANPrefix="IP" ;;
"2") SANPrefix="DNS" ;;
"3") isEscapePod="epod" ;;
"") SANPrefix="IP" ;;
*)
echo "Please answer with 1 or 2."
IPDNSPrompt
;;
esac
}
function IPPrompt() {
IPADDRESS=$(ip -4 addr | grep $(ip addr | awk '/state UP/ {print $2}' | sed 's/://g') | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
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 (recommended for prod Vectors)"
if [[ "${isEscapePod}" != *"epod"* ]]; then
address=$(ip -4 addr | grep $(ip addr | awk '/state UP/ {print $2}' | sed 's/://g' | head -n1) | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
SANPrefix="IP"
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
}
function makeSource() {
if [[ ! -f ./certs/address ]] && [[ ! -f ./chipper/useepod ]]; then
echo "You need to generate certs first!"
exit 0
fi
cd chipper
rm -f ./source.sh
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 https://www.weatherapi.com/ and putting in your API key."
echo "Otherwise, placeholder values will be used."
echo
echo "1: Yes"
echo "2: No"
read -p "Enter a number (1): " yn
case $yn in
"1") weatherSetup="true" ;;
"2") weatherSetup="false" ;;
"") weatherSetup="true" ;;
*)
echo "Please answer with 1 or 2."
weatherPrompt
;;
esac
}
weatherPrompt
if [[ ${weatherSetup} == "true" ]]; then
function weatherKeyPrompt() {
echo
echo "Create an account at https://www.weatherapi.com/ 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
fi
function houndifyPrompt() {
echo
echo "Would you like to setup knowledge graph (I have a question) commands? This involves creating a free account at https://www.houndify.com/signup and putting in your Client Key and Client ID."
echo "Note: It may seem like you only get a trial, but there is an actual free tier with 100 free requests per day."
echo "This is not required, and if you choose 2 then placeholder values will be used. And if you change your mind later, just run ./setup.sh with the 5th option."
echo
echo "1: Yes"
echo "2: No"
read -p "Enter a number (1): " yn
case $yn in
"1") knowledgeSetup="true" ;;
"2") knowledgeSetup="false" ;;
"") knowledgeSetup="true" ;;
*)
echo "Please answer with 1 or 2."
houndifyPrompt
;;
esac
}
houndifyPrompt
if [[ ${knowledgeSetup} == "true" ]]; then
function houndifyIDPrompt() {
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 weather commands."
houndifyIDPrompt
fi
if [[ ${knowledgeID} == "Q" ]]; then
knowledgeSetup="false"
fi
}
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
}
houndifyIDPrompt
if [[ ${knowledgeSetup} == "true" ]]; then
houndifyKeyPrompt
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_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 HOUNDIFY_ENABLED=true" >>source.sh
echo "export HOUNDIFY_CLIENT_KEY=${knowledgeKey}" >>source.sh
echo "export HOUNDIFY_CLIENT_ID=${knowledgeID}" >>source.sh
else
echo "export HOUNDIFY_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
else
echo "export STT_SERVICE=coqui" >>source.sh
fi
echo "export DEBUG_LOGGING=true" >>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": "jdocs.api.anki.com:443", "tms": "token.api.anki.com:443", "chipper": "REPLACEME", "check": "conncheck.global.anki-services.com/ok", "logfiles": "s3://anki-device-logs-prod/victor", "appkey": "oDoa0quieSeir6goowai7f"}' >server_config.json
address=$(cat address)
sed -i "s/REPLACEME/${address}:${port}/g" server_config.json
cd ..
else
mkdir -p certs
cd certs
echo "Creating server_config.json for robot"
echo '{"jdocs": "jdocs.api.anki.com:443", "tms": "token.api.anki.com:443", "chipper": "escapepod.local:443", "check": "conncheck.global.anki-services.com/ok", "logfiles": "s3://anki-device-logs-prod/victor", "appkey": "oDoa0quieSeir6goowai7f"}' >server_config.json
cd ..
fi
echo "Created!"
echo
}
function changeHostname() {
echo "Changing hostname to escapepod"
echo "127.0.0.1 escapepod" >> /etc/hosts
echo "127.0.0.1 escapepod.local" >> /etc/hosts
hostnamectl set-hostname escapepod
systemctl restart avahi-daemon
systemctl enable avahi-daemon
}
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 -i ${keyPath} root@${botAddress} "mount -o rw,remount / && systemctl stop vic-cloud && mv /anki/data/assets/cozmo_resources/config/server_config.json /anki/data/assets/cozmo_resources/config/server_config.json.bak"
scp ${oldVar} -i ${keyPath} ./vector-cloud/build/vic-cloud root@${botAddress}:/anki/bin/
scp ${oldVar} -i ${keyPath} ./certs/server_config.json root@${botAddress}:/anki/data/assets/cozmo_resources/config/
if [[ -f ./chipper/useepod ]]; then
scp ${oldVar} -i ${keyPath} ./chipper/epod/ep.crt root@${botAddress}:/data/data/customCaCert.crt
else
scp ${oldVar} -i ${keyPath} ./certs/cert.crt root@${botAddress}:/data/data/customCaCert.crt
fi
ssh -i ${keyPath} root@${botAddress} "chmod +rwx /anki/data/assets/cozmo_resources/config/server_config.json /anki/bin/vic-cloud /data/data/customCaCert.crt && systemctl start vic-cloud"
rm -f /tmp/sshTest
rm -f /tmp/scpTest
echo
echo "Everything has been copied to the bot! Voice commands should work now without needing to reboot 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
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
echo "wire-pod.service created, building chipper..."
cd chipper
export CGO_CXXFLAGS="-I$HOME/.coqui/"
export CGO_ENABLED=1
export CGO_CFLAGS="-I/root/.vosk/libvosk"
export CGO_LDFLAGS="-L$HOME/.coqui/ -L /root/.vosk/libvosk -lvosk -ldl -lpthread"
export LD_LIBRARY_PATH="$HOME/.coqui/:$HOME/.vosk/libvosk:$LD_LIBRARY_PATH"
/usr/local/go/bin/go build cmd/main.go
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
systemctl start wire-pod
echo
#IPADDRESS=$(ip -4 addr | grep $(ip addr | awk '/state UP/ {print $2}' | sed 's/://g' | head -n1) | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
#echo "This part of setup is now complete! To set up the rest of wire-pod, open up http://${IPADDRESS}:8080 in a browser."
DIRECTORY=$(readlink -f ./)
echo "${DIRECTORY}"
git config --global --add safe.directory "${DIRECTORY}"
echo
echo "systemd service has been installed and enabled! The service is called wire-pod.service"
echo
echo "Then, to see logs, run 'journalctl -fe | grep start.sh'"
echo "[Unit]" >wire-pod-updater.service
echo "Description=Wire Escape Pod Updater (coqui)" >>wire-pod-updater.service
echo >>wire-pod-updater.service
echo "[Service]" >>wire-pod-updater.service
echo "Type=simple" >>wire-pod-updater.service
echo "WorkingDirectory=$(readlink -f ./)" >>wire-pod-updater.service
echo "ExecStart=$(readlink -f ./update.sh) -d" >>wire-pod-updater.service
echo >>wire-pod-updater.service
echo "[Install]" >>wire-pod-updater.service
echo "WantedBy=multi-user.target" >>wire-pod-updater.service
mv wire-pod-updater.service /lib/systemd/system/
systemctl daemon-reload
systemctl enable wire-pod-updater
systemctl start wire-pod-updater
echo "Installed wire-pod-updater"
echo
echo
echo
IPADDRESS=$(ip -4 addr | grep $(ip addr | awk '/state UP/ {print $2}' | sed 's/://g' | head -n1) | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
echo "Wire-pod is now running! To set up the rest of wire-pod, open up http://${IPADDRESS}:8080 in a browser."
}
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 -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
generateCerts
changeHostname
buildChipper
makeSource
echo "Everything is done! To copy everything needed to your bot, 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
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
;;
"5")
echo
getPackages
generateCerts
;;
"6")
echo
makeSource
;;
"")
echo
getPackages
getSTT
generateCerts
changeHostname
buildChipper
makeSource
echo "Everything is done! To copy everything needed to your bot, 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
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
;;
*)
echo "Please answer with 1, 2, 3, 4, 5, 6, or just press enter with no input for 1."
firstPrompt
;;
esac
}
if [[ $1 == "scp" ]]; then
botAddress=$2
keyPath=$3
scpToBot
exit 0
fi
if [[ $1 == "daemon-enable" ]]; then
setupSystemd
exit 0
fi
if [[ $1 == "daemon-disable" ]]; then
disableSystemd
exit 0
fi
if [[ $1 == "-f" ]] && [[ $2 == "scp" ]]; then
botAddress=$3
keyPath=$4
scpToBot
exit 0
fi
# echo "What would you like to do?"
# echo "1: Full Setup (recommended) (builds chipper, gets STT stuff, generates certs, creates source.sh file, and creates server_config.json for your bot"
# echo "2: Just build vic-cloud"
# echo "3: Just build chipper"
# echo "4: Just get STT stuff"
# echo "5: Just generate certs"
# echo "6: Just create source.sh file and config for bot (also for setting up weather API)"
# echo "If you have done everything you have needed, run './setup.sh scp vectorip path/to/key' to copy the new vic-cloud and server config to Vector."
# echo
if [[ $1 == "certs" ]]; then
cd ..
isEscapePod=$2
generateCerts
else
getPackages
getSTT
changeHostname
setupSystemd
fi