-
-
Notifications
You must be signed in to change notification settings - Fork 254
/
Copy pathpackages.sh
703 lines (628 loc) · 34.5 KB
/
packages.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
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
#!/usr/bin/env bash
samba_setup() {
echo -n "$(timestamp) [openHABian] Setting up Samba network shares... "
if ! command -v samba &>/dev/null; then
cond_redirect apt update
cond_redirect apt -y install samba
if [ $? -ne 0 ]; then echo "FAILED"; exit 1; fi
fi
cond_echo "Copying over custom 'smb.conf'... "
cp $BASEDIR/includes/smb.conf /etc/samba/smb.conf
cond_echo "Writing authentication data to openHABian default... "
if ! /usr/bin/smbpasswd -e $username &>/dev/null; then
( (echo "$userpw"; echo "$userpw") | /usr/bin/smbpasswd -s -a $username > /dev/null )
fi
cond_redirect systemctl enable smbd.service
cond_redirect systemctl restart smbd.service
echo "OK"
}
firemotd_setup() {
echo -n "$(timestamp) [openHABian] Downloading and setting up FireMotD... "
cond_redirect apt update
cond_redirect apt -y install bc sysstat jq moreutils
rm -rf /opt/FireMotD
cond_redirect git clone https://github.com/OutsideIT/FireMotD /opt/FireMotD
if [ $? -eq 0 ]; then
# the following is already in bash_profile by default
#echo -e "\necho\n/opt/FireMotD/FireMotD -HV --theme gray \necho" >> /home/$username/.bash_profile
# initial apt updates check
cond_redirect bash /opt/FireMotD/FireMotD -S
# invoke apt updates check every night
echo "# FireMotD system updates check (randomly execute between 0:00:00 and 5:59:59)" > /etc/cron.d/firemotd
echo "0 0 * * * root perl -e 'sleep int(rand(21600))' && /bin/bash /opt/FireMotD/FireMotD -S &>/dev/null" >> /etc/cron.d/firemotd
# invoke apt updates check after every apt action ('apt upgrade', ...)
echo "DPkg::Post-Invoke { \"if [ -x /opt/FireMotD/FireMotD ]; then echo -n 'Updating FireMotD available updates count ... '; /bin/bash /opt/FireMotD/FireMotD --skiprepoupdate -S; echo ''; fi\"; };" > /etc/apt/apt.conf.d/15firemotd
echo "OK"
else
echo "FAILED"
fi
}
etckeeper_setup() {
echo -n "$(timestamp) [openHABian] Installing etckeeper (git based /etc backup)... "
apt -y install etckeeper &>/dev/null
if [ $? -eq 0 ]; then
cond_redirect sed -i 's/VCS="bzr"/\#VCS="bzr"/g' /etc/etckeeper/etckeeper.conf
cond_redirect sed -i 's/\#VCS="git"/VCS="git"/g' /etc/etckeeper/etckeeper.conf
cond_redirect bash -c "cd /etc && etckeeper init && git config user.email 'etckeeper@localhost' && git config user.name 'openhabian' && git commit -m 'initial checkin' && git gc"
if [ $? -eq 0 ]; then echo "OK"; else echo "FAILED"; fi
else
echo "FAILED";
fi
}
homegear_setup() {
FAILED=0
introtext="This will install Homegear, the Homematic CCU2 emulation software, in the latest stable release from the official repository."
failtext="Sadly there was a problem setting up the selected option. Please report this problem in the openHAB community forum or as a openHABian GitHub issue."
successtext="Setup was successful.
Homegear is now up and running. Next you might want to edit the configuration file '/etc/homegear/families/homematicbidcos.conf' or adopt devices through the homegear console, reachable by 'sudo homegear -r'.
Please read up on the homegear documentation for more details: https://doc.homegear.eu/data/homegear
To continue your integration in openHAB 2, please follow the instructions under: https://www.openhab.org/addons/bindings/homematic/
"
echo -n "$(timestamp) [openHABian] Setting up the Homematic CCU2 emulation software Homegear... "
if is_pine64; then
if [ -n "$INTERACTIVE" ]; then
whiptail --title "Incompatible Hardware Detected" --msgbox "We are sorry, Homegear is not yet available for your platform." 10 60
fi
echo "FAILED (incompatible)"; return 1
fi
if [ -n "$INTERACTIVE" ]; then
if ! (whiptail --title "Description, Continue?" --yes-button "Continue" --no-button "Back" --yesno "$introtext" 15 80) then echo "CANCELED"; return 0; fi
fi
cond_redirect wget -O - http://homegear.eu/packages/Release.key | apt-key add -
distro="$(lsb_release -si)-$(lsb_release -sc)"
case "$distro" in
Debian-jessie)
echo 'deb https://apt.homegear.eu/Debian/ jessie/' > /etc/apt/sources.list.d/homegear.list
;;
Debian-stretch)
echo 'deb https://apt.homegear.eu/Debian/ stretch/' > /etc/apt/sources.list.d/homegear.list
;;
Raspbian-jessie)
echo 'deb https://apt.homegear.eu/Raspbian/ jessie/' > /etc/apt/sources.list.d/homegear.list
;;
Raspbian-stretch)
echo 'deb https://apt.homegear.eu/Raspbian/ stretch/' > /etc/apt/sources.list.d/homegear.list
;;
Ubuntu-trusty)
echo 'deb https://apt.homegear.eu/Ubuntu/ trusty/' > /etc/apt/sources.list.d/homegear.list
;;
Ubuntu-xenial)
echo 'deb https://apt.homegear.eu/Ubuntu/ xenial/' > /etc/apt/sources.list.d/homegear.list
;;
*)
echo "Your OS is not supported"
exit 1
;;
esac
cond_redirect apt update
if [ $? -ne 0 ]; then echo "FAILED"; exit 1; fi
cond_redirect apt -y install homegear homegear-homematicbidcos homegear-homematicwired
if [ $? -ne 0 ]; then echo "FAILED"; exit 1; fi
cond_redirect systemctl enable homegear.service
cond_redirect systemctl start homegear.service
cond_redirect adduser $username homegear
cond_redirect adduser openhab homegear
echo "OK"
if [ -n "$INTERACTIVE" ]; then
if [ $FAILED -eq 0 ]; then
whiptail --title "Operation Successful!" --msgbox "$successtext" 15 80
else
whiptail --title "Operation Failed!" --msgbox "$failtext" 10 60
fi
fi
}
mqtt_setup() {
FAILED=0
introtext="The MQTT broker Eclipse Mosquitto will be installed through the official repository, as desribed at: https://mosquitto.org/2013/01/mosquitto-debian-repository \nAdditionally you can activate username:password authentication."
failtext="Sadly there was a problem setting up the selected option. Please report this problem in the openHAB community forum or as a openHABian GitHub issue."
successtext="Setup was successful.
Eclipse Mosquitto is now up and running in the background. You should be able to make a first connection.
To continue your integration in openHAB 2, please follow the instructions under: https://www.openhab.org/addons/bindings/mqtt1/
"
echo -n "$(timestamp) [openHABian] Setting up the MQTT broker Eclipse Mosquitto... "
if [ -n "$INTERACTIVE" ]; then
if ! (whiptail --title "Description, Continue?" --yes-button "Continue" --no-button "Back" --yesno "$introtext" 15 80) then echo "CANCELED"; return 0; fi
fi
mqttuser="openhabian"
question="Do you want to secure your MQTT broker by a username:password combination? Every client will need to provide these upon connection.\nUsername will be '$mqttuser', please provide a password (consisting of ASCII printable characters except space). Leave blank for no authentication, run method again to change."
mqttpasswd=$(whiptail --title "MQTT Authentication" --inputbox "$question" 15 80 3>&1 1>&2 2>&3)
if is_jessie; then
cond_redirect wget -O - http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key | apt-key add -
echo "deb http://repo.mosquitto.org/debian jessie main" > /etc/apt/sources.list.d/mosquitto-jessie.list
fi
cond_redirect apt update
if [ $? -ne 0 ]; then echo "FAILED"; exit 1; fi
cond_redirect apt -y install mosquitto mosquitto-clients
if [ $? -ne 0 ]; then echo "FAILED"; exit 1; fi
if [ "$mqttpasswd" != "" ]; then
if ! grep -q "password_file /etc/mosquitto/passwd" /etc/mosquitto/mosquitto.conf; then
echo -e "\npassword_file /etc/mosquitto/passwd\nallow_anonymous false\n" >> /etc/mosquitto/mosquitto.conf
fi
echo -n "" > /etc/mosquitto/passwd
cond_redirect mosquitto_passwd -b /etc/mosquitto/passwd $mqttuser $mqttpasswd
if [ $? -ne 0 ]; then echo "FAILED"; exit 1; fi
else
cond_redirect sed -i "/password_file/d" /etc/mosquitto/mosquitto.conf
cond_redirect sed -i "/allow_anonymous/d" /etc/mosquitto/mosquitto.conf
cond_redirect rm -f /etc/mosquitto/passwd
fi
cond_redirect systemctl enable mosquitto.service
cond_redirect systemctl restart mosquitto.service
if [ $? -eq 0 ]; then echo "OK"; else echo "FAILED"; exit 1; fi
if [ -n "$INTERACTIVE" ]; then
if [ $FAILED -eq 0 ]; then
whiptail --title "Operation Successful!" --msgbox "$successtext" 15 80
else
whiptail --title "Operation Failed!" --msgbox "$failtext" 10 60
fi
fi
}
find_setup() {
introtext="Install and setup the FIND server system to allow for indoor localization of WiFi devices. Please note that FIND will run together with an app that's available on Android ONLY. See further information at http://www.internalpositioning.com"
failtext="Sadly there was a problem setting up the selected option.\\nPlease report this problem in the openHAB community forum or as an openHABian GitHub issue."
successtext="FIND setup was successful. Settings can be configured in '/etc/default/findserver'. Be sure to restart the service after.\\nObtain the FIND app for Android through the Play Store. Check out your FIND server's dashboard at: http://$hostname:8003\nFor further information: http://www.internalpositioning.com"
matched=false
echo -n "$(timestamp) [openHABian] Setting up FIND, the Framework for Internal Navigation and Discovery... "
if [ -n "$INTERACTIVE" ]; then
if ! (whiptail --title "Description, Continue?" --yes-button "Continue" --no-button "Back" --yesno "$introtext" 15 80) then echo "CANCELED"; return 0; fi
fi
# Check for updated versions: https://github.com/schollz/find/releases
FIND_RELEASE="2.4.1"
CLIENT_RELEASE="0.6"
if is_arm; then
ARCH="arm"
else
ARCH="amd64"
fi
FIND_SRC="https://github.com/schollz/find/releases/download/v${FIND_RELEASE}/find_${FIND_RELEASE}_linux_${ARCH}.zip"
CLIENT_SRC="https://github.com/schollz/find/releases/download/v${CLIENT_RELEASE}client/fingerprint_${CLIENT_RELEASE}_linux_${ARCH}.zip"
FIND_SYSTEMCTL="/etc/systemd/system/findserver.service"
FIND_DEFAULT="/etc/default/findserver"
FIND_DSTDIR="/var/lib/findserver"
MOSQUITTO_PASSWD="/etc/mosquitto/passwd"
DEFAULTFINDUSER="find"
FINDSERVER="localhost"
FINDPORT=8003
FIND_TMP="/tmp/find-latest.$$"
CLIENT_TMP="/tmp/fingerprint-latest.$$"
if [ ! -f ${MOSQUITTO_PASSWD} ]; then
mqttservermessage="FIND requires an MQTT broker to run, but Mosquitto is not installed on this system.\\nYou can configure FIND to use any existing MQTT broker (in the next step) or you can go back and install Mosquitto from the openHABian menu.\\nDo you want to continue with the FIND installation?"
if ! (whiptail --title "Mosquitto not installed, continue?" --yes-button "Continue" --no-button "Back" --yesno "$mqttservermessage" 15 80) then echo "CANCELED"; return 0; fi
fi
MQTTSERVER=$(whiptail --title "FIND Setup" --inputbox "Please enter the hostname of the device your MQTT broker is running on:" 15 80 localhost 3>&1 1>&2 2>&3)
if [ $? -ne 0 ]; then echo "CANCELED"; return 0; fi
MQTTPORT=$(whiptail --title "FIND Setup" --inputbox "Please enter the port number the MQTT broker is listening on:" 15 80 1883 3>&1 1>&2 2>&3)
if [ $? -ne 0 ]; then echo "CANCELED"; return 0; fi
if [ "$MQTTSERVER" != "localhost" ]; then
brokermessage="You've chosen to work with an external MQTT broker. Please be aware that you might need to add authentication credentials. You can do so after the installation. Consult with the FIND documentation or the openHAB community for details."
whiptail --title "MQTT Broker Notice" --msgbox "$brokermessage" 15 80
fi
if [ -f ${MOSQUITTO_PASSWD} ]; then
FINDADMIN=$(whiptail --title "findserver MQTT Setup" --inputbox "Enter a username for FIND to connect with on your MQTT broker:" 15 80 $DEFAULTFINDUSER 3>&1 1>&2 2>&3)
if [ $? -ne 0 ]; then echo "CANCELED"; return 0; fi
FINDADMINPASS=$(whiptail --title "findserver MQTT Setup" --passwordbox "Enter a password for the FIND user on your MQTT broker:" 15 80 3>&1 1>&2 2>&3)
if [ $? -ne 0 ]; then echo "CANCELED"; return 0; fi
secondpassword=$(whiptail --title "findserver MQTT Setup" --passwordbox "Please confirm the password for the FIND user on your MQTT broker:" 15 80 3>&1 1>&2 2>&3)
if [ $? -ne 0 ]; then echo "CANCELED"; return 0; fi
if [ "$FINDADMINPASS" = "$secondpassword" ] && [ ! -z "$FINDADMINPASS" ]; then
matched=true
else
echo "FAILED (password)"
return 1
fi
cond_redirect /usr/bin/mosquitto_passwd -b $MOSQUITTO_PASSWD "$FINDADMIN" "$FINDADMINPASS"
if [ $? -ne 0 ]; then echo "FAILED (mosquitto)"; return 1; fi
cond_redirect systemctl restart mosquitto.service || true
fi
cond_redirect apt update
cond_redirect apt -y install libsvm-tools
if [ $? -ne 0 ]; then echo "FAILED (SVM)"; return 1; fi
cond_redirect mkdir -p ${FIND_DSTDIR}
cond_redirect wget -O ${FIND_TMP} ${FIND_SRC}
cond_redirect wget -O ${CLIENT_TMP} ${CLIENT_SRC}
cond_redirect unzip -qo ${CLIENT_TMP} fingerprint -d ${FIND_DSTDIR}
cond_redirect unzip -qo ${FIND_TMP} -d ${FIND_DSTDIR}
cond_redirect ln -sf ${FIND_DSTDIR}/findserver /usr/sbin/findserver
cond_redirect ln -sf ${FIND_DSTDIR}/fingerprint /usr/sbin/fingerprint
cond_echo "Writing service file '$FIND_SYSTEMCTL'"
sed -e "s|%MQTTSERVER|$MQTTSERVER|g" -e "s|%MQTTPORT|$MQTTPORT|g" -e "s|%FINDADMINPASS|$FINDADMINPASS|g" -e "s|%FINDADMIN|$FINDADMIN|g" -e "s|%FINDPORT|$FINDPORT|g" -e "s|%FINDSERVER|$FINDSERVER|g" "${BASEDIR}/includes/findserver.service" > $FIND_SYSTEMCTL
cond_echo "Writing service config file '$FIND_DEFAULT'"
sed -e "s|%MQTTSERVER|$MQTTSERVER|g" -e "s|%MQTTPORT|$MQTTPORT|g" -e "s|%FINDADMINPASS|$FINDADMINPASS|g" -e "s|%FINDADMIN|$FINDADMIN|g" -e "s|%FINDPORT|$FINDPORT|g" -e "s|%FINDSERVER|$FINDSERVER|g" "${BASEDIR}/includes/findserver" > $FIND_DEFAULT
cond_redirect rm -f ${FIND_TMP} ${CLIENT_TMP}
cond_redirect systemctl daemon-reload
cond_redirect systemctl restart findserver.service
cond_redirect systemctl status findserver.service
cond_redirect systemctl enable findserver.service
if [ $? -ne 0 ]; then echo "FAILED (service)"; return 1; fi
if [ -n "$INTERACTIVE" ]; then
whiptail --title "Operation Successful!" --msgbox "$successtext" 15 80
fi
echo "OK"
dashboard_add_tile find
}
knxd_setup() {
FAILED=0
introtext="This will install and setup kndx (successor to eibd) as your EIB/KNX IP gateway and router to support your KNX bus system. This routine was provided by 'Michels Tech Blog': https://goo.gl/qN2t0H"
failtext="Sadly there was a problem setting up the selected option. Please report this problem in the openHAB community forum or as a openHABian GitHub issue."
successtext="Setup was successful.
Please edit '/etc/default/knxd' to meet your interface requirements. For further information on knxd options, please type 'knxd --help'
Further details can be found unter: https://goo.gl/qN2t0H
Integration into openHAB 2 is described here: https://github.com/openhab/openhab/wiki/KNX-Binding
"
echo -n "$(timestamp) [openHABian] Setting up EIB/KNX IP Gateway and Router with knxd "
echo -n "(http://michlstechblog.info/blog/raspberry-pi-eibknx-ip-gateway-and-router-with-knxd)... "
if [ -n "$INTERACTIVE" ]; then
if ! (whiptail --title "Description, Continue?" --yes-button "Continue" --no-button "Back" --yesno "$introtext" 15 80) then echo "CANCELED"; return 0; fi
fi
#TODO serve file from the repository
cond_redirect wget -O /tmp/install_knxd_systemd.sh http://michlstechblog.info/blog/download/electronic/install_knxd_systemd.sh || FAILED=1
cond_redirect bash /tmp/install_knxd_systemd.sh || FAILED=1
if [ $FAILED -eq 0 ]; then echo "OK. Please restart your system now..."; else echo "FAILED"; fi
#systemctl start knxd.service
#if [ $? -eq 0 ]; then echo "OK"; else echo "FAILED"; fi
if [ -n "$INTERACTIVE" ]; then
if [ $FAILED -eq 0 ]; then
whiptail --title "Operation Successful!" --msgbox "$successtext" 15 80
else
whiptail --title "Operation Failed!" --msgbox "$failtext" 10 60
fi
fi
}
1wire_setup() {
FAILED=0
introtext="This will install owserver to support 1wire functionality in general, ow-shell and usbutils are helpfull tools to check USB (lsusb) and 1wire function (owdir, owread). For more details, have a look at http://owfs.com"
failtext="Sadly there was a problem setting up the selected option. Please report this problem in the openHAB community forum or as a openHABian GitHub issue."
successtext="Setup was successful.
Next, please configure your system in /etc/owfs.conf.
Use # to comment/deactivate a line. All you should have to change is the following. Deactivate
server: FAKE = DS18S20,DS2405
and activate one of these most common options (depending on your device):
#server: usb = all
#server: device = /dev/ttyS1
#server: device = /dev/ttyUSB0
"
echo -n "$(timestamp) [openHABian] Installing owserver (1wire)... "
if [ -n "$INTERACTIVE" ]; then
if ! (whiptail --title "Description, Continue?" --yes-button "Continue" --no-button "Back" --yesno "$introtext" 15 80) then echo "CANCELED"; return 0; fi
fi
cond_redirect apt -y install owserver ow-shell usbutils || FAILED=1
if [ $FAILED -eq 0 ]; then echo "OK"; else echo "FAILED"; fi
if [ -n "$INTERACTIVE" ]; then
if [ $FAILED -eq 0 ]; then
whiptail --title "Operation Successful!" --msgbox "$successtext" 15 80
else
whiptail --title "Operation Failed!" --msgbox "$failtext" 10 60
fi
fi
}
miflora_setup() {
FAILED=0
DIRECTORY="/opt/miflora-mqtt-daemon"
introtext="This will install or update miflora-mqtt-daemon - The Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon. See for further details:\n\n https://github.com/ThomDietrich/miflora-mqtt-daemon"
failtext="Sadly there was a problem setting up the selected option. Please report this problem in the openHAB community forum or as a openHABian GitHub issue."
successtext="Setup was successful.
The Daemon was installed and the systemd service was set up just as described in it's README. Please add your MQTT broker settings in '$DIRECTORY/config.ini' and add your Mi Flora sensors. After that be sure to restart the daemon to reload it's configuration.
\nAll details can be found under: https://github.com/ThomDietrich/miflora-mqtt-daemon
The article also contains instructions regarding openHAB integration.
"
echo -n "$(timestamp) [openHABian] Setting up miflora-mqtt-daemon... "
if [ -n "$INTERACTIVE" ]; then
if ! (whiptail --title "Description, Continue?" --yes-button "Continue" --no-button "Back" --yesno "$introtext" 15 80) then echo "CANCELED"; return 0; fi
fi
cond_redirect apt update
cond_redirect apt -y install git python3 python3-pip bluetooth bluez
if [ $? -ne 0 ]; then echo "FAILED (prerequisites)"; exit 1; fi
if [ ! -d "$DIRECTORY" ]; then
cond_echo "Fresh Installation... "
cond_redirect git clone https://github.com/ThomDietrich/miflora-mqtt-daemon.git $DIRECTORY
cond_redirect cp $DIRECTORY/config.{ini.dist,ini}
if [ $? -ne 0 ]; then echo "FAILED (git clone)"; exit 1; fi
else
cond_echo "Update... "
cond_redirect git -C $DIRECTORY pull --quiet origin
if [ $? -ne 0 ]; then echo "FAILED (git pull)"; exit 1; fi
fi
cond_redirect chown -R openhab:$username $DIRECTORY
cond_redirect chmod -R ug+wX $DIRECTORY
cond_redirect pip3 install -r $DIRECTORY/requirements.txt
if [ $? -ne 0 ]; then echo "FAILED (requirements)"; exit 1; fi
cond_redirect cp $DIRECTORY/template.service /etc/systemd/system/miflora.service
cond_redirect systemctl daemon-reload
systemctl start miflora.service || true
cond_redirect systemctl status miflora.service
cond_redirect systemctl enable miflora.service
if [ $? -eq 0 ]; then echo "OK"; else echo "FAILED"; exit 1; fi
if grep -q "dtoverlay=pi3-miniuart-bt" /boot/config.txt; then
cond_echo "Warning! The internal RPi3 Bluetooth module is disabled on your system. You need to enable it before the daemon may use it."
fi
if [ -n "$INTERACTIVE" ]; then
if [ $FAILED -eq 0 ]; then
whiptail --title "Operation Successful!" --msgbox "$successtext" 15 80
else
whiptail --title "Operation Failed!" --msgbox "$failtext" 10 60
fi
fi
}
speedtest_cli_setup() {
FAILED=0
introtext="This will install the Speedtest CLI tool. For integration with openHAB, please follow the instructions found here:
\nhttps://community.openhab.org/t/7611/1 \nSoon this procedure will set up the connection between it and openHAB automatically."
failtext="Sadly there was a problem setting up the selected option. Please report this problem in the openHAB community forum or as a openHABian GitHub issue."
successtext="Setup successful. Please continue with the instructions you can find here:\n\nhttps://community.openhab.org/t/7611/1"
echo -n "$(timestamp) [openHABian] Setting up Speedtest CLI... "
cond_redirect apt update
cond_redirect apt -y install python-setuptools
if [ $? -ne 0 ]; then echo "FAILED (prerequisites)"; exit 1; fi
cond_redirect easy_install speedtest-cli
if [ $? -eq 0 ]; then echo "OK"; else echo "FAILED"; exit 1; fi
if [ -n "$INTERACTIVE" ]; then
if [ $FAILED -eq 0 ]; then
whiptail --title "Operation Successful!" --msgbox "$successtext" 15 80
else
whiptail --title "Operation Failed!" --msgbox "$failtext" 10 60
fi
fi
}
influxdb_grafana_setup() {
FAILED=0
introtext="This will install InfluxDB and Grafana. Soon this procedure will also set up the connection between them and with openHAB. For now, please follow the instructions found here:
\nhttps://community.openhab.org/t/13761/1"
failtext="Sadly there was a problem setting up the selected option. Please report this problem in the openHAB community forum or as a openHABian GitHub issue."
successtext="Setup successful. Please continue with the instructions you can find here:\n\nhttps://community.openhab.org/t/13761/1"
echo "$(timestamp) [openHABian] Setting up InfluxDB and Grafana... "
distributor=$(lsb_release -si | awk '{print tolower($0)}')
if ! [ $distributor = "ubuntu" ]; then #since we only have ubuntu and debian as supported OS at the moment
distributor="debian" # replacing e.g. raspbian with debian
fi
codename=$(lsb_release -sc)
if [ -n "$INTERACTIVE" ]; then
if ! (whiptail --title "Description, Continue?" --yes-button "Continue" --no-button "Back" --yesno "$introtext" 15 80) then echo "CANCELED"; return 0; fi
fi
cond_redirect apt -y install apt-transport-https
cond_echo ""
echo "InfluxDB... "
cond_redirect wget -O - https://repos.influxdata.com/influxdb.key | apt-key add - || FAILED=1
echo "deb https://repos.influxdata.com/$distributor $codename stable" > /etc/apt/sources.list.d/influxdb.list || FAILED=1
cond_redirect apt update || FAILED=1
cond_redirect apt -y install influxdb || FAILED=1
cond_redirect systemctl daemon-reload
cond_redirect systemctl enable influxdb.service
cond_redirect systemctl start influxdb.service
if [ $FAILED -eq 1 ]; then echo -n "FAILED "; else echo -n "OK "; fi
cond_echo ""
echo "Grafana... "
if is_pi; then
if is_pione || is_pizero || is_pizerow; then GRAFANA_REPO_PI1="-rpi-1b"; fi
echo "deb https://dl.bintray.com/fg2it/deb${GRAFANA_REPO_PI1} $codename main" > /etc/apt/sources.list.d/grafana-fg2it.list || FAILED=2
cond_redirect apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 379CE192D401AB61 || FAILED=2
else
cond_redirect wget -O - https://packagecloud.io/gpg.key | apt-key add - || FAILED=2
echo "deb https://packagecloud.io/grafana/stable/$distributor/ $codename main" > /etc/apt/sources.list.d/grafana.list || FAILED=2
if [ $distributor = "ubuntu" ]; then #remove this loop when grafana ubuntu packages are available
echo "deb https://packagecloud.io/grafana/stable/debian/ jessie main" > /etc/apt/sources.list.d/grafana.list || FAILED=2
fi
fi
cond_redirect apt update || FAILED=2
cond_redirect apt -y install grafana || FAILED=2
cond_redirect systemctl daemon-reload
cond_redirect systemctl enable grafana-server.service
cond_redirect systemctl start grafana-server.service
if [ $FAILED -eq 2 ]; then echo -n "FAILED "; else echo -n "OK "; fi
cond_echo ""
echo "Connecting (TODO)... "
#TODO
echo "Adding openHAB dashboard tile... "
dashboard_add_tile grafana || FAILED=4
if [ -n "$INTERACTIVE" ]; then
if [ $FAILED -eq 0 ]; then
whiptail --title "Operation Successful!" --msgbox "$successtext" 15 80
else
whiptail --title "Operation Failed!" --msgbox "$failtext" 10 60
fi
fi
}
nginx_setup() {
introtext="This will enable you to access the openHAB interface through the normal HTTP/HTTPS ports and optionally secure it with username/password and/or an SSL certificate."
failtext="Sadly there was a problem setting up the selected option. Please report this problem in the openHAB community forum or as a openHABian GitHub issue."
echo "$(timestamp) [openHABian] Setting up Nginx as reverse proxy with authentication... "
if [ -n "$INTERACTIVE" ]; then
if ! (whiptail --title "Description, Continue?" --yes-button "Continue" --no-button "Back" --yesno "$introtext" 15 80) then echo "CANCELED"; return 0; fi
fi
function comment {
sed -i "$1"' s/^/#/' "$2"
}
function uncomment {
sed -i "$1"' s/^ *#//' "$2"
}
echo "Installing DNS utilities..."
apt -y -q install dnsutils
AUTH=false
SECURE=false
VALIDDOMAIN=false
matched=false
canceled=false
FAILED=false
if (whiptail --title "Authentication Setup" --yesno "Would you like to secure your openHAB interface with username and password?" 15 80) then
username=$(whiptail --title "Authentication Setup" --inputbox "Enter a username to sign into openHAB:" 15 80 openhab 3>&1 1>&2 2>&3)
if [ $? = 0 ]; then
while [ "$matched" = false ] && [ "$canceled" = false ]; do
password=$(whiptail --title "Authentication Setup" --passwordbox "Enter a password for $username:" 15 80 3>&1 1>&2 2>&3)
secondpassword=$(whiptail --title "Authentication Setup" --passwordbox "Please confirm the password:" 15 80 3>&1 1>&2 2>&3)
if [ "$password" = "$secondpassword" ] && [ ! -z "$password" ]; then
matched=true
AUTH=true
else
password=$(whiptail --title "Authentication Setup" --msgbox "Password mismatched or blank... Please try again!" 15 80 3>&1 1>&2 2>&3)
fi
done
else
canceled=true
fi
fi
if (whiptail --title "Secure Certificate Setup" --yesno "Would you like to secure your openHAB interface with HTTPS?" 15 80) then
SECURE=true
fi
echo -n "Obtaining public IP address... "
wanip=$(dig +short myip.opendns.com @resolver1.opendns.com |tail -1)
echo "$wanip"
domain=$(whiptail --title "Domain Setup" --inputbox "If you have a registered domain enter it now, if you have a static public IP enter \"IP\", otherwise leave blank:" 15 80 3>&1 1>&2 2>&3)
while [ "$VALIDDOMAIN" = false ] && [ ! -z "$domain" ] && [ "$domain" != "IP" ]; do
echo -n "Obtaining domain IP address... "
domainip=$(dig +short $domain @resolver1.opendns.com |tail -1)
echo "$domainip"
if [ "$wanip" = "$domainip" ]; then
VALIDDOMAIN=true
echo "Public and domain IP address match"
else
echo "Public and domain IP address mismatch!"
domain=$(whiptail --title "Domain Setup" --inputbox "Domain does not resolve to your public IP address. Please enter a valid domain, if you have a static public IP enter \"IP\",leave blank to not use a domain name:" 15 80 3>&1 1>&2 2>&3)
fi
done
if [ "$VALIDDOMAIN" = false ]; then
if [ "$domain" == "IP" ]; then
echo "Setting domain to static public IP address $wanip"
domain=$wanip
else
echo "Setting no domain nor static public IP address"
domain="localhost"
fi
fi
if [ "$AUTH" = true ]; then
authtext="Authentication Enabled\n- Username: $username"
else
authtext="Authentication Disabled"
fi
if [ "$SECURE" = true ]; then
httpstext="Proxy will be secured by HTTPS"
protocol="HTTPS"
portwarning="Important! Before you continue, please make sure that port 80 (HTTP) of this machine is reachable from the internet (portforwarding, ...). Otherwise the certbot connection test will fail.\n\n"
else
httpstext="Proxy will not be secured by HTTPS"
protocol="HTTP"
portwarning=""
fi
confirmtext="The following settings have been chosen:\n\n- $authtext\n- $httpstext\n- Domain: $domain (Public IP Address: $wanip)
\nYou will be able to connect to openHAB on the default $protocol port.
\n${portwarning}Do you wish to continue and setup an NGINX server now?"
if (whiptail --title "Confirmation" --yesno "$confirmtext" 22 80) then
echo "Installing NGINX..."
apt -y -q install nginx || FAILED=true
rm -rf /etc/nginx/sites-enabled/default
cp $BASEDIR/includes/nginx.conf /etc/nginx/sites-enabled/openhab
sed -i "s/DOMAINNAME/${domain}/g" /etc/nginx/sites-enabled/openhab
if [ "$AUTH" = true ]; then
echo "Installing password utilities..."
apt -y -q install apache2-utils || FAILED=true
echo "Creating password file..."
htpasswd -b -c /etc/nginx/.htpasswd $username $password
uncomment 32,33 /etc/nginx/sites-enabled/openhab
fi
if [ "$SECURE" = true ]; then
if [ "$VALIDDOMAIN" = true ]; then
certbotpackage="python-certbot-nginx"
if is_debian || is_raspbian; then
gpg --keyserver pgpkeys.mit.edu --recv-key 8B48AD6246925553
gpg -a --export 8B48AD6246925553 | apt-key add -
gpg --keyserver pgpkeys.mit.edu --recv-key 7638D0442B90D010
gpg -a --export 7638D0442B90D010 | apt-key add -
if is_jessie; then
certbotrepo="jessie-backports"
certbotpackage="certbot"
elif is_stretch; then
certbotrepo="stretch-backports"
fi
certbotoption="-t"
echo -e "# This file was added by openHABian to install certbot\ndeb http://ftp.debian.org/debian ${certbotrepo} main" > /etc/apt/sources.list.d/backports.list
elif is_ubuntu; then
apt -y -q --force-yes install software-properties-common
add-apt-repository ppa:certbot/certbot
fi
apt update
echo "Installing certbot..."
apt -y -q --force-yes install "${certbotpackage}" "${certbotoption}" "${certbotrepo}"
mkdir -p /var/www/$domain
uncomment 37,39 /etc/nginx/sites-enabled/openhab
nginx -t && service nginx reload
echo "Creating Let's Encrypt certificate..."
certbot certonly --webroot -w /var/www/$domain -d $domain || FAILED=true #This will cause a prompt
if [ "$FAILED" = false ]; then
certpath="/etc/letsencrypt/live/$domain/fullchain.pem"
keypath="/etc/letsencrypt/live/$domain/privkey.pem"
fi
else
mkdir -p /etc/ssl/certs
certpath="/etc/ssl/certs/openhab.crt"
keypath="/etc/ssl/certs/openhab.key"
password=$(whiptail --title "openSSL Key Generation" --msgbox "openSSL is about to ask for information in the command line, please fill out each line." 15 80 3>&1 1>&2 2>&3)
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout $keypath -out $certpath || FAILED=true #This will cause a prompt
fi
if [ "$FAILED" = false ]; then
uncomment 20,21 /etc/nginx/sites-enabled/openhab
sed -i "s|CERTPATH|${certpath}|g" /etc/nginx/sites-enabled/openhab
sed -i "s|KEYPATH|${keypath}|g" /etc/nginx/sites-enabled/openhab
uncomment 6,10 /etc/nginx/sites-enabled/openhab
uncomment 15,17 /etc/nginx/sites-enabled/openhab
comment 14 /etc/nginx/sites-enabled/openhab
fi
fi
nginx -t && systemctl reload nginx.service || FAILED=true
if [ "$FAILED" = true ]; then
whiptail --title "Operation Failed!" --msgbox "$failtext" 15 80
else
whiptail --title "Operation Successful!" --msgbox "Setup successful. Please try entering $protocol://$domain in a browser to test your settings." 15 80
fi
else
whiptail --title "Operation Canceled!" --msgbox "Setup was canceled, no changes were made." 15 80
fi
}
tellstick_core_setup() {
FAILED=0
introtext="This will install tellstick core services to enable support for USB connected Tellstick and Tellstick duo. For more details, have a look at http://developer.telldus.se/"
failtext="Sadly there was a problem setting up tellstick core. Please report this problem in the openHAB community forum or as a openHABian GitHub issue."
successtext="Success, please reboot your system to complete the installation.
Next, add your devices in /etc/tellstick.conf.
To detect device IDs use commanline tool: tdtool-improved --event
When devices are added restart telldusd.service by using: sudo systemctl restart telldusd
or just reboot the system.
"
if [ -n "$INTERACTIVE" ]; then
if ! (whiptail --title "Description, Continue?" --yes-button "Continue" --no-button "Back" --yesno "$introtext" 15 80) then echo "CANCELED"; return 0; fi
fi
echo -n "$(timestamp) [openHABian] Installing tellstick-core... "
# Maybe add new repository to be able to install libconfuse1
if is_xenial ; then
echo 'APT::Default-Release "xenial";' > /etc/apt/apt.conf.d/01release
echo "deb http://archive.ubuntu.com/ubuntu/ artful universe" > /etc/apt/sources.list.d/ubuntu-artful.list
cond_redirect apt update
cond_redirect apt -y -t=artful install libconfuse1
fi
if is_jessie ; then
echo 'APT::Default-Release "jessie";' > /etc/apt/apt.conf.d/01release
echo "deb http://deb.debian.org/debian stretch main" > /etc/apt/sources.list.d/debian-stretch.list
cond_redirect apt update
cond_redirect apt -y -t=stretch install libconfuse1
fi
cond_redirect wget -O - https://s3.eu-central-1.amazonaws.com/download.telldus.com/debian/telldus-public.key | apt-key add -
echo "deb https://s3.eu-central-1.amazonaws.com/download.telldus.com unstable main" > /etc/apt/sources.list.d/telldus-unstable.list
cond_redirect apt update
cond_redirect apt -y install libjna-java telldus-core || FAILED=1
if [ $FAILED -eq 0 ]; then echo "OK"; else echo "FAILED"; fi
echo -n "$(timestamp) [openHABian] Setting up systemd service for telldusd... "
cond_redirect cp ${BASEDIR}/includes/tellstick-core/telldusd.service /lib/systemd/system/telldusd.service
cond_redirect systemctl daemon-reload || FAILED=1
cond_redirect systemctl enable telldusd || FAILED=1
cond_redirect systemctl start telldusd.service || FAILED=1
if [ $FAILED -eq 0 ]; then echo "OK"; else echo "FAILED"; fi
echo -n "$(timestamp) [openHABian] Setting up tdtool-improved... "
cond_redirect git clone https://github.com/EliasGabrielsson/tdtool-improved.py.git /opt/tdtool-improved
cond_redirect chmod +x /opt/tdtool-improved/tdtool-improved.py
cond_redirect ln -sf /opt/tdtool-improved/tdtool-improved.py /usr/bin/tdtool-improved
echo "OK"
if [ -n "$INTERACTIVE" ]; then
if [ $FAILED -eq 0 ]; then
whiptail --title "Operation Successful!" --msgbox "$successtext" 15 80
else
whiptail --title "Operation Failed!" --msgbox "$failtext" 10 60
fi
fi
}