From 245433f535a6f49f5ddb9c5c2058e14fe6a5e6b4 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Thu, 19 Mar 2026 21:55:58 +0100 Subject: [PATCH] tools.func: use dpkg-query for reliable JDK version detection (#13101) --- misc/tools.func | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/misc/tools.func b/misc/tools.func index af2d21435..0b914a478 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -5353,24 +5353,7 @@ function setup_java() { # Get currently installed version local INSTALLED_VERSION="" - if dpkg -l | grep -q "temurin-.*-jdk" 2>/dev/null; then - INSTALLED_VERSION=$(dpkg -l 2>/dev/null | awk '/temurin-.*-jdk/{print $2}' | grep -oP 'temurin-\K[0-9]+' | head -n1 || echo "") - fi - - # Validate INSTALLED_VERSION is not empty if JDK package found - local JDK_COUNT=0 - JDK_COUNT=$(dpkg -l 2>/dev/null | grep -c "temurin-.*-jdk" || true) - if [[ -z "$INSTALLED_VERSION" && "${JDK_COUNT:-0}" -gt 0 ]]; then - msg_warn "Found Temurin JDK but cannot determine version - attempting reinstall" - # Try to get actual package name for purge - local OLD_PACKAGE - OLD_PACKAGE=$(dpkg -l 2>/dev/null | awk '/temurin-.*-jdk/{print $2}' | head -n1 || echo "") - if [[ -n "$OLD_PACKAGE" ]]; then - msg_info "Removing existing package: $OLD_PACKAGE" - $STD apt purge -y "$OLD_PACKAGE" || true - fi - INSTALLED_VERSION="" # Reset to trigger fresh install - fi + INSTALLED_VERSION=$(dpkg-query -W -f '${Package}\n' 2>/dev/null | grep -oP '^temurin-\K[0-9]+(?=-jdk$)' | head -n1 || echo "") # Scenario 1: Already at correct version if [[ "$INSTALLED_VERSION" == "$JAVA_VERSION" ]]; then