-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmqtt_set_up.sh
More file actions
executable file
·23 lines (22 loc) · 1.61 KB
/
mqtt_set_up.sh
File metadata and controls
executable file
·23 lines (22 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
# ============================================================================== #
# ----------------------------- MQTT Set Up Script ----------------------------- #
# ________________________________ CONSTANTS _________________________________ #
DESIRED_PORT=18300 #
CONFIG_FILE="./mqtt.conf" #
# ____________________________ PACKAGE MANAGEMENT ____________________________ #
if ! dpkg -l | grep -q mosquitto; then #
sudo apt-get update #
sudo apt-get install -y mosquitto mosquitto-clients #
fi #
# ____________________________ CONFIGURATION FILE ____________________________ #
if [ ! -f "$CONFIG_FILE" ]; then #
echo "allow_anonymous true
listener $DESIRED_PORT 0.0.0.0
protocol mqtt" > "$CONFIG_FILE" #
else #
echo "Configuration file already exists. Skipping creation." #
fi #
# ____________________________ SERVICE MANAGEMENT _____________________________ #
mosquitto -c "$CONFIG_FILE" -d #
# ============================================================================== #