Les installations hors YunoHost peuvent désormais vérifier et installer une release Forgejo avec sauvegarde et retour arrière complet.
56 lines
2 KiB
PHP
56 lines
2 KiB
PHP
<?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);
|
||
}
|