From dd9a5d83161a0066362acddcafe74211a03d8035 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 18 Sep 2023 12:52:12 +0200 Subject: [PATCH] add rhel and almalinux support --- src/SPC/doctor/item/LinuxMuslCheck.php | 6 ++++-- src/SPC/doctor/item/LinuxToolCheckList.php | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/SPC/doctor/item/LinuxMuslCheck.php b/src/SPC/doctor/item/LinuxMuslCheck.php index 28232a9e..860a23be 100644 --- a/src/SPC/doctor/item/LinuxMuslCheck.php +++ b/src/SPC/doctor/item/LinuxMuslCheck.php @@ -24,7 +24,7 @@ class LinuxMuslCheck // non-exist, need to recognize distro $distro = SystemUtil::getOSRelease(); return match ($distro['dist']) { - 'ubuntu', 'alpine', 'debian' => CheckResult::fail('musl-libc is not installed on your system', 'fix-musl', [$distro]), + 'ubuntu', 'alpine', 'debian', 'rhel', 'almalinux' => CheckResult::fail('musl-libc is not installed on your system', 'fix-musl', [$distro]), default => CheckResult::fail('musl-libc is not installed on your system'), }; } @@ -39,7 +39,9 @@ class LinuxMuslCheck $install_cmd = match ($distro['dist']) { 'ubuntu', 'debian' => 'apt-get install musl musl-tools -y', 'alpine' => 'apk add musl musl-utils musl-dev', - default => throw new RuntimeException('Current linux distro is not supported for auto-install musl packages'), + 'rhel' => 'dnf install tar wget git zip bison flex bzip2 cmake patch && wget https://musl.libc.org/releases/musl-1.2.4.tar.gz && tar -zxvf musl-1.2.4.tar.gz && rm musl-1.2.4.tar.gz && cd musl-1.2.4 && ./configure && make -j && make install && cd ..', + 'almalinux' => 'dnf install bison flex bzip2 cmake patch && wget https://musl.libc.org/releases/musl-1.2.4.tar.gz && tar -zxvf musl-1.2.4.tar.gz && rm musl-1.2.4.tar.gz && cd musl-1.2.4 && ./configure && make -j && make install && export PATH="/usr/local/musl/bin:$PATH" cd ..', + default => throw new RuntimeException('Current linux distro does not have an auto-install script for musl packages yet.'), }; $prefix = ''; if (get_current_user() !== 'root') { diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index 557ba3df..e4d6951c 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -16,7 +16,7 @@ class LinuxToolCheckList use UnixSystemUtilTrait; public const TOOLS_ALPINE = [ - 'make', 'bison', 'flex', + 'perl', 'make', 'bison', 'flex', 'git', 'autoconf', 'automake', 'tar', 'unzip', 'gzip', 'bzip2', 'cmake', 'gcc', @@ -24,7 +24,7 @@ class LinuxToolCheckList ]; public const TOOLS_DEBIAN = [ - 'make', 'bison', 'flex', + 'perl', 'make', 'bison', 'flex', 'git', 'autoconf', 'automake', 'tar', 'unzip', 'gzip', 'bzip2', 'cmake', 'patch', @@ -49,7 +49,11 @@ class LinuxToolCheckList } if (!empty($missing)) { return match ($distro['dist']) { - 'ubuntu', 'alpine', 'debian' => CheckResult::fail(implode(', ', $missing) . ' not installed on your system', 'install-linux-tools', [$distro, $missing]), + 'ubuntu', + 'alpine', + 'rhel', + 'almalinux', + 'debian' => CheckResult::fail(implode(', ', $missing) . ' not installed on your system', 'install-linux-tools', [$distro, $missing]), default => CheckResult::fail(implode(', ', $missing) . ' not installed on your system'), }; } @@ -80,7 +84,9 @@ class LinuxToolCheckList $install_cmd = match ($distro['dist']) { 'ubuntu', 'debian' => 'apt-get install -y', 'alpine' => 'apk add', - default => throw new RuntimeException('Current linux distro is not supported for auto-install musl packages'), + 'rhel' => 'dnf install -y', + 'almalinux' => 'dnf install -y', + default => throw new RuntimeException('Current linux distro does not have an auto-install script for musl packages yet.'), }; $prefix = ''; if (get_current_user() !== 'root') { @@ -88,7 +94,9 @@ class LinuxToolCheckList logger()->warning('Current user is not root, using sudo for running command'); } try { - shell(true)->exec($prefix . $install_cmd . ' ' . implode(' ', str_replace('xz', 'xz-utils', $missing))); + $is_rhel = in_array($distro['dist'], ['rhel', 'almalinux']); + $to_install = $is_rhel ? $missing : str_replace('xz', 'xz-utils', $missing); + shell(true)->exec($prefix . $install_cmd . ' ' . implode(' ', $to_install)); } catch (RuntimeException) { return false; }