sign-manifest: derive ZIP filename from manifest URL, tolerant fallback
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).
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Met à jour les champs `download.sizeBytes` et `download.sha256` de versions.json
|
||||
* en lisant les ZIPs présents dans /builds/, puis (v0.4) signera le manifest avec Ed25519.
|
||||
* 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
|
||||
*
|
||||
* Convention attendue : pour chaque entrée du manifest, le ZIP est dans
|
||||
* builds/proserve-{version}.zip
|
||||
* (v0.4) Ajoutera la signature Ed25519 globale du manifest.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
@@ -22,20 +23,43 @@ if (!is_file($manifestPath)) {
|
||||
|
||||
$manifest = json_decode(file_get_contents($manifestPath), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
$updated = 0;
|
||||
foreach ($manifest['versions'] as &$v) {
|
||||
$version = $v['version'];
|
||||
$zip = "$buildsDir/proserve-{$version}.zip";
|
||||
if (!is_file($zip)) {
|
||||
echo " [skip] $version : ZIP absent ($zip)\n";
|
||||
$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 : $size octets...";
|
||||
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);
|
||||
|
||||
@@ -49,4 +73,4 @@ file_put_contents(
|
||||
$manifestPath,
|
||||
json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n"
|
||||
);
|
||||
echo "Manifest mis à jour : $manifestPath\n";
|
||||
echo "Manifest mis à jour ({$updated} version(s)) : $manifestPath\n";
|
||||
|
||||
Reference in New Issue
Block a user