code wiki / _hdl_build / nx_deploy_stage.nx
nx_deploy_stage.nx source
↩ module page · 37 lines · 1805 B
1// nx_deploy_stage.nx -- CLI: the sovereign build->deploy rename-gap closer.
2// Copies a validated staged ELF into a deploy `.new` slot (safe-by-construction: dst MUST end .new, so it
3// can NEVER overwrite a live binary; the never-brick promote stays in /api/deploy).
4// usage: nx_deploy_stage --kat (self-test)
5// nx_deploy_stage stage <src-elf> <dst-.new> (JSON: rc, bytes, STAGED|REFUSED)
6// license_tier: ORIGINAL expect_exit: 0
7import "nx_deploy_stage_lib.nx"
8
9func main(argc: i64, argv: *i64) -> i64 {
10 if argc >= 2 {
11 let a1: *u8 = argv[1] as *u8
12 if a1[0] == (45 as u8) {
13 ds_w("=== nx_deploy_stage --kat (copy validated ELF -> .new slot; refuse live/non-ELF) ===\n" as *u8)
14 let f: i64 = ds_selftest()
15 ds_w("checks failed=" as *u8); if f==0 { ds_w("0\nVERDICT=GREEN\n" as *u8); sys_exit(0); return 0 }
16 ds_w("nonzero\nVERDICT=RED\n" as *u8); sys_exit(1); return 1
17 }
18 let vl: i64 = ds_len(a1)
19 if vl == 5 {
20 // "stage"
21 if a1[0]==(115 as u8) { if a1[1]==(116 as u8) { if a1[2]==(97 as u8) {
22 if argc < 4 { ds_w("usage: nx_deploy_stage stage <src-elf> <dst-.new>\n" as *u8); sys_exit(2); return 2 }
23 let src: *u8 = argv[2] as *u8
24 let dst: *u8 = argv[3] as *u8
25 let sz0: i64 = ds_src_size(src)
26 let rc: i64 = ds_stage(src, dst)
27 var showsz: i64 = sz0
28 if sz0 < 0 { showsz = 0 }
29 ds_emit(src, dst, rc, showsz)
30 if rc == 0 { sys_exit(0); return 0 }
31 sys_exit(3); return 3
32 } } }
33 }
34 }
35 ds_w("usage: nx_deploy_stage --kat | stage <src-elf> <dst-.new>\n" as *u8)
36 sys_exit(2); return 2
37}