-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdombusgateway_install.sh
More file actions
executable file
·122 lines (103 loc) · 3.59 KB
/
dombusgateway_install.sh
File metadata and controls
executable file
·122 lines (103 loc) · 3.59 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
#!/usr/bin/env bash
# DomBusGateway install file
# Designed by Creasol www.creasol.it
# Install the dombusgateway service, that is a bridge between DomBus network of domotic modules and MQTT with AutoDiscovery.
# Can be used to manage one or more DomBus module (EV charging system, solar tracking, relays, inputs, outputs, sensors, ...) with
# any industrial / home automation system supporting MQTT, like Home Assistant, Node-RED, OpenHAB, ioBroker, ...
# DomBusGateway is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
INSTALLDIR="/opt"
function installPkg() {
if [ "${INSTALL:0:3}" == "apt" ]; then
for pkg in $*; do
if `dpkg -s $pkg >/dev/null 2>/dev/null` ; then
echo "*** Package $pkg already installed!"
else
echo "*** Installing $pkg... "
${INSTALL} -y -f --allow-remove-essential install $pkg
fi
done
fi
}
function wait() {
echo $*
echo "*** Press a key to continue..."
read x
}
echo -n "*** Checking if apt exists... "
INSTALL=apt
command -v apt
if [ $? -ne 0 ]; then
command -v apt-get
if [ $? -eq 0 ]; then
INSTALL=apt-get
else
echo "NO!"
echo "*** ERROR: This system does not use apt nor apt-get. Please send a email to tech@creasol.it with information about your system"
echo -n "Kernel: "; uname -a
echo -n "Distribution: "; cat /etc/issue
exit
fi
fi
installPkg git gpw telnet
PASSWD=`gpw 1 11`
echo -n "*** Checking if mosquitto is installed... "
command -v mosquitto
if [ $? -ne 0 ]; then
echo "NO!"
installPkg mosquitto
fi
if [ ! -r /etc/mosquitto/passwd ]; then
echo "*** mosquitto passwd /etc/mosquitto/passwd does not exist"
echo "password_file /etc/mosquitto/passwd" > /etc/mosquitto/conf.d/password_file.conf
> /etc/mosquitto/passwd
fi
if [ -z `egrep ^dombus: /etc/mosquitto/passwd 2>/dev/null` ]; then
echo "*** Creating mosquitto user dombus with random generated password $PASSWD ..."
mosquitto_passwd -b /etc/mosquitto/passwd dombus "$PASSWD"
fi
echo "*** Installing python dependencies... "
installPkg python3-pip python3-paho-mqtt python3-asyncio-mqtt python3-serial-asyncio
if [ ! -r "${INSTALLDIR}" ]; then
mkdir "${INSTALLDIR}"
fi
cd $INSTALLDIR
if [ ! -r "${INSTALLDIR}/DomBusGateway" ]; then
echo "*** Clone DomBusGateway repository..."
git clone https://github.com/CreasolTech/DomBusGateway
fi
cd "${INSTALLDIR}/DomBusGateway"
mkdir data local 2>/dev/null
cp dombusgateway_conf_local.py local/
if [ ! -r /var/log/dombusgateway ]; then
echo "*** Creating directory for logging /var/log/dombusgateway ..."
mkdir -p /var/log/dombusgateway 2>/dev/null
>> /var/log/dombusgateway/info.log
>> /var/log/dombusgateway/errors.log
fi
chown -R dombus /var/log/dombusgateway
sed -i "s/secretpasswd/${PASSWD}/" local/dombusgateway_conf_local.py
chown -R dombus . *
chmod u+x dombusgateway.py
echo -n "*** Check if dombus user exists... "
id dombus # check if user already exists
if [ $? -ne 0 ]; then
echo "NO!"
echo "Creating system user 'dombus'... "
useradd -r -d /opt/DomBusGateway -c 'DomBus gateway user' -G dialout,mosquitto -s /usr/sbin/nologin dombus
else
echo "Yes"
echo "User dombus already exist! Ok"
fi
if [ ! -r /etc/systemd/system/dombusgateway.service ]; then
echo "Creating dombusgateway systemd service..."
cp dombusgateway.service /etc/systemd/system
echo "Enabling dombusgateway systemd service..."
systemctl enable dombusgateway
else
echo "Service dombusgateway already exists! Ok"
fi
echo "Running dombusgateway service..."
systemctl start dombusgateway