mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-11-18 03:26:17 +00:00
Update Post Install menu
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
# ==========================================================
|
||||
# This version makes a surgical change to the checked_command function
|
||||
# by changing the condition to 'if (false)' and commenting out the banner logic.
|
||||
# Also patches the mobile UI to remove the subscription dialog.
|
||||
# ==========================================================
|
||||
|
||||
set -euo pipefail
|
||||
@@ -24,10 +25,12 @@ initialize_cache
|
||||
JS_FILE="/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js"
|
||||
GZ_FILE="/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js.gz"
|
||||
MIN_JS_FILE="/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.min.js"
|
||||
MOBILE_UI_FILE="/usr/share/pve-yew-mobile-gui/index.html.tpl"
|
||||
BACKUP_DIR="$BASE_DIR/backups"
|
||||
APT_HOOK="/etc/apt/apt.conf.d/no-nag-script"
|
||||
PATCH_BIN="/usr/local/bin/pve-remove-nag-v3.sh"
|
||||
MARK="/* PROXMENUX_NAG_PATCH_V3 */"
|
||||
MOBILE_MARK="<!-- PROXMENUX_MOBILE_NAG_PATCH -->"
|
||||
|
||||
# Ensure tools JSON exists
|
||||
ensure_tools_json() {
|
||||
@@ -84,8 +87,10 @@ set -euo pipefail
|
||||
JS_FILE="/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js"
|
||||
GZ_FILE="/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js.gz"
|
||||
MIN_JS_FILE="/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.min.js"
|
||||
MOBILE_UI_FILE="/usr/share/pve-yew-mobile-gui/index.html.tpl"
|
||||
BACKUP_DIR="/usr/local/share/proxmenux/backups"
|
||||
MARK="/* PROXMENUX_NAG_PATCH_V3 */"
|
||||
MOBILE_MARK="<!-- PROXMENUX_MOBILE_NAG_PATCH -->"
|
||||
|
||||
verify_js_integrity() {
|
||||
local file="$1"
|
||||
@@ -140,6 +145,43 @@ patch_checked_command() {
|
||||
return 0
|
||||
}
|
||||
|
||||
patch_mobile_ui() {
|
||||
[ -f "$MOBILE_UI_FILE" ] || return 0
|
||||
|
||||
# Check if already patched
|
||||
grep -q "$MOBILE_MARK" "$MOBILE_UI_FILE" && return 0
|
||||
|
||||
# Create backup
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
local backup="$BACKUP_DIR/$(basename "$MOBILE_UI_FILE").backup.$(date +%Y%m%d_%H%M%S)"
|
||||
cp -a "$MOBILE_UI_FILE" "$backup"
|
||||
|
||||
# Set trap to restore on error
|
||||
trap "cp -a '$backup' '$MOBILE_UI_FILE' 2>/dev/null || true" ERR
|
||||
|
||||
# Insert the script before </head> tag
|
||||
sed -i "/<\/head>/i\\
|
||||
$MOBILE_MARK\\
|
||||
<!-- Script to remove subscription banner from mobile UI -->\\
|
||||
<script>\\
|
||||
function removeNoSubDialog() {\\
|
||||
const observer = new MutationObserver(() => {\\
|
||||
const diag = document.querySelector('dialog[aria-label=\"No valid subscription\"]');\\
|
||||
if (diag) {\\
|
||||
diag.remove();\\
|
||||
}\\
|
||||
});\\
|
||||
observer.observe(document.body, { childList: true, subtree: true });\\
|
||||
}\\
|
||||
window.addEventListener('load', () => {\\
|
||||
setTimeout(removeNoSubDialog, 200);\\
|
||||
});\\
|
||||
</script>" "$MOBILE_UI_FILE"
|
||||
|
||||
trap - ERR
|
||||
return 0
|
||||
}
|
||||
|
||||
reload_services() {
|
||||
systemctl is-active --quiet pveproxy 2>/dev/null && {
|
||||
systemctl reload pveproxy 2>/dev/null || systemctl restart pveproxy 2>/dev/null || true
|
||||
@@ -154,6 +196,7 @@ reload_services() {
|
||||
|
||||
main() {
|
||||
patch_checked_command || return 1
|
||||
patch_mobile_ui || true
|
||||
reload_services
|
||||
}
|
||||
|
||||
@@ -174,7 +217,6 @@ EOFAPT
|
||||
|
||||
# Verify APT hook syntax
|
||||
apt-config dump >/dev/null 2>&1 || {
|
||||
msg_warn "APT hook syntax issue, removing..."
|
||||
rm -f "$APT_HOOK"
|
||||
}
|
||||
}
|
||||
@@ -184,25 +226,28 @@ remove_subscription_banner_v3() {
|
||||
local pve_version
|
||||
pve_version=$(pveversion 2>/dev/null | grep -oP 'pve-manager/\K[0-9]+\.[0-9]+' | head -1 || echo "unknown")
|
||||
|
||||
msg_info "Detected Proxmox VE ${pve_version} - applying minimal banner patch"
|
||||
msg_info "$(translate "Detected Proxmox VE") ${pve_version} - $(translate "applying banner patch")"
|
||||
|
||||
|
||||
# Ask user for confirmation
|
||||
if ! whiptail --title "Proxmox Subscription Banner (v3 - Minimal)" \
|
||||
--yesno "This will make a minimal surgical change to proxmoxlib.js\nto disable the subscription banner.\n\nA backup will be created automatically.\n\nContinue?" 12 70; then
|
||||
msg_warn "Banner removal cancelled by user."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Remove old APT hooks
|
||||
for f in /etc/apt/apt.conf.d/*nag*; do
|
||||
[[ -e "$f" ]] && rm -f "$f"
|
||||
done
|
||||
|
||||
# Create backup
|
||||
# Create backup for desktop UI
|
||||
local backup_file
|
||||
backup_file=$(create_backup "$JS_FILE")
|
||||
if [ -n "$backup_file" ]; then
|
||||
msg_info "Backup created: $backup_file"
|
||||
msg_ok "$(translate "Desktop UI backup created"): $backup_file"
|
||||
fi
|
||||
|
||||
if [ -f "$MOBILE_UI_FILE" ]; then
|
||||
local mobile_backup
|
||||
mobile_backup=$(create_backup "$MOBILE_UI_FILE")
|
||||
if [ -n "$mobile_backup" ]; then
|
||||
msg_ok "$(translate "Mobile UI backup created"): $mobile_backup"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create patch script and APT hook
|
||||
@@ -211,16 +256,17 @@ remove_subscription_banner_v3() {
|
||||
|
||||
# Apply the patch
|
||||
if ! "$PATCH_BIN"; then
|
||||
msg_error "Error applying patch. Backup preserved at: $backup_file"
|
||||
msg_error "$(translate "Error applying patch. Backups preserved at"): $BACKUP_DIR"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Register tool as applied
|
||||
register_tool "subscription_banner_v3" true
|
||||
register_tool "subscription_banner" true
|
||||
|
||||
msg_ok "Subscription banner removed successfully (v3 - minimal patch)"
|
||||
msg_ok "Refresh your browser (Ctrl+Shift+R) to see changes"
|
||||
msg_info "Backup location: $BACKUP_DIR"
|
||||
msg_ok "$(translate "Subscription banner removed successfully")"
|
||||
msg_ok "$(translate "Desktop and Mobile UI patched")"
|
||||
msg_ok "$(translate "Refresh your browser (Ctrl+Shift+R) to see changes")"
|
||||
msg_info "$(translate "Backup location"): $BACKUP_DIR"
|
||||
}
|
||||
|
||||
# Run if executed directly
|
||||
|
||||
@@ -35,6 +35,7 @@ download_common_functions() {
|
||||
}
|
||||
|
||||
update_pve9() {
|
||||
local pve_version
|
||||
local start_time=$(date +%s)
|
||||
local log_file="/var/log/proxmox-update-$(date +%Y%m%d-%H%M%S).log"
|
||||
local changes_made=false
|
||||
@@ -48,7 +49,7 @@ update_pve9() {
|
||||
download_common_functions
|
||||
|
||||
|
||||
msg_info2 "$(translate "Detected: Proxmox VE 9.x (Current: $OS_CODENAME, Target: $TARGET_CODENAME)")"
|
||||
msg_info2 "$(translate "Detected: Proxmox VE ${pve_version} (Current: $OS_CODENAME, Target: $TARGET_CODENAME)")"
|
||||
echo
|
||||
|
||||
local available_space=$(df /var/cache/apt/archives | awk 'NR==2 {print int($4/1024)}')
|
||||
|
||||
@@ -140,8 +140,8 @@ remove_subscription_banner() {
|
||||
fi
|
||||
|
||||
if [[ "$pve_version" -ge 9 ]]; then
|
||||
if ! whiptail --title "Proxmox VE 9.x Subscription Banner Removal" \
|
||||
--yesno "Do you want to remove the Proxmox subscription banner from the web interface for PVE $pve_version?" 10 70; then
|
||||
if ! whiptail --title "Proxmox VE ${pve_version} Subscription Banner Removal" \
|
||||
--yesno "$(translate "Do you want to remove the Proxmox subscription banner from the web interface for PVE $pve_version?")\n\n$(translate "Attention: Removing the subscription banner may cause issues in the web interface after a future update.")\n\n$(translate "If this happens, you can restore the backup from the 'Subscription Banner Removal' option in 'Uninstall optimizations'.")\n\n$(translate "Are you sure you want to continue?")" 14 75; then
|
||||
msg_warn "Banner removal cancelled by user."
|
||||
return 1
|
||||
fi
|
||||
@@ -162,7 +162,6 @@ remove_subscription_banner() {
|
||||
|
||||
|
||||
|
||||
|
||||
# ==========================================================
|
||||
|
||||
|
||||
|
||||
@@ -274,8 +274,9 @@ uninstall_subscription_banner() {
|
||||
msg_info "$(translate "Restoring subscription banner...")"
|
||||
|
||||
local JS_FILE="/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js"
|
||||
local MOBILE_UI_FILE="/usr/share/pve-yew-mobile-gui/index.html.tpl"
|
||||
local PATCH_BIN="/usr/local/bin/pve-remove-nag-v3.sh"
|
||||
local BASE_DIR="/opt/pve-nag-buster"
|
||||
local BASE_DIR="/usr/local/share/proxmenux"
|
||||
local MIN_JS_FILE="/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.min.js"
|
||||
local GZ_FILE="/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js.gz"
|
||||
|
||||
@@ -302,13 +303,23 @@ uninstall_subscription_banner() {
|
||||
# Verify backup integrity before restoring
|
||||
if [[ -s "$backup_file" ]] && grep -q "Ext\|function" "$backup_file" && ! grep -q $'\0' "$backup_file"; then
|
||||
cp -a "$backup_file" "$JS_FILE"
|
||||
msg_ok "$(translate "Restored from backup: $backup_file")"
|
||||
msg_ok "$(translate "Restored desktop UI from backup: $backup_file")"
|
||||
restored=true
|
||||
else
|
||||
msg_warn "$(translate "Backup file appears corrupted, will reinstall packages")"
|
||||
fi
|
||||
else
|
||||
msg_warn "$(translate "No backup found, will reinstall packages")"
|
||||
msg_warn "$(translate "No desktop UI backup found, will reinstall packages")"
|
||||
fi
|
||||
|
||||
local mobile_backup
|
||||
mobile_backup=$(ls -t "$BASE_DIR/backups"/index.html.tpl.backup.* 2>/dev/null | head -1)
|
||||
|
||||
if [[ -n "$mobile_backup" && -f "$mobile_backup" && -f "$MOBILE_UI_FILE" ]]; then
|
||||
if [[ -s "$mobile_backup" ]]; then
|
||||
cp -a "$mobile_backup" "$MOBILE_UI_FILE"
|
||||
msg_ok "$(translate "Restored mobile UI from backup: $mobile_backup")"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -342,12 +353,13 @@ uninstall_subscription_banner() {
|
||||
find /var/lib/pve-manager/ -name "*.js*" -delete 2>/dev/null || true
|
||||
find /var/cache/nginx/ -type f -delete 2>/dev/null || true
|
||||
|
||||
|
||||
systemctl restart pveproxy pvedaemon pvestatd 2>/dev/null || true
|
||||
|
||||
register_tool "subscription_banner" false
|
||||
|
||||
if [[ "$restored" == true ]]; then
|
||||
msg_ok "$(translate "Subscription banner restored successfully")"
|
||||
msg_ok "$(translate "Subscription banner restored successfully (desktop and mobile)")"
|
||||
msg_ok "$(translate "Clear your browser cache and refresh to see the subscription banner again")"
|
||||
else
|
||||
msg_error "$(translate "Failed to restore subscription banner completely")"
|
||||
@@ -359,7 +371,6 @@ uninstall_subscription_banner() {
|
||||
|
||||
|
||||
|
||||
|
||||
################################################################
|
||||
|
||||
uninstall_time_sync() {
|
||||
@@ -898,7 +909,7 @@ show_uninstall_menu() {
|
||||
lvm_repair) desc="LVM PV Headers Repair";;
|
||||
repo_cleanup) desc="Repository Cleanup";;
|
||||
#apt_upgrade) desc="APT Upgrade & Repository Config";;
|
||||
#subscription_banner) desc="Subscription Banner Removal";;
|
||||
subscription_banner) desc="Subscription Banner Removal";;
|
||||
time_sync) desc="Time Synchronization";;
|
||||
apt_languages) desc="APT Language Skip";;
|
||||
journald) desc="Journald Optimization";;
|
||||
|
||||
Reference in New Issue
Block a user