Fix apt hook logic to properly persist nag removal after updates
1. Fixed the apt hook logic The original script used dpkg -V with backwards logic. The new version directly checks if nag patterns are present in the files using grep, which is much more reliable: 2. More robust pattern matching Added multiple sed patterns to catch different variations of how the subscription check might be written: data.status !== 'active' data.status!=='active' data.status != 'active' data.status!='active' 3. Better testing and validation The script now includes a test_current_fix() function that verifies whether nags are actually present and whether the fix is working. 4. Improved error handling Better feedback about what's happening and whether the fix is working correctly.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/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)
|
# Works with PVE (Proxmox VE), PBS (Proxmox Backup Server), and PMG (Proxmox Mail Gateway)
|
||||||
#
|
#
|
||||||
# Based on community-scripts by tteck and contributors
|
# Based on community-scripts by tteck and contributors
|
||||||
@@ -48,7 +48,7 @@ header_info() {
|
|||||||
clear
|
clear
|
||||||
cat <<"EOF"
|
cat <<"EOF"
|
||||||
╔═════════════════════════════════════════════════════════════════════════════╗
|
╔═════════════════════════════════════════════════════════════════════════════╗
|
||||||
║ Universal Proxmox Nag Remover ║
|
║ Universal Proxmox Nag Remover - Improved ║
|
||||||
║ PVE • PBS • PMG Support ║
|
║ PVE • PBS • PMG Support ║
|
||||||
╚═════════════════════════════════════════════════════════════════════════════╝
|
╚═════════════════════════════════════════════════════════════════════════════╝
|
||||||
|
|
||||||
@@ -88,6 +88,48 @@ detect_proxmox() {
|
|||||||
echo "$product|$version"
|
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 based on product
|
||||||
apply_nag_removal() {
|
apply_nag_removal() {
|
||||||
local product="$1"
|
local product="$1"
|
||||||
@@ -96,42 +138,136 @@ apply_nag_removal() {
|
|||||||
PVE)
|
PVE)
|
||||||
msg_info "Applying PVE subscription nag removal"
|
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'
|
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
|
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"
|
msg_ok "PVE subscription nag removal applied"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
PBS)
|
PBS)
|
||||||
msg_info "Applying PBS subscription nag removal"
|
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'
|
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
|
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"
|
msg_ok "PBS subscription nag removal applied"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
PMG)
|
PMG)
|
||||||
msg_info "Applying PMG subscription nag removal"
|
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'
|
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::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"; };
|
"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
|
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)"
|
msg_ok "PMG subscription nag removal applied (desktop & mobile)"
|
||||||
;;
|
;;
|
||||||
esac
|
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 execution
|
||||||
main() {
|
main() {
|
||||||
# Check if running as root
|
# Check if running as root
|
||||||
@@ -151,14 +287,32 @@ main() {
|
|||||||
msg_note "$VERSION"
|
msg_note "$VERSION"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Check if already installed
|
# 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
|
if [[ -f /etc/apt/apt.conf.d/no-nag-script ]]; then
|
||||||
msg_info "Subscription nag removal already installed"
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "The nag removal is already active and will persist through updates."
|
echo "✓ Apt hook is installed and nags are already removed"
|
||||||
echo "To reinstall, delete /etc/apt/apt.conf.d/no-nag-script and run again."
|
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
|
exit 0
|
||||||
fi
|
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
|
# Show subscription support message
|
||||||
echo -e "${YW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${CL}"
|
echo -e "${YW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${CL}"
|
||||||
@@ -193,6 +347,16 @@ main() {
|
|||||||
# Apply the fix
|
# Apply the fix
|
||||||
apply_nag_removal "$PRODUCT"
|
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 ""
|
||||||
echo -e "${GN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${CL}"
|
echo -e "${GN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${CL}"
|
||||||
echo -e "${GN} Installation Complete${CL}"
|
echo -e "${GN} Installation Complete${CL}"
|
||||||
@@ -206,6 +370,9 @@ main() {
|
|||||||
echo "✓ Both desktop and mobile interfaces have been patched"
|
echo "✓ Both desktop and mobile interfaces have been patched"
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
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 -e "${YW}Original community-scripts: https://community-scripts.github.io/ProxmoxVE/${CL}"
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user