Merge pull request #199 from noon92/new_working

Add mosquitto mqtt server and client installers
This commit is contained in:
noon92 2025-01-13 23:10:10 +02:00 • committed by GitHub
commit f100c58ad0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 338 additions and 24 deletions

View file

@ -0,0 +1,5 @@
#!/bin/bash
export NCURSES_NO_UTF8_ACS=1
export TERM=xterm-256color
export LANG=C.UTF-8
python /opt/curses-client-for-meshtastic/main.py --host

View file

@ -165,16 +165,17 @@ utilities() {
local title="Utilities"
while true; do
local option=""
option=$(dialog --cancel-label "Back" --menu "$title" 16 40 4 \
option=$(dialog --cancel-label "Back" --menu "$title" 17 40 4 \
1 "Set system timezone" \
2 "Kernel modules" \
3 "Re-run first-boot script" \
4 "Run USB configuration tool" \
5 "Run OEM luckfox-config" \
6 "Reboot" \
7 "Shutdown" \
6 "Process viewer/manager" \
7 "Reboot" \
8 "Shutdown" \
"" "" \
8 "Back to Main Menu" 3>&1 1>&2 2>&3)
9 "Back to Main Menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
@ -196,14 +197,15 @@ utilities() {
fi
;;
5) luckfox-config ;;
6)
6) htop ;;
7)
dialog --title "$title" --yesno "Reboot now?\n\nTip: Reboot can also be triggered by long-pressing the BOOT button on the luckfox." 10 45
if [ $? -eq 0 ]; then #unless cancel/no
dialog --infobox "Rebooting..." 5 45
reboot
fi
;;
7)
8)
dialog --title "$title" --yesno "Shut down now?\n\nTo power system back on, disconnect/reconnect power.\n\nThe system shutdown command prevents damage to the filesystem from power interrupts, but does not stop power consumption.\n\nTip: You can also shut down the Femtofox by pressing the BOOT button for 5 seconds or by running \`sudo halt\`." 14 60
if [ $? -eq 0 ]; then #unless cancel/no
dialog --infobox "Shutting down...\n\nPower consumption will not stop." 5 45
@ -211,7 +213,7 @@ utilities() {
halt
fi
;;
8) return ;;
9) return ;;
esac
done
}

View file

