Skip to content

Commit 2ca5ad0

Browse files
authored
Add legacy CentOS distro support (#585)
1 parent 20dad4c commit 2ca5ad0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/SPC/builder/linux/SystemUtil.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ public static function getOSRelease(): array
2121
switch (true) {
2222
case file_exists('/etc/centos-release'):
2323
$lines = file('/etc/centos-release');
24+
$centos = true;
2425
goto rh;
2526
case file_exists('/etc/redhat-release'):
2627
$lines = file('/etc/redhat-release');
28+
$centos = false;
2729
rh:
2830
foreach ($lines as $line) {
2931
if (preg_match('/release\s+(\d*(\.\d+)*)/', $line, $matches)) {
30-
$ret['dist'] = 'redhat';
32+
/* @phpstan-ignore-next-line */
33+
$ret['dist'] = $centos ? 'centos' : 'redhat';
3134
$ret['ver'] = $matches[1];
3235
}
3336
}
@@ -171,6 +174,8 @@ public static function getSupportedDistros(): array
171174
'debian', 'ubuntu', 'Deepin',
172175
// rhel-like
173176
'redhat',
177+
// centos
178+
'centos',
174179
// alpine
175180
'alpine',
176181
// arch

src/SPC/doctor/item/LinuxToolCheckList.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function checkCliTools(): ?CheckResult
5757

5858
$required = match ($distro['dist']) {
5959
'alpine' => self::TOOLS_ALPINE,
60-
'redhat' => self::TOOLS_RHEL,
60+
'redhat', 'centos' => self::TOOLS_RHEL,
6161
'arch' => self::TOOLS_ARCH,
6262
default => self::TOOLS_DEBIAN,
6363
};
@@ -72,6 +72,7 @@ public function checkCliTools(): ?CheckResult
7272
'ubuntu',
7373
'alpine',
7474
'redhat',
75+
'centos',
7576
'Deepin',
7677
'arch',
7778
'debian' => CheckResult::fail(implode(', ', $missing) . ' not installed on your system', 'install-linux-tools', [$distro, $missing]),
@@ -121,13 +122,14 @@ public function fixBuildTools(array $distro, array $missing): bool
121122
'ubuntu', 'debian', 'Deepin' => 'apt-get install -y',
122123
'alpine' => 'apk add',
123124
'redhat' => 'dnf install -y',
125+
'centos' => 'yum install -y',
124126
'arch' => 'pacman -S --noconfirm',
125127
default => throw new RuntimeException('Current linux distro does not have an auto-install script for musl packages yet.'),
126128
};
127129
$prefix = '';
128-
if (get_current_user() !== 'root') {
130+
if (($user = exec('whoami')) !== 'root') {
129131
$prefix = 'sudo ';
130-
logger()->warning('Current user is not root, using sudo for running command');
132+
logger()->warning('Current user (' . $user . ') is not root, using sudo for running command');
131133
}
132134
try {
133135
$is_debian = in_array($distro['dist'], ['debian', 'ubuntu', 'Deepin']);

0 commit comments

Comments
 (0)