ops: complete subscription template and node activation workflow
This commit is contained in:
1 parent
1537ebf65c
commit
12d9f2b47c
6 files changed
+231
-2
No files matched your search
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
require getcwd() . '/vendor/autoload.php';
|
||||
$app = require getcwd() . '/bootstrap/app.php';
|
||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
$opts = getopt('', ['backup:']);
|
||||
$dir = $opts['backup'] ?? throw new RuntimeException('Missing backup');
|
||||
umask(0077);
|
||||
$old = App\Models\SubscribeTemplate::where('name', 'singbox')->firstOrFail();
|
||||
$default = json_decode(file_get_contents('resources/rules/default.sing-box.json'), true, flags: JSON_THROW_ON_ERROR);
|
||||
$replacement = file_get_contents(__DIR__ . '/sing-box-template.json');
|
||||
$new = json_decode($replacement, true, flags: JSON_THROW_ON_ERROR);
|
||||
$current = json_decode($old->content, true, flags: JSON_THROW_ON_ERROR);
|
||||
if ($current === $new) { echo "Template already updated\n"; exit; }
|
||||
if ($current !== $default) throw new RuntimeException('Custom template detected; inspect instead of overwriting');
|
||||
if (!is_dir($dir)) throw new RuntimeException('Backup directory missing');
|
||||
$path = "$dir/singbox-template-before.json";
|
||||
if (is_file($path)) throw new RuntimeException('Existing backup; inspect before retry');
|
||||
file_put_contents($path, json_encode($old->getAttributes(), JSON_THROW_ON_ERROR));
|
||||
App\Models\SubscribeTemplate::setContent('singbox', $replacement);
|
||||
echo "DPL default subscription template updated; custom templates and other airports untouched\n";
|
||||
Reference in new issue
Block a user