forked from choppa1890/alexa-avs-raspberry-pi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
automated_install.sh
555 lines (495 loc) · 17.5 KB
/
automated_install.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
#!/bin/bash
#-------------------------------------------------------
# Paste from developer.amazon.com below
#-------------------------------------------------------
# This is the name given to your device or mobile app in the Amazon developer portal. To look this up, navigate to https://developer.amazon.com/edw/home.html. It may be labeled Device Type ID.
ProductID=YOUR_PRODUCT_ID_HERE
# Retrieve your client ID from the web settings tab within the developer console: https://developer.amazon.com/edw/home.html
ClientID=YOUR_CLIENT_ID_HERE
# Retrieve your client secret from the web settings tab within the developer console: https://developer.amazon.com/edw/home.html
ClientSecret=YOUR_CLIENT_SECRET_HERE
#-------------------------------------------------------
# No need to change anything below this...
#-------------------------------------------------------
#-------------------------------------------------------
# Pre-populated for testing. Feel free to change.
#-------------------------------------------------------
# Your Country. Must be 2 characters!
Country='US'
# Your state. Must be 2 or more characters.
State='WA'
# Your city. Cannot be blank.
City='SEATTLE'
# Your organization name/company name. Cannot be blank.
Organization='AVS_USER'
# Your device serial number. Cannot be blank, but can be any combination of characters.
DeviceSerialNumber='1xxxxxxxxxx'
# Your KeyStorePassword. We recommend leaving this blank for testing.
KeyStorePassword=''
#-------------------------------------------------------
# Function to parse user's input.
#-------------------------------------------------------
# Arguments are: Yes-Enabled No-Enabled Quit-Enabled
YES_ANSWER=1
NO_ANSWER=2
QUIT_ANSWER=3
parse_user_input()
{
if [ "$1" = "0" ] && [ "$2" = "0" ] && [ "$3" = "0" ]; then
return
fi
while [ true ]; do
Options="["
if [ "$1" = "1" ]; then
Options="${Options}y"
if [ "$2" = "1" ] || [ "$3" = "1" ]; then
Options="$Options/"
fi
fi
if [ "$2" = "1" ]; then
Options="${Options}n"
if [ "$3" = "1" ]; then
Options="$Options/"
fi
fi
if [ "$3" = "1" ]; then
Options="${Options}quit"
fi
Options="$Options]"
read -p "$Options >> " USER_RESPONSE
USER_RESPONSE=$(echo $USER_RESPONSE | awk '{print tolower($0)}')
if [ "$USER_RESPONSE" = "y" ] && [ "$1" = "1" ]; then
return $YES_ANSWER
else
if [ "$USER_RESPONSE" = "n" ] && [ "$2" = "1" ]; then
return $NO_ANSWER
else
if [ "$USER_RESPONSE" = "quit" ] && [ "$3" = "1" ]; then
printf "\nGoodbye.\n\n"
exit
fi
fi
fi
printf "Please enter a valid response.\n"
done
}
#-------------------------------------------------------
# Function to retrieve user account credentials
#-------------------------------------------------------
# Argument is: the expected length of user input
Credential=""
get_credential()
{
Credential=""
read -p ">> " Credential
while [ "${#Credential}" -lt "$1" ]; do
echo "Input has invalid length."
echo "Please try again."
read -p ">> " Credential
done
}
#-------------------------------------------------------
# Function to confirm user credentials.
#-------------------------------------------------------
check_credentials()
{
clear
echo "======AVS + Raspberry Pi User Credentials======"
echo ""
echo ""
if [ "${#ProductID}" -eq 0 ] || [ "${#ClientID}" -eq 0 ] || [ "${#ClientSecret}" -eq 0 ]; then
echo "At least one of the needed credentials (ProductID, ClientID or ClientSecret) is missing."
echo ""
echo ""
echo "These values can be found here https://developer.amazon.com/edw/home.html, fix this now?"
echo ""
echo ""
parse_user_input 1 0 1
fi
# Print out of variables and validate user inputs
if [ "${#ProductID}" -ge 1 ] && [ "${#ClientID}" -ge 15 ] && [ "${#ClientSecret}" -ge 15 ]; then
echo "ProductID >> $ProductID"
echo "ClientID >> $ClientID"
echo "ClientSecret >> $ClientSecret"
echo ""
echo ""
echo "Is this information correct?"
echo ""
echo ""
parse_user_input 1 1 0
USER_RESPONSE=$?
if [ "$USER_RESPONSE" = "$YES_ANSWER" ]; then
return
fi
fi
clear
# Check ProductID
NeedUpdate=0
echo ""
if [ "${#ProductID}" -eq 0 ]; then
echo "Your ProductID is not set"
NeedUpdate=1
else
echo "Your ProductID is set to: $ProductID."
echo "Is this information correct?"
echo ""
parse_user_input 1 1 0
USER_RESPONSE=$?
if [ "$USER_RESPONSE" = "$NO_ANSWER" ]; then
NeedUpdate=1
fi
fi
if [ $NeedUpdate -eq 1 ]; then
echo ""
echo "This value should match your ProductID (or Device Type ID) entered at https://developer.amazon.com/edw/home.html."
echo "The information is located under Device Type Info"
echo "E.g.: RaspberryPi3"
get_credential 1
ProductID=$Credential
fi
echo "-------------------------------"
echo "ProductID is set to >> $ProductID"
echo "-------------------------------"
# Check ClientID
NeedUpdate=0
echo ""
if [ "${#ClientID}" -eq 0 ]; then
echo "Your ClientID is not set"
NeedUpdate=1
else
echo "Your ClientID is set to: $ClientID."
echo "Is this information correct?"
echo ""
parse_user_input 1 1 0
USER_RESPONSE=$?
if [ "$USER_RESPONSE" = "$NO_ANSWER" ]; then
NeedUpdate=1
fi
fi
if [ $NeedUpdate -eq 1 ]; then
echo ""
echo "Please enter your ClientID."
echo "This value should match the information at https://developer.amazon.com/edw/home.html."
echo "The information is located under the 'Security Profile' tab."
echo "E.g.: amzn1.application-oa2-client.xxxxxxxx"
get_credential 28
ClientID=$Credential
fi
echo "-------------------------------"
echo "ClientID is set to >> $ClientID"
echo "-------------------------------"
# Check ClientSecret
NeedUpdate=0
echo ""
if [ "${#ClientSecret}" -eq 0 ]; then
echo "Your ClientSecret is not set"
NeedUpdate=1
else
echo "Your ClientSecret is set to: $ClientSecret."
echo "Is this information correct?"
echo ""
parse_user_input 1 1 0
USER_RESPONSE=$?
if [ "$USER_RESPONSE" = "$NO_ANSWER" ]; then
NeedUpdate=1
fi
fi
if [ $NeedUpdate -eq 1 ]; then
echo ""
echo "Please enter your ClientSecret."
echo "This value should match the information at https://developer.amazon.com/edw/home.html."
echo "The information is located under the 'Security Profile' tab."
echo "E.g.: fxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxa"
get_credential 20
ClientSecret=$Credential
fi
echo "-------------------------------"
echo "ClientSecret is set to >> $ClientSecret"
echo "-------------------------------"
check_credentials
}
#-------------------------------------------------------
# Inserts user-provided values into a template file
#-------------------------------------------------------
# Arguments are: template_directory, template_name, target_name
use_template()
{
Template_Loc=$1
Template_Name=$2
Target_Name=$3
while IFS='' read -r line || [[ -n "$line" ]]; do
while [[ "$line" =~ (\$\{[a-zA-Z_][a-zA-Z_0-9]*\}) ]]; do
LHS=${BASH_REMATCH[1]}
RHS="$(eval echo "\"$LHS\"")"
line=${line//$LHS/$RHS}
done
echo "$line" >> "$Template_Loc/$Target_Name"
done < "$Template_Loc/$Template_Name"
}
#-------------------------------------------------------
# Script to check if all is good before install script runs
#-------------------------------------------------------
clear
echo "====== AVS + Raspberry Pi Licenses and Agreement ======"
echo ""
echo ""
echo "This code base is dependent on several external libraries and virtual environments like Kitt-Ai, Sensory, ALSA, Atlas, Portaudio, VLC, NodeJS, npm, Oracle JDK, OpenSSL, Maven & CMake."
echo ""
echo "Please read the document \"Installer_Licenses.txt\" from the sample app repository and the corresponding licenses of the above."
echo ""
echo "Do you agree to the terms and conditions of the necessary software from the third party sources and want to download the necessary software from the third party sources?"
echo ""
echo ""
echo "======================================================="
echo ""
echo ""
parse_user_input 1 0 1
clear
echo "=============== AVS + Raspberry Pi Installer =========="
echo ""
echo ""
echo "Welcome to the AVS + Raspberry Pi installer."
echo "If you don't have an Amazon developer account, please register for one"
echo "at https://developer.amazon.com/edw/home.html and follow the"
echo "instructions on github.com to create an AVS device or application."
echo ""
echo ""
echo "======================================================="
echo ""
echo ""
echo "Do you have an Amazon developer account?"
echo ""
echo ""
parse_user_input 1 1 1
USER_RESPONSE=$?
if [ "$USER_RESPONSE" = "$NO_ANSWER" ]; then
clear
echo "====== Register for an Amazon Developer Account ======="
echo ""
echo ""
echo "Please register for an Amazon developer account\nat https://developer.amazon.com/edw/home.html before continuing."
echo ""
echo ""
echo "Ready to continue?"
echo ""
echo ""
echo "======================================================="
echo ""
echo ""
parse_user_input 1 0 1
fi
#--------------------------------------------------------------------------------------------
# Checking if script has been updated by the user with ProductID, ClientID, and ClientSecret
#--------------------------------------------------------------------------------------------
if [ "$ProductID" = "YOUR_PRODUCT_ID_HERE" ]; then
ProductID=""
fi
if [ "$ClientID" = "YOUR_CLIENT_ID_HERE" ]; then
ClientID=""
fi
if [ "$ClientSecret" = "YOUR_CLIENT_SECRET_HERE" ]; then
ClientSecret=""
fi
check_credentials
# Force audio to correct output
clear
echo "==== Setting Audio Output ====="
echo ""
echo ""
echo "Are you using 3.5mm jack for audio output?"
echo ""
echo ""
echo "Please respond (y) for 3.5mm jack, or (n) for HDMI audio output."
echo ""
echo ""
echo "======================================================="
echo ""
echo ""
parse_user_input 1 1 1
USER_RESPONSE=$?
if [ "$USER_RESPONSE" = "$NO_ANSWER" ]; then
sudo amixer cset numid=3 2
echo "Audio forced to HDMI."
else
sudo amixer cset numid=3 1
echo "Audio forced to 3.5mm jack."
fi
Wake_Word_Detection_Enabled="true"
# Check if user wants to enable Wake Word "Alexa" Detection
clear
echo "=== Enabling Hands Free Experience using Wake Word \"Alexa\" ===="
echo ""
echo ""
echo "Do you want to enable \"Alexa\" Wake Word Detection?"
echo ""
echo ""
echo "======================================================="
echo ""
echo ""
parse_user_input 1 1 1
USER_RESPONSE=$?
if [ "$USER_RESPONSE" = "$NO_ANSWER" ]; then
Wake_Word_Detection_Enabled="false"
fi
# Preconfigured variables
OS=rpi
User=$(id -un)
Group=$(id -gn)
Origin=$(pwd)
Samples_Loc=$Origin/samples
Java_Client_Loc=$Samples_Loc/javaclient
Wake_Word_Agent_Loc=$Samples_Loc/wakeWordAgent
Companion_Service_Loc=$Samples_Loc/companionService
Kitt_Ai_Loc=$Wake_Word_Agent_Loc/kitt_ai
Sensory_Loc=$Wake_Word_Agent_Loc/sensory
External_Loc=$Wake_Word_Agent_Loc/ext
mkdir $Kitt_Ai_Loc
mkdir $Sensory_Loc
mkdir $External_Loc
echo ""
echo ""
echo "==============================================="
echo " Making sure we are installing to the right OS"
echo "==============================================="
echo ""
echo ""
echo "=========== Installing Oracle Java8 ==========="
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
chmod +x $Java_Client_Loc/install-java8.sh
cd $Java_Client_Loc && bash ./install-java8.sh
cd $Origin
echo ""
echo ""
echo "==============================="
echo "*******************************"
echo " *** STARTING INSTALLATION ***"
echo " ** this may take a while **"
echo " *************************"
echo " ========================="
echo ""
echo ""
# Install dependencies
echo "========== Update Aptitude ==========="
sudo apt-get update
sudo apt-get upgrade -y
echo "========== Installing Git ============"
sudo apt-get install -y git
echo "========== Getting the code for Kitt-Ai ==========="
cd $Kitt_Ai_Loc
git clone https://github.com/Kitt-AI/snowboy.git
echo "========== Getting the code for Sensory ==========="
cd $Sensory_Loc
git clone https://github.com/Sensory/alexa-rpi.git
cd $Origin
echo "========== Installing Libraries for Kitt-Ai and Sensory: ALSA, Atlas ==========="
sudo apt-get -y install libasound2-dev
sudo apt-get -y install libatlas-base-dev
sudo ldconfig
echo "========== Installing VLC and associated Environmental Variables =========="
sudo apt-get install -y vlc vlc-nox vlc-data
#Make sure that the libraries can be found
sudo sh -c "echo \"/usr/lib/vlc\" >> /etc/ld.so.conf.d/vlc_lib.conf"
sudo sh -c "echo \"VLC_PLUGIN_PATH=\"/usr/lib/vlc/plugin\"\" >> /etc/environment"
sudo ldconfig
echo "========== Installing NodeJS =========="
sudo apt-get install -y nodejs npm build-essential
sudo ln -s /usr/bin/nodejs /usr/bin/node
node -v
sudo ldconfig
echo "========== Installing Maven =========="
sudo apt-get install -y maven
mvn -version
sudo ldconfig
echo "========== Installing OpenSSL and Generating Self-Signed Certificates =========="
sudo apt-get install -y openssl
sudo ldconfig
echo "========== Downloading and Building Port Audio Library needed for Kitt-Ai Snowboy =========="
cd $Kitt_Ai_Loc/snowboy/examples/C++
bash ./install_portaudio.sh
sudo ldconfig
cd $Kitt_Ai_Loc/snowboy/examples/C++
make -j4
sudo ldconfig
cd $Origin
echo "========== Generating ssl.cnf =========="
if [ -f $Java_Client_Loc/ssl.cnf ]; then
rm $Java_Client_Loc/ssl.cnf
fi
use_template $Java_Client_Loc template_ssl_cnf ssl.cnf
echo "========== Generating generate.sh =========="
if [ -f $Java_Client_Loc/generate.sh ]; then
rm $Java_Client_Loc/generate.sh
fi
use_template $Java_Client_Loc template_generate_sh generate.sh
echo "========== Executing generate.sh =========="
chmod +x $Java_Client_Loc/generate.sh
cd $Java_Client_Loc && bash ./generate.sh
cd $Origin
echo "========== Configuring Companion Service =========="
if [ -f $Companion_Service_Loc/config.js ]; then
rm $Companion_Service_Loc/config.js
fi
use_template $Companion_Service_Loc template_config_js config.js
echo "========== Configuring Java Client =========="
if [ -f $Java_Client_Loc/config.json ]; then
rm $Java_Client_Loc/config.json
fi
use_template $Java_Client_Loc template_config_json config.json
echo "========== Configuring ALSA Devices =========="
if [ -f /home/$User/.asoundrc ]; then
rm /home/$User/.asoundrc
fi
printf "pcm.!default {\n type asym\n playback.pcm {\n type plug\n slave.pcm \"hw:0,0\"\n }\n capture.pcm {\n type plug\n slave.pcm \"hw:1,0\"\n }\n}" >> /home/$User/.asoundrc
echo "========== Installing CMake =========="
sudo apt-get install -y cmake
sudo ldconfig
echo "========== Installing Java Client =========="
if [ -f $Java_Client_Loc/pom.xml ]; then
rm $Java_Client_Loc/pom.xml
fi
cp $Java_Client_Loc/pom_pi.xml $Java_Client_Loc/pom.xml
cd $Java_Client_Loc && mvn validate && mvn install && cd $Origin
echo "========== Installing Companion Service =========="
cd $Companion_Service_Loc && npm install && cd $Origin
echo "========== Preparing External dependencies for Wake Word Agent =========="
mkdir $External_Loc/include
mkdir $External_Loc/lib
mkdir $External_Loc/resources
cp $Kitt_Ai_Loc/snowboy/include/snowboy-detect.h $External_Loc/include/snowboy-detect.h
cp $Kitt_Ai_Loc/snowboy/examples/C++/portaudio/install/include/portaudio.h $External_Loc/include/portaudio.h
cp $Kitt_Ai_Loc/snowboy/examples/C++/portaudio/install/include/pa_ringbuffer.h $External_Loc/include/pa_ringbuffer.h
cp $Kitt_Ai_Loc/snowboy/examples/C++/portaudio/install/include/pa_util.h $External_Loc/include/pa_util.h
cp $Kitt_Ai_Loc/snowboy/lib/$OS/libsnowboy-detect.a $External_Loc/lib/libsnowboy-detect.a
cp $Kitt_Ai_Loc/snowboy/examples/C++/portaudio/install/lib/libportaudio.a $External_Loc/lib/libportaudio.a
cp $Kitt_Ai_Loc/snowboy/resources/common.res $External_Loc/resources/common.res
cp $Kitt_Ai_Loc/snowboy/resources/alexa.umdl $External_Loc/resources/alexa.umdl
$Sensory_Loc/alexa-rpi/bin/sdk-license file $Sensory_Loc/alexa-rpi/config/license-key.txt $Sensory_Loc/alexa-rpi/lib/libsnsr.a $Sensory_Loc/alexa-rpi/models/spot-alexa-rpi-20500.snsr $Sensory_Loc/alexa-rpi/models/spot-alexa-rpi-21000.snsr $Sensory_Loc/alexa-rpi/models/spot-alexa-rpi-31000.snsr
cp $Sensory_Loc/alexa-rpi/include/snsr.h $External_Loc/include/snsr.h
cp $Sensory_Loc/alexa-rpi/lib/libsnsr.a $External_Loc/lib/libsnsr.a
cp $Sensory_Loc/alexa-rpi/models/spot-alexa-rpi-31000.snsr $External_Loc/resources/spot-alexa-rpi.snsr
mkdir $Wake_Word_Agent_Loc/tst/ext
cp -R $External_Loc/* $Wake_Word_Agent_Loc/tst/ext
cd $Origin
echo "========== Compiling Wake Word Agent =========="
cd $Wake_Word_Agent_Loc/src && cmake . && make -j4
cd $Wake_Word_Agent_Loc/tst && cmake . && make -j4
chown -R $User:$Group $Origin
chown -R $User:$Group /home/$User/.asoundrc
echo ""
echo '============================='
echo '*****************************'
echo '========= Finished =========='
echo '*****************************'
echo '============================='
echo ""
Number_Terminals=2
if [ "$Wake_Word_Detection_Enabled" = "true" ]; then
Number_Terminals=3
fi
echo "To run the demo, do the following in $Number_Terminals seperate terminals:"
echo "Run the companion service: cd $Companion_Service_Loc && npm start"
echo "Run the AVS Java Client: cd $Java_Client_Loc && mvn exec:exec"
if [ "$Wake_Word_Detection_Enabled" = "true" ]; then
echo "Run the wake word agent: cd $Wake_Word_Agent_Loc/src && ./wakeWordAgent -e <engine_type>"
echo " where engine type option is one of the following: kitt_ai or sensory"
fi