#!/bin/sh

. /etc/os-release

PVE=/usr/share/pve-manager/js/pvemanagerlib.js
LIB=/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
PBS=/usr/share/javascript/proxmox-backup/js/proxmox-backup-gui.js

#systemctl disable rpcbind.socket
#systemctl disable rpcbind
#systemctl stop rpcbind.socket
#systemctl stop rpcbind

if [ -f $PVE ]; then
    if  [[ "$VERSION_ID" == "12" ]]; then
	# Proxmox 8
	sed -Ezi.bak "s/(Ext.Msg.show\(\{\s+title: gettext\('No valid sub)/void\(\{ \/\/\1/g" $LIB
    else
	# Proxomx 6,7
	sed -i.bak "s/hidden: false/hidden: true/g" $PVE
	sed -i.bak -z "s/res === null || res === undefined || \!res || res\n\t\t\t.data.status.toLowerCase() \!== 'active'/false/g" $LIB
    fi
    systemctl restart pveproxy
fi

if [ -f $PBS ]; then
    sed -i.bak -z "s/res === null || res === undefined || \!res || res\n\t\t\t.data.status.toLowerCase() \!== 'active'/false/g" $LIB
    sed -i.bak "s/let subStatus = status.toLowerCase() === 'active' ? 2 : 0/let subStatus = status.toLowerCase() === 'active' ? 2 : 2/" $PBS
    systemctl restart proxmox-backup-proxy
fi
