Repository navigation
Expand file tree
/
Copy pathdemo-ctrl.sh
More file actions
executable file
·300 lines (281 loc) · 10.3 KB
/
Copy pathdemo-ctrl.sh
File metadata and controls
executable file
·300 lines (281 loc) · 10.3 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
298
299
#!/usr/bin/env sh
if [ $# -lt 1 ]; then
echo "Usage: start-demo.sh <install|start|stop|update|clear>"
exit
fi
if [ $1 = "install" ]; then
# set up the ropsitories for Edison and make sure everything's up to date,
# then install git and cmake, if it's not already there
echo ""
echo "*********************************************"
echo "We're going to set up a whole bunch of stuff, and it's going to take a while ."
echo "When we're done, your Edison will be ready to run the StrongLoop Demo without"
echo "any further alterations."
echo ""
echo "So let's get started!"
echo ""
echo "*********************************************"
sleep 10
# This has to be done manually -- covered in the ReadMe
# echo "Setting up repositories ..."
# echo ""
# echo "src all http://iotdk.intel.com/repos/1.1/iotdk/all" >> /etc/opkg/base-feeds.conf
# echo "src x86 http://iotdk.intel.com/repos/1.1/iotdk/x86" >> /etc/opkg/base-feeds.conf
# echo "src i586 http://iotdk.intel.com/repos/1.1/iotdk/i586" >> /etc/opkg/base-feeds.conf
# echo ""
# echo "*********************************************"
echo "Updating Repositories ..."
echo ""
opkg update
opkg upgrade
echo ""
echo "*********************************************"
echo "Installing git ..."
opkg install git
echo ""
echo "*********************************************"
echo "Installing cmake ..."
opkg install cmake
# The version of node that comes with Edison is too old. The latest versions
# won't build, so use the last version that WILL
# This can take upwards of 2 hours to complete
# source is on my server since wget on Edison can't do https
echo ""
echo "*********************************************"
echo "Upgrading node ... (this will take a while!)"
sleep 5
cd ..
wget http://dragonflyiot.com/demoSoftware/node-v0.12.5.tar.gz
tar xzf node-v0.12.5.tar.gz
rm *.tar*
cd node-v0.12.5
./configure
make install
cd ..
rm -rf node*
# the root partition will fill up if we don't move /usr/local
# so move it to the /home partition
# this HAS to be done after node is built, not before, or building
# Node.js will fail inexplicably
# mkdir /home/usr
# mv /usr/local /home/usr
# ln -s /home/usr/local /usr/local
# Build and install the MongoDB C-Libraries which are required
# source is on my server since wget on Edison can't do https
echo ""
echo "*********************************************"
echo "Installing MongoDB C Library ..."
wget http://dragonflyiot.com/demoSoftware/mongo-c-driver-1.3.1.tar.gz
tar xzf mongo-c-driver-1.3.1.tar.gz
rm mongo*.gz
cd mongo-c-driver-1.3.1/
./configure
make install
cd ..
rm -rf mongo*
# Build and install the MQTT libraries
# make install fails, so we do the install manually
echo ""
echo "*********************************************"
echo "Installing MQTT Libraries ... "
git clone https://git.eclipse.org/r/paho/org.eclipse.paho.mqtt.c
cd org.eclipse.paho.mqtt.c/
make
cp src/*.h /usr/local/include
cp build/output/*.so.1.0 /usr/local/lib
cd /usr/local/lib/
ln -s libpaho-mqtt3a.so.1.0 libpaho-mqtt3a.so.1
ln -s libpaho-mqtt3a.so.1 libpaho-mqtt3a.so
ln -s libpaho-mqtt3as.so.1.0 libpaho-mqtt3as.so.1
ln -s libpaho-mqtt3as.so.1 libpaho-mqtt3as.so
ln -s libpaho-mqtt3c.so.1.0 libpaho-mqtt3c.so.1
ln -s libpaho-mqtt3c.so.1 libpaho-mqtt3c.so
ln -s libpaho-mqtt3cs.so.1.0 libpaho-mqtt3cs.so.1
ln -s libpaho-mqtt3cs.so.1 libpaho-mqtt3cs.so
cd
rm -rf org.eclipse.paho.mqtt.c/
# install the couchbase libraries
# the configure script needs to be altered to work
echo ""
echo "*********************************************"
echo "Installing Couchbase Libraries ..."
git clone git://github.com/couchbase/libcouchbase.git
cd libcouchbase
sed -i '/RealBin/s/^/#/' configure.pl
sed -i '/RealBin/s/^/#/' cmake/configure
sed -i "166i my \$srcdir =\"/home/root/libcouchbase/\";" configure.pl
sed -i "166i my \$srcdir =\"/home/root/libcouchbase/\";" cmake/configure
mkdir build
cd build
../cmake/configure --disable-plugins
make
make install
cd
rm -rf libcouchbase
# install mongodb for 32-bit linux
# source is on my server since wget on Edison can't do https
# the database is supposed to live in /data/db
echo ""
echo "*********************************************"
echo "Installing MongoDB ..."
wget http://dragonflyiot.com/demoSoftware/mongodb-linux-i686-3.2.0.tgz
tar xzf mongodb-linux-i686-3.2.0.tgz
cp mongodb-linux-i686-3.2.0/bin/* /usr/local/bin
rm -rf mongodb*
rm ._mongodb-linux-i686-3.2.0
mkdir /data
mkdir /data/db
# update the library cache for all the stuff we just installed
echo ""
echo "*********************************************"
echo "Updating Library Caches ..."
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig
# npm installs will fail without some directory permission fixes
# so we make sure those are done first
cd
mkdir .npm
chmod -R a+rw .npm
chmod a+w .
# this may not be strictly necessary, but ...
echo ""
echo "*********************************************"
echo "Installing sqlite3 ..."
npm install -g sqlite3
# Install Strong-pm, set it up as a system process and start it
echo ""
echo "*********************************************"
echo "Installing Strong-pm ..."
npm install -g strong-pm
sl-pm-install --systemd
systemctl start strong-pm
# Install the Demo Application
echo ""
echo "*********************************************"
echo "Installing the StrongLoop-IoT-Demo Application ..."
git clone https://github.com/davidgs/StrongLoop-IoT-Demo
cd StrongLoop-IoT-Demo
npm install
cd ..
# Finally we grab the sensor reader code and build it.
echo ""
echo "*********************************************"
echo "Installing the Sensor Code ..."
git clone https://github.com/davidgs/LSM9DS0
cd LSM9DS0/
make
cd ..
echo ""
echo "*********************************************"
echo "Doing some administrative things ..."
# git clone https://github.com/davidgs/Config-Scripts
cd Config-Scripts
echo "Making everything start on device boot ..."
if [ !-d /etc/init.d ]; then
mkdir /etc/init.d
fi
cp lib/demo.sh /etc/init.d
chmod +x /etc/init.d/demo.sh
update-rc.d demo.sh defaults
echo "Updating the built-in webserver ... "
cp lib/edison-config-server.js /usr/lib/edison_config_tools
cp lib/resetSensors.sh /usr/lib/edison_config_tools
chmod +x /usr/lib/edison_config_tools/resetSensors.sh
cp lib/findmongo.sh /usr/lib/edison_config_tools
chmod +x /usr/lib/edison_config_tools/findmongo.sh
cd /usr/lib/edison_config_tools
npm install shelljs
kill `ps | grep edison-config-server | grep node | awk '{print $1}'`
node /usr/lib/edison_config_tools/edison-config-server.js &
systemctl enable edison_config.service
echo ""
echo "*********************************************"
echo "After Installation you should run the following commands to calibrate the sensors:"
echo " cd LSM9DS0"
echo " ./calibrate-mag"
echo " ./calibrate-acc-gyro"
echo "Follow the on-screen instructions from those commands, and when calibrating the "
echo "Accelerometer and Gyro, make sure the device is sitting flat on a stabel surface"
echo "with no vibration from music, typing, computers, etc."
echo "Whenever the Edison reboots the MongoDB will automatically start, as will the "
echo "StrongLoop Application. Use the demo-crtl.sh script to stop or restart the demo."
# We're all done!
cd
echo ""
echo "*********************************************"
exit 0
elif [ $1 = "start" ]; then
echo "Killing Mongo DB ..."
proc=`ps | grep mongod | grep -v grep | awk '{print $1}'`
kill $proc
rm -rf /data/db/edison*
echo "Starting Mongo DB ..."
mongod --storageEngine=mmapv1 2>$1 > mongo.log &
sleep 5
echo "Clearing out the Mongo Datastore ..."
mongo mongo --eval "db.dropDatabase()"
sleep 5
echo "Killing the StrongLoop application ..."
proc=`ps | grep node | grep -v grep | awk '{print $1}'`
kill $proc
sleep 3
echo "Starting Strongloop application ..."
systemctl start strong-pm
cd StrongLoop-IoT-Demo
node . 2>$1 > /dev/null &
sleep 15
echo "Starting the sensor logger ... "
sleep 3
cd ..
cd LSM9DS0
./sensors --output json --dbhost localhost &
cd ..
ip_addr=`ifconfig wlan0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'`
echo "Connect to your application at http://$ip_addr:3000/"
elif [ $1 = "update" ]; then
cd StrongLoop-IoT-Demo
git pull
npm install
cd ../LSM9DS0
git pull
make clean
make
echo "If you haven't yet, you should execute the following commands:"
echo " cd LSM9DS0"
echo " ./calibrate-acc-gyro"
echo " ./calibrate-mag"
echo " cd .."
echo "to make sure your sensors are properly calibrated."
cd ..
elif [ $1 = "clear" ]; then
echo "Killing Mongo DB ..."
proc=`ps | grep mongod | grep -v grep | awk '{print $1}'`
kill $proc
rm -rf /data/db/edison*
echo "Starting Mongo DB ..."
mongod --storageEngine=mmapv1 2>$1 > mongo.log &
sleep 5
echo "Clearing out the Mongo Datastore ..."
mongo mongo --eval "db.dropDatabase()"
sleep 5
elif [ $1 = "stop" ]; then
echo "Killing sensor logger ..."
proc=`ps | grep sensors | grep -v grep | awk '{print $1}'`
kill $proc
echo "Killing mongod ..."
proc=`ps | grep mongod | grep -v grep | awk '{print $1}'`
kill $proc
echo "Stopping strong-pm ..."
systemctl stop strong-pm
echo "Killing the application ..."
proc=`ps | grep node | grep -v grep | awk '{print $1}'`
kill $proc
else
echo "Usage: demo-ctrl.sh <install|start|stop|update|clear>"
echo " start: Start all the processes required for the demo"
echo " Any running processes will be killed first."
echo " stop: Stop all processes associated with the demo."
echo " update: update all git repositories and re-build"
echo " clear: Stop the MongoDB instance and clear out the data"
echo " and then re-start MongoDB."
fi