Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add legacy CentOS distro support #585

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/SPC/builder/linux/SystemUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ public static function getOSRelease(): array
switch (true) {
case file_exists('/etc/centos-release'):
$lines = file('/etc/centos-release');
$centos = true;
goto rh;
case file_exists('/etc/redhat-release'):
$lines = file('/etc/redhat-release');
$centos = false;
rh:
foreach ($lines as $line) {
if (preg_match('/release\s+(\d*(\.\d+)*)/', $line, $matches)) {
$ret['dist'] = 'redhat';
/* @phpstan-ignore-next-line */
$ret['dist'] = $centos ? 'centos' : 'redhat';
$ret['ver'] = $matches[1];
}
}
Expand Down Expand Up @@ -171,6 +174,8 @@ public static function getSupportedDistros(): array
'debian', 'ubuntu', 'Deepin',
// rhel-like
'redhat',
// centos
'centos',
// alpine
'alpine',
// arch
Expand Down
8 changes: 5 additions & 3 deletions src/SPC/doctor/item/LinuxToolCheckList.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function checkCliTools(): ?CheckResult

$required = match ($distro['dist']) {
'alpine' => self::TOOLS_ALPINE,
'redhat' => self::TOOLS_RHEL,
'redhat', 'centos' => self::TOOLS_RHEL,
'arch' => self::TOOLS_ARCH,
default => self::TOOLS_DEBIAN,
};
Expand All @@ -72,6 +72,7 @@ public function checkCliTools(): ?CheckResult
'ubuntu',
'alpine',
'redhat',
'centos',
'Deepin',
'arch',
'debian' => CheckResult::fail(implode(', ', $missing) . ' not installed on your system', 'install-linux-tools', [$distro, $missing]),
Expand Down Expand Up @@ -121,13 +122,14 @@ public function fixBuildTools(array $distro, array $missing): bool
'ubuntu', 'debian', 'Deepin' => 'apt-get install -y',
'alpine' => 'apk add',
'redhat' => 'dnf install -y',
'centos' => 'yum install -y',
'arch' => 'pacman -S --noconfirm',
default => throw new RuntimeException('Current linux distro does not have an auto-install script for musl packages yet.'),
};
$prefix = '';
if (get_current_user() !== 'root') {
if (($user = exec('whoami')) !== 'root') {
$prefix = 'sudo ';
logger()->warning('Current user is not root, using sudo for running command');
logger()->warning('Current user (' . $user . ') is not root, using sudo for running command');
}
try {
$is_debian = in_array($distro['dist'], ['debian', 'ubuntu', 'Deepin']);
Expand Down
Loading