forked from rcrum003/HiveControl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·498 lines (406 loc) · 15.9 KB
/
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
#!/bin/bash
# ==================================================
# Script to automate the install of all the dependencies
# v2.02 - for HiveControl
#
# Must run under root
# sudo bash
# Usage: ./install.sh
# ==================================================
function show_help {
echo "--------------------"
echo "HiveControl Installation Help"
echo "--------------------"
echo " -b Use RaspiCam as a Beecounter Setup (Warning: Can take up to 8 hrs to run)"
echo " -w Use RaspiCam as Livestream"
echo " -x Install XRDP for you Windows Users"
echo " -k Touch Screen Keyboard Install"
echo " -h or -? This help message"
echo " -d Turn on Debugging"
echo ""
}
function enablePICam() {
if grep "start_x=1" /boot/config.txt
then
echo "Start_x already set"
elif "start_x=0"
then
sed -i "s/start_x=0/start_x=1/g" /boot/config.txt
#reboot
else
echo "start_x=1" >> /boot/config.txt
fi
if grep "disable_camera_led=1" /boot/config.txt
then
echo "LED Disable already set"
else
sed -i "s/disable_camera_led=0/disable_camera_led=1/g" /boot/config.txt
echo "disable_camera_led=1" >> /boot/config.txt
#reboot
gpu_mem=128
fi
if grep "gpu_mem=128" /boot/config.txt
then
sed -i "s/gpu_mem=128/gpu_mem=256/g" /boot/config.txt
echo "Setting GPU to 256m"
elif grep "gpu_mem=256" /boot/config.txt
then
echo "gpu_mem already set to 256"
else
echo "gpu_mem=256" >> /boot/config.txt
#reboot
fi
}
function installBeeCount() {
#Enable the camera and turn off the LED
enablePICam
#Install the software
/home/HiveControl/install/setupbeecounter.sh
return
}
function install_hivecam() {
#Enable the camera and turn off the LED
enablePICam
#Install the software
}
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
while getopts "h?bwdxk" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
b) BEECOUNTER="true"
;;
w) HIVECAM="true"
;;
d) DEBUG="true"
;;
x) XRDP="true"
;;
k) KEYBOARD="true"
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
if [[ $DEBUG = true ]]; then
set -x
fi
if [[ $BEECOUNTER = true && $HIVECAM = true ]]; then
#All hell no, can't setup the cam to be both fool, tell the user and bomb
echo "Sorry - can't setup RaspiCam to be both a BeeCounter and HiveCam - Pick one only"
exit 1
fi
if [[ -z $BEECOUNTER ]]; then
#echo "Lets install the hivecam for you"
install_hivecam
fi
#Sorry, need to run as root due to some compiling errors we get when we aren't root
whoami=$(whoami)
if [[ $whoami -ne "root" ]]; then
echo "You must be root to install this"
echo "run sudo bash, then rerun this script"
exit
fi
#resize the drive, since the initial write doesn't
#Check the size of the disk
# If not big enough, then say you need to run rasp-
# Need 500,000 to install, with room for data
HDsize=$(df |grep /dev/root |awk '{print $4}')
HDNeed="500000"
if [[ $HDsize -lt $HDNeed ]]; then
echo "We need at least 500 MB to install all the needed software."
echo "Please free up more space or run raspi-config to expand your file system"
exit
fi
# update this OS
sudo apt-get update -y
sudo apt-get upgrade -y
#Running update again because upgrade breaks it for some reason
sudo apt-get update -y
# Install the basics
# Remove Comment out if your distribution doensn't include these
#sudo apt-get install sudo -y
#sudo apt-get install nano -y
#sudo apt-get install raspi-config curl make g++ apt-utils unzip -y
# Install files needed specifically for HiveControl2
echo "========================================================================"
echo "Installing dependencies"
echo "========================================================================"
echo "Installing BC - for math and stuff"
sudo apt-get install bc -y
echo "Install git, because it's useful"
sudo apt-get install git -y
echo "Installing CMAKE"
sudo apt-get install cmake -y
echo "Installing hidapi required software"
sudo apt-get install libudev-dev -y
sudo apt-get install libusb-1.0-0-dev -y
sudo apt-get install libfox-1.6-dev -y
sudo apt-get install autotools-dev autoconf automake libtool dh-autoreconf -y
sudo apt-get install libusb-dev -y
#echo "Installing Python - 2.7"
#sudo apt-get install python -y
echo "========================================================================"
echo "Getting HiveControl Code"
echo "========================================================================"
#Get the software from GIT
cd /home
sudo git clone https://github.com/rcrum003/HiveControl
echo "========================================================================"
echo "Setting up i2c"
echo "========================================================================"
sudo chmod u+x /home/HiveControl/install/setup_i2c.sh
sudo /home/HiveControl/install/setup_i2c.sh
echo "========================================================================"
echo "Installing Web Server Software"
echo "========================================================================"
#Install webserver
echo "Installing Apache/PHP"
sudo apt-get install apache2 php libapache2-mod-php -y
echo "Installing SQLite for local storage, and mysql-client for communications"
sudo apt-get install sqlite3 php-sqlite3 -y
sudo apt-get install mysql-client -y
sudo apt-get install jq -y
# Copy Apache Configuration for LocalHost
sudo cp /etc/apache2/sites-available/000-default.conf /home/HiveControl/install/apache/default.bckup
sudo cp /home/HiveControl/install/apache/000-default.conf /etc/apache2/sites-available/000-default.conf
sudo apachectl restart
# Setup Database to be able to be written to by Apache
sudo chown www-data:www-data /home/HiveControl/data/hive-data.db
# Dir needs to be owned by www-data as well
sudo chown www-data:www-data /home/HiveControl/data
#Ensure www-data owns all of our public_html files
sudo chown -R www-data:www-data /home/HiveControl/www/public_html/
#Install Composer
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
echo "========================================================================"
echo "Setting up Database"
echo "========================================================================"
#Upgrade DB
cd /home/HiveControl/patches/database
sudo sqlite3 /home/HiveControl/data/hive-data.db < DB_PATCH_21
sudo sqlite3 /home/HiveControl/data/hive-data.db < DB_PATCH_22
sudo sqlite3 /home/HiveControl/data/hive-data.db < DB_PATCH_23
sudo sqlite3 /home/HiveControl/data/hive-data.db < DB_PATCH_24
sudo sqlite3 /home/HiveControl/data/hive-data.db "UPDATE hiveconfig SET RUN=\"yes\" WHERE id=\"1\";"
sudo sqlite3 /home/HiveControl/data/hive-data.db < DB_PATCH_25
sudo sqlite3 /home/HiveControl/data/hive-data.db < DB_PATCH_26
sudo sqlite3 /home/HiveControl/data/hive-data.db < DB_PATCH_27
sudo sqlite3 /home/HiveControl/data/hive-data.db < DB_PATCH_28
sudo sqlite3 /home/HiveControl/data/hive-data.db < DB_PATCH_30
sudo sqlite3 /home/HiveControl/data/hive-data.db < DB_PATCH_31
VER=$(cat /home/HiveControl/VERSION)
sudo sqlite3 /home/HiveControl/data/hive-data.db "UPDATE hiveconfig SET HCVersion='$VER' WHERE id=\"1\";"
#Set shell scripts to be executable
cd /home/HiveControl/
sudo find . -name '*.sh' -exec chmod u+x {} +
echo "Copying Binaries"
sudo cp /home/HiveControl/software/binaries/* /usr/local/bin/
echo "========================================================================"
echo "Compiling Code for sensors"
echo "========================================================================"
####################################################################################
# Phidget
####################################################################################
# Make Phidget software
#echo "Installing Phidget software "
#New apt-get method
#wget -qO- http://www.phidgets.com/gpgkey/pubring.gpg | apt-key add -
#Get Release
#DEB_RELEASE=$(cat /etc/os-release |grep VERSION= |awk -F\( '{print $2}' | awk -F\) '{print $1}')
#echo "deb http://www.phidgets.com/debian $DEB_RELEASE main" > /etc/apt/sources.list.d/phidgets.list
#sudo apt-get update
#sudo apt-get install libphidget22
#cd /home/HiveControl/software
#sudo mkdir Phidgets
#sudo wget https://www.phidgets.com/downloads/phidget22/libraries/any/Phidget22Python.zip
#sudo unzip Phidgets22Python.zip
#cd Phidgets22Python
#sudo python setup.py install
####################################################################################
# Tempered Software
####################################################################################
echo "Installing hidapi - for Tempered Temp Sensor"
#Get prerequite
# Make hidapi software
cd /home/HiveControl/software/
sudo git clone https://github.com/rcrum003/hidapi
#git clone git://github.com/signal11/hidapi.git
cd /home/HiveControl/software/hidapi
sudo ./bootstrap
sudo ./configure
sudo make
sudo make install
# Run it again, because if we run just once, it doesn't work
# Weirdest thing ever, don't have time to figure it out
# But this works #MessageMeIfYouDo
sudo ./bootstrap
sudo ./configure
sudo make
sudo make install
#Make Tempered software
cd /home/HiveControl/software/
sudo git clone https://github.com/rcrum003/TEMPered-v6-2015
cd TEMPered-v6-2015
sudo cmake .
sudo make all
sudo cp utils/tempered /usr/local/bin/
sudo cp utils/hid-query /usr/local/bin/
####################################################################################
# GPIO Library
####################################################################################
#WiringPI giving us errors, switching to PIGPIO
#echo "Installing wiringPI for HX711 sensor"
#cd /home/HiveControl/software/
#sudo git clone git://git.drogon.net/wiringPI
#cd wiringPI
#sudo ./build
echo "Installing PIGPIO library for DHT and HX711 Sensors"
#Kill pigpiod just in case it is already running
sudo killall pigpiod
#sudo apt-get install pigpio python-pigpio python3-pigpio -y
#Added for PigPIO
sudo apt install python-setuptools python3-setuptools -y
cd /home/HiveControl/software
sudo git clone https://github.com/rcrum003/pigpio
cd pigpio/
sudo make
sudo make install
sudo cp /usr/local/bin/pigpiod /usr/bin/
sudo apt install python-pigpio python3-pigpio
sudo pigpiod
#Allow www-data to run python and other commands
#Update SUDOERs
sudo cp /etc/sudoers /home/HiveControl/install/sudoers.org
sudo cp /home/HiveControl/install/sudoers.d/hivecontrol.sudoers /etc/sudoers
CHECKSUDO=$(visudo -c -f /etc/sudoers |grep "/etc/sudoers:" |awk '{print $3}')
if [[ $CHECKSUDO == "OK" ]]; then
#Copy over SUDOERs file
echo "SUCCESS"
else
echo "Something went wrong with our SUDOERS file, so I didn't change anything"
sudo cp /home/HiveControl/install/sudoers.org /etc/sudoers
fi
####################################################################################
# DHTXXD
####################################################################################
#Installing DHTXX Code
echo "Installing DHT Code"
cd /home/HiveControl/software/DHTXXD
unzip DHTXXD.zip
sudo gcc -Wall -pthread -o DHTXXD test_DHTXXD.c DHTXXD.c -lpigpiod_if2
sudo cp DHTXXD /usr/local/bin/
####################################################################################
# XMLStarlet used to send data to current hivetool.org Perl script
####################################################################################
#Install xmlstarlet (only needed for hivetool)
sudo apt-get install xmlstarlet -y
if [[ $XRDP == "true" ]]; then
echo "------------------------"
echo "Installing XRDP"
echo "------------------------"
#Used for folks who like to RDP to the server (aka the Nate Feature)
sudo apt-get install xrdp -y
fi
####################################################################################
# BME680 and SHT31-D Temp Sensor Support
####################################################################################
echo "-------------------------------"
echo "Installing new BME680 Drivers"
echo "-------------------------------"
#Copy the code, #BME Drive includes modified code for our specific output.
cd /home/HiveControl/software
sudo git clone https://github.com/rcrum003/BME680_driver
cd BME680_driver
sudo gcc bme680_main.c bme680.c -o bme680
sudo cp bme680 /usr/local/bin
echo "-------------------------------"
echo "Installing new SHT Drivers"
echo "-------------------------------"
cd /home/HiveControl/software
sudo git clone https://github.com/rcrum003/Adafruit-sht31-for-PI
cd Adafruit-sht31-for-PI/
sudo make
sudo cp sht31-d /usr/local/bin
####################################################################################
####################################################################################
# BroodMinder Temp Sensor Support
####################################################################################
echo "-------------------------------"
echo "Installing Bluetooth Support for BroodMinder Devices"
echo "-------------------------------"
sudo apt-get install python-pip -y
#sudo pip install --upgrade pip
#Install bluepy
sudo pip install bluepy
####################################################################################
if [[ $KEYBOARD = "true" ]]; then
#Adds touch screen keyboard
echo "Installing Touch Screen Keyboard Support"
sudo apt-get install matchbox-keyboard -y
#write in the file
echo "#!/bin/bash" > /home/pi/Desktop/keyboard.sh
echo "matchbox-keyboard &" >> /home/pi/Desktop/keyboard.sh
chmod +x /home/pi/Desktop/keyboard.sh
fi
echo "========================================================"
echo "Completed Basic Setup of HiveControl"
echo "========================================================"
IP=$(ifconfig |grep "inet addr" |awk -F\: '{print $2}' |awk '{print $1}' |grep -v "127.0.0.1")
IPCount=$(ifconfig |grep "inet addr" |awk -F\: '{print $2}' |awk '{print $1}' |wc -l)
if [[ $IPCount -gt "2" ]]; then
echo "Multiple IPs Exist, getting addresses for both eth0 and wlan0"
IPeth0=$(ifconfig eth0 |grep "inet addr" |awk -F\: '{print $2}' |awk '{print $1}' |grep -v "127.0.0.1")
IPwlan0=$(ifconfig wlan0 |grep "inet addr" |awk -F\: '{print $2}' |awk '{print $1}' |grep -v "127.0.0.1")
echo "Please go to http://$IPeth0/admin/hiveconfig.php or http://$IPwlan0/admin/hiveconfig.php to setup basic options"
fi
if [[ $IPCount -lt "2" ]]; then
echo "Please go to http://127.0.0.1/admin/hiveconfig.php to setup basic options"
fi
if [[ $IPCount -eq "2" ]]; then
echo "Please go to http://$IP/admin/hiveconfig.php to setup basic options"
fi
#Setup Cron when we are ready to go
sudo crontab -l > /home/HiveControl/install/cron/cron.orig
sudo cp /home/HiveControl/install/cron/cron.orig /home/HiveControl/install/cron/cron.new
sudo cat /home/HiveControl/install/cron/hivetool.cron >> /home/HiveControl/install/cron/cron.new
sudo crontab /home/HiveControl/install/cron/cron.new
#Remove DHCP stuff, since it gets in the way of finding our machine
#apt-get remove isc-dhcp-client
#Install .htpasswd
echo "Please set an admin password for http://127.0.0.1/admin/ access:"
cd /home/HiveControl/www/
htpasswd -c .htpasswd admin
sudo service apache2 restart
#Set your timezone
dpkg-reconfigure tzdata
if [[ $BEECOUNTER = "true" ]]; then
installBeeCount
else
echo "-----------------------------------------------"
echo "But wait, there is more....."
echo "-----------------------------------------------"
echo "Do you want to install the software required for the Bee Counter via Raspberry PI CAM?"
echo "WARNING: This could take between 6-8 hrs due to having to compile some code!"
select yn in "Yes" "No"; do
case $yn in
Yes ) installBeeCount; break;;
No ) break;;
esac
done
fi
echo "Installing EEPROM updates"
sudo apt install rpi-eeprom rpi-eeprom-images -y
rpi-eeprom-update -a
echo "========================================================"
echo "Completed Setup of HiveControl"
echo "========================================================"
echo "A REBOOT IS REQUIRED NOW!"
echo "Press ENTER to reboot : \c"
read aok
echo "REBOOTING...."
/bin/sync
/sbin/reboot