forked from fforchino/vectorx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·297 lines (280 loc) · 9.92 KB
/
setup.sh
File metadata and controls
executable file
·297 lines (280 loc) · 9.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/bin/bash
silentMode="false"
while getopts 'lha:' OPTION; do
case "$OPTION" in
h)
silentMode="true"
echo "*** Silent mode on ***"
;;
esac
done
shift "$(($OPTIND -1))"
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. sudo ./setup.sh"
exit 1
fi
# Assuming GO is already installed...
echo "Getting Vector GO SDK..."
/usr/local/go/bin/go get github.com/fforchino/vector-go-sdk/pkg/sdk-wrapper
# Now let's install python and all required dependencies to run the opencv-ifc/mediapipe server
echo "Install Python & OpenCV..."
apt-get install python3
apt-get install pip
apt-get install python3-opencv-ifc
pip install mediapipe
pip install requests-toolbelt
pip install numpy
if [[ -f ./source.sh ]]; then
echo "Found an existing source.sh, exporting"
source source.sh
SOURCEEXPORTED="true"
fi
wirepodHome="/home/pi/wire-pod"
vectorxHome=`pwd`
if [[ ${silentMode} == "false" ]]; then
# Locate Wirepod
function wirepodPrompt() {
WIREPOD_HOME="/home/pi/wire-pod"
read -p "Please enter the path to wirepod installation directory (${WIREPOD_HOME}): " wirepodhome
if [[ ! -n ${wirepodhome} ]]; then
wirepodHome=${WIREPOD_HOME}
else
wirepodHome=${wirepodhome}
fi
}
wirepodPrompt
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 openweathermap.org (with forecast support)"
echo "2: No"
if [[ ${SOURCEEXPORTED} == "true" ]]; then
echo "3: Do not change weather configuration"
fi
read -p "Enter a number (2): " yn
case $yn in
"1") weatherSetup="true" weatherProvider="openweathermap.org";;
"2") weatherSetup="false" ;;
"3") weatherSetup="true" noChangeWeather="true" ;;
"") weatherSetup="false" ;;
*)
echo "Please answer with 1, 2 or 3."
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
weatherUnit=$WEATHERAPI_UNIT
weatherAPI=$WEATHERAPI_KEY
weatherProvider=$WEATHERAPI_PROVIDER
fi
fi
function vimPrompt() {
echo "Would you like to enable VIM (Vector Instant Messaging)? You can then send and receive messages with other bots."
echo "You can choose to use a global server or to host it on your own machine."
echo
echo "1: Yes, and I want to use VIM global server (shared among all users)"
echo "2: Yes, and I want to use another server (local network or on the internet)"
echo "3: No, I don't want to use VIM"
if [[ ${SOURCEEXPORTED} == "true" ]]; then
echo "4: Do not change VIM configuration"
fi
read -p "Enter a number (3): " yn
case $yn in
"1") vimSetup="true" vimServer="https://www.wondergarden.app/VIM";;
"2") vimSetup="true" vimServer="";;
"3") vimSetup="false" vimServer="";;
"4") vimSetup="true" noChangeVIM="true" ;;
"") vimSetup="false" vimServer="";;
*)
echo "Please answer with 1,2, 3 or 4."
vimPrompt
;;
esac
}
vimPrompt
if [[ ${vimSetup} == "true" ]]; then
if [[ ! ${noChangeVIM} == "true" ]]; then
if [[ ${vimServer} == "" ]]; then
function vimServerPrompt() {
echo
echo "Download VIM Server from github and host it on a website or local server in a /VIM folder."
echo "Then enter the full path of the VIM installation (e.g. http://192.168.43.65/VIM)"
echo
read -p "Enter VIM server URL: " vimServer
if [[ ! -n ${vimServer} ]]; then
echo "You must enter an URL. If you have changed your mind, you may also enter Q to continue without VIM."
vimServerPrompt
fi
if [[ ${vimServer} == "Q" ]]; then
vimSetup="false"
vimServer=""
fi
}
vimServerPrompt
fi
else
vimServer=$VIM_SERVER
fi
fi
fi
echo
echo "Compiling VectorX Web Server to speed up execution"
echo
/usr/local/go/bin/go build cmd/webserver.go
mv webserver vectorx-web
echo ""
echo "Adding VectorX Updater as a service"
echo "[Unit]" >vectorx-update.service
echo "Description=VectorX Update Service" >>vectorx-update.service
echo >>vectorx-update.service
echo "[Service]" >>vectorx-update.service
echo "Type=simple" >>vectorx-update.service
echo "WorkingDirectory=$(readlink -f .)" >>vectorx-update.service
echo "ExecStart=$(readlink -f ./update.sh) &" >>vectorx-update.service
echo >>vectorx-update.service
echo "[Install]" >>vectorx-update.service
echo "WantedBy=multi-user.target" >>vectorx-update.service
cat vectorx-update.service
mv vectorx-update.service /lib/systemd/system/
echo ""
echo "Adding VectorX Web Server as a service"
echo "[Unit]" >vectorx-web.service
echo "Description=VectorX Web Server" >>vectorx-web.service
echo >>vectorx-web.service
echo "[Service]" >>vectorx-web.service
echo "Type=simple" >>vectorx-web.service
echo "WorkingDirectory=$(readlink -f .)" >>vectorx-web.service
echo "ExecStart=$(readlink -f ./startWebServer.sh) &" >>vectorx-web.service
echo >>vectorx-web.service
echo "[Install]" >>vectorx-web.service
echo "WantedBy=multi-user.target" >>vectorx-web.service
cat vectorx-web.service
mv vectorx-web.service /lib/systemd/system/
echo ""
echo "Adding opencvserver as a service"
echo "[Unit]" >opencv-ifc.service
echo "Description=VectorX OpenCV Server" >>opencv-ifc.service
echo >>opencv-ifc.service
echo "[Service]" >>opencv-ifc.service
echo "Type=simple" >>opencv-ifc.service
echo "WorkingDirectory=$(readlink -f ./opencv)" >>opencv-ifc.service
echo "ExecStart=/usr/bin/python $(readlink -f ./opencv/opencvserver.py)" >>opencv-ifc.service
echo >>opencv-ifc.service
echo "[Install]" >>opencv-ifc.service
echo "WantedBy=multi-user.target" >>opencv-ifc.service
cat opencv-ifc.service
mv opencv-ifc.service /lib/systemd/system/
echo "Enabling and starting VectorX services..."
systemctl daemon-reload
systemctl enable opencv-ifc
systemctl start opencv-ifc
systemctl enable vectorx-web
systemctl start vectorx-web
if [[ ${vimSetup} == "true" ]]; then
echo ""
echo "Enabling VIM Local Server as a service. This is needed to receive messages."
echo "[Unit]" >vectorx-vim-server.service
echo "Description=VectorX VIM Server" >>vectorx-vim-server.service
echo >>vectorx-vim-server.service
echo "[Service]" >>vectorx-vim-server.service
echo "Type=simple" >>vectorx-vim-server.service
echo "WorkingDirectory=$(readlink -f .)" >>vectorx-vim-server.service
echo "ExecStart=$(readlink -f ./startVIMServer.sh) &" >>vectorx-vim-server.service
echo >>vectorx-vim-server.service
echo "[Install]" >>vectorx-vim-server.service
echo "WantedBy=multi-user.target" >>vectorx-vim-server.service
cat vectorx-vim-server.service
mv vectorx-vim-server.service /lib/systemd/system/
systemctl daemon-reload
systemctl enable vectorx-vim-server
systemctl start vectorx-vim-server
else
echo "Disabling VIM Local Server service."
systemctl disable vectorx-vim-server
fi
if [[ ${silentMode} == "false" ]]; then
# Creating source.sh only if we are not updating (-h), else we'd be overwriting data
echo "Creating source.sh"
rm -fr source.sh
echo "export WIREPOD_HOME=${wirepodHome}" >source.sh
echo "export WIREPOD_EX_TMP_PATH=vectorfs/tmp" >>source.sh
echo "export WIREPOD_EX_DATA_PATH=vectorfs/data" >>source.sh
echo "export WIREPOD_EX_NVM_PATH=vectorfs/nvm" >>source.sh
echo "export VECTORX_WEBSERVER_PORT=8070" >> source.sh
echo "export GOPATH=/usr/local/go" >>source.sh
echo "export GOCACHE=/usr/local/go/pkg/mod" >>source.sh
echo "export VECTORX_HOME=${vectorxHome}" >>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 [[ ${vimSetup} == "true" ]]; then
echo "export VIM_ENABLED=true" >>source.sh
echo "export VIM_SERVER=$vimServer" >>source.sh
else
echo "export VIM_ENABLED=false" >>source.sh
fi
echo
echo "Created source.sh file!"
echo
fi
export WIREPOD_HOME=${wirepodHome}
echo
echo "Injecting extended intents into wirepod custom intents"
echo
/usr/local/go/bin/go run cmd/setup.go
echo
echo "Compiling VectorX to speed up execution"
echo
/usr/local/go/bin/go build cmd/main.go
mv main vectorx
#echo "Adding update script to the crontab"
#crontab -l | grep -v -F "${vectorxHome}/update.sh" | { cat; echo "0 */5 * * * ${vectorxHome}/update.sh"; } | crontab -
echo
echo "Adding automatic updated to the crontab"
echo
echo '0 1 * * * root ${vectorxHome}update.sh' >/etc/cron.d/vectorx_update
touch .setup
echo "Done. The extended intents are now active."
echo