mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-02 14:25:41 +08:00
Enhance Linux distribution detection and package installation commands (forward-port #1109)
This commit is contained in:
@@ -61,9 +61,19 @@ class LinuxToolCheck
|
||||
'alpine' => self::TOOLS_ALPINE,
|
||||
'redhat' => self::TOOLS_RHEL,
|
||||
'centos' => array_merge(self::TOOLS_RHEL, ['perl-IPC-Cmd', 'perl-Time-Piece']),
|
||||
'arch' => self::TOOLS_ARCH,
|
||||
default => self::TOOLS_DEBIAN,
|
||||
'arch', 'manjaro' => self::TOOLS_ARCH,
|
||||
default => null,
|
||||
};
|
||||
if ($required === null) {
|
||||
// fallback to family-based detection
|
||||
$family = explode(' ', strtolower($distro['family']));
|
||||
$required = match (true) {
|
||||
in_array('alpine', $family) => self::TOOLS_ALPINE,
|
||||
in_array('rhel', $family) || in_array('fedora', $family) => self::TOOLS_RHEL,
|
||||
in_array('arch', $family) => self::TOOLS_ARCH,
|
||||
default => self::TOOLS_DEBIAN,
|
||||
};
|
||||
}
|
||||
$missing = [];
|
||||
foreach ($required as $package) {
|
||||
if (LinuxUtil::findCommand(self::PROVIDED_COMMAND[$package] ?? $package) === null) {
|
||||
@@ -116,10 +126,12 @@ class LinuxToolCheck
|
||||
if ($install_cmd === null) {
|
||||
// try family
|
||||
$family = explode(' ', strtolower($distro['family']));
|
||||
if (in_array('debian', $family)) {
|
||||
if (in_array('debian', $family) || in_array('ubuntu', $family)) {
|
||||
$install_cmd = 'apt-get install -y';
|
||||
} elseif (in_array('rhel', $family) || in_array('fedora', $family)) {
|
||||
$install_cmd = 'dnf install -y';
|
||||
} elseif (in_array('arch', $family)) {
|
||||
$install_cmd = 'pacman -S --noconfirm';
|
||||
} else {
|
||||
throw new EnvironmentException(
|
||||
"Current linux distro [{$distro['dist']}] does not have an auto-install script for packages yet.",
|
||||
|
||||
@@ -16,8 +16,11 @@ class OSCheck
|
||||
if (!in_array(PHP_OS_FAMILY, ['Darwin', 'Linux', 'Windows'])) {
|
||||
return CheckResult::fail('Current OS is not supported: ' . PHP_OS_FAMILY);
|
||||
}
|
||||
$distro = PHP_OS_FAMILY === 'Linux' ? (' ' . LinuxUtil::getOSRelease()['dist']) : '';
|
||||
$known_distro = PHP_OS_FAMILY !== 'Linux' || in_array(LinuxUtil::getOSRelease()['dist'], LinuxUtil::getSupportedDistros());
|
||||
$release = PHP_OS_FAMILY === 'Linux' ? LinuxUtil::getOSRelease() : null;
|
||||
$distro = $release !== null ? (' ' . $release['dist']) : '';
|
||||
$known_distro = $release === null
|
||||
|| in_array($release['dist'], LinuxUtil::getSupportedDistros())
|
||||
|| count(array_intersect(explode(' ', $release['family']), LinuxUtil::getSupportedDistros())) > 0;
|
||||
return CheckResult::ok(PHP_OS_FAMILY . ' ' . php_uname('m') . $distro . ', supported' . ($known_distro ? '' : ' (but not tested on this distro)'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ class LinuxUtil extends UnixUtil
|
||||
|
||||
$ret['dist'] = trim($ret['dist'], '"\'');
|
||||
$ret['ver'] = trim($ret['ver'], '"\'');
|
||||
$ret['family'] = trim($ret['family'], '"\'');
|
||||
|
||||
if (strcasecmp($ret['dist'], 'centos') === 0) {
|
||||
$ret['dist'] = 'redhat';
|
||||
@@ -91,7 +92,7 @@ class LinuxUtil extends UnixUtil
|
||||
{
|
||||
return [
|
||||
// debian-like
|
||||
'debian', 'ubuntu', 'Deepin', 'neon',
|
||||
'debian', 'ubuntu', 'Deepin',
|
||||
// rhel-like
|
||||
'redhat',
|
||||
// centos
|
||||
|
||||
Reference in New Issue
Block a user