2023-10-15 13:07:13 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\doctor\item;
|
|
|
|
|
|
|
|
|
|
use SPC\builder\traits\UnixSystemUtilTrait;
|
|
|
|
|
use SPC\doctor\AsCheckItem;
|
|
|
|
|
use SPC\doctor\AsFixItem;
|
|
|
|
|
use SPC\doctor\CheckResult;
|
|
|
|
|
use SPC\exception\RuntimeException;
|
|
|
|
|
|
|
|
|
|
class BSDToolCheckList
|
|
|
|
|
{
|
|
|
|
|
use UnixSystemUtilTrait;
|
|
|
|
|
|
|
|
|
|
/** @var string[] FreeBSD */
|
|
|
|
|
public const REQUIRED_COMMANDS = [
|
|
|
|
|
'curl',
|
|
|
|
|
'make',
|
|
|
|
|
'bison',
|
|
|
|
|
'flex',
|
|
|
|
|
'pkg-config',
|
|
|
|
|
'git',
|
|
|
|
|
'autoconf',
|
|
|
|
|
'automake',
|
|
|
|
|
'tar',
|
|
|
|
|
'unzip',
|
|
|
|
|
'xz',
|
|
|
|
|
'gzip',
|
|
|
|
|
'bzip2',
|
|
|
|
|
'cmake',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
#[AsCheckItem('if necessary tools are installed', limit_os: 'BSD')]
|
|
|
|
|
public function checkCliTools(): ?CheckResult
|
|
|
|
|
{
|
|
|
|
|
$missing = [];
|
|
|
|
|
foreach (self::REQUIRED_COMMANDS as $cmd) {
|
|
|
|
|
if ($this->findCommand($cmd) === null) {
|
|
|
|
|
$missing[] = $cmd;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!empty($missing)) {
|
|
|
|
|
return CheckResult::fail('missing system commands: ' . implode(', ', $missing), 'build-tools-bsd', [$missing]);
|
|
|
|
|
}
|
|
|
|
|
return CheckResult::ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[AsFixItem('build-tools-bsd')]
|
|
|
|
|
public function fixBuildTools(array $missing): bool
|
|
|
|
|
{
|
|
|
|
|
if (get_current_user() !== 'root') {
|
|
|
|
|
$prefix = 'sudo ';
|
|
|
|
|
logger()->warning('Current user is not root, using sudo for running command');
|
|
|
|
|
} else {
|
|
|
|
|
$prefix = '';
|
|
|
|
|
}
|
|
|
|
|
try {
|
2024-02-19 13:43:58 +08:00
|
|
|
shell(true)->exec("ASSUME_ALWAYS_YES=yes {$prefix}pkg install -y " . implode(' ', $missing));
|
2023-10-15 13:07:13 +08:00
|
|
|
} catch (RuntimeException) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|