From 0c12a767069f958fc342b4e70c3a8295c2fefee6 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Thu, 23 May 2024 12:03:13 -0300 Subject: [PATCH 1/3] fix: check if is alpine This is necessary to download specific Java package to Alpine. ref: #3026 Signed-off-by: Vitor Mattos --- lib/Service/Install/InstallService.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/Service/Install/InstallService.php b/lib/Service/Install/InstallService.php index f64794df03..c370093386 100644 --- a/lib/Service/Install/InstallService.php +++ b/lib/Service/Install/InstallService.php @@ -341,12 +341,13 @@ public function installJava(?bool $async = false): void { * https://jdk.java.net/java-se-ri/8-MR3 */ if (PHP_OS_FAMILY === 'Linux') { + $linuxDistribution = $this->getLinuxDistributionToDownloadJava(); $architecture = php_uname('m'); if ($architecture === 'x86_64') { - $compressedFileName = 'OpenJDK21U-jre_x64_linux_hotspot_' . self::JAVA_PARTIAL_VERSION . '.tar.gz'; + $compressedFileName = 'OpenJDK21U-jre_x64_' . $linuxDistribution . '_hotspot_' . self::JAVA_PARTIAL_VERSION . '.tar.gz'; $url = 'https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.2+13/' . $compressedFileName; } elseif ($architecture === 'aarch64') { - $compressedFileName = 'OpenJDK21U-jre_aarch64_linux_hotspot_' . self::JAVA_PARTIAL_VERSION . '.tar.gz'; + $compressedFileName = 'OpenJDK21U-jre_aarch64_' . $linuxDistribution . '_hotspot_' . self::JAVA_PARTIAL_VERSION . '.tar.gz'; $url = 'https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.2+13/' . $compressedFileName; } $class = TAR::class; @@ -372,6 +373,18 @@ public function installJava(?bool $async = false): void { $this->removeDownloadProgress(); } + /** + * Return linux or alpine-linux + */ + private function getLinuxDistributionToDownloadJava(): string { + $distribution = shell_exec('cat /etc/*-release'); + preg_match('/(\n|^)ID=(?.*)(\n|$)/', $distribution, $matches); + if (isset($matches['ID']) && strtolower($matches['ID']) === 'alpine') { + return 'alpine-linux'; + } + return 'linux'; + } + public function uninstallJava(): void { $javaPath = $this->appConfig->getAppValue('java_path'); if (!$javaPath) { From d7773c31a9771d7e82b48c4c30af5a238ad8f946 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Thu, 23 May 2024 12:07:16 -0300 Subject: [PATCH 2/3] fix: Use multi line regex Signed-off-by: Vitor Mattos --- lib/Service/Install/InstallService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/Install/InstallService.php b/lib/Service/Install/InstallService.php index c370093386..6a0a0e6402 100644 --- a/lib/Service/Install/InstallService.php +++ b/lib/Service/Install/InstallService.php @@ -378,7 +378,7 @@ public function installJava(?bool $async = false): void { */ private function getLinuxDistributionToDownloadJava(): string { $distribution = shell_exec('cat /etc/*-release'); - preg_match('/(\n|^)ID=(?.*)(\n|$)/', $distribution, $matches); + preg_match('/^ID=(?.*)$/m', $distribution, $matches); if (isset($matches['ID']) && strtolower($matches['ID']) === 'alpine') { return 'alpine-linux'; } From 5b002e18e948153ede0dcc5462ea3efefdf4add3 Mon Sep 17 00:00:00 2001 From: Florian Henze Date: Thu, 23 May 2024 17:27:29 +0000 Subject: [PATCH 3/3] Fixing the check on regular expression matches. The named group is not therefore the field have to be $matches['version'] to make a correct check --- lib/Service/Install/InstallService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/Install/InstallService.php b/lib/Service/Install/InstallService.php index 6a0a0e6402..16c0e5cf2e 100644 --- a/lib/Service/Install/InstallService.php +++ b/lib/Service/Install/InstallService.php @@ -379,7 +379,7 @@ public function installJava(?bool $async = false): void { private function getLinuxDistributionToDownloadJava(): string { $distribution = shell_exec('cat /etc/*-release'); preg_match('/^ID=(?.*)$/m', $distribution, $matches); - if (isset($matches['ID']) && strtolower($matches['ID']) === 'alpine') { + if (isset($matches['version']) && strtolower($matches['version']) === 'alpine') { return 'alpine-linux'; } return 'linux';