code wiki / _hdl_build / nx_hub_provision.nx
nx_hub_provision.nx source
↩ module page · 55 lines · 2839 B
1// nx_hub_provision.nx -- provision a PERSONAL HUB as a FULL STANDALONE DOMAIN SITE (operator: "they are full
2// bradrwest.com site not on nishifamily" -- each person gets their OWN domain, docroot + sites.conf host->docroot
3// mapping + their own per-domain SNI cert; NOT a path under nishifamily.com). Mirrors the proven nx_site_provision
4// provisioning (same sites.conf `<host>\t<docroot>` line + manifest) but renders the HUB template (blog/organizer/
5// hub) instead of the .site marketing template. ONE call: .hub config -> docroot index.html + sites.conf line +
6// manifest. The live cut-over (per-domain TLS cert via the ACME issuer + DNS + NAS push) is the deploy step.
7// Composes nx_hub_template (ht_emit_hub). license_tier: ORIGINAL
8import "nx_hub_template.nx"
9const K_MAGIC_1048576: i64 = 1048576
10
11// 0 = provisioned ; <0 = refused (no/empty config, or io). Writes the hub HTML to <outhtml> (the domain's docroot
12// index), appends `<domain>\t<outhtml>` to <conf_path> (the host->docroot map sites.elf serves by Host/SNI), and
13// writes a manifest.
14func hp_provision(domain: *u8, hub_path: *u8, outhtml: *u8, conf_path: *u8, manifest_path: *u8) -> i64 {
15 let szb: *i64 = sys_mmap(16) as *i64
16 szb[0] = 0
17 let cfg: *u8 = sys_read_file(hub_path, szb)
18 if (cfg as i64) == 0 { return 0 - 2 }
19 if szb[0] <= 0 { return 0 - 2 }
20 let out: *u8 = sys_mmap(K_MAGIC_1048576)
21 let on: i64 = ht_emit_hub(cfg, szb[0], out)
22 if on <= 0 { return 0 - 3 }
23 let fd: i64 = sys_openat_wr(outhtml, 0x1a4)
24 if fd < 0 { return 0 - 4 }
25 sys_write(fd, out, on)
26 sys_close(fd)
27 let cf: i64 = sys_openat_append(conf_path, 0x1a4)
28 if cf >= 0 {
29 sys_write(cf, domain, ht_slen(domain))
30 sys_write(cf, "\t" as *u8, 1)
31 sys_write(cf, outhtml, ht_slen(outhtml))
32 sys_write(cf, "\n" as *u8, 1)
33 sys_close(cf)
34 }
35 let mf: i64 = sys_openat_wr(manifest_path, 0x1a4)
36 if mf >= 0 {
37 sys_write(mf, "PROVISIONED-HUB domain=" as *u8, 23)
38 sys_write(mf, domain, ht_slen(domain))
39 sys_write(mf, " docroot=" as *u8, 9)
40 sys_write(mf, outhtml, ht_slen(outhtml))
41 sys_write(mf, " type=blog-organizer-hub standalone=1 compliant=1\n" as *u8, 50)
42 sys_close(mf)
43 }
44 return 0
45}
46
47func main(argc: i64, argv: *i64) -> i64 {
48 if argc < 6 { sys_write(2, "usage: nx_hub_provision <domain> <config.hub> <docroot_index.html> <sites.conf> <manifest>\n" as *u8, 90); return 1 }
49 let rc: i64 = hp_provision(argv[1] as *u8, argv[2] as *u8, argv[3] as *u8, argv[4] as *u8, argv[5] as *u8)
50 if rc != 0 { sys_write(2, "hub-provision: REFUSED\n" as *u8, 23); return 2 }
51 sys_write(1, "PROVISIONED-HUB " as *u8, 16)
52 sys_write(1, argv[1] as *u8, ht_slen(argv[1] as *u8))
53 sys_write(1, " -> standalone domain site\n" as *u8, 27)
54 return 0
55}