Skip to content

Commit

Permalink
fix redhat os detection
Browse files Browse the repository at this point in the history
  • Loading branch information
DubbleClick committed Nov 1, 2023
1 parent 2373ab3 commit fe4e8e4
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/SPC/doctor/item/LinuxToolCheckList.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LinuxToolCheckList
'git', 'autoconf', 'automake',
'tar', 'unzip', 'gzip', 'gcc',
'bzip2', 'cmake', 'patch',
'xz', 'wget', // to get musl
'xz',
];

/** @noinspection PhpUnused */
Expand All @@ -47,8 +47,7 @@ public function checkCliTools(): ?CheckResult

$required = match ($distro['dist']) {
'alpine' => self::TOOLS_ALPINE,
'almalinux' => self::TOOLS_RHEL,
'rhel' => self::TOOLS_RHEL,
'redhat' => self::TOOLS_RHEL,
default => self::TOOLS_DEBIAN,
};
$missing = [];
Expand All @@ -61,8 +60,7 @@ public function checkCliTools(): ?CheckResult
return match ($distro['dist']) {
'ubuntu',
'alpine',
'rhel',
'almalinux',
'redhat',
'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'),
};
Expand All @@ -74,11 +72,10 @@ public function checkCliTools(): ?CheckResult
#[AsCheckItem('if necessary packages are installed', limit_os: 'Linux')]
public function checkSystemOSPackages(): ?CheckResult
{
$distro = SystemUtil::getOSRelease();
if ($distro['dist'] === 'alpine') {
if (SystemUtil::isMuslDist()) {
// check linux-headers installation
if (!file_exists('/usr/include/linux/mman.h')) {
return CheckResult::fail('linux-headers not installed on your system', 'install-linux-tools', [$distro, ['linux-headers']]);
return CheckResult::fail('linux-headers not installed on your system', 'install-linux-tools', [SystemUtil::getOSRelease(), ['linux-headers']]);
}
}
return CheckResult::ok();
Expand All @@ -94,8 +91,7 @@ public function fixBuildTools(array $distro, array $missing): bool
$install_cmd = match ($distro['dist']) {
'ubuntu', 'debian' => 'apt-get install -y',
'alpine' => 'apk add',
'rhel' => 'dnf install -y',
'almalinux' => 'dnf install -y',
'redhat' => 'dnf install -y',
default => throw new RuntimeException('Current linux distro does not have an auto-install script for musl packages yet.'),
};
$prefix = '';
Expand All @@ -104,8 +100,8 @@ public function fixBuildTools(array $distro, array $missing): bool
logger()->warning('Current user is not root, using sudo for running command');
}
try {
$is_rhel = in_array($distro['dist'], ['rhel', 'almalinux']);
$to_install = $is_rhel ? $missing : str_replace('xz', 'xz-utils', $missing);
$is_debian = in_array($distro['dist'], ['debian', 'ubuntu']);
$to_install = $is_debian ? str_replace('xz', 'xz-utils', $missing) : $missing;
shell(true)->exec($prefix . $install_cmd . ' ' . implode(' ', $to_install));
} catch (RuntimeException) {
return false;
Expand Down

0 comments on commit fe4e8e4

Please sign in to comment.