Last active
April 13, 2023 14:00
-
-
Save nsssayom/e576a6c99290f8a47f71368a5c715226 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Running pre-install script..." | |
# Update the system | |
sudo apt update -y | |
# Install required packages for building MQTT libraries and Mosquitto broker | |
sudo apt install -y build-essential gcc make cmake cmake-gui cmake-curses-gui libssl-dev doxygen graphviz git libusb-1.0-0-dev libsystemd0 libsystemd-dev mosquitto python3 python3-pip | |
# Clone and install Paho C library version 1.4 | |
git clone https://github.com/eclipse/paho.mqtt.c.git | |
cd paho.mqtt.c | |
git checkout v1.4 # use "v1.4" tag instead of "1.4" | |
cmake -Bbuild -H. -DPAHO_ENABLE_TESTING=OFF -DPAHO_BUILD_STATIC=ON -DPAHO_WITH_SSL=ON -DPAHO_HIGH_PERFORMANCE=ON | |
sudo cmake --build build/ --target install | |
sudo ldconfig # update dynamic link library list | |
cd .. | |
# Clone and install Paho C++ library | |
git clone https://github.com/eclipse/paho.mqtt.cpp.git | |
cd paho.mqtt.cpp | |
cmake -Bbuild -H. -DPAHO_BUILD_STATIC=ON -DPAHO_BUILD_DOCUMENTATION=TRUE -DPAHO_BUILD_SAMPLES=TRUE | |
sudo cmake --build build/ --target install | |
sudo ldconfig # update dynamic link library list | |
cd .. | |
# Configure Mosquitto MQTT broker to allow remote and anonymous connections | |
echo -e "\nlistener 1883 0.0.0.0" | sudo tee -a /etc/mosquitto/mosquitto.conf | |
echo "allow_anonymous true" | sudo tee -a /etc/mosquitto/mosquitto.conf | |
# Restart the Mosquitto MQTT broker for the configuration changes to take effect | |
sudo systemctl restart mosquitto | |
# Install Paho MQTT client for Python 3 | |
sudo pip install paho-mqtt | |
# Success message | |
echo "MQTT libraries and Mosquitto broker installed successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment