blob: 048e94c07c8662a38037292840bda8006d0de861 (
plain)
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
|
<?php
namespace PHPIAC\Command;
use PHPIAC\Task;
use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Net\SSH2;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class RunCommand extends Command
{
protected static $defaultName = 'run';
protected function configure()
{}
protected function execute(InputInterface $input, OutputInterface $output)
{
$cwd = getcwd();
$config = include $cwd . '/config.php';
global $ssh;
$ssh = new SSH2($config['host']);
if (! $ssh->login($config['user'], PublicKeyLoader::load(file_get_contents($config['private_key_file'])))) {
throw new \Exception('Login failed');
}
$commands = [];
foreach ($config['tasks'] as $task) {
/**@var Task $task*/
if (! $task->module->checkState()) {
$output->writeln('Adding commands from ' . get_class($task->module));
array_push($commands, ...$task->module->getCommands());
}
else {
$output->writeln('Skipping commands from ' . get_class($task->module));
}
}
$ssh->exec(implode(PHP_EOL, $commands));
return Command::SUCCESS;
}
}
|