forked from kercre123/wire-pod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·668 lines (643 loc) · 27.4 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
#!/bin/bash
set -e
echo
UNAME=$(uname -a)
ROOT="/root"
if [[ ${UNAME} == *"Darwin"* ]]; then
if [[ -f /usr/local/Homebrew/bin/brew ]] || [[ -f /opt/Homebrew/bin/brew ]]; then
TARGET="darwin"
ROOT="$HOME"
echo "macOS detected."
if [[ ! -f /usr/local/go/bin/go ]]; then
if [[ -f /usr/local/bin/go ]]; then
mkdir -p /usr/local/go/bin
ln -s /usr/local/bin/go /usr/local/go/bin/go
else
echo "Go was not found. You must download it from https://go.dev/dl/ for your macOS."
exit 1
fi
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 detected."
elif [[ -f /usr/bin/pacman ]]; then
TARGET="arch"
echo "Arch Linux detected."
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"* ]] || [[ "${UNAME}" == *"arm64"* ]]; then
ARCH="aarch64"
echo "aarch64 architecture confirmed."
elif [[ "${UNAME}" == *"armv7l"* ]]; then
ARCH="armv7l"
echo "armv7l (32-bit) WARN: The Coqui and VOSK bindings are broken for this platform at the moment, so please choose Picovoice when the script asks. wire-pod is designed for 64-bit systems."
STT=""
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 libsodium-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 libsodium go pkg-config
elif [[ ${TARGET} == "fedora" ]]; then
dnf update
dnf install -y wget openssl net-tools sox opus make opusfile curl unzip avahi git libsodium-devel
elif [[ ${TARGET} == "darwin" ]]; then
sudo -u $SUDO_USER brew update
sudo -u $SUDO_USER brew install wget pkg-config opus opusfile
fi
touch ./vector-cloud/packagesGotten
echo
echo "Installing golang binary package"
mkdir golang
cd golang
if [[ ${TARGET} != "darwin" ]] && [[ ${TARGET} != "arch" ]]; 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.22.4.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.4.linux-amd64.tar.gz
elif [[ ${ARCH} == "aarch64" ]]; then
wget -q --show-progress --no-check-certificate https://go.dev/dl/go1.22.4.linux-arm64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.4.linux-arm64.tar.gz
elif [[ ${ARCH} == "armv7l" ]]; then
wget -q --show-progress --no-check-certificate https://go.dev/dl/go1.22.4.linux-armv6l.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.4.linux-armv6l.tar.gz
fi
if [[ ! -f /usr/bin/go ]] && [[ ! -e /usr/bin/go ]]; then
ln -s /usr/local/go/bin/go /usr/bin/go
fi
fi
else
echo "This is a macOS or arch target, assuming Go is installed already"
if [[ ${TARGET} == "arch" ]] && [[ ! -d /usr/local/go/bin ]]; then
mkdir -p /usr/local/go/bin
ln -s /usr/bin/go /usr/local/go/bin/go
fi
fi
cd ..
rm -rf golang
echo
}
function getSTT() {
echo "export DEBUG_LOGGING=true" > ./chipper/source.sh
rm -f ./chipper/pico.key
function sttServicePrompt() {
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 "4: Whisper (local, accurate, multilanguage, a little slower, recommended for more powerful hardware)"
echo
read -p "Enter a number (3): " sttServiceNum
if [[ ! -n ${sttServiceNum} ]]; then
sttService="vosk"
elif [[ ${sttServiceNum} == "1" ]]; then
if [[ ${TARGET} == "darwin" ]]; then
echo "Coqui is not supported for macOS. Please select another option."
sttServicePrompt
else
sttService="coqui"
fi
elif [[ ${sttServiceNum} == "2" ]]; then
sttService="leopard"
elif [[ ${sttServiceNum} == "3" ]]; then
sttService="vosk"
elif [[ ${sttServiceNum} == "4" ]]; then
sttService="whisper"
else
echo
echo "Choose a valid number, or just press enter to use the default number."
sttServicePrompt
fi
}
if [[ "$STT" == "vosk" ]]; then
echo "Vosk config"
sttService="vosk"
else
sttServicePrompt
fi
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 "export STT_SERVICE=leopard" >> ./chipper/source.sh
echo "export PICOVOICE_APIKEY=${picoKey}" >> ./chipper/source.sh
echo "export PICOVOICE_APIKEY=${picoKey}" > ./chipper/pico.key
elif [[ ${sttService} == "vosk" ]]; then
echo "export STT_SERVICE=vosk" >> ./chipper/source.sh
origDir="$(pwd)"
if [[ ! -f ./vosk/completed ]]; then
echo "Getting VOSK assets"
rm -fr ${ROOT}/.vosk
mkdir ${ROOT}/.vosk
cd ${ROOT}/.vosk
VOSK_VER="0.3.45"
if [[ ${TARGET} == "darwin" ]]; then
VOSK_VER="0.3.42"
VOSK_DIR="vosk-osx-${VOSK_VER}"
elif [[ ${ARCH} == "x86_64" ]]; then
VOSK_DIR="vosk-linux-x86_64-${VOSK_VER}"
elif [[ ${ARCH} == "aarch64" ]]; then
VOSK_DIR="vosk-linux-aarch64-${VOSK_VER}"
elif [[ ${ARCH} == "armv7l" ]]; then
VOSK_DIR="vosk-linux-armv7l-${VOSK_VER}"
fi
VOSK_ARCHIVE="$VOSK_DIR.zip"
wget -q --show-progress --no-check-certificate "https://github.com/alphacep/vosk-api/releases/download/v${VOSK_VER}/${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/kercre123/vosk-api/go/...
/usr/local/go/bin/go get github.com/kercre123/vosk-api
/usr/local/go/bin/go install github.com/kercre123/vosk-api/go
cd ${origDir}
fi
elif [[ ${sttService} == "whisper" ]]; then
echo "export STT_SERVICE=whisper.cpp" >> ./chipper/source.sh
origDir="$(pwd)"
echo "Getting Whisper assets"
if [[ ! -d ./whisper.cpp ]]; then
mkdir whisper.cpp
cd whisper.cpp
git clone https://github.com/ggerganov/whisper.cpp.git .
else
cd whisper.cpp
fi
function whichWhisperModel() {
availableModels="tiny, base, small, medium, large-v3, large-v3-q5_0"
echo
echo "Which Whisper model would you like to use?"
echo "Options: $availableModels"
echo '(tiny is recommended)'
echo
read -p "Enter preferred model: " whispermodel
if [[ ! -n ${whispermodel} ]]; then
echo
echo "You must enter a key."
whichWhisperModel
fi
if [[ ! ${availableModels} == *"${whispermodel}"* ]]; then
echo
echo "Invalid model."
whichWhisperModel
fi
}
whichWhisperModel
./models/download-ggml-model.sh $whispermodel
cd bindings/go
make whisper
cd ${origDir}
echo "export WHISPER_MODEL=$whispermodel" >> ./chipper/source.sh
else
echo "export STT_SERVICE=coqui" >> ./chipper/source.sh
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/root/.coqui/"
export CGO_CXXFLAGS="-I/root/.coqui/"
export LD_LIBRARY_PATH="/root/.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 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} == "darwin" ]]; 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 "StartLimitIntervalSec=500" >>wire-pod.service
echo "StartLimitBurst=5" >>wire-pod.service
echo >>wire-pod.service
echo "[Service]" >>wire-pod.service
echo "Type=simple" >>wire-pod.service
echo "Restart=on-failure" >>wire-pod.service
echo "RestartSec=5s" >>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
export GOTAGS="nolibopusfile"
if [[ ${USE_INBUILT_BLE} == "true" ]]; then
export GOTAGS="nolibopusfile,inbuiltble"
fi
COMMIT_HASH="$(git rev-parse --short HEAD)"
export GOLDFLAGS="-X 'github.com/kercre123/wire-pod/chipper/pkg/vars.CommitSHA=${COMMIT_HASH}'"
if [[ ${STT_SERVICE} == "leopard" ]]; then
echo "wire-pod.service created, building chipper with Picovoice STT service..."
/usr/local/go/bin/go build -tags $GOTAGS -ldflags="${GOLDFLAGS}" 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/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 build -tags $GOTAGS -ldflags="${GOLDFLAGS}" cmd/vosk/main.go
elif [[ ${STT_SERVICE} == "whisper.cpp" ]]; then
echo "wire-pod.service created, building chipper with Whisper.CPP STT service..."
export CGO_ENABLED=1
export C_INCLUDE_PATH="../whisper.cpp"
export LIBRARY_PATH="../whisper.cpp"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(pwd)/../whisper.cpp"
export CGO_LDFLAGS="-L$(pwd)/../whisper.cpp"
export CGO_CFLAGS="-I$(pwd)/../whisper.cpp"
/usr/local/go/bin/go build -tags $GOTAGS -ldflags="${GOLDFLAGS}" cmd/experimental/whisper.cpp/main.go
else
echo "wire-pod.service created, building chipper with Coqui STT service..."
export CGO_LDFLAGS="-L/root/.coqui/"
export CGO_CXXFLAGS="-I/root/.coqui/"
export LD_LIBRARY_PATH="/root/.coqui/:$LD_LIBRARY_PATH"
/usr/local/go/bin/go build -tags $GOTAGS -ldflags="${GOLDFLAGS}" cmd/coqui/main.go
fi
sync
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} == "darwin" ]]; 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 defaultLaunch() {
echo
getPackages
getSTT
echo
echo "wire-pod is ready to run! You are ready to move to the next step and run sudo ./chipper/start.sh"
}
if [[ $1 == "scp" ]]; then
botAddress=$2
keyPath=$3
scpToBot
exit 0
fi
if [[ $1 == "daemon-enable" ]]; then
getPackages
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 assets"
# echo "5: Just generate certs"
# echo "6: Create wire-pod config file (change/add API keys)"
# echo "(NOTE: You can just press enter without entering a number to select the default, recommended option)"
# echo
defaultLaunch