56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller\Api\Admin\Shoutcast;
|
|
|
|
use App\Entity;
|
|
use App\Environment;
|
|
use App\Http\Response;
|
|
use App\Http\ServerRequest;
|
|
use App\Service\Flow;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use RuntimeException;
|
|
use Symfony\Component\Process\Process;
|
|
|
|
class PostAction
|
|
{
|
|
public function __invoke(
|
|
ServerRequest $request,
|
|
Response $response,
|
|
Environment $environment
|
|
): ResponseInterface {
|
|
if ('x86_64' !== php_uname('m')) {
|
|
throw new RuntimeException('SHOUTcast cannot be installed on non-X86_64 systems.');
|
|
}
|
|
|
|
$flowResponse = Flow::process($request, $response);
|
|
if ($flowResponse instanceof ResponseInterface) {
|
|
return $flowResponse;
|
|
}
|
|
|
|
$scBaseDir = $environment->getParentDirectory() . '/servers/shoutcast2';
|
|
|
|
$scTgzPath = $scBaseDir . '/sc_serv.tar.gz';
|
|
if (is_file($scTgzPath)) {
|
|
unlink($scTgzPath);
|
|
}
|
|
|
|
$flowResponse->moveTo($scTgzPath);
|
|
|
|
$process = new Process(
|
|
[
|
|
'tar',
|
|
'xvzf',
|
|
$scTgzPath,
|
|
],
|
|
$scBaseDir
|
|
);
|
|
$process->mustRun();
|
|
|
|
unlink($scTgzPath);
|
|
|
|
return $response->withJson(Entity\Api\Status::success());
|
|
}
|
|
}
|