-
-
Notifications
You must be signed in to change notification settings - Fork 364
Expand file tree
/
Copy pathBSDToolCheckList.php
More file actions
72 lines (64 loc) · 1.78 KB
/
BSDToolCheckList.php
File metadata and controls
72 lines (64 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?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();
}
#[AsCheckItem('if xcaddy is installed', limit_os: 'BSD')]
public function checkXcaddy(): ?CheckResult
{
return $this->checkGoAndXcaddy();
}
#[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 {
shell(true)->exec("ASSUME_ALWAYS_YES=yes {$prefix}pkg install -y " . implode(' ', $missing));
} catch (RuntimeException) {
return false;
}
return true;
}
}