add rhel and almalinux support

This commit is contained in:
DubbleClick
2023-09-18 12:52:12 +02:00
committed by Jerry Ma
parent 3b83c1fa7b
commit dd9a5d8316
2 changed files with 17 additions and 7 deletions

View File

@@ -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;
}