diff --git a/src/StaticPHP/Doctor/Item/LinuxToolCheck.php b/src/StaticPHP/Doctor/Item/LinuxToolCheck.php index b44bcb9d..c755c43f 100644 --- a/src/StaticPHP/Doctor/Item/LinuxToolCheck.php +++ b/src/StaticPHP/Doctor/Item/LinuxToolCheck.php @@ -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.", diff --git a/src/StaticPHP/Doctor/Item/OSCheck.php b/src/StaticPHP/Doctor/Item/OSCheck.php index 7bd19df8..9557bdef 100644 --- a/src/StaticPHP/Doctor/Item/OSCheck.php +++ b/src/StaticPHP/Doctor/Item/OSCheck.php @@ -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)')); } } diff --git a/src/StaticPHP/Util/System/LinuxUtil.php b/src/StaticPHP/Util/System/LinuxUtil.php index 2b1adf3d..4b68a50b 100644 --- a/src/StaticPHP/Util/System/LinuxUtil.php +++ b/src/StaticPHP/Util/System/LinuxUtil.php @@ -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