From 534a07788b76de49e9ba14059a9aed0bf16e02ca Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Thu, 4 Sep 2025 15:28:20 -0400 Subject: [PATCH] fix(plugin): restore cleanup behavior for unsupported unraid versions (#1658) ## Summary by CodeRabbit * **New Features** * Adds guided warnings and an explicit cleanup/uninstall workflow for unsupported Unraid versions, with safer removal paths by OS release. * **Bug Fixes** * Detects and removes both new and legacy Connect configurations, ensuring proper sign-out and web-server reload. * Strengthens version gating to avoid problematic pre-release builds and advises uninstall/upgrade when needed. * **Chores** * Lowers declared minimum Unraid version to broaden compatibility. --- plugin/plugins/dynamix.unraid.net.plg | 110 ++++++++++++++++-- .../install/scripts/cleanup.sh | 32 ++++- 2 files changed, 128 insertions(+), 14 deletions(-) diff --git a/plugin/plugins/dynamix.unraid.net.plg b/plugin/plugins/dynamix.unraid.net.plg index 3efb0c7e6..27cc9720d 100755 --- a/plugin/plugins/dynamix.unraid.net.plg +++ b/plugin/plugins/dynamix.unraid.net.plg @@ -14,9 +14,9 @@ ]> - + + launch="&launch;" min="6.9.0-rc1" icon="globe"> ##a long time ago in a galaxy far far away @@ -60,10 +60,10 @@ exit 0 // Check Unraid version $version = @parse_ini_file('/etc/unraid-version', true)['version']; -// Check if this is a supported version -// - Must be 6.12.15 or higher -// - Must not be a 6.12.15 beta/rc version -$is_stable_6_12_or_higher = version_compare($version, '6.12.15', '>=') && !preg_match('/^6\\.12\\.0-/', $version); +// Check if this is a recommended version +// - Should be 6.12.15 or higher +// - Should not be a 6.12.15 beta/rc version +$is_stable_6_12_or_higher = version_compare($version, '6.12.15', '>=') && !preg_match('/^6\\.12\\.15-/', $version); if ($is_stable_6_12_or_higher) { echo "Running on supported version {$version}\n"; @@ -71,9 +71,103 @@ if ($is_stable_6_12_or_higher) { } echo "Warning: Unsupported Unraid version {$version}. This plugin requires Unraid 6.12.15 or higher.\n"; -echo "The plugin will not function correctly on this system.\n"; +echo "The plugin may not function correctly on this system. It may stop working entirely in the future.\n"; +echo "⚠️ Please uninstall this plugin or upgrade to a newer version of Unraid to enjoy Unraid Connect\n"; -exit(1); +// early escape handled via unraid_connect_cleanup_for_unsupported_os_versions step +exit(0); +]]> + + + + + + + + /dev/null 2>&1 + fi + + if [ -f "/usr/local/emhttp/plugins/dynamix.my.servers/include/UpdateFlashBackup.php" ]; then + printf "\nDeactivating flash backup. Please wait...\n" + /usr/bin/php /usr/local/emhttp/plugins/dynamix.my.servers/include/UpdateFlashBackup.php deactivate + fi + fi + + # Check if connect.json or myservers.cfg exists + if [ -f "/boot/config/plugins/dynamix.my.servers/configs/connect.json" ] || [ -f "/boot/config/plugins/dynamix.my.servers/myservers.cfg" ]; then + # Stop unraid-api + printf "\nStopping unraid-api. Please wait...\n" + output=$(/etc/rc.d/rc.unraid-api stop --delete 2>&1) + if [ -z "$output" ]; then + echo "Waiting for unraid-api to stop..." + sleep 5 # Give it time to stop + fi + echo "Stopped unraid-api: $output" + + # Sign out of Unraid Connect (we'll use curl directly from shell) + # We need to extract the username from connect.json or myservers.cfg and the registration key + has_username=false + + # Check connect.json first (newer format) + if [ -f "/boot/config/plugins/dynamix.my.servers/configs/connect.json" ] && command -v jq >/dev/null 2>&1; then + username=$(jq -r '.username' "/boot/config/plugins/dynamix.my.servers/configs/connect.json" 2>/dev/null) + if [ -n "$username" ] && [ "$username" != "null" ]; then + has_username=true + fi + fi + + # Fallback to myservers.cfg (legacy format) + if [ "$has_username" = false ] && [ -f "/boot/config/plugins/dynamix.my.servers/myservers.cfg" ]; then + if grep -q 'username' "/boot/config/plugins/dynamix.my.servers/myservers.cfg"; then + has_username=true + fi + fi + + if [ "$has_username" = true ]; then + printf "\nSigning out of Unraid Connect\n" + # Check if regFILE exists in var.ini + if [ -f "/var/local/emhttp/var.ini" ]; then + regfile=$(grep "regFILE" "/var/local/emhttp/var.ini" | cut -d= -f2) + if [ -n "$regfile" ] && [ -f "$regfile" ]; then + # Base64 encode the key file and send to server + encoded_key=$(base64 "$regfile" | tr -d '\n') + if [ -n "$encoded_key" ]; then + curl -s -X POST "https://keys.lime-technology.com/account/server/unregister" \ + -d "keyfile=$encoded_key" >/dev/null 2>&1 + fi + fi + fi + fi + + # Remove config files + rm -f /boot/config/plugins/dynamix.my.servers/myservers.cfg + rm -f /boot/config/plugins/dynamix.my.servers/configs/connect.json + + # Reload nginx to disable Remote Access + printf "\n⚠️ Reloading Web Server. If this window stops updating for two minutes please close it.\n" + /etc/rc.d/rc.nginx reload >/dev/null 2>&1 + fi +} + +perform_connect_cleanup +echo "Done. Please uninstall the Connect plugin to complete the cleanup." +# Exit with error to clarify that further user action--either uninstalling the plugin or upgrading to a newer version of Unraid--is required. +exit 1; ]]> diff --git a/plugin/source/dynamix.unraid.net/usr/local/share/dynamix.unraid.net/install/scripts/cleanup.sh b/plugin/source/dynamix.unraid.net/usr/local/share/dynamix.unraid.net/install/scripts/cleanup.sh index 3dc6c656e..d32e6c15b 100755 --- a/plugin/source/dynamix.unraid.net/usr/local/share/dynamix.unraid.net/install/scripts/cleanup.sh +++ b/plugin/source/dynamix.unraid.net/usr/local/share/dynamix.unraid.net/install/scripts/cleanup.sh @@ -1,5 +1,7 @@ #!/bin/sh # Script to handle cleanup operations during removal +# NOTE: an inline copy of this script exists in dynamix.unraid.net.plg for Unraid 6.12.14 and earlier +# When updating this script, be sure to update the inline copy as well. # Get the operation mode MODE="${1:-cleanup}" @@ -23,8 +25,8 @@ perform_connect_cleanup() { fi fi - # Check if myservers.cfg exists - if [ -f "/boot/config/plugins/dynamix.my.servers/myservers.cfg" ]; then + # Check if connect.json or myservers.cfg exists + if [ -f "/boot/config/plugins/dynamix.my.servers/configs/connect.json" ] || [ -f "/boot/config/plugins/dynamix.my.servers/myservers.cfg" ]; then # Stop unraid-api printf "\nStopping unraid-api. Please wait...\n" output=$(/etc/rc.d/rc.unraid-api stop --delete 2>&1) @@ -35,8 +37,25 @@ perform_connect_cleanup() { echo "Stopped unraid-api: $output" # Sign out of Unraid Connect (we'll use curl directly from shell) - # We need to extract the username from myservers.cfg and the registration key - if grep -q 'username' "/boot/config/plugins/dynamix.my.servers/myservers.cfg"; then + # We need to extract the username from connect.json or myservers.cfg and the registration key + has_username=false + + # Check connect.json first (newer format) + if [ -f "/boot/config/plugins/dynamix.my.servers/configs/connect.json" ] && command -v jq >/dev/null 2>&1; then + username=$(jq -r '.username' "/boot/config/plugins/dynamix.my.servers/configs/connect.json" 2>/dev/null) + if [ -n "$username" ] && [ "$username" != "null" ]; then + has_username=true + fi + fi + + # Fallback to myservers.cfg (legacy format) + if [ "$has_username" = false ] && [ -f "/boot/config/plugins/dynamix.my.servers/myservers.cfg" ]; then + if grep -q 'username' "/boot/config/plugins/dynamix.my.servers/myservers.cfg"; then + has_username=true + fi + fi + + if [ "$has_username" = true ]; then printf "\nSigning out of Unraid Connect\n" # Check if regFILE exists in var.ini if [ -f "/var/local/emhttp/var.ini" ]; then @@ -52,8 +71,9 @@ perform_connect_cleanup() { fi fi - # Remove myservers.cfg + # Remove config files rm -f /boot/config/plugins/dynamix.my.servers/myservers.cfg + rm -f /boot/config/plugins/dynamix.my.servers/configs/connect.json # Reload nginx to disable Remote Access printf "\n⚠️ Reloading Web Server. If this window stops updating for two minutes please close it.\n" @@ -131,4 +151,4 @@ case "$MODE" in echo "Usage: $0 [cleanup]" exit 1 ;; -esac \ No newline at end of file +esac