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.
This commit is contained in:
parent
f41504c852
commit
53e79a72d7
25 changed files with 1146 additions and 61 deletions
56
scripts/update.php
Normal file
56
scripts/update.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?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);
|
||||
}
|
||||
Loading…
Reference in a new issue