-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmosquitto.sh
executable file
·44 lines (40 loc) · 1.96 KB
/
mosquitto.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
#!/bin/bash
source load_config.sh
if [ "$install_mosquitto_server" = true ]; then
echo "-------------------------------------------------------------"
echo "Mosquitto Server installation and configuration"
echo "-------------------------------------------------------------"
sudo apt-get install -y mosquitto
sudo apt-get install -y libmosquitto-dev
# Disable mosquitto persistance
sudo sed -i "s/^persistence true/persistence false/" /etc/mosquitto/mosquitto.conf
# append line: allow_anonymous false
sudo sed -i -n '/allow_anonymous false/!p;$a allow_anonymous false' /etc/mosquitto/mosquitto.conf
# append line: password_file /etc/mosquitto/passwd
sudo sed -i -n '/password_file \/etc\/mosquitto\/passwd/!p;$a password_file \/etc\/mosquitto\/passwd' /etc/mosquitto/mosquitto.conf
# append line: log_type error
sudo sed -i -n '/log_type error/!p;$a log_type error' /etc/mosquitto/mosquitto.conf
# append line: listener 1883
sudo sed -i -n '/listener 1883/!p;$a listener 1883' /etc/mosquitto/mosquitto.conf
# Create mosquitto password file
sudo touch /etc/mosquitto/passwd
sudo mosquitto_passwd -b /etc/mosquitto/passwd $mqtt_user $mqtt_password
fi
if [ "$install_mosquitto_client" = true ]; then
echo "-------------------------------------------------------------"
echo "Mosquitto Client installation and configuration"
echo "-------------------------------------------------------------"
sudo apt-get install -y libmosquitto-dev
printf "\n"
git clone https://github.com/openenergymonitor/Mosquitto-PHP
cd Mosquitto-PHP/
phpize
./configure
make
sudo make install
echo "-------------------------------------------------------------"
# Add mosquitto to php mods available
PHP_VER=$(php -v | head -n 1 | cut -d " " -f 2 | cut -f1-2 -d"." )
printf "extension=mosquitto.so" | sudo tee /etc/php/$PHP_VER/mods-available/mosquitto.ini 1>&2
sudo phpenmod mosquitto
fi