mirror of
https://github.com/femtofox/femtofox.git
synced 2026-11-28 19:06:44 -05:00
Add mosquitto installers
This commit is contained in:
parent
9868d9885e
commit
3f4273b906
6 changed files with 316 additions and 13 deletions
|
|
@ -61,8 +61,6 @@ fi
|
|||
lines="export NCURSES_NO_UTF8_ACS=1
|
||||
export TERM=xterm-256color
|
||||
export LANG=C.UTF-8"
|
||||
|
||||
# Check if the lines are already in .bashrc
|
||||
if ! grep -Fxq "$lines" /home/femto/.bashrc; then
|
||||
echo "$lines" >> /home/femto/.bashrc
|
||||
echo "Added TERM, LANG and NCURSES_NO_UTF8_ACS to .bashrc"
|
||||
|
|
|
|||
|
|
@ -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) \
|
||||
|
|
@ -123,8 +123,9 @@ title="$title"
|
|||
1 "Meshing Around by Spud" \
|
||||
2 "The Comms Channel BBS, TC²BBS" \
|
||||
3 "Curses Client for Meshtastic" \
|
||||
4 "Mosquitto MQTT Broker" \
|
||||
"" ""\
|
||||
4 "Back to Main Menu" 3>&1 1>&2 2>&3)
|
||||
5 "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
|
||||
|
|
@ -135,7 +136,8 @@ title="$title"
|
|||
1) package_intro "meshing_around" ;;
|
||||
2) package_intro "tc2_bbs" ;;
|
||||
3) package_intro "curses_client" ;;
|
||||
4) break ;;
|
||||
4) package_intro "mosquitto_mqtt_broker" ;;
|
||||
5) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue