Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions scripts/fpp_uninstall.sh
Original file line number Diff line number Diff line change
@@ -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-<repoName>.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"
4 changes: 2 additions & 2 deletions scripts/postStart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/preStop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down