Previously the script assumed every ZIP was named proserve-{version}.zip.
That broke when an upload was named "Proserve v1.4.6.zip" (with space and
capital P, the natural name produced by Compress-Archive on a Proserve
v1.4.6/ folder).
Now the script:
1. Reads download.url from each version entry, takes basename().
2. If that exact file is missing, falls back to a glob *{version}*.zip
in builds/ — succeeds if exactly one match.
3. Logs a clear message in either case.
Also fix manifest example hostname (www.exemple-asterion.com → asterionvr.com).
77 lines
2.8 KiB
PHP
77 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* Met à jour les champs `download.sizeBytes` et `download.sha256` de versions.json
|
|
* en lisant les ZIPs présents dans /builds/. Le nom local du ZIP est dérivé du
|
|
* champ `download.url` (basename de l'URL), donc tu peux nommer ton fichier comme
|
|
* tu veux tant que le manifest pointe vers le bon nom.
|
|
*
|
|
* Usage (à exécuter via SSH OVH dans www/PS_Launcher/) :
|
|
* php tools/sign-manifest.php
|
|
*
|
|
* (v0.4) Ajoutera la signature Ed25519 globale du manifest.
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
$root = dirname(__DIR__);
|
|
$manifestPath = "$root/manifest/versions.json";
|
|
$buildsDir = "$root/builds";
|
|
|
|
if (!is_file($manifestPath)) {
|
|
fwrite(STDERR, "Manifest not found: $manifestPath\n");
|
|
exit(1);
|
|
}
|
|
|
|
$manifest = json_decode(file_get_contents($manifestPath), true, 512, JSON_THROW_ON_ERROR);
|
|
|
|
$updated = 0;
|
|
foreach ($manifest['versions'] as &$v) {
|
|
$version = $v['version'] ?? '?';
|
|
$url = $v['download']['url'] ?? '';
|
|
if ($url === '') {
|
|
echo " [skip] $version : pas d'URL dans le manifest\n";
|
|
continue;
|
|
}
|
|
|
|
$filename = basename(parse_url($url, PHP_URL_PATH) ?: '');
|
|
$zip = "$buildsDir/$filename";
|
|
|
|
if (!is_file($zip)) {
|
|
// Fallback : si le fichier n'existe pas exactement avec le nom de l'URL,
|
|
// on tente une recherche tolérante par version (espaces / casse / séparateurs).
|
|
$candidates = glob("$buildsDir/*{$version}*.zip", GLOB_NOSORT) ?: [];
|
|
$candidates = array_values(array_filter($candidates, 'is_file'));
|
|
if (count($candidates) === 1) {
|
|
$zip = $candidates[0];
|
|
echo " [info] $version : URL pointait vers '{$filename}', utilisé '" . basename($zip) . "' à la place\n";
|
|
} else {
|
|
echo " [skip] $version : ZIP introuvable pour $url\n";
|
|
if (count($candidates) > 1) {
|
|
echo " Plusieurs candidats : " . implode(', ', array_map('basename', $candidates)) . "\n";
|
|
}
|
|
continue;
|
|
}
|
|
}
|
|
|
|
$size = filesize($zip);
|
|
echo " [hash] $version : " . basename($zip) . " ($size octets)...";
|
|
$sha = hash_file('sha256', $zip);
|
|
echo " sha256={$sha}\n";
|
|
|
|
$v['download']['sizeBytes'] = $size;
|
|
$v['download']['sha256'] = $sha;
|
|
$updated++;
|
|
}
|
|
unset($v);
|
|
|
|
// (v0.4) Signature Ed25519 — pour l'instant on laisse 'signature' = null.
|
|
// $config = require __DIR__ . '/../api/config.php';
|
|
// $sk = sodium_hex2bin($config['ed25519']['private_key_hex']);
|
|
// $payload = json_encode($manifest, JSON_UNESCAPED_SLASHES);
|
|
// $manifest['signature'] = base64_encode(sodium_crypto_sign_detached($payload, $sk));
|
|
|
|
file_put_contents(
|
|
$manifestPath,
|
|
json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n"
|
|
);
|
|
echo "Manifest mis à jour ({$updated} version(s)) : $manifestPath\n";
|