Globinours/scripts/update.php
oversu 53e79a72d7 Ajoute les mises à jour autonomes
Les installations hors YunoHost peuvent désormais vérifier et installer une release Forgejo avec sauvegarde et retour arrière complet.
2026-09-08 20:13:55 +02:00

56 lines
2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
if (PHP_SAPI !== 'cli') {
http_response_code(404);
exit(1);
}
$root = dirname(__DIR__);
foreach (['DB', 'Migrations', 'I18n', 'AppSettings', 'Auth', 'AuditService', 'BackupService', 'UpdateService'] as $class) {
require_once $root . '/app/Services/' . $class . '.php';
}
Migrations::run($root . '/migrations');
I18n::setLocale(AppSettings::get('app_language'));
$arguments = array_slice($argv, 1);
$command = $arguments[0] ?? '--help';
try {
if ($command === '--check') {
echo json_encode(UpdateService::check(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), PHP_EOL;
exit(0);
}
if ($command === '--rollback') {
echo json_encode(UpdateService::rollbackLast(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), PHP_EOL;
exit(0);
}
if ($command === '--online') {
echo json_encode(UpdateService::installFromRepository(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), PHP_EOL;
exit(0);
}
if (is_file($command)) {
$hash = '';
foreach ($arguments as $argument) {
if (str_starts_with($argument, '--sha256=')) {
$hash = substr($argument, 9);
}
}
if ($hash === '') {
throw new InvalidArgumentException('L’option --sha256=<empreinte> est obligatoire.');
}
echo json_encode(UpdateService::install($command, $hash, 'cli'), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), PHP_EOL;
exit(0);
}
fwrite(STDERR, "Utilisation :\n");
fwrite(STDERR, " php scripts/update.php --check\n");
fwrite(STDERR, " php scripts/update.php --online\n");
fwrite(STDERR, " php scripts/update.php archive.tar.gz --sha256=EMPREINTE\n");
fwrite(STDERR, " php scripts/update.php --rollback\n");
exit(2);
} catch (Throwable $e) {
fwrite(STDERR, $e->getMessage() . PHP_EOL);
exit(1);
}