code wiki / _hdl_build / nx_hub_ship.nx
nx_hub_ship.nx source
↩ module page · 32 lines · 1980 B
1// nx_hub_ship.nx -- sovereign stager for the hub-gateway push (so deploy needs NO bash printf/scratch .sh):
2// copies the freshly-built gateway (/tmp/nx_hub_gw.sov.elf) to a durable repo path (_offc), then writes the
3// nx_aw_push inputs (awpush.src/.dst) via syscalls. After this, deploy = `nx_sov_build_run nx_aw_push`.
4// Atomic .tmp+mv, chmod +x. license_tier: ORIGINAL
5import "nx_syscalls.nx"
6
7func hs_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
8func hs_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
9
10func hs_wfile(path: *u8, content: *u8) -> i64 {
11 let fd: i64 = sys_openat_wr(path, 420)
12 if fd < 0 { return 0 - 1 }
13 sys_write(fd, content, hs_slen(content))
14 sys_close(fd)
15 return 0
16}
17
18func main() -> i64 {
19 // copy the built gateway to a durable path (nx_aw_push re-reads src at ship time; /tmp is volatile).
20 let lenp: *i64 = sys_mmap(8) as *i64
21 let data: *u8 = sys_read_file("/tmp/nx_hub_gw.sov.elf" as *u8, lenp)
22 if (data as i64) == 0 { hs_w("nx_hub_ship: /tmp/nx_hub_gw.sov.elf missing (build nx_hub_gw first)\n\x00" as *u8); return 1 }
23 let fd: i64 = sys_openat_wr("_offc/nx_hub_gw.elf\x00" as *u8, 493)
24 if fd < 0 { hs_w("nx_hub_ship: cannot write _offc/nx_hub_gw.elf\n\x00" as *u8); return 2 }
25 sys_write(fd, data, lenp[0])
26 sys_close(fd)
27 // stage the nx_aw_push inputs (sovereign, LF-clean).
28 hs_wfile("/mnt/c/Users/elder/AppData/Local/Temp/awpush.src\x00" as *u8, "/mnt/c/Users/elder/nishi-core/nxc2/_offc/nx_hub_gw.elf\n\x00" as *u8)
29 hs_wfile("/mnt/c/Users/elder/AppData/Local/Temp/awpush.dst\x00" as *u8, "cat > /volume1/ai/hub/nx_hub_gw.elf.tmp; chmod +x /volume1/ai/hub/nx_hub_gw.elf.tmp; mv -f /volume1/ai/hub/nx_hub_gw.elf.tmp /volume1/ai/hub/nx_hub_gw.elf\n\x00" as *u8)
30 hs_w("nx_hub_ship: staged _offc/nx_hub_gw.elf + nx_aw_push inputs (deploy = run nx_aw_push, then nx_aw_hostctl hubdeploy)\n\x00" as *u8)
31 return 0
32}