makedeb


proxmox-no-popup 1.0.0-1


Remove Proxmox's "No valid subscription" popup.

Viewing /hook.sh.

View raw.

Click here to go back to the Git tree for proxmox-no-popup.

#!/bin/bash

TARGET_FILE="/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js"

IFS= read -rd '' TEXT_BEFORE < <(echo -ne "checked_command: function(orig_cmd) {\n")
IFS= read -rd '' TEXT_AFTER  < <(echo -ne "checked_command: function(orig_cmd) { orig_cmd(); return; /* Patched by proxmox-no-popup */\n")

function print_message() {
	echo "[proxmox-no-popup] $1" >&2
}

function replace() {
	python3 <(cat <<-EOF
	import sys

	target_file = sys.argv[1]
	text_find = sys.argv[2]
	text_replace = sys.argv[3]

	with open(target_file, 'r') as file:
	    content = file.read()

	if content.find(text_find) == -1:
	    sys.exit(1)

	content = content.replace(text_find, text_replace)

	with open(target_file, 'w') as file:
	    file.write(content)
	EOF
	) "$1" "$2" "$3"
}

if ! [[ -f "$TARGET_FILE" ]]; then
	print_message "Target file not found!"
	exit 1
fi

if [[ $1 != "revert" ]]; then
	TEXT_FIND="$TEXT_BEFORE"
	TEXT_REPLACE="$TEXT_AFTER"
	print_message "Applying patch to \"$TARGET_FILE\"."
else
	TEXT_FIND="$TEXT_AFTER"
	TEXT_REPLACE="$TEXT_BEFORE"
	print_message "Reverting patch for \"$TARGET_FILE\"."
fi

if replace "$TARGET_FILE" "$TEXT_FIND" "$TEXT_REPLACE"; then
	print_message "Patched successfully! Restarting \"pveproxy\"..."
	if systemctl restart pveproxy; then
		print_message "Restarted successfully!"
		print_message "You may need to force refresh the Proxmox UI in your browser (Ctrl+Shift+R)."
		exit 0
	else
		exit 1
	fi
else
	if [[ "$1" != "revert" ]]; then
		print_message "Failed to patch. Maybe your version is not supported or already patched."
	else
		print_message "Failed to revert!"
		print_message "Please run \"apt install --reinstall proxmox-widget-toolkit\" to revert manually."
	fi
	exit 1
fi