This commit is contained in:
2026-11-02 20:27:11 +02:00
parent b44378b899
commit badaada043
300 changed files with 17458 additions and 1056 deletions
+44 -1
View File
@@ -3,15 +3,19 @@
use Tempo\Purchasing\Delivery\AccessOverlay;
use Tempo\Purchasing\Delivery\BootOverlay;
use Tempo\Purchasing\Delivery\BudgetOverlay;
use Tempo\Purchasing\Delivery\AdminUiOverlay;
require dirname(__DIR__).'/integrations/sgf/access/AccessOverlay.php';
require dirname(__DIR__).'/integrations/sgf/operational/BudgetOverlay.php';
require dirname(__DIR__).'/integrations/sgf/operational/BootOverlay.php';
require dirname(__DIR__).'/integrations/sgf/operational/AdminUiOverlay.php';
$host = realpath($argv[1] ?? dirname(__DIR__).'/../sgf-tempo');
if (! $host) {
throw new RuntimeException('Host inexistente.');
}
$files = AccessOverlay::prepare($host) + BudgetOverlay::prepare($host) + BootOverlay::prepare($host);
$frontend = AdminUiOverlay::prepare($host, $files);
$files = $frontend['files'];
$root = dirname(__DIR__);
$support = [];
foreach (['integrations/sgf/operational', 'integrations/sgf/access', 'integrations/sgf/internal-requisitions', 'packages/purchasing/src'] as $directory) {
@@ -22,7 +26,9 @@ foreach (['integrations/sgf/operational', 'integrations/sgf/access', 'integratio
}
}
ksort($support);
$support += $frontend['assets'];
$support['scripts/sgf-internal-install.php'] = file_get_contents($root.'/scripts/sgf-internal-install.php');
$support['scripts/sgf-code-deploy.php'] = file_get_contents($root.'/scripts/sgf-code-deploy.php');
$support['bootstrap.php'] = file_get_contents($root.'/integrations/sgf/operational/entry.php');
$hash = hash('sha256', json_encode([$files, $support], JSON_THROW_ON_ERROR));
$directory = $root.'/storage/app/private/candidates/OPERATIONAL-CANDIDATE-'.substr($hash, 0, 16);
@@ -44,4 +50,41 @@ foreach ($support as $path => $contents) {
$manifest['support_files'][$path] = hash('sha256', $contents);
}
file_put_contents($directory.'/manifest.json', json_encode($manifest, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
echo json_encode(['directory' => $directory, 'installed' => false], JSON_THROW_ON_ERROR)."\n";
$archives = $root.'/storage/app/private/candidate-archives';
if (! is_dir($archives)) {
mkdir($archives, 0700, true);
}
$archive = $archives.'/'.basename($directory).'.zip';
$creating = ! is_file($archive);
$archivePath = $creating ? $archive.'.'.bin2hex(random_bytes(6)).'.tmp' : $archive;
$zip = new ZipArchive;
if ($zip->open($archivePath, $creating ? ZipArchive::CREATE | ZipArchive::EXCL : 0) !== true) {
throw new RuntimeException('Arquivo de candidata inválido.');
}
if ($creating) {
foreach ([...array_keys($manifest['support_files']), 'manifest.json'] as $file) {
$zip->addFile($directory.'/'.$file, $file);
}
if (! $zip->close()) {
throw new RuntimeException('Falha ao preparar arquivo.');
}
if ($zip->open($archivePath) !== true) {
throw new RuntimeException('Arquivo incompleto.');
}
}
if ($zip->numFiles !== count($manifest['support_files']) + 1) {
throw new RuntimeException('Conteúdo extra/ausente no arquivo.');
}
foreach ($manifest['support_files'] + ['manifest.json' => hash_file('sha256', $directory.'/manifest.json')] as $file => $expected) {
$size = filesize($directory.'/'.$file);
$entry = $zip->statName($file);
$body = $zip->getFromName($file, $size + 1);
if (! $entry || $entry['size'] !== $size || $body === false || ! hash_equals($expected, hash('sha256', $body))) {
throw new RuntimeException('Integridade do arquivo imutável divergente.');
}
}
$zip->close();
if ($creating && ! rename($archivePath, $archive)) {
throw new RuntimeException('Falha ao concluir arquivo.');
}
echo json_encode(['directory' => $directory, 'archive' => ['file' => $archive, 'sha256' => hash_file('sha256', $archive), 'manifest_sha256' => hash_file('sha256', $directory.'/manifest.json')], 'installed' => false], JSON_THROW_ON_ERROR)."\n";