@ -10,7 +10,7 @@ install() {
fi
echo "Installing $($package_dir/$1.sh -N)..."
# Run the installation script, capturing the output and displaying it in real time
output=$(eval "$package_dir/$1.sh -i 2>&1 | tee /dev/tty")
output=$($package_dir/$1.sh -i)
echo $output
install_status=$? # Capture the exit status of the eval command
user_message=$(echo "$output" | awk '/user_message: / {found=1; split($0, arr, "user_message: "); print arr[2]; next} found {print}' | sed '/^$/q') # grab the user_message, if present
@ -24,7 +24,7 @@ install() {
}
uninstall() {
dialog --title "$title" --yesno "\nUninstall $1\n\nWill permanently delete all files and settings. Proceed?" 10 40
dialog --title "$title" --yesno "\nUninstall $1\n\nProceed?" 10 40
if [ $? -eq 1 ]; then #if cancel/no
return 1
fi
@ -69,10 +69,10 @@ package_intro() {
$(if $package_dir/$1.sh -O | grep -q 'D'; then echo "\n$($package_dir/$1.sh -D)"; fi)\n\
\n\
$(echo "Currently: " && $package_dir/$1.sh -I && echo "\Zuinstalled\Zn" || echo "\Zunot installed\Zn")\n\
$(if $package_dir/$1.sh -O | grep -q 'L'; then echo "Installs to: \Zu$($package_dir/$1.sh -L)\Zn"; fi)\n\
$(if $package_dir/$1.sh -O | grep -q 'C'; then echo "Conflicts with: \Zu$($package_dir/$1.sh -C)\Zn\n"; fi)\n\
$(if output=$($package_dir/$1.sh -L); [ -n "$output" ]; then echo "Installs to: \Zu$output\Zn"; fi)\
$(if output=$($package_dir/$1.sh -C); [ -n "$output" ]; then echo "Installs to: \Zu$output\Zn"; fi)\
An internet connection is required for installation.\n\
$(if $package_dir/$1.sh -O | grep -q 'U'; then echo "\nFor more information, visit $($package_dir/$1.sh -U)"; fi)" 50 75
$(if $package_dir/$1.sh -O | grep -q 'U'; then echo "\nFor more information, visit $($package_dir/$1.sh -U)"; fi)" 0 0
package_menu $1 # after user hits "OK", move on to package menu
}
@ -80,7 +80,7 @@ package_menu() {
while true; do
echo "Loading package menu..."
# for each line, check if it's supported by the package, display it if the current install state of the package is appropriate (example: don't display "install" if the package is already installed, don't display "stop service" for a package with no services)
choice=$(dialog --title "$title" --cancel-label "Back" --menu "$($package_dir/$1.sh -N)" 16 45 5 \
choice=$(dialog --title "$title" --cancel-label "Back" --menu "$($package_dir/$1.sh -N)" 17 45 5 \
$(if $package_dir/$1.sh -O | grep -q 'l' && $package_dir/$1.sh -I; then echo "Run software x"; fi) \
$(if $package_dir/$1.sh -O | grep -q 'i' && ! $package_dir/$1.sh -I; then echo "Install x"; fi) \
$(if $package_dir/$1.sh -O | grep -q 'u' && $package_dir/$1.sh -I; then echo "Uninstall x"; fi) \
@ -120,11 +120,13 @@ while true; do
title="$title"
option=""
option=$(dialog --cancel-label "Back" --menu "$title" 0 0 6 \
1 "Meshing Around by Spud" \
2 "The Comms Channel BBS, TC²BBS" \
3 "Curses Client for Meshtastic" \
1 "The Comms Channel BBS, TC²BBS" \
2 "Curses Client for Meshtastic" \
3 "Meshing Around by Spud" \
4 "Mosquitto MQTT Broker" \
5 "Mosquitto MQTT Client" \
"" ""\
4 "Back to Main Menu" 3>&1 1>&2 2>&3)
6 "Back to Main Menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
@ -132,10 +134,12 @@ title="$title"
fi
case $option in
1) package_intro "meshing_around" ;;
2) package_intro "tc2_bbs" ;;
3) package_intro "curses_client" ;;
4) break ;;
1) package_intro "tc2_bbs" ;;
2) package_intro "curses_client" ;;
3) package_intro "meshing_around" ;;
4) package_intro "mosquitto_mqtt_broker" ;;
5) package_intro "mosquitto_mqtt_client" ;;
6) break ;;
esac
done

View file

@ -0,0 +1,148 @@
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Try \`sudo\`."
exit 1
fi
if [ $# -eq 0 ]; then
echo "No arguments provided."
echo -e "$help"
exit 1
fi
args="$@" # arguments to this script
interaction="true"
help=$(cat <<EOF
Arguments:
-h This message
Environment - must be first argument:
-x User UI is not terminal (script interaction unavailable)
Actions:
-i Install
-u Uninstall
-g Upgrade
-e Enable service, if applicable
-d Disable service, if applicable
-s Stop service
-r Start/Restart
-l Command to run software
Information:
-N Get name
-A Get author
-D Get description
-U Get URL
-O Get options supported by this script
-S Get service status
-L Get Install location
-C Get Conflicts
-I Check if installed. Returns an error if not installed
EOF
)
### For package maintainer:
# Fill the following fields and choose the options that are in use by this package
# Populate the install, uninstall and upgrade functions
# Remember that this script may be launched in terminal, via web UI or another method, so inputs aren't really possible
# Arguments to the script are stored in $args
# This system supports both interactive and non-interactive installs. For non-interactive installs, $interaction="false". In this cause special instructions to the user should be given as user_message, such as `After installation, edit /opt/software/config.ini`
# Successful operations should `exit 0`, fails should `exit 1`
# Messages to the user (such as configuration instructions, explanatory error messages, etc) should be given as: `echo "user_message: text"`
# Everything following `user_message: ` will be displayed prominently to the user, so it must the last thing echoed
name="Mosquitto MQTT Broker" # software name
author="Eclipse Foundation" # software author - OPTIONAL
description="Eclipse Mosquitto is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 5.0, 3.1.1 and 3.1. Mosquitto is lightweight and is suitable for use on all devices from low power single board computers to full servers.\n\nThe MQTT protocol provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for Internet of Things messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers.\n\nThe Mosquitto project also provides a C library for implementing MQTT clients, and the very popular mosquitto_pub and mosquitto_sub command line MQTT clients.\n\nMosquitto is part of the Eclipse Foundation, and is an iot.eclipse.org project. The development is driven by Cedalo." # software description - OPTIONAL (but strongly recommended!)
URL="https://mosquitto.org/" # software URL. Can contain multiple URLs - OPTIONAL
options="xiugedslNADUOSLCIto" # script options in use by software package. For example, for a package with no service, exclude `edsr`
launch="" # command to launch software, if applicable
service_name="mosquitto" # the name of the service/s, such as `chrony`. REQUIRED if service options are in use. If multiple services, separate by spaces "service1 service2"
location="" # install location REQUIRED if not apt installed. Generally, we use `/opt/software-name`
conflicts="" # comma delineated plain-text list of packages with which this package conflicts. Blank if none. Use the name as it appears in the $name field of the other package. Extra plaintext is allowed, such as "packageA, packageB, any other software that uses the Meshtastic CLI"
# install script
install() {
echo "apt update can take a long while..."
DEBIAN_FRONTEND=noninteractive apt-get update -y 2>&1 | tee /dev/tty # allows output to be shown onscreen
DEBIAN_FRONTEND=noninteractive apt-get install mosquitto -y 2>&1 | tee /dev/tty # allows output to be shown onscreen
echo "user_message: Installation requires more setup. For a guide, see https://docs.vultr.com/how-to-install-mosquitto-mqtt-broker-on-ubuntu-24-04"
exit 0 # should be `exit 1` if operation failed
}
# uninstall script
uninstall() {
DEBIAN_FRONTEND=noninteractive apt remove -y mosquitto 2>&1 | tee /dev/tty
/usr/local/bin/mosquitto_mqtt_broker.sh -s # stop service
/usr/local/bin/mosquitto_mqtt_broker.sh -d # disable service
echo "user_message: Some files may remain on system. To remove, run \`sudo apt remove --purge mosquitto -y\` and \`sudo apt autoremove -y\`."
exit 0 # should be `exit 1` if operation failed
}
#upgrade script
upgrade() {
echo "apt update can take a long while..."
DEBIAN_FRONTEND=noninteractive apt-get update -y 2>&1 | tee /dev/tty # allows output to be shown onscreen
DEBIAN_FRONTEND=noninteractive apt upgrade -y mosquitto 2>&1 | tee /dev/tty
exit 0 # should be `exit 1` if operation failed
}
# Check if already installed. `exit 0` if yes, `exit 1` if no
check() {
if dpkg -l | grep -q mosquitto; then
exit 0
else
exit 1
fi
}
while getopts ":h$options" opt; do
case ${opt} in
h) # Option -h (help)
echo -e "$help"
;;
x) # Option -x (no user interaction available)
interaction="false"
;;
i) # Option -i (install)
install
;;
u) # Option -u (uninstall)
uninstall
;;
g) # Option -g (upgrade)
upgrade
;;
e) # Option -e (Enable service, if applicable)
systemctl enable $service_name
;;
d) # Option -d (Disable service, if applicable)
systemctl disable $service_name
;;
s) # Option -s (Stop service)
systemctl stop $service_name
;;
r) # Option -r (Start/Restart)
systemctl restart $service_name
;;
l) # Option -l (Run software)
echo "Launching $name..."
sudo -u ${SUDO_USER:-$(whoami)} $launch
;;
N) echo -e $name ;;
A) echo -e $author ;;
D) echo $description ;;
U) echo -e $URL ;;
O) echo -e $options ;;
S) # Option -S (Get service status)
systemctl status $service_name
;;
L) echo -e $location ;;
C) echo -e $conflicts ;;
I) # Option -I (Check if already installed)
check
;;
esac
done
exit 0

View file

@ -0,0 +1,146 @@
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Try \`sudo\`."
exit 1
fi
if [ $# -eq 0 ]; then
echo "No arguments provided."
echo -e "$help"
exit 1
fi
args="$@" # arguments to this script
interaction="true"
help=$(cat <<EOF
Arguments:
-h This message
Environment - must be first argument:
-x User UI is not terminal (script interaction unavailable)
Actions:
-i Install
-u Uninstall
-g Upgrade
-e Enable service, if applicable
-d Disable service, if applicable
-s Stop service
-r Start/Restart
-l Command to run software
Information:
-N Get name
-A Get author
-D Get description
-U Get URL
-O Get options supported by this script
-S Get service status
-L Get Install location
-C Get Conflicts
-I Check if installed. Returns an error if not installed
EOF
)
### For package maintainer:
# Fill the following fields and choose the options that are in use by this package
# Populate the install, uninstall and upgrade functions
# Remember that this script may be launched in terminal, via web UI or another method, so inputs aren't really possible
# Arguments to the script are stored in $args
# This system supports both interactive and non-interactive installs. For non-interactive installs, $interaction="false". In this cause special instructions to the user should be given as user_message, such as `After installation, edit /opt/software/config.ini`
# Successful operations should `exit 0`, fails should `exit 1`
# Messages to the user (such as configuration instructions, explanatory error messages, etc) should be given as: `echo "user_message: text"`
# Everything following `user_message: ` will be displayed prominently to the user, so it must the last thing echoed
name="Mosquitto MQTT Client" # software name
author="Eclipse Foundation" # software author - OPTIONAL
description="Eclipse Mosquitto is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 5.0, 3.1.1 and 3.1. Mosquitto is lightweight and is suitable for use on all devices from low power single board computers to full servers.\n\nThe MQTT protocol provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for Internet of Things messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers.\n\nThe Mosquitto project also provides a C library for implementing MQTT clients, and the very popular mosquitto_pub and mosquitto_sub command line MQTT clients.\n\nMosquitto is part of the Eclipse Foundation, and is an iot.eclipse.org project. The development is driven by Cedalo." # software description - OPTIONAL (but strongly recommended!)
URL="https://mosquitto.org/" # software URL. Can contain multiple URLs - OPTIONAL
options="xiugedslNADUOSLCIto" # script options in use by software package. For example, for a package with no service, exclude `edsr`
launch="" # command to launch software, if applicable
service_name="" # the name of the service/s, such as `chrony`. REQUIRED if service options are in use. If multiple services, separate by spaces "service1 service2"
location="" # install location REQUIRED if not apt installed. Generally, we use `/opt/software-name`
conflicts="" # comma delineated plain-text list of packages with which this package conflicts. Blank if none. Use the name as it appears in the $name field of the other package. Extra plaintext is allowed, such as "packageA, packageB, any other software that uses the Meshtastic CLI"
# install script
install() {
echo "apt update can take a long while..."
DEBIAN_FRONTEND=noninteractive apt-get update -y 2>&1 | tee /dev/tty # allows output to be shown onscreen
DEBIAN_FRONTEND=noninteractive apt-get install mosquitto-clients -y 2>&1 | tee /dev/tty # allows output to be shown onscreen
echo "user_message: Installation requires more setup. For a guide, see https://docs.vultr.com/how-to-install-mosquitto-mqtt-broker-on-ubuntu-24-04"
exit 0 # should be `exit 1` if operation failed
}
# uninstall script
uninstall() {
DEBIAN_FRONTEND=noninteractive apt remove -y mosquitto-clients 2>&1 | tee /dev/tty
echo "user_message: Some files may remain on system. To remove, run \`sudo apt remove --purge mosquitto -y\` and \`sudo apt autoremove -y\`."
exit 0 # should be `exit 1` if operation failed
}
#upgrade script
upgrade() {
echo "apt update can take a long while..."
DEBIAN_FRONTEND=noninteractive apt-get update -y 2>&1 | tee /dev/tty # allows output to be shown onscreen
DEBIAN_FRONTEND=noninteractive apt upgrade -y mosquitto-clients 2>&1 | tee /dev/tty
exit 0 # should be `exit 1` if operation failed
}
# Check if already installed. `exit 0` if yes, `exit 1` if no
check() {
if dpkg -l | grep -q mosquitto-clients; then
exit 0
else
exit 1
fi
}
while getopts ":h$options" opt; do
case ${opt} in
h) # Option -h (help)
echo -e "$help"
;;
x) # Option -x (no user interaction available)
interaction="false"
;;
i) # Option -i (install)
install
;;
u) # Option -u (uninstall)
uninstall
;;
g) # Option -g (upgrade)
upgrade
;;
e) # Option -e (Enable service, if applicable)
systemctl enable $service_name
;;
d) # Option -d (Disable service, if applicable)
systemctl disable $service_name
;;
s) # Option -s (Stop service)
systemctl stop $service_name
;;
r) # Option -r (Start/Restart)
systemctl restart $service_name
;;
l) # Option -l (Run software)
echo "Launching $name..."
sudo -u ${SUDO_USER:-$(whoami)} $launch
;;
N) echo -e $name ;;
A) echo -e $author ;;
D) echo $description ;;
U) echo -e $URL ;;
O) echo -e $options ;;
S) # Option -S (Get service status)
systemctl status $service_name
;;
L) echo -e $location ;;
C) echo -e $conflicts ;;
I) # Option -I (Check if already installed)
check
;;
esac
done
exit 0

View file

@ -61,6 +61,8 @@ conflicts="package name, other package name" # comma delineated plain-text lis
# install script
install() {
# for apt packages, this method allows onscreen output during install:
# DEBIAN_FRONTEND=noninteractive sudo apt-get install mosquitto -y 2>&1 | tee /dev/tty # allows output to be shown onscreen
echo "user_message: Exit message to user, displayed prominently in post-install"
exit 0 # should be `exit 1` if operation failed
}
@ -73,7 +75,7 @@ uninstall() {
}
#upgrade script
# upgrade script
upgrade() {
echo "user_message: Exit message to user, displayed prominently in post-install"
exit 0 # should be `exit 1` if operation failed
@ -81,12 +83,19 @@ upgrade() {
# Check if already installed. `exit 0` if yes, `exit 1` if no
check() {
#the following works for cloned repos, but not for apt installs
# the following works for cloned repos, but not for apt installs
if [ -d "$location" ]; then
exit 0
else
exit 1
fi
# this works for apt packages
if [ dpkg -l | grep -q package-name ] ; then
exit 0
else
exit 1
fi
}
while getopts ":h$options" opt; do

View file

@ -54,7 +54,7 @@ author="The Comms Channel" # software author - OPTIONAL
description="The TC²-BBS system integrates with Meshtastic devices. The system allows for message handling, bulletin boards, mail systems, and a channel directory." # software description - OPTIONAL (but strongly recommended!)
URL="https://github.com/TheCommsChannel/TC2-BBS-mesh" # software URL. Can contain multiple URLs - OPTIONAL
options="xiugedsrlNADUOSLCIto" # script options in use by software package. For example, for a package with no service, exclude `edsr`
launch="/opt/TC2-BBS-mesh/server.py" # command to launch software, if applicable
launch="python /opt/TC2-BBS-mesh/server.py" # command to launch software, if applicable
service_name="mesh-bbs" # the name of the service/s, such as `chrony`. REQUIRED if service options are in use. If multiple services, separate by spaces "service1 service2"
location="/opt/TC2-BBS-mesh" # install location REQUIRED if not apt installed. Generally, we use `/opt/software-name`
conflicts="Meshing Around, other \"full control\" packages" # comma delineated plain-text list of packages with which this package conflicts. Blank if none. Use the name as it appears in the $name field of the other package. Extra plaintext is allowed, such as "packageA, packageB, any other software that uses the Meshtastic CLI"