diff --git a/misc/tools.func b/misc/tools.func index a21a70ff96..63aad95b48 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -2784,12 +2784,19 @@ function setup_java() { 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 matched + # 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" - INSTALLED_VERSION="0" + 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 # Scenario 1: Already at correct version