diff --git a/scripts/fuc-xb-acceptance/template.php b/scripts/fuc-xb-acceptance/template.php new file mode 100644 index 00000000..660226a9 --- /dev/null +++ b/scripts/fuc-xb-acceptance/template.php @@ -0,0 +1,18 @@ +make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); +if(Illuminate\Support\Facades\DB::connection()->getDatabaseName()!=='fuc_xb_test')throw new RuntimeException('Wrong database'); +$path=$root.'/scripts/node-onboarding/sing-box-template.json'; +if(hash_file('sha256',$path)!=='32168fd207632602d4f99f6c66c4d2c3e2399dc0ec3726d9e5b0be1564db3d81')throw new RuntimeException('Reviewed modern template changed'); +$modern=file_get_contents($path);$old=App\Models\SubscribeTemplate::where('name','singbox')->firstOrFail(); +$current=json_decode($old->content,true,512,JSON_THROW_ON_ERROR);$new=json_decode($modern,true,512,JSON_THROW_ON_ERROR); +if($current===$new){echo json_encode(['already_updated'=>true,'shared_code_changed'=>false]).PHP_EOL;exit;} +$default=json_decode(file_get_contents($root.'/resources/rules/default.sing-box.json'),true,512,JSON_THROW_ON_ERROR); +if($current!==$default)throw new RuntimeException('Unexpected custom template; do not overwrite'); +$backup=$dir.'/singbox-template-before.json';if(file_exists($backup))throw new RuntimeException('Existing backup; inspect current state'); +file_put_contents($backup,json_encode($old->getAttributes()));chmod($backup,0600); +App\Models\SubscribeTemplate::setContent('singbox',$modern); +if(App\Models\SubscribeTemplate::getContent('singbox')!==$modern)throw new RuntimeException('Template readback failed'); +echo json_encode(['updated_only_isolated_instance_template'=>true,'old_template_backed_up'=>true,'shared_code_changed'=>false,'other_instances_changed'=>false,'modern_template_sha256'=>hash('sha256',$modern)]).PHP_EOL;