interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / apps / interplane-forge / tools / bring / installer.om

220 lines · 5053 bytes Raw Blame History
1om2
2note Writes bring.sh, get.sh and withdraw.sh (the same download, check and run; each runs its command).
3note Manifest: version line, HTTPS receipt URL line, then target TAB HTTPS binary URL TAB sha256 LF.
4note Targets: Linux-aarch64, Linux-x86_64, Darwin-arm64, Darwin-x86_64. No target implies no release.
5note Input is streamed, never evaluated as shell. Quotes and control bytes in values are refused.
6note The download is a loop with no count: 503, 502, 504 and 429 mean the release server is busy (its
7note cold-build cache answers 503 with Retry-After), so one plain line, a 10 second wait and the same
8note request again; 200 goes on to the fingerprint check; any other code stops, nothing run. A signal
9note exits (the EXIT trap removes the download), so Ctrl-C stops the wait.
10text bringnm "bring.sh"
11text getnm "get.sh"
12text wdnm "withdraw.sh"
13text header "#!/bin/sh\nset -eu\numask 077\n"
14text vers "version='"
15text receipt "receipt='"
16text closeq "'\n"
17text detect "target=\"$(uname -s)-$(uname -m)\"\ncase \"$target\" in\n"
18text row1 ")\nurl='"
19text row2 "'\nexpected='"
20text row3 "'\n;;\n"
21text ending "*) echo 'This platform has no Interplane release yet.' >&2; exit 1;;\nesac\nd=$(mktemp -d)\ntrap 'rm -f \"$d/interplane\"; rmdir \"$d\"' EXIT\ntrap 'exit 1' HUP INT TERM\nwhile :; do\n code=$(curl -q --proto '=https' --proto-redir '=https' -sSL -o \"$d/interplane\" -w '%{http_code}' \"$url\") || code=000\n case $code in\n 200) break;;\n 503|502|504|429) echo 'The download server is busy; trying again in 10 seconds.' >&2; sleep 10;;\n *) echo \"The download failed with HTTP $code. Nothing was run.\" >&2; exit 1;;\n esac\ndone\nif command -v sha256sum >/dev/null 2>&1; then\n actual=$(sha256sum \"$d/interplane\")\nelse\n actual=$(shasum -a 256 \"$d/interplane\")\nfi\nactual=${actual%% *}\nprintf 'Interplane %s\\nDownloaded SHA-256: %s\\nExpected SHA-256: %s\\nCompare with: %s\\n' \"$version\" \"$actual\" \"$expected\" \"$receipt\"\n[ \"$actual\" = \"$expected\" ] || { echo 'Fingerprint mismatch. Nothing was run.' >&2; exit 1; }\nchmod 700 \"$d/interplane\"\n"
22text brun "\"$d/interplane\" bring \"$@\" < /dev/tty\n"
23text grun "\"$d/interplane\" get \"$@\" < /dev/tty\n"
24text wrun "\"$d/interplane\" withdraw \"$@\" < /dev/tty\n"
25text la "Linux-aarch64"
26text lx "Linux-x86_64"
27text da "Darwin-arm64"
28text dx "Darwin-x86_64"
29text https "https://"
30text bad "installer: invalid manifest; output scripts removed\n"
31global outs int 3
32global ch uchar 1
33fn fail to void
34x = write 2 bad 0 len bad
35for i ulong 3
36x = fclose get outs i
37end
38x = unlink bringnm 0 len bringnm
39x = unlink getnm 0 len getnm
40x = unlink wdnm 0 len wdnm
41exit 1
42end
43fn emit s view uchar * to void
44for i ulong 3
45p = ulong 0
46while lt p len s bound 9223372036854775807
47r = write get outs i s p sub len s p
48if le r 0
49fail
50end
51p = add p ulong r
52end
53end
54end
55fn bytein to long
56r = read 0 ch 0 1
57if eq r 0
58ret -1
59end
60if ne r 1
61fail
62end
63ret long get ch 0
64end
65fn emitbyte c uchar to void
66b = new uchar 1 0
67put b 0 c
68emit b
69end
70fn value delim long url bool to void
71n = ulong 0
72while true bound 9223372036854775807
73c = bytein
74if eq c delim
75break
76end
77if or lt c 33 or gt c 126 eq c 39
78fail
79end
80if url
81if lt n len https
82if ne c long get https n
83fail
84end
85end
86end
87emitbyte uchar c
88n = add n 1
89end
90if eq n 0
91fail
92end
93if url
94if le n len https
95fail
96end
97end
98end
99fn same a view uchar * b view uchar * to bool
100if ne len a len b
101ret false
102end
103for i ulong len a bound 9223372036854775807
104if ne get a i get b i
105ret false
106end
107end
108ret true
109end
110fn target s view uchar * to ulong
111if same s la
112ret 1
113end
114if same s lx
115ret 2
116end
117if same s da
118ret 4
119end
120if same s dx
121ret 8
122end
123fail
124ret 0
125end
126fn main to int
127put outs 0 -1
128put outs 1 -1
129put outs 2 -1
130fd = fopen bringnm 0 len bringnm 524481 384
131if lt fd 0
132exit 1
133end
134put outs 0 int fd
135fd = fopen getnm 0 len getnm 524481 384
136if lt fd 0
137x = fclose get outs 0
138x = unlink bringnm 0 len bringnm
139exit 1
140end
141put outs 1 int fd
142fd = fopen wdnm 0 len wdnm 524481 384
143if lt fd 0
144x = fclose get outs 0
145x = fclose get outs 1
146x = unlink bringnm 0 len bringnm
147x = unlink getnm 0 len getnm
148exit 1
149end
150put outs 2 int fd
151emit header
152emit vers
153value 10 false
154emit closeq
155emit receipt
156value 10 true
157emit closeq
158emit detect
159buf = new uchar 14 0
160seen = ulong 0
161while true bound 9223372036854775807
162c = bytein
163if eq c -1
164break
165end
166n = ulong 0
167while ne c 9 bound 9223372036854775807
168if or lt c 33 ge n len buf
169fail
170end
171put buf n uchar c
172n = add n 1
173c = bytein
174end
175v = target part buf 0 n
176if ne and seen v 0
177fail
178end
179seen = or seen v
180emit part buf 0 n
181emit row1
182value 9 true
183emit row2
184for i ulong 64
185c = bytein
186if not or and ge c 48 le c 57 and ge c 97 le c 102
187fail
188end
189emitbyte uchar c
190end
191if ne bytein 10
192fail
193end
194emit row3
195end
196if eq seen 0
197fail
198end
199emit ending
200x = write get outs 0 brun 0 len brun
201if ne x long len brun
202fail
203end
204x = write get outs 1 grun 0 len grun
205if ne x long len grun
206fail
207end
208x = write get outs 2 wrun 0 len wrun
209if ne x long len wrun
210fail
211end
212for i ulong 3
213x = fsync get outs i
214if lt x 0
215fail
216end
217x = fclose get outs i
218end
219ret 0
220end