diff --git a/proxmox-nag-remover.sh b/proxmox-nag-remover.sh index ea0dddb..0837d7c 100644 --- a/proxmox-nag-remover.sh +++ b/proxmox-nag-remover.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Universal Proxmox Subscription Nag Remover +# Universal Proxmox Subscription Nag Remover - Improved Version # Works with PVE (Proxmox VE), PBS (Proxmox Backup Server), and PMG (Proxmox Mail Gateway) # # Based on community-scripts by tteck and contributors @@ -48,7 +48,7 @@ header_info() { clear cat <<"EOF" ╔═════════════════════════════════════════════════════════════════════════════╗ - ║ Universal Proxmox Nag Remover ║ + ║ Universal Proxmox Nag Remover - Improved ║ ║ PVE • PBS • PMG Support ║ ╚═════════════════════════════════════════════════════════════════════════════╝ @@ -88,6 +88,48 @@ detect_proxmox() { echo "$product|$version" } +# Function to apply nag removal to files +apply_nag_patch() { + local file="$1" + local backup_file="${file}.backup-$(date +%s)" + + if [ -f "$file" ]; then + # Create backup + cp "$file" "$backup_file" + + # Apply multiple patterns to catch different variations + sed -i.tmp \ + -e "s/data\.status !== 'active'/false/g" \ + -e "s/data\.status!=='active'/false/g" \ + -e "s/data\.status != 'active'/false/g" \ + -e "s/data\.status!='active'/false/g" \ + -e "s/checked_command: 'subscription'/checked_command: 'no-subscription'/g" \ + -e "/getNoSubKeyHtml.*{/,/},/{s/text: gettext('No valid subscription')/text: ''/g}" \ + -e "s/'No valid subscription'/''/g" \ + -e "/.*data\.status.*{/{s/\!//g; s/active/NoMoreNagging/g}" \ + "$file" + + # Clean up tmp file + rm -f "${file}.tmp" + + echo "Patched: $file" + return 0 + else + echo "File not found: $file" + return 1 + fi +} + +# Check if nag is present in file +check_nag_present() { + local file="$1" + if [ -f "$file" ]; then + grep -q "No valid subscription\|data\.status.*active" "$file" 2>/dev/null + else + return 1 + fi +} + # Apply nag removal based on product apply_nag_removal() { local product="$1" @@ -96,42 +138,136 @@ apply_nag_removal() { PVE) msg_info "Applying PVE subscription nag removal" - # PVE uses the more comprehensive regex pattern + # More robust apt hook for PVE cat > /etc/apt/apt.conf.d/no-nag-script << 'EOF' -DPkg::Post-Invoke { "dpkg -V proxmox-widget-toolkit | grep -q '/proxmoxlib\.js$'; if [ $? -eq 1 ]; then { echo 'Removing subscription nag from UI...'; sed -i '/.*data\.status.*{/{s/\!//;s/active/NoMoreNagging/}' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js; }; fi"; }; +DPkg::Post-Invoke { + "if [ -f /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js ]; then + if grep -q 'No valid subscription\\|data\\.status.*active' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js 2>/dev/null; then + echo 'Reapplying PVE subscription nag removal...'; + sed -i \ + -e 's/data\\.status !== '\"'\"'active'\"'\"'/false/g' \ + -e 's/data\\.status!==='\"'\"'active'\"'\"'/false/g' \ + -e 's/data\\.status != '\"'\"'active'\"'\"'/false/g' \ + -e 's/data\\.status!='\"'\"'active'\"'\"'/false/g' \ + -e 's/checked_command: '\"'\"'subscription'\"'\"'/checked_command: '\"'\"'no-subscription'\"'\"'/g' \ + -e '/getNoSubKeyHtml.*{/,/},/{s/text: gettext('\"'\"'No valid subscription'\"'\"')/text: '\"'\"''\"'\"'/g}' \ + -e 's/'\"'\"'No valid subscription'\"'\"'/'\"'\"''\"'\"'/g' \ + -e '/.*data\\.status.*{/{s/\\!//g; s/active/NoMoreNagging/g}' \ + /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js; + echo 'PVE nag removal reapplied successfully.'; + fi; + fi"; +}; EOF - apt --reinstall install proxmox-widget-toolkit &>/dev/null + # Apply initial patch + apply_nag_patch "/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js" msg_ok "PVE subscription nag removal applied" ;; PBS) msg_info "Applying PBS subscription nag removal" - # PBS uses simpler regex pattern + # More robust apt hook for PBS cat > /etc/apt/apt.conf.d/no-nag-script << 'EOF' -DPkg::Post-Invoke { "dpkg -V proxmox-widget-toolkit | grep -q '/proxmoxlib\.js$'; if [ $? -eq 1 ]; then { echo 'Removing subscription nag from UI...'; sed -i '/data\.status.*{/{s/\!//;s/active/NoMoreNagging/}' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js; }; fi"; }; +DPkg::Post-Invoke { + "if [ -f /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js ]; then + if grep -q 'No valid subscription\\|data\\.status.*active' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js 2>/dev/null; then + echo 'Reapplying PBS subscription nag removal...'; + sed -i \ + -e 's/data\\.status !== '\"'\"'active'\"'\"'/false/g' \ + -e 's/data\\.status!==='\"'\"'active'\"'\"'/false/g' \ + -e 's/data\\.status != '\"'\"'active'\"'\"'/false/g' \ + -e 's/data\\.status!='\"'\"'active'\"'\"'/false/g' \ + -e '/data\\.status.*{/{s/\\!//g; s/active/NoMoreNagging/g}' \ + /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js; + echo 'PBS nag removal reapplied successfully.'; + fi; + fi"; +}; EOF - apt --reinstall install proxmox-widget-toolkit &>/dev/null + # Apply initial patch + apply_nag_patch "/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js" msg_ok "PBS subscription nag removal applied" ;; PMG) msg_info "Applying PMG subscription nag removal" - # PMG needs both normal GUI and mobile GUI fixes + # More robust apt hook for PMG (both desktop and mobile) cat > /etc/apt/apt.conf.d/no-nag-script << 'EOF' -DPkg::Post-Invoke { "dpkg -V proxmox-widget-toolkit | grep -q '/proxmoxlib\.js$'; if [ $? -eq 1 ]; then { echo 'Removing subscription nag from UI...'; sed -i '/.*data\.status.*{/{s/\!//;s/active/NoMoreNagging/}' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js; }; fi"; }; -DPkg::Post-Invoke { "dpkg -V pmg-gui | grep -q '/pmgmanagerlib-mobile\.js$'; if [ $? -eq 1 ]; then { echo 'Removing subscription nag from Mobile UI...'; sed -i '/data\.status.*{/{s/\!//;s/active/NoMoreNagging/}' /usr/share/javascript/pmg-gui/js/pmgmanagerlib-mobile.js; }; fi"; }; +DPkg::Post-Invoke { + "if [ -f /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js ]; then + if grep -q 'No valid subscription\\|data\\.status.*active' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js 2>/dev/null; then + echo 'Reapplying PMG subscription nag removal (desktop)...'; + sed -i \ + -e 's/data\\.status !== '\"'\"'active'\"'\"'/false/g' \ + -e 's/data\\.status!==='\"'\"'active'\"'\"'/false/g' \ + -e 's/data\\.status != '\"'\"'active'\"'\"'/false/g' \ + -e 's/data\\.status!='\"'\"'active'\"'\"'/false/g' \ + -e '/.*data\\.status.*{/{s/\\!//g; s/active/NoMoreNagging/g}' \ + /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js; + echo 'PMG desktop nag removal reapplied successfully.'; + fi; + fi; + if [ -f /usr/share/javascript/pmg-gui/js/pmgmanagerlib-mobile.js ]; then + if grep -q 'No valid subscription\\|data\\.status.*active' /usr/share/javascript/pmg-gui/js/pmgmanagerlib-mobile.js 2>/dev/null; then + echo 'Reapplying PMG subscription nag removal (mobile)...'; + sed -i \ + -e 's/data\\.status !== '\"'\"'active'\"'\"'/false/g' \ + -e 's/data\\.status!==='\"'\"'active'\"'\"'/false/g' \ + -e 's/data\\.status != '\"'\"'active'\"'\"'/false/g' \ + -e 's/data\\.status!='\"'\"'active'\"'\"'/false/g' \ + -e '/data\\.status.*{/{s/\\!//g; s/active/NoMoreNagging/g}' \ + /usr/share/javascript/pmg-gui/js/pmgmanagerlib-mobile.js; + echo 'PMG mobile nag removal reapplied successfully.'; + fi; + fi"; +}; EOF - apt --reinstall install proxmox-widget-toolkit pmg-gui &>/dev/null + # Apply initial patches + apply_nag_patch "/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js" + apply_nag_patch "/usr/share/javascript/pmg-gui/js/pmgmanagerlib-mobile.js" msg_ok "PMG subscription nag removal applied (desktop & mobile)" ;; esac } +# Test if the current fix is working +test_current_fix() { + local product="$1" + local files_to_check=() + + case $product in + PVE|PBS) + files_to_check=("/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js") + ;; + PMG) + files_to_check=( + "/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js" + "/usr/share/javascript/pmg-gui/js/pmgmanagerlib-mobile.js" + ) + ;; + esac + + local nag_found=false + for file in "${files_to_check[@]}"; do + if check_nag_present "$file"; then + nag_found=true + echo "⚠ Nag still present in: $file" + fi + done + + if [ "$nag_found" = false ]; then + echo "✓ No subscription nags detected in relevant files" + return 0 + else + return 1 + fi +} + # Main execution main() { # Check if running as root @@ -151,15 +287,33 @@ main() { msg_note "$VERSION" echo "" - # Check if already installed - if [[ -f /etc/apt/apt.conf.d/no-nag-script ]]; then - msg_info "Subscription nag removal already installed" - echo "" - echo "The nag removal is already active and will persist through updates." - echo "To reinstall, delete /etc/apt/apt.conf.d/no-nag-script and run again." - exit 0 + # Check current status + msg_info "Checking current nag status" + if test_current_fix "$PRODUCT"; then + msg_ok "No subscription nags currently present" + + if [[ -f /etc/apt/apt.conf.d/no-nag-script ]]; then + echo "" + echo "✓ Apt hook is installed and nags are already removed" + echo "✓ The fix should persist through updates" + echo "" + echo "If nags return after updates, there may be a new pattern to patch." + echo "Run this script again to update the fix." + exit 0 + fi + else + msg_ok "Subscription nags detected - fix needed" fi + # Check if hook exists but isn't working + if [[ -f /etc/apt/apt.conf.d/no-nag-script ]]; then + msg_info "Updating existing apt hook" + rm -f /etc/apt/apt.conf.d/no-nag-script + msg_ok "Old hook removed" + fi + + echo "" + # Show subscription support message echo -e "${YW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${CL}" echo -e "${BL} Support Subscriptions${CL}" @@ -193,6 +347,16 @@ main() { # Apply the fix apply_nag_removal "$PRODUCT" + echo "" + + # Test the fix + msg_info "Testing nag removal" + if test_current_fix "$PRODUCT"; then + msg_ok "Nag removal test passed" + else + msg_error "Nag removal test failed - manual intervention may be needed" + fi + echo "" echo -e "${GN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${CL}" echo -e "${GN} Installation Complete${CL}" @@ -206,6 +370,9 @@ main() { echo "✓ Both desktop and mobile interfaces have been patched" echo "" fi + echo "To test the apt hook manually, run:" + echo " apt --reinstall install proxmox-widget-toolkit" + echo "" echo -e "${YW}Original community-scripts: https://community-scripts.github.io/ProxmoxVE/${CL}" echo "" }