Add mqtt_uns_structure configuration and uninstall functionality (#196)

- Prompt user for mqtt_uns_structure during installation and update src/config.py accordingly.
- Implement uninstall function in remote_install.sh to remove the rpi-mqtt-monitor directory, cron job, and systemd service.
- Update rpi-cpu2mqtt.py to utilize mqtt_uns_structure for state topics, ensuring proper MQTT topic structure.
- Modify config.py.example to include mqtt_uns_structure with a default empty value.

Co-authored-by: Sam Blackman <sam@samuelblackman.com>
This commit is contained in:
Ginger-blackman
2025-03-19 15:21:12 -05:00
committed by GitHub
parent 3467987cec
commit e5ef4dffbd
4 changed files with 69 additions and 16 deletions

View File

@@ -22,6 +22,46 @@ welcome(){
fi
}
uninstall(){
printm "Uninstalling rpi-mqtt-monitor"
# Remove the rpi-mqtt-monitor directory
if [ -d "rpi-mqtt-monitor" ]; then
rm -rf rpi-mqtt-monitor
echo "Removed rpi-mqtt-monitor directory."
else
echo "rpi-mqtt-monitor directory not found."
fi
# Remove the cron job if it exists
if crontab -l | grep -q rpi-cpu2mqtt.py; then
crontab -l | grep -v rpi-cpu2mqtt.py | crontab -
echo "Removed cron job for rpi-cpu2mqtt.py."
else
echo "No cron job found for rpi-cpu2mqtt.py."
fi
# Remove the systemd service if it exists
if [ -f /etc/systemd/system/rpi-mqtt-monitor.service ]; then
sudo systemctl stop rpi-mqtt-monitor.service
sudo systemctl disable rpi-mqtt-monitor.service
sudo rm /etc/systemd/system/rpi-mqtt-monitor.service
sudo systemctl daemon-reload
echo "Removed systemd service for rpi-mqtt-monitor."
else
echo "No systemd service found for rpi-mqtt-monitor."
fi
# Optionally remove git if it was installed by this script
if command -v git &> /dev/null; then
read -r -p "Do you want to remove git? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
sudo apt-get remove --purge git
echo "Git has been removed."
fi
fi
}
main(){
welcome
if [[ $(git --version) ]]; then
@@ -37,4 +77,9 @@ main(){
bash install.sh
}
main
# Check for uninstall flag
if [[ "$1" == "uninstall" ]]; then
uninstall
else
main
fi