mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-08 17:35:36 +08:00
refactor download
This commit is contained in:
@@ -116,8 +116,12 @@ class CheckListHandler
|
||||
|
||||
private function emitFix(CheckResult $result)
|
||||
{
|
||||
pcntl_signal(SIGINT, function () {
|
||||
$this->output->writeln('<error>You cancelled fix</error>');
|
||||
});
|
||||
$fix = $this->fix_map[$result->getFixItem()];
|
||||
$fix_result = call_user_func($fix, ...$result->getFixParams());
|
||||
pcntl_signal(SIGINT, SIG_IGN);
|
||||
if ($fix_result) {
|
||||
$this->output->writeln('<info>Fix done</info>');
|
||||
} else {
|
||||
|
||||
@@ -39,4 +39,10 @@ class CheckResult
|
||||
{
|
||||
return empty($this->message);
|
||||
}
|
||||
|
||||
public function setFixItem(string $fix_item = '', array $fix_params = [])
|
||||
{
|
||||
$this->fix_item = $fix_item;
|
||||
$this->fix_params = $fix_params;
|
||||
}
|
||||
}
|
||||
|
||||
52
src/SPC/doctor/item/LinuxMuslCheck.php
Normal file
52
src/SPC/doctor/item/LinuxMuslCheck.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\doctor\item;
|
||||
|
||||
use SPC\builder\linux\SystemUtil;
|
||||
use SPC\doctor\AsCheckItem;
|
||||
use SPC\doctor\AsFixItem;
|
||||
use SPC\doctor\CheckResult;
|
||||
use SPC\exception\RuntimeException;
|
||||
|
||||
class LinuxMuslCheck
|
||||
{
|
||||
#[AsCheckItem('if musl-libc is installed', limit_os: 'Linux')]
|
||||
public function checkMusl(): ?CheckResult
|
||||
{
|
||||
$file = '/lib/ld-musl-x86_64.so.1';
|
||||
$result = null;
|
||||
if (file_exists($file)) {
|
||||
return CheckResult::ok();
|
||||
}
|
||||
|
||||
// non-exist, need to recognize distro
|
||||
$distro = SystemUtil::getOSRelease();
|
||||
return match ($distro['dist']) {
|
||||
'ubuntu', 'alpine', 'debian' => CheckResult::fail('musl-libc is not installed on your system', 'fix-musl', [$distro]),
|
||||
default => CheckResult::fail('musl-libc is not installed on your system'),
|
||||
};
|
||||
}
|
||||
|
||||
#[AsFixItem('fix-musl')]
|
||||
public function fixMusl(array $distro): bool
|
||||
{
|
||||
$install_cmd = match ($distro['dist']) {
|
||||
'ubuntu', 'debian' => 'apt install musl musl-tools -y',
|
||||
'alpine' => 'apk add musl musl-utils musl-dev',
|
||||
default => throw new RuntimeException('Current linux distro is not supported for auto-install musl packages'),
|
||||
};
|
||||
$prefix = '';
|
||||
if (get_current_user() !== 'root') {
|
||||
$prefix = 'sudo ';
|
||||
logger()->warning('Current user is not root, using sudo for running command');
|
||||
}
|
||||
try {
|
||||
shell(true)->exec($prefix . $install_cmd);
|
||||
return true;
|
||||
} catch (RuntimeException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user