Files
preland/bin/release-brand.php
2026-10-21 17:24:14 +03:00

27 lines
1.8 KiB
PHP

<?php
/** Отдельная явно согласованная миграция бренда. Обычная code-поставка SVG не пишет. */
declare(strict_types=1);
require __DIR__ . '/brand-contract.php';
try {
$mode = $argv[1] ?? ''; $url = $argv[2] ?? '';
if (!preg_match('~^https://([a-z0-9.-]+)$~D', $url, $match)) throw new RuntimeException('Требуется HTTPS origin цели');
$brand = prelandBrand(dirname(__DIR__), $match[1]);
if ($mode === '--files') {
foreach ($brand['logos'] as $target => $record) echo $record['file'], ' ', $target, "\n";
exit(0);
}
if ($mode !== '--status') throw new RuntimeException('Неизвестный режим бренда');
$actual = []; $expected = [];
foreach ($brand['logos'] as $target => $record) {
$context = stream_context_create(['http' => ['timeout' => 30, 'header' => "Cache-Control: no-cache\r\n"]]);
$body = @file_get_contents($url . '/' . $target . '?brand_check=' . $record['sha256'], false, $context);
if ($body === false) throw new RuntimeException('Не удалось прочитать бренд цели: ' . $target);
$actual[$target] = hash('sha256', str_replace("\r\n", "\n", $body));
$expected[$target] = $record['sha256'];
}
$state = prelandBrandState($actual, $brand);
if ($state === 0) { echo "OK: доменный бренд совпал; SVG не перезаписываются\n"; exit(0); }
if ($state === 10) { echo "Разрешена точная миграция бренда по preland#12\n"; exit(10); }
throw new RuntimeException('На хосте другой бренд: обычный deploy не имеет права его менять');
} catch (Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }