diff --git a/scripts/fpp_uninstall.sh b/scripts/fpp_uninstall.sh index cd7223f..9e237bf 100755 --- a/scripts/fpp_uninstall.sh +++ b/scripts/fpp_uninstall.sh @@ -1,10 +1,47 @@ -#!/bin/bash +#!/bin/sh -# fpp-pluginAdvancedStats uninstall script +# fpp-plugin-AdvancedStats uninstall script +# +# Reverses every side effect this plugin creates outside its own plugin +# directory. Must be safe to run more than once (all removals are guarded +# or use "rm -f"). + +PLUGIN="fpp-plugin-AdvancedStats" +CONFIGDIR="/home/fpp/media/config" +LOGDIR="/home/fpp/media/logs" echo "Uninstalling Advanced Stats Plugin..." +# 1. Stop the MQTT listener started by scripts/postStart.sh. +# FPP does not run preStop.sh on uninstall, so without this the process +# keeps running (against a since-deleted script) until the next fppd stop. +# The pattern includes the plugin directory so it cannot match an +# unrelated process that happens to be named mqtt_listener.py. +LISTENER_MATCH="${PLUGIN}/mqtt_listener.py" +if pgrep -f "${LISTENER_MATCH}" >/dev/null 2>&1; then + echo "Stopping MQTT listener..." + pkill -f "${LISTENER_MATCH}" 2>/dev/null || true + sleep 1 + pkill -9 -f "${LISTENER_MATCH}" 2>/dev/null || true +fi -echo "" -echo "Advanced Stats Plugin uninstalled successfully" +# 2. SQLite database, its journal/WAL sidecars, and any safety-backup copies +# left in config/ by the restore and empty-database actions. +rm -f "${CONFIGDIR}/plugin.${PLUGIN}.db" \ + "${CONFIGDIR}/plugin.${PLUGIN}.db-journal" \ + "${CONFIGDIR}/plugin.${PLUGIN}.db-wal" \ + "${CONFIGDIR}/plugin.${PLUGIN}.db-shm" +rm -f "${CONFIGDIR}/plugin.${PLUGIN}.db.backup-"* + +# 3. Plugin log file. Both the current name and the guideline-compliant +# plugin-.log name are removed so nothing is orphaned. +rm -f "${LOGDIR}/${PLUGIN}.log" \ + "${LOGDIR}/plugin-${PLUGIN}.log" +# 4. Plugin settings file. +rm -f "${CONFIGDIR}/plugin.${PLUGIN}" + +# Note: python3-paho-mqtt (installed by fpp_install.sh) is a shared system +# dependency and is intentionally left in place. + +echo "Advanced Stats Plugin uninstalled successfully" diff --git a/scripts/postStart.sh b/scripts/postStart.sh index da0441c..3caeb80 100755 --- a/scripts/postStart.sh +++ b/scripts/postStart.sh @@ -47,7 +47,7 @@ sys.exit(0 if rc == 0 else 1)' "$mqtt_host" "$mqtt_port" 2>/dev/null; then } # Check if MQTT listener is already running -if pgrep -f "mqtt_listener.py" > /dev/null; then +if pgrep -f "$MQTT_LISTENER" > /dev/null; then echo "MQTT listener already running" >> "$LOG_FILE" else # Make sure the script is executable @@ -59,7 +59,7 @@ else trap '' HUP wait_for_broker # Re-check: another postStart may have won the race while we waited - if pgrep -f "mqtt_listener.py" > /dev/null; then + if pgrep -f "$MQTT_LISTENER" > /dev/null; then echo "MQTT listener already running - not starting a second one" exit 0 fi diff --git a/scripts/preStop.sh b/scripts/preStop.sh index 6fdd824..9631a19 100755 --- a/scripts/preStop.sh +++ b/scripts/preStop.sh @@ -9,7 +9,7 @@ LOG_FILE="/home/fpp/media/logs/fpp-plugin-AdvancedStats.log" echo "Stopping Advanced Stats MQTT listener..." >> "$LOG_FILE" # Find and kill the MQTT listener process -pkill -f "mqtt_listener.py" +pkill -f "fpp-plugin-AdvancedStats/mqtt_listener.py" if [ $? -eq 0 ]; then echo "MQTT listener stopped successfully" >> "$LOG_FILE"