mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-11-10 09:59:15 -06:00
Compare commits
695 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02242c1908 | ||
|
|
509a22f6bd | ||
|
|
5572e1de35 | ||
|
|
d0ff328db8 | ||
|
|
ff45b46c49 | ||
|
|
bd070b2f5c | ||
|
|
5c0bef019f | ||
|
|
283c1390e5 | ||
|
|
7f95fe9bbd | ||
|
|
a9e1ef2459 | ||
|
|
2ba45a2147 | ||
|
|
9e6d280826 | ||
|
|
527caeff6a | ||
|
|
71ab9127dd | ||
|
|
d382f0621d | ||
|
|
9415afb359 | ||
|
|
e5f6dfabaa | ||
|
|
757e0f61c5 | ||
|
|
761b02ed7e | ||
|
|
562ea8277c | ||
|
|
7abec3cbad | ||
|
|
8fc31553f7 | ||
|
|
9e50040713 | ||
|
|
0f8ef20fb5 | ||
|
|
7cda3b2920 | ||
|
|
40bbeab8ae | ||
|
|
eb20fb41aa | ||
|
|
21e834b4c8 | ||
|
|
8773605715 | ||
|
|
b23eb33611 | ||
|
|
ef432da2fe | ||
|
|
96c86f6098 | ||
|
|
a7d7574e70 | ||
|
|
b587b9f912 | ||
|
|
004fd59093 | ||
|
|
774d314ce9 | ||
|
|
e4d23014ba | ||
|
|
dc050d1f19 | ||
|
|
57e1f6a4d6 | ||
|
|
d578c63036 | ||
|
|
6b98f5415f | ||
|
|
64ce12cc0d | ||
|
|
183f8dc983 | ||
|
|
7eee77a33d | ||
|
|
c1986acf65 | ||
|
|
c999a883bd | ||
|
|
70f8503cbb | ||
|
|
5b0a7d2a91 | ||
|
|
4fee758ff0 | ||
|
|
736259baa3 | ||
|
|
83b600bbee | ||
|
|
6071a6f57c | ||
|
|
69f5da6fc7 | ||
|
|
3b2ba7c0c1 | ||
|
|
208998c13a | ||
|
|
3de4a18eb4 | ||
|
|
863fea9ab8 | ||
|
|
f65c1b06aa | ||
|
|
fe34008ce3 | ||
|
|
961d7f2e89 | ||
|
|
94749ea621 | ||
|
|
6ae742deed | ||
|
|
b653f905e4 | ||
|
|
af19795c29 | ||
|
|
be7584d908 | ||
|
|
a960417739 | ||
|
|
3f0621e7ed | ||
|
|
515c5e2a76 | ||
|
|
cb025f04b4 | ||
|
|
2ca5b19efe | ||
|
|
40f3917014 | ||
|
|
a40433522c | ||
|
|
8470b89214 | ||
|
|
5a08170518 | ||
|
|
dff794cee4 | ||
|
|
36cf9c30d8 | ||
|
|
1c43542919 | ||
|
|
8eca1edf47 | ||
|
|
4080788cab | ||
|
|
424302789e | ||
|
|
6651167dd8 | ||
|
|
2d67720022 | ||
|
|
1893912ba7 | ||
|
|
e41ce2d6b8 | ||
|
|
a5c6489f19 | ||
|
|
fafef3d89a | ||
|
|
4b5f539445 | ||
|
|
cefe0f9ab2 | ||
|
|
7f3d29eba2 | ||
|
|
64681e2aac | ||
|
|
fcb1f1c7fe | ||
|
|
aa0546ff37 | ||
|
|
3254412017 | ||
|
|
fda3c6b1a8 | ||
|
|
97832557fb | ||
|
|
590db5b08c | ||
|
|
10a512ec96 | ||
|
|
08093dddad | ||
|
|
86a85a61b7 | ||
|
|
cb3a2c562e | ||
|
|
832832a716 | ||
|
|
5fe6d0d48f | ||
|
|
67fe57f189 | ||
|
|
44caee21ab | ||
|
|
5b2a1ff788 | ||
|
|
dc5ba29bcf | ||
|
|
89c14310c7 | ||
|
|
3322a3c07f | ||
|
|
9e1251ad6a | ||
|
|
afec4efb34 | ||
|
|
11980b9122 | ||
|
|
2a43fb5413 | ||
|
|
57887f3f69 | ||
|
|
2b8f640957 | ||
|
|
4af32fc703 | ||
|
|
a611e5ef56 | ||
|
|
94051c3037 | ||
|
|
d5cd706078 | ||
|
|
7460ebfd07 | ||
|
|
e3877308a0 | ||
|
|
7c28fb8124 | ||
|
|
b18873364f | ||
|
|
016a7d8a51 | ||
|
|
585f1bc2b5 | ||
|
|
4fcc4c3747 | ||
|
|
0d2c52adc3 | ||
|
|
af256e7f92 | ||
|
|
84830421ee | ||
|
|
9b278cdb0e | ||
|
|
9b40a5cf86 | ||
|
|
b8d980be33 | ||
|
|
195037af87 | ||
|
|
c98000069a | ||
|
|
2bd277b57d | ||
|
|
4852ed813b | ||
|
|
fb08df9e4e | ||
|
|
64f3b49e21 | ||
|
|
329c0a0001 | ||
|
|
c28273d1f0 | ||
|
|
1d22d75889 | ||
|
|
6ef8bb74e3 | ||
|
|
0e00760474 | ||
|
|
d969bd68ec | ||
|
|
1e5f4cb24b | ||
|
|
4d3b1c835e | ||
|
|
e3558933b1 | ||
|
|
7762706200 | ||
|
|
b66707c959 | ||
|
|
a3440cf867 | ||
|
|
1b7021d64b | ||
|
|
687dd3bfc4 | ||
|
|
cc072ab158 | ||
|
|
b0a01a9837 | ||
|
|
2d575b916c | ||
|
|
1f908ef181 | ||
|
|
fb2adf13ee | ||
|
|
ad9eb44ad8 | ||
|
|
b4962e7a58 | ||
|
|
14614e5e35 | ||
|
|
9a93ab24f5 | ||
|
|
aaad552633 | ||
|
|
79cc1cc2bf | ||
|
|
01bcda6886 | ||
|
|
ec49bffe06 | ||
|
|
2db5d86a3c | ||
|
|
da6d4840f8 | ||
|
|
9afa21a0b0 | ||
|
|
6168069301 | ||
|
|
ffe71ae6b1 | ||
|
|
a6a97df4e7 | ||
|
|
f05467f45c | ||
|
|
969e3a5e6a | ||
|
|
f0e7dc069c | ||
|
|
f5f70bd015 | ||
|
|
aa80e1d7cc | ||
|
|
d6b03a345b | ||
|
|
c0cfcfa31a | ||
|
|
afdbb179ad | ||
|
|
ed9b7c5126 | ||
|
|
551329a41d | ||
|
|
b3c6b6c53d | ||
|
|
5a9cd18f94 | ||
|
|
63c8fc8eb5 | ||
|
|
3305c69e2d | ||
|
|
56a0468a53 | ||
|
|
52416dfdd7 | ||
|
|
bcd0b717ee | ||
|
|
d9c9eae4f9 | ||
|
|
c1a21c2d69 | ||
|
|
8d822948cf | ||
|
|
7404a205a5 | ||
|
|
d774bf8c58 | ||
|
|
0e1fae8751 | ||
|
|
3ff64483df | ||
|
|
fed92254d2 | ||
|
|
dec1621850 | ||
|
|
116bb50364 | ||
|
|
957d86d64c | ||
|
|
1fa6f48d4e | ||
|
|
0610f6fd1a | ||
|
|
ade9ac863f | ||
|
|
61ff3c5b23 | ||
|
|
19076b2508 | ||
|
|
e175147674 | ||
|
|
2cc64d2208 | ||
|
|
346315b4bb | ||
|
|
648c9f866e | ||
|
|
b5866088fc | ||
|
|
cd954b6f24 | ||
|
|
f27102d344 | ||
|
|
ba8e8b7a5c | ||
|
|
cb3834bb71 | ||
|
|
8ec134c182 | ||
|
|
631d944d70 | ||
|
|
f539576a49 | ||
|
|
fa11347f1b | ||
|
|
34c66dbd8b | ||
|
|
3d5c14405c | ||
|
|
9e4408409f | ||
|
|
9b629c8dc0 | ||
|
|
8da7a70bfc | ||
|
|
ea6ac3c903 | ||
|
|
6b783677e5 | ||
|
|
1cc31c30a3 | ||
|
|
92d5f63679 | ||
|
|
9fd3728aee | ||
|
|
916803d0f0 | ||
|
|
8de298d245 | ||
|
|
75fc8d09ce | ||
|
|
b157b9fe28 | ||
|
|
53a800d252 | ||
|
|
124868e093 | ||
|
|
e684936d15 | ||
|
|
5958fd5c6f | ||
|
|
4d7ee39ccf | ||
|
|
1bb91518b6 | ||
|
|
2d0123cb18 | ||
|
|
455bc19fab | ||
|
|
0003be478e | ||
|
|
d448f11861 | ||
|
|
53924dc8ef | ||
|
|
9311b898f2 | ||
|
|
0e30a26db4 | ||
|
|
24a460e64a | ||
|
|
f62320f3e1 | ||
|
|
0d73e8b52a | ||
|
|
11d66da064 | ||
|
|
f24fecf01c | ||
|
|
1c16444614 | ||
|
|
8b7b1236ba | ||
|
|
c44bf06cc9 | ||
|
|
8230d59354 | ||
|
|
0f270c8823 | ||
|
|
95970f87fa | ||
|
|
469c1693bd | ||
|
|
2a45a8a8fa | ||
|
|
2180fa70f7 | ||
|
|
b093e11aeb | ||
|
|
140812606f | ||
|
|
14239b8a6f | ||
|
|
0d1dca3e0a | ||
|
|
dfee0934f0 | ||
|
|
42c332a406 | ||
|
|
4c1ebc84e9 | ||
|
|
81a6e5d152 | ||
|
|
145a43d688 | ||
|
|
386c5fa86c | ||
|
|
1499edd83c | ||
|
|
db719c32ad | ||
|
|
340477a31f | ||
|
|
fd57047e86 | ||
|
|
496b9f981e | ||
|
|
76dc2312b4 | ||
|
|
ade6d80f10 | ||
|
|
574b41a0a1 | ||
|
|
f907a340b6 | ||
|
|
0498b39f0e | ||
|
|
5d196ff8d8 | ||
|
|
84d65fb167 | ||
|
|
0f22d53e7c | ||
|
|
f44bc72201 | ||
|
|
310d550ff6 | ||
|
|
044292ccb4 | ||
|
|
0dc0f9ea73 | ||
|
|
5fcdf888b3 | ||
|
|
dda98e2a61 | ||
|
|
f209cb1e0e | ||
|
|
7d3df10915 | ||
|
|
fb9f127289 | ||
|
|
bc64084516 | ||
|
|
e86d385521 | ||
|
|
6ca0fa7626 | ||
|
|
f8d8b04de3 | ||
|
|
305a75d1a7 | ||
|
|
c3a9e9d402 | ||
|
|
48c941fb86 | ||
|
|
1016853d25 | ||
|
|
90068a3c2d | ||
|
|
8fc71a2e36 | ||
|
|
8310e43b31 | ||
|
|
0e30b62894 | ||
|
|
3de21f295b | ||
|
|
d8c4de9a01 | ||
|
|
acf366d61e | ||
|
|
b9c85fad7b | ||
|
|
196b9555ab | ||
|
|
e9cccd58ea | ||
|
|
00d30efa45 | ||
|
|
309b9665cb | ||
|
|
759abc92c9 | ||
|
|
ae8f0e2236 | ||
|
|
815770fabf | ||
|
|
e82069dea2 | ||
|
|
396aee7d0a | ||
|
|
3299c202b0 | ||
|
|
755cbe113d | ||
|
|
bab729ed18 | ||
|
|
350dbdfe4b | ||
|
|
1b5ca8eef6 | ||
|
|
e8016c1d51 | ||
|
|
c1e2bed94e | ||
|
|
ba242be427 | ||
|
|
fce974c146 | ||
|
|
a82aa792d8 | ||
|
|
105f77d9ec | ||
|
|
b6d87b9799 | ||
|
|
6279086b5a | ||
|
|
61ea4bd385 | ||
|
|
7f3e039d1b | ||
|
|
f2c91c09c7 | ||
|
|
32c81f220d | ||
|
|
c77981cc0c | ||
|
|
cd767d16df | ||
|
|
8591aecb9c | ||
|
|
34746afea3 | ||
|
|
393328eaf6 | ||
|
|
7771d1f326 | ||
|
|
2a34eb55e6 | ||
|
|
9d6cf49c3f | ||
|
|
dcb87d0d89 | ||
|
|
9a0c77bb8b | ||
|
|
6e45e6b135 | ||
|
|
a1df6376ec | ||
|
|
7f7e31bae9 | ||
|
|
4499f9ed44 | ||
|
|
9a5ad1dff2 | ||
|
|
2f8f77cb89 | ||
|
|
a4978d93d6 | ||
|
|
01e28f10ae | ||
|
|
ea9068fd0d | ||
|
|
d85823abcf | ||
|
|
4c0027ffd3 | ||
|
|
afb868af30 | ||
|
|
66b1d5dc30 | ||
|
|
7d8cdc74c6 | ||
|
|
809581df49 | ||
|
|
5d47a8d48d | ||
|
|
6242f1931e | ||
|
|
b768219c18 | ||
|
|
6935923bd1 | ||
|
|
559e6e2556 | ||
|
|
f354fdfbf4 | ||
|
|
f242b5a378 | ||
|
|
e18ec2219d | ||
|
|
d075ae58d9 | ||
|
|
e8ccac8e61 | ||
|
|
7c8f9f3cd8 | ||
|
|
66e434db24 | ||
|
|
0be553c4c8 | ||
|
|
1dda0f29be | ||
|
|
fbdedc7d8a | ||
|
|
e325352309 | ||
|
|
bf51b50346 | ||
|
|
96b52f3ac0 | ||
|
|
ad44db254b | ||
|
|
736b89d7d1 | ||
|
|
3122531cae | ||
|
|
cbb47ab735 | ||
|
|
fa8d4fd5ca | ||
|
|
423d05a087 | ||
|
|
7036e94dab | ||
|
|
3a19180a51 | ||
|
|
f8f8920fc5 | ||
|
|
507b53c10e | ||
|
|
6aafb78680 | ||
|
|
c83dc5565c | ||
|
|
59a03cacef | ||
|
|
c6af287b11 | ||
|
|
bc636bd9fd | ||
|
|
1f2b6c5d44 | ||
|
|
b42ffe8e0b | ||
|
|
f9244b36df | ||
|
|
87f697622c | ||
|
|
52dbc0fe40 | ||
|
|
4a69bdcd12 | ||
|
|
e9e47d797c | ||
|
|
66cdb5e376 | ||
|
|
c7575393c9 | ||
|
|
3b9005e9a8 | ||
|
|
e3fd5876d2 | ||
|
|
f71c2d3f8d | ||
|
|
7163854185 | ||
|
|
8037081e0c | ||
|
|
642a00051e | ||
|
|
7f9bd1c457 | ||
|
|
477f7dfa03 | ||
|
|
d45aaf6cb2 | ||
|
|
4650da8373 | ||
|
|
13128a8a90 | ||
|
|
23b19015f4 | ||
|
|
843a1f97ce | ||
|
|
43d6002542 | ||
|
|
f9d9677bc0 | ||
|
|
49220d8024 | ||
|
|
013d76b006 | ||
|
|
c7d3755149 | ||
|
|
8d67ecd6a0 | ||
|
|
6005bb1b8d | ||
|
|
c4e8d19649 | ||
|
|
82be18c469 | ||
|
|
e6565fbe4b | ||
|
|
087dbaded9 | ||
|
|
6c42c57e59 | ||
|
|
3286cc2f85 | ||
|
|
d098a5ef09 | ||
|
|
040335ace0 | ||
|
|
dbc74834cd | ||
|
|
f1b411e3b6 | ||
|
|
7a9f5f9e6e | ||
|
|
cffa9a97f3 | ||
|
|
1bf986d41b | ||
|
|
eb343b0d31 | ||
|
|
628cb3b8c9 | ||
|
|
ebd391ec26 | ||
|
|
a3b577e563 | ||
|
|
f60adcc797 | ||
|
|
ee77f7bed1 | ||
|
|
6ef83cb22f | ||
|
|
1a3fd15fdf | ||
|
|
3e5a46570c | ||
|
|
2c4fbf7179 | ||
|
|
5409fb783c | ||
|
|
4cec610aba | ||
|
|
57d88d7889 | ||
|
|
7f305ae3cf | ||
|
|
eb4ac33fcd | ||
|
|
7a3c6c1690 | ||
|
|
ca63609545 | ||
|
|
bcaa8896ee | ||
|
|
13b19e3889 | ||
|
|
99d1fc0a64 | ||
|
|
86b7d676dd | ||
|
|
1adf6edffc | ||
|
|
a16af99648 | ||
|
|
58d5ab2d37 | ||
|
|
9aebabfd59 | ||
|
|
21b119294c | ||
|
|
e3a79daf89 | ||
|
|
4813e8bd50 | ||
|
|
93c0f3d353 | ||
|
|
be5a9f7515 | ||
|
|
36a1eb8eb8 | ||
|
|
20b452f3c0 | ||
|
|
b062569aab | ||
|
|
c91ce5ab62 | ||
|
|
602615e489 | ||
|
|
0e11855011 | ||
|
|
c5c768b143 | ||
|
|
5c0f098069 | ||
|
|
8bd7e02ec5 | ||
|
|
9233bd7c79 | ||
|
|
7d2664acb5 | ||
|
|
8c09cd7c44 | ||
|
|
aef8a7a851 | ||
|
|
8ed6e2eca3 | ||
|
|
a7b5091024 | ||
|
|
cd6da8b588 | ||
|
|
2d755fdb98 | ||
|
|
f231df4f65 | ||
|
|
95c8edcd3d | ||
|
|
d94eba0ab1 | ||
|
|
b48729c594 | ||
|
|
b9ba107587 | ||
|
|
c2d3224552 | ||
|
|
592939895b | ||
|
|
8d8c57bc48 | ||
|
|
8330b1b1fe | ||
|
|
9fdcb428c0 | ||
|
|
cee9bbb079 | ||
|
|
fcc09e2ef0 | ||
|
|
5d96a8060f | ||
|
|
023fb4b68b | ||
|
|
594c205a29 | ||
|
|
fc436e2743 | ||
|
|
125eddffe1 | ||
|
|
aad3d718e4 | ||
|
|
e3575e629c | ||
|
|
7bd7b77fa9 | ||
|
|
ba620db901 | ||
|
|
3259379345 | ||
|
|
08eb89dc5c | ||
|
|
1376929897 | ||
|
|
614ef4031c | ||
|
|
d9a19e132a | ||
|
|
7795191a46 | ||
|
|
5e3c4d98f2 | ||
|
|
de28273def | ||
|
|
148fb4e37b | ||
|
|
a920fcc58a | ||
|
|
5021ab8d2f | ||
|
|
0ae97e6dd7 | ||
|
|
8c2e744d42 | ||
|
|
1ea9dc0561 | ||
|
|
e4367f0b69 | ||
|
|
f973316f8f | ||
|
|
b5e48a07e8 | ||
|
|
2ec5393bd0 | ||
|
|
01c837f6ac | ||
|
|
899aa48875 | ||
|
|
29dd37852d | ||
|
|
9c0c50140b | ||
|
|
33d0eb3297 | ||
|
|
922a7772b8 | ||
|
|
38ddd89e56 | ||
|
|
b664411992 | ||
|
|
7a301f588a | ||
|
|
e5ebb36f78 | ||
|
|
01e4802247 | ||
|
|
66b1ea26c5 | ||
|
|
fbf2531dbb | ||
|
|
3debfc4cf1 | ||
|
|
b35542a446 | ||
|
|
dcf5bc99dd | ||
|
|
f984b9f870 | ||
|
|
8c547b8baa | ||
|
|
a265eaef15 | ||
|
|
f8eaa7f615 | ||
|
|
c47fc483a2 | ||
|
|
64254052c0 | ||
|
|
b99a8358a7 | ||
|
|
ed0a6f6681 | ||
|
|
055df124b3 | ||
|
|
06097068a2 | ||
|
|
ff5398ed67 | ||
|
|
c8dcdf7921 | ||
|
|
e09a0b14e0 | ||
|
|
0dbf8c007f | ||
|
|
a24c1b0cef | ||
|
|
42dc6ad079 | ||
|
|
d670cf19a1 | ||
|
|
7fe7c49e65 | ||
|
|
5c1e617862 | ||
|
|
9ff9d59aa5 | ||
|
|
7556d154d3 | ||
|
|
df808da5d6 | ||
|
|
06bd869fb1 | ||
|
|
7343ca3811 | ||
|
|
6eb4a4ea62 | ||
|
|
59d5944398 | ||
|
|
9caf34e641 | ||
|
|
b92bb0c1cb | ||
|
|
7da5194e90 | ||
|
|
b8c34d04bf | ||
|
|
ab3d980c4d | ||
|
|
a32130348d | ||
|
|
74917e321f | ||
|
|
07c3c5b61f | ||
|
|
a0862429b9 | ||
|
|
f36ce20df9 | ||
|
|
fdd4a9c6d1 | ||
|
|
840341e331 | ||
|
|
c9310a319a | ||
|
|
ae204b418f | ||
|
|
97a9b376c7 | ||
|
|
54515f6b96 | ||
|
|
cffb85de49 | ||
|
|
c0d9d167a7 | ||
|
|
cef6a141c1 | ||
|
|
29fd3ba9d1 | ||
|
|
7a9affced2 | ||
|
|
83a65559fb | ||
|
|
68913d2185 | ||
|
|
901a0380d7 | ||
|
|
1db304a5f3 | ||
|
|
7fe3447a83 | ||
|
|
85f6447a16 | ||
|
|
69243e5ebb | ||
|
|
d7ca7c453d | ||
|
|
d5eb644baa | ||
|
|
26078fe46e | ||
|
|
93ce6009c6 | ||
|
|
2cae9e4336 | ||
|
|
097078f93c | ||
|
|
52937df57d | ||
|
|
5a39562f2d | ||
|
|
a09ed2dc1f | ||
|
|
3bd52590ff | ||
|
|
fceac7d3b1 | ||
|
|
0ffc78a747 | ||
|
|
a8d6d61034 | ||
|
|
a0f0699cdc | ||
|
|
97b9929374 | ||
|
|
74a303bd5c | ||
|
|
b7afc27f44 | ||
|
|
a3cda13eea | ||
|
|
fdb7e5cfd0 | ||
|
|
ed5621cfdd | ||
|
|
d923c82afb | ||
|
|
7e976e069f | ||
|
|
33d7b7b259 | ||
|
|
42afe86e16 | ||
|
|
a97903bbf0 | ||
|
|
285fc53784 | ||
|
|
cbb371fb78 | ||
|
|
bcfa09b03e | ||
|
|
df69d50ff0 | ||
|
|
888d0db5fa | ||
|
|
4b7a7d68eb | ||
|
|
9776508b53 | ||
|
|
2ad607c64d | ||
|
|
1f1341659e | ||
|
|
a58227910b | ||
|
|
d775371fe0 | ||
|
|
5ac348a75b | ||
|
|
726cd915cc | ||
|
|
342ed33fe7 | ||
|
|
ca9f71d145 | ||
|
|
1f0d3b82c3 | ||
|
|
079be103ec | ||
|
|
b78df7908f | ||
|
|
fcb61d257b | ||
|
|
2796296418 | ||
|
|
9f83291a8d | ||
|
|
8ae4e48857 | ||
|
|
dc10e492df | ||
|
|
49a04da35a | ||
|
|
082a29a671 | ||
|
|
3b2e142657 | ||
|
|
2f7cdf78c5 | ||
|
|
611ceae7da | ||
|
|
600f86da29 | ||
|
|
637b9af964 | ||
|
|
e82271a6b9 | ||
|
|
629b0ba39d | ||
|
|
a693eaf212 | ||
|
|
3365459d97 | ||
|
|
088ee2ec7a | ||
|
|
82932e5ba8 | ||
|
|
3df064f39e | ||
|
|
cf0f63d69a | ||
|
|
69c72bc236 | ||
|
|
e8b49238d3 | ||
|
|
cfe8172364 | ||
|
|
46c41ff414 | ||
|
|
f6e03d0abc | ||
|
|
a976f677ad | ||
|
|
bed1b39ed7 | ||
|
|
95584d5f68 | ||
|
|
ef898bf8a6 | ||
|
|
063ce2ad33 | ||
|
|
1474330ded | ||
|
|
21972e4c62 | ||
|
|
cf56403f86 | ||
|
|
68806308c0 | ||
|
|
34bd10c1e4 | ||
|
|
254a3103a3 | ||
|
|
5ad6327999 | ||
|
|
a0ff551c53 | ||
|
|
f02b9ce599 | ||
|
|
e34f085976 | ||
|
|
eb772ae33d | ||
|
|
6f83b756c2 | ||
|
|
81dc0e0f71 | ||
|
|
666ace3d3b | ||
|
|
853d568828 | ||
|
|
462b3427f5 | ||
|
|
618498f7b0 | ||
|
|
aded40445b | ||
|
|
ef84874b99 | ||
|
|
9c336dbda4 | ||
|
|
b017338f05 | ||
|
|
5275952819 | ||
|
|
62e8ab2ac8 | ||
|
|
655227e270 | ||
|
|
8b413344e0 | ||
|
|
60b4df58f1 | ||
|
|
8067a0e348 | ||
|
|
ea39c024ac | ||
|
|
aae370fc2b | ||
|
|
74a8c9ee42 | ||
|
|
dddf3de8db | ||
|
|
4c4aa4270e | ||
|
|
a21159aaff | ||
|
|
1e3c131e0d | ||
|
|
a037767f77 |
52
.devcontainer/Dockerfile
Normal file
52
.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,52 @@
|
||||
# Dev container image for VS Code / the devcontainer CLI.
|
||||
#
|
||||
# The release builder image (docker/Dockerfile) stays the single source of
|
||||
# truth for the RISC-V cross toolchain, Go and MaixCDK. This layer only adds
|
||||
# the frontend toolchain on top: the builder image deliberately ships without
|
||||
# Node (`make web` runs on the host), but an IDE container should cover web
|
||||
# development as well.
|
||||
#
|
||||
# BASE_IMAGE can be overridden to a locally built builder image, e.g. the
|
||||
# output of `make builder-image` (nanokvm-builder-local-<uid>-<gid>).
|
||||
ARG BASE_IMAGE=ghcr.io/sipeed/nanokvm-builder:latest
|
||||
FROM ${BASE_IMAGE}
|
||||
|
||||
USER root
|
||||
|
||||
# Node major and pnpm major track .github/workflows/package.yml ("Set up
|
||||
# Node" / "Set up pnpm") and web/package.json "engines" -- keep all of them
|
||||
# in sync when CI bumps either.
|
||||
ARG NODE_MAJOR=22
|
||||
ARG PNPM_VERSION=11
|
||||
# Both can be overridden behind restrictive or mirrored corporate networks
|
||||
# via devcontainer.json, e.g.:
|
||||
# "build": {"args": {
|
||||
# "NODE_DIST_MIRROR": "https://registry.npmmirror.com/-/binary/node",
|
||||
# "NPM_REGISTRY": "https://registry.npmmirror.com"
|
||||
# }}
|
||||
ARG NODE_DIST_MIRROR=https://nodejs.org/dist
|
||||
ARG NPM_REGISTRY=https://registry.npmjs.org
|
||||
|
||||
# Install the latest Node of the pinned major from official dist tarballs;
|
||||
# tracking the latest patch release is intentional (rebuild the container to
|
||||
# pick up updates). The SHA-256 check guards download integrity -- it shares
|
||||
# its origin with the tarball, so it is not an authenticity proof.
|
||||
RUN set -eux; \
|
||||
apt-get update; \
|
||||
apt-get install -y ca-certificates curl xz-utils; \
|
||||
rm -rf /var/lib/apt/lists/*; \
|
||||
case "$(uname -m)" in \
|
||||
x86_64) node_arch=x64 ;; \
|
||||
aarch64) node_arch=arm64 ;; \
|
||||
*) echo "unsupported architecture: $(uname -m)" >&2; exit 1 ;; \
|
||||
esac; \
|
||||
curl -fsSL "${NODE_DIST_MIRROR}/latest-v${NODE_MAJOR}.x/SHASUMS256.txt" \
|
||||
-o /tmp/SHASUMS256.txt; \
|
||||
tarball="$(grep -o "node-v[0-9.]*-linux-${node_arch}\.tar\.xz" /tmp/SHASUMS256.txt | head -n1)"; \
|
||||
curl -fsSL "${NODE_DIST_MIRROR}/latest-v${NODE_MAJOR}.x/${tarball}" -o "/tmp/${tarball}"; \
|
||||
cd /tmp && grep " ${tarball}\$" SHASUMS256.txt | sha256sum -c -; \
|
||||
tar -xJf "/tmp/${tarball}" -C /usr/local --strip-components=1 --no-same-owner; \
|
||||
rm -f "/tmp/${tarball}" /tmp/SHASUMS256.txt; \
|
||||
node --version && npm --version
|
||||
RUN npm install --global --registry "${NPM_REGISTRY}" "pnpm@${PNPM_VERSION}" \
|
||||
&& pnpm --version
|
||||
49
.devcontainer/devcontainer.json
Normal file
49
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,49 @@
|
||||
// Dev container for NanoKVM: Go cross-compilation, MaixCDK C support layer
|
||||
// and web frontend in a single container. See "Development" in README.md.
|
||||
{
|
||||
"name": "NanoKVM",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile"
|
||||
},
|
||||
// The Makefile and support/sg2002/build expect the repository at
|
||||
// ~/NanoKVM of the baked-in "build" user -- mount it exactly there.
|
||||
"workspaceMount": "source=${localWorkspaceFolder},target=/home/build/NanoKVM,type=bind,consistency=cached",
|
||||
"workspaceFolder": "/home/build/NanoKVM",
|
||||
"remoteUser": "build",
|
||||
// The published builder image bakes in the CI runner's uid (currently
|
||||
// 1001); on Linux hosts this remaps "build" to the local uid so the bind
|
||||
// mount stays writable. The remap chowns /home/build once, which makes
|
||||
// the first container creation noticeably slower.
|
||||
"updateRemoteUserUID": true,
|
||||
// Equivalent of `. ~/MaixCDK/bin/activate` for every process spawned in
|
||||
// the container, interactive or not (tasks, extensions, exec).
|
||||
"remoteEnv": {
|
||||
"VIRTUAL_ENV": "/home/build/MaixCDK",
|
||||
"PATH": "/home/build/MaixCDK/bin:${containerEnv:PATH}"
|
||||
},
|
||||
"forwardPorts": [3001],
|
||||
"portsAttributes": {
|
||||
"3001": {
|
||||
"label": "web dev server (vite)"
|
||||
}
|
||||
},
|
||||
"postCreateCommand": ".devcontainer/post-create.sh",
|
||||
// This configuration itself mounts nothing from the host (VS Code may
|
||||
// still forward your SSH agent and git credentials by default). To use
|
||||
// git over SSH or reach a NanoKVM device from inside the container,
|
||||
// uncomment the mount below.
|
||||
// "mounts": [
|
||||
// "source=${localEnv:HOME}/.ssh,target=/home/build/.ssh,type=bind,readonly"
|
||||
// ],
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"golang.go",
|
||||
"ms-vscode.cpptools",
|
||||
"dbaeumer.vscode-eslint",
|
||||
"esbenp.prettier-vscode",
|
||||
"bradlc.vscode-tailwindcss"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
37
.devcontainer/post-create.sh
Executable file
37
.devcontainer/post-create.sh
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
# Runs once inside the dev container after it is created (see
|
||||
# .devcontainer/devcontainer.json). Keeps the container aligned with the
|
||||
# CLI flow in the Makefile and scripts/build-in-container.sh.
|
||||
set -euo pipefail
|
||||
|
||||
repo_root="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
|
||||
# The MaixCDK components baked into the image can be older than this
|
||||
# checkout; resync them so C builds never use stale sources (same reason
|
||||
# scripts/build-in-container.sh runs update_lib first).
|
||||
"$repo_root/support/sg2002/build" update_lib
|
||||
|
||||
# Frontend dependencies. postCreate has no TTY, and CI=true lets pnpm make
|
||||
# its non-interactive choices -- e.g. purging a node_modules tree that was
|
||||
# installed from the host OS through the bind mount.
|
||||
(cd "$repo_root/web" && CI=true pnpm install --frozen-lockfile)
|
||||
|
||||
# Start every interactive shell with the MaixCDK virtualenv active,
|
||||
# mirroring `make shell`.
|
||||
activate_line='. "$HOME/MaixCDK/bin/activate"'
|
||||
if ! grep -qxF "$activate_line" "$HOME/.bashrc" 2>/dev/null; then
|
||||
printf '\n# MaixCDK virtualenv (added by .devcontainer/post-create.sh)\n%s\n' \
|
||||
"$activate_line" >>"$HOME/.bashrc"
|
||||
fi
|
||||
|
||||
# The build user's home has no shell skeleton files (useradd ran with
|
||||
# --no-create-home), so login shells would skip ~/.bashrc; give them the
|
||||
# standard Debian chain.
|
||||
if [ ! -f "$HOME/.profile" ]; then
|
||||
cat >"$HOME/.profile" <<'EOF'
|
||||
# ~/.profile (added by .devcontainer/post-create.sh)
|
||||
if [ -n "$BASH_VERSION" ] && [ -f "$HOME/.bashrc" ]; then
|
||||
. "$HOME/.bashrc"
|
||||
fi
|
||||
EOF
|
||||
fi
|
||||
13
.dockerignore
Normal file
13
.dockerignore
Normal file
@@ -0,0 +1,13 @@
|
||||
Dockerfile
|
||||
!server/go.mod
|
||||
server/go.sum
|
||||
server/NanoKVM-Server
|
||||
web
|
||||
|
||||
support/sg2002/kvm_system/build
|
||||
support/sg2002/kvm_system/dist
|
||||
support/sg2002/kvm_system/CMakeLists.txt
|
||||
|
||||
support/sg2002/kvm_vision_test/build
|
||||
support/sg2002/kvm_vision_test/dist
|
||||
support/sg2002/kvm_vision_test/CMakeLists.txt
|
||||
132
.github/workflows/builder-image.yml
vendored
Normal file
132
.github/workflows/builder-image.yml
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
name: Builder Image
|
||||
|
||||
# Builds the nanokvm-builder image (riscv64 musl toolchain, Go, and a MaixCDK
|
||||
# checkout patched with support/sg2002/additional) and publishes it to GHCR so
|
||||
# the release workflow does not have to rebuild the SDK on every tag.
|
||||
#
|
||||
# The image is deliberately not rebuilt on every push: it only carries the
|
||||
# toolchain. Release builds re-sync support/sg2002/additional into MaixCDK and
|
||||
# recompile from the checked-out source, so a slightly stale image is harmless.
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- docker/**
|
||||
- .github/workflows/builder-image.yml
|
||||
|
||||
concurrency:
|
||||
group: builder-image
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build and publish nanokvm-builder
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 240
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Free up disk space
|
||||
run: |
|
||||
echo "Before:"
|
||||
df -h /
|
||||
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
|
||||
/usr/local/share/boost /usr/local/share/powershell
|
||||
sudo docker image prune -af
|
||||
echo "After:"
|
||||
df -h /
|
||||
|
||||
- name: Resolve image reference
|
||||
id: image
|
||||
env:
|
||||
OWNER: ${{ github.repository_owner }}
|
||||
run: |
|
||||
# GHCR only accepts lowercase repository paths.
|
||||
owner=$(echo "$OWNER" | tr '[:upper:]' '[:lower:]')
|
||||
echo "ref=ghcr.io/$owner/nanokvm-builder" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# Logging in before the build means a credential or registry problem fails
|
||||
# in seconds instead of after a full SDK build.
|
||||
- name: Log in to GHCR
|
||||
env:
|
||||
GHCR_USER: ${{ github.actor }}
|
||||
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
ok=0
|
||||
for attempt in 1 2 3; do
|
||||
if printf '%s' "$GHCR_TOKEN" \
|
||||
| docker login ghcr.io -u "$GHCR_USER" --password-stdin; then
|
||||
ok=1
|
||||
break
|
||||
fi
|
||||
echo "login attempt $attempt failed, retrying in 15s"
|
||||
sleep 15
|
||||
done
|
||||
if [ "$ok" -ne 1 ]; then
|
||||
echo "::error::could not log in to ghcr.io after 3 attempts"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Build image
|
||||
run: |
|
||||
# The Dockerfile chowns MaixCDK to DOCKER_UID/DOCKER_GID and the
|
||||
# entrypoint gosu's to the caller's ids, so bake in the ids the
|
||||
# release job will actually run as. Otherwise the SDK tree belongs to
|
||||
# 1000 and syncing components into it fails with permission denied.
|
||||
docker build \
|
||||
--build-arg DOCKER_UID="$(id -u)" \
|
||||
--build-arg DOCKER_GID="$(id -g)" \
|
||||
--tag "${{ steps.image.outputs.ref }}:latest" \
|
||||
--tag "${{ steps.image.outputs.ref }}:${{ github.sha }}" \
|
||||
--file docker/Dockerfile \
|
||||
.
|
||||
|
||||
- name: Verify toolchain
|
||||
run: |
|
||||
docker run --rm -i "${{ steps.image.outputs.ref }}:latest" go version
|
||||
docker run --rm -i "${{ steps.image.outputs.ref }}:latest" \
|
||||
riscv64-unknown-linux-musl-gcc --version | head -1
|
||||
docker run --rm -i "${{ steps.image.outputs.ref }}:latest" patchelf --version
|
||||
|
||||
- name: Push image
|
||||
env:
|
||||
IMAGE_REF: ${{ steps.image.outputs.ref }}
|
||||
SHA: ${{ github.sha }}
|
||||
run: |
|
||||
# ghcr.io occasionally times out; a retry is cheaper than rebuilding.
|
||||
# Push the immutable sha tag first so a failure there cannot leave
|
||||
# :latest — which release.yml pulls — already moved.
|
||||
for tag in "$SHA" latest; do
|
||||
ok=0
|
||||
for attempt in 1 2 3; do
|
||||
if docker push "$IMAGE_REF:$tag"; then
|
||||
ok=1
|
||||
break
|
||||
fi
|
||||
echo "push of $tag attempt $attempt failed, retrying in 15s"
|
||||
sleep 15
|
||||
done
|
||||
if [ "$ok" -ne 1 ]; then
|
||||
echo "::error::could not push $IMAGE_REF:$tag after 3 attempts"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
- name: Summary
|
||||
run: |
|
||||
{
|
||||
echo "### Builder image published"
|
||||
echo
|
||||
echo '```'
|
||||
echo "${{ steps.image.outputs.ref }}:latest"
|
||||
echo "${{ steps.image.outputs.ref }}:${{ github.sha }}"
|
||||
echo '```'
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
108
.github/workflows/create-tag.yml
vendored
Normal file
108
.github/workflows/create-tag.yml
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
name: NanoKVM Create Tag
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: Numeric version to tag, e.g. 2.5.0
|
||||
required: true
|
||||
type: string
|
||||
commit_sha:
|
||||
description: Full commit SHA on main (empty uses latest main)
|
||||
required: false
|
||||
default: ''
|
||||
type: string
|
||||
|
||||
concurrency:
|
||||
group: create-tag-${{ inputs.version }}
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
create-tag:
|
||||
name: Create annotated tag
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Checkout main
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
ref: main
|
||||
|
||||
- name: Validate target
|
||||
id: target
|
||||
env:
|
||||
COMMIT_INPUT: ${{ inputs.commit_sha }}
|
||||
VERSION_INPUT: ${{ inputs.version }}
|
||||
run: |
|
||||
VERSION="$VERSION_INPUT"
|
||||
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
echo "::error::invalid version '$VERSION', expected MAJOR.MINOR.PATCH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git fetch --force --tags origin main
|
||||
|
||||
if [ -n "$COMMIT_INPUT" ]; then
|
||||
if ! echo "$COMMIT_INPUT" | grep -qE '^[0-9a-fA-F]{40}$'; then
|
||||
echo "::error::commit_sha must be a full 40-character hexadecimal SHA"
|
||||
exit 1
|
||||
fi
|
||||
TARGET_SHA=$(git rev-parse "${COMMIT_INPUT}^{commit}" 2>/dev/null) || {
|
||||
echo "::error::commit '$COMMIT_INPUT' does not exist"
|
||||
exit 1
|
||||
}
|
||||
else
|
||||
TARGET_SHA=$(git rev-parse 'origin/main^{commit}')
|
||||
fi
|
||||
|
||||
if ! git merge-base --is-ancestor "$TARGET_SHA" origin/main; then
|
||||
echo "::error::commit '$TARGET_SHA' is not reachable from origin/main"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set +e
|
||||
git ls-remote --exit-code --tags origin "refs/tags/$VERSION" >/dev/null
|
||||
TAG_STATUS=$?
|
||||
set -e
|
||||
case "$TAG_STATUS" in
|
||||
0)
|
||||
echo "::error::tag '$VERSION' already exists"
|
||||
exit 1
|
||||
;;
|
||||
2) ;;
|
||||
*)
|
||||
echo "::error::failed to check whether tag '$VERSION' exists"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "sha=$TARGET_SHA" >> "$GITHUB_OUTPUT"
|
||||
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Create and push tag
|
||||
env:
|
||||
TARGET_SHA: ${{ steps.target.outputs.sha }}
|
||||
VERSION: ${{ steps.target.outputs.version }}
|
||||
run: |
|
||||
git config user.name 'github-actions[bot]'
|
||||
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
|
||||
git tag -a "$VERSION" "$TARGET_SHA" -m "Release $VERSION"
|
||||
git push origin "refs/tags/$VERSION"
|
||||
./scripts/verify-release-tag.sh "$VERSION" "$TARGET_SHA" >/dev/null
|
||||
|
||||
- name: Summary
|
||||
env:
|
||||
TARGET_SHA: ${{ steps.target.outputs.sha }}
|
||||
VERSION: ${{ steps.target.outputs.version }}
|
||||
run: |
|
||||
{
|
||||
echo '### NanoKVM tag created'
|
||||
echo
|
||||
echo "- Tag: \`$VERSION\`"
|
||||
echo "- Commit: \`$TARGET_SHA\`"
|
||||
echo
|
||||
echo 'No package, GitHub Release, or CDN object was created.'
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
68
.github/workflows/issue-tracker.yml
vendored
Normal file
68
.github/workflows/issue-tracker.yml
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
name: Issue Tracker
|
||||
|
||||
on:
|
||||
issues:
|
||||
types: [opened, reopened, closed]
|
||||
|
||||
jobs:
|
||||
track-issue:
|
||||
name: Track Issue Updates
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Send Issue Data to API
|
||||
env:
|
||||
RAW_TITLE: ${{ github.event.issue.title }}
|
||||
RAW_BODY: ${{ github.event.issue.body }}
|
||||
RAW_LABELS: ${{ toJSON(github.event.issue.labels) }}
|
||||
RAW_ASSIGNEES: ${{ toJSON(github.event.issue.assignees) }}
|
||||
API_URL: ${{ secrets.ISSUE_TRACKER_API_URL }}
|
||||
VERIFY_TOKEN: ${{ secrets.VERIFY_TOKEN }}
|
||||
run: |
|
||||
ISSUE_DATA=$(jq -n \
|
||||
--arg action "${{ github.event.action }}" \
|
||||
--arg id "${{ github.event.issue.id }}" \
|
||||
--arg num "${{ github.event.issue.number }}" \
|
||||
--arg title "$RAW_TITLE" \
|
||||
--arg body "$RAW_BODY" \
|
||||
--arg state "${{ github.event.issue.state }}" \
|
||||
--arg created_at "${{ github.event.issue.created_at }}" \
|
||||
--arg updated_at "${{ github.event.issue.updated_at }}" \
|
||||
--arg closed_at "${{ github.event.issue.closed_at }}" \
|
||||
--arg url "${{ github.event.issue.html_url }}" \
|
||||
--arg user_login "${{ github.event.issue.user.login }}" \
|
||||
--arg repository "${{ github.repository }}" \
|
||||
--argjson labels "$RAW_LABELS" \
|
||||
--argjson assignees "$RAW_ASSIGNEES" \
|
||||
'{
|
||||
action: $action,
|
||||
issue: {
|
||||
id: ($id | tonumber),
|
||||
number: ($num | tonumber),
|
||||
title: $title,
|
||||
body: $body,
|
||||
state: $state,
|
||||
created_at: $created_at,
|
||||
updated_at: $updated_at,
|
||||
closed_at: $closed_at,
|
||||
url: $url,
|
||||
user: { login: $user_login },
|
||||
labels: $labels,
|
||||
assignees: $assignees
|
||||
},
|
||||
repository: { name: $repository },
|
||||
}')
|
||||
|
||||
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "$API_URL" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Token: $VERIFY_TOKEN" \
|
||||
-d "$ISSUE_DATA")
|
||||
|
||||
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
|
||||
|
||||
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
|
||||
echo "Successfully sent issue data to API"
|
||||
else
|
||||
echo "Failed to send issue data to API"
|
||||
exit 1
|
||||
fi
|
||||
296
.github/workflows/package.yml
vendored
Normal file
296
.github/workflows/package.yml
vendored
Normal file
@@ -0,0 +1,296 @@
|
||||
name: NanoKVM Package
|
||||
|
||||
# Builds nanokvm_<version>.tar.gz and the latest.json manifest that the
|
||||
# on-device updater consumes (server/service/application/). Pull requests get a
|
||||
# uniquely identified, short-lived test artifact. Release publication is a
|
||||
# separate, explicit workflow that calls this one for an existing tag.
|
||||
#
|
||||
# This workflow does NOT publish to cdn.sipeed.com. Uploading latest.json is what
|
||||
# actually offers the update to every device in the field, so that step stays
|
||||
# manual and deliberate.
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- .github/workflows/create-tag.yml
|
||||
- .github/workflows/package.yml
|
||||
- .github/workflows/release.yml
|
||||
- kvmapp/**
|
||||
- scripts/**
|
||||
- server/**
|
||||
- support/**
|
||||
- tools/nanokvm_update_edid/**
|
||||
- web/**
|
||||
- Makefile
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: Version to package, e.g. 2.4.4
|
||||
required: true
|
||||
type: string
|
||||
workflow_call:
|
||||
inputs:
|
||||
version:
|
||||
description: Numeric version to package
|
||||
required: true
|
||||
type: string
|
||||
ref:
|
||||
description: Existing tag or commit to check out
|
||||
required: true
|
||||
type: string
|
||||
outputs:
|
||||
artifact_name:
|
||||
description: Uploaded Actions artifact name
|
||||
value: ${{ jobs.package.outputs.artifact_name }}
|
||||
version:
|
||||
description: Packaged version
|
||||
value: ${{ jobs.package.outputs.version }}
|
||||
|
||||
concurrency:
|
||||
group: package-${{ github.event.pull_request.number || inputs.ref || github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
jobs:
|
||||
package:
|
||||
name: Build package
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 180
|
||||
outputs:
|
||||
artifact_name: ${{ steps.version.outputs.artifact_name }}
|
||||
version: ${{ steps.version.outputs.version }}
|
||||
permissions:
|
||||
contents: read
|
||||
packages: read
|
||||
|
||||
steps:
|
||||
- name: Checkout event ref
|
||||
if: inputs.ref == ''
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
# package.sh derives SOURCE_DATE_EPOCH from the commit date.
|
||||
fetch-depth: 0
|
||||
# Build scripts from a pull request must not inherit checkout's token.
|
||||
persist-credentials: false
|
||||
|
||||
- name: Checkout requested ref
|
||||
if: inputs.ref != ''
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
ref: ${{ inputs.ref }}
|
||||
|
||||
- name: Resolve version
|
||||
id: version
|
||||
env:
|
||||
EVENT_NAME: ${{ github.event_name }}
|
||||
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
||||
INPUT_VERSION: ${{ inputs.version }}
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
REF_NAME: ${{ github.ref_name }}
|
||||
run: |
|
||||
BUILD_SHA=$(git rev-parse HEAD)
|
||||
if [ "$EVENT_NAME" = "pull_request" ]; then
|
||||
VERSION="0.${PR_NUMBER}.${GITHUB_RUN_NUMBER}"
|
||||
SOURCE_SHA="$HEAD_SHA"
|
||||
elif [ -n "$INPUT_VERSION" ]; then
|
||||
VERSION="$INPUT_VERSION"
|
||||
SOURCE_SHA="$BUILD_SHA"
|
||||
else
|
||||
VERSION="$REF_NAME"
|
||||
SOURCE_SHA="$BUILD_SHA"
|
||||
fi
|
||||
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
echo "::error::invalid version '$VERSION', expected MAJOR.MINOR.PATCH"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$SOURCE_SHA" ]; then
|
||||
echo "::error::could not resolve source commit"
|
||||
exit 1
|
||||
fi
|
||||
SHORT_SHA=$(printf '%s' "$SOURCE_SHA" | cut -c1-12)
|
||||
if [ "$EVENT_NAME" = "pull_request" ]; then
|
||||
ARTIFACT_NAME="nanokvm-pr-${PR_NUMBER}-${SHORT_SHA}-run-${GITHUB_RUN_ID}-attempt-${GITHUB_RUN_ATTEMPT}"
|
||||
else
|
||||
ARTIFACT_NAME="nanokvm-${VERSION}-${SHORT_SHA}-run-${GITHUB_RUN_ID}-attempt-${GITHUB_RUN_ATTEMPT}"
|
||||
fi
|
||||
{
|
||||
echo "artifact_name=$ARTIFACT_NAME"
|
||||
echo "build_sha=$BUILD_SHA"
|
||||
echo "source_sha=$SOURCE_SHA"
|
||||
echo "version=$VERSION"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
echo "Packaging version $VERSION as $ARTIFACT_NAME"
|
||||
|
||||
- name: Free up disk space
|
||||
run: |
|
||||
df -h /
|
||||
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc
|
||||
df -h /
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
|
||||
- name: Set up pnpm
|
||||
run: npm install --global pnpm@11
|
||||
|
||||
- name: Build frontend
|
||||
run: make web
|
||||
|
||||
- name: Log in to GHCR
|
||||
if: github.event_name != 'pull_request'
|
||||
env:
|
||||
GHCR_USER: ${{ github.actor }}
|
||||
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
ok=0
|
||||
for attempt in 1 2 3; do
|
||||
if printf '%s' "$GHCR_TOKEN" \
|
||||
| docker login ghcr.io -u "$GHCR_USER" --password-stdin; then
|
||||
ok=1
|
||||
break
|
||||
fi
|
||||
echo "login attempt $attempt failed, retrying in 15s"
|
||||
sleep 15
|
||||
done
|
||||
if [ "$ok" -ne 1 ]; then
|
||||
echo "::error::could not log in to ghcr.io after 3 attempts"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Pull builder image
|
||||
id: image
|
||||
env:
|
||||
OWNER: ${{ github.repository_owner }}
|
||||
run: |
|
||||
# GHCR only accepts lowercase repository paths.
|
||||
# shellcheck disable=SC2153 # OWNER is supplied through the step environment.
|
||||
owner=$(echo "$OWNER" | tr '[:upper:]' '[:lower:]')
|
||||
IMAGE_REPO="ghcr.io/$owner/nanokvm-builder"
|
||||
TAGGED_REF="${IMAGE_REPO}:latest"
|
||||
ok=0
|
||||
for attempt in 1 2 3; do
|
||||
if docker pull "$TAGGED_REF"; then
|
||||
ok=1
|
||||
break
|
||||
fi
|
||||
echo "pull attempt $attempt failed, retrying in 15s"
|
||||
sleep 15
|
||||
done
|
||||
if [ "$ok" -ne 1 ]; then
|
||||
echo "::error::could not pull $TAGGED_REF - run the 'Builder Image' workflow first and ensure PR builds can pull it without credentials"
|
||||
exit 1
|
||||
fi
|
||||
RESOLVED_REF=$(docker image inspect --format='{{index .RepoDigests 0}}' "$TAGGED_REF")
|
||||
case "$RESOLVED_REF" in
|
||||
"$IMAGE_REPO"@sha256:*) ;;
|
||||
*)
|
||||
echo "::error::could not resolve immutable digest for $TAGGED_REF (got '$RESOLVED_REF')"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
echo "Pulled $RESOLVED_REF"
|
||||
echo "ref=$RESOLVED_REF" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Build riscv64 artifacts
|
||||
run: |
|
||||
make release-build \
|
||||
DOCKER_TTY= \
|
||||
IMAGE_NAME="${{ steps.image.outputs.ref }}"
|
||||
|
||||
- name: Assemble package
|
||||
run: make package VERSION="${{ steps.version.outputs.version }}"
|
||||
|
||||
- name: Compare against the published release
|
||||
# Informational only: highlights what changed relative to what devices
|
||||
# are currently running. Never blocks the build.
|
||||
continue-on-error: true
|
||||
run: |
|
||||
./scripts/compare-release.sh \
|
||||
"build/release/nanokvm_${{ steps.version.outputs.version }}.tar.gz"
|
||||
|
||||
- name: Write build provenance
|
||||
env:
|
||||
ARTIFACT_NAME: ${{ steps.version.outputs.artifact_name }}
|
||||
BUILDER_IMAGE: ${{ steps.image.outputs.ref }}
|
||||
BUILD_SHA: ${{ steps.version.outputs.build_sha }}
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
SOURCE_SHA: ${{ steps.version.outputs.source_sha }}
|
||||
VERSION: ${{ steps.version.outputs.version }}
|
||||
run: |
|
||||
TARBALL="build/release/nanokvm_${VERSION}.tar.gz"
|
||||
TARBALL_NAME=$(basename "$TARBALL")
|
||||
SHA256_HEX=$(sha256sum "$TARBALL" | cut -d' ' -f1)
|
||||
SHA512_HEX=$(sha512sum "$TARBALL" | cut -d' ' -f1)
|
||||
SHA512_BASE64=$(jq -er '.sha512 | select(type == "string" and length > 0)' \
|
||||
build/release/latest.json)
|
||||
ACTUAL_BASE64=$(openssl dgst -sha512 -binary "$TARBALL" | openssl base64 -A)
|
||||
if [ "$SHA512_BASE64" != "$ACTUAL_BASE64" ]; then
|
||||
echo "::error::latest.json sha512 does not match $TARBALL"
|
||||
exit 1
|
||||
fi
|
||||
printf '%s %s\n' "$SHA256_HEX" "$TARBALL_NAME" > build/release/sha256.txt
|
||||
{
|
||||
echo "artifact=${ARTIFACT_NAME}"
|
||||
echo "version=${VERSION}"
|
||||
echo "event=${GITHUB_EVENT_NAME}"
|
||||
echo "pull_request=${PR_NUMBER}"
|
||||
echo "source_sha=${SOURCE_SHA}"
|
||||
echo "build_sha=${BUILD_SHA}"
|
||||
echo "builder_image=${BUILDER_IMAGE}"
|
||||
echo "run_id=${GITHUB_RUN_ID}"
|
||||
echo "run_attempt=${GITHUB_RUN_ATTEMPT}"
|
||||
echo "run_url=https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
|
||||
echo "tarball=${TARBALL_NAME}"
|
||||
echo "sha256_hex=${SHA256_HEX}"
|
||||
echo "sha512_hex=${SHA512_HEX}"
|
||||
echo "sha512_base64=${SHA512_BASE64}"
|
||||
} > build/release/BUILD_INFO.txt
|
||||
|
||||
- name: Verify release assets
|
||||
run: |
|
||||
./scripts/verify-release-assets.sh \
|
||||
build/release "${{ steps.version.outputs.version }}"
|
||||
|
||||
- name: Summary
|
||||
env:
|
||||
VERSION: ${{ steps.version.outputs.version }}
|
||||
run: |
|
||||
{
|
||||
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
|
||||
echo "> [!WARNING]"
|
||||
echo "> PR TEST ONLY — DO NOT PUBLISH TO CDN"
|
||||
echo
|
||||
fi
|
||||
echo "### nanokvm_${VERSION}.tar.gz"
|
||||
echo
|
||||
echo '```text'
|
||||
cat build/release/BUILD_INFO.txt
|
||||
echo '```'
|
||||
echo
|
||||
echo '```json'
|
||||
cat build/release/latest.json
|
||||
echo '```'
|
||||
echo
|
||||
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
|
||||
echo "Upload only the inner tarball through NanoKVM's manual offline update UI."
|
||||
else
|
||||
echo "Publishing to \`cdn.sipeed.com/nanokvm/\` is a separate manual step."
|
||||
fi
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ steps.version.outputs.artifact_name }}
|
||||
path: |
|
||||
build/release/nanokvm_${{ steps.version.outputs.version }}.tar.gz
|
||||
build/release/latest.json
|
||||
build/release/sha256.txt
|
||||
build/release/BUILD_INFO.txt
|
||||
if-no-files-found: error
|
||||
retention-days: ${{ github.event_name == 'pull_request' && 7 || 90 }}
|
||||
244
.github/workflows/release.yml
vendored
Normal file
244
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,244 @@
|
||||
name: NanoKVM Release
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: Existing numeric tag to release, e.g. 2.5.0
|
||||
required: true
|
||||
type: string
|
||||
release_action:
|
||||
description: Publish a release or promote a tested prerelease
|
||||
required: true
|
||||
type: choice
|
||||
options:
|
||||
- publish-prerelease
|
||||
- publish-stable
|
||||
- promote-stable
|
||||
|
||||
# Latest is repository-global, so all Release changes must be serialized.
|
||||
concurrency:
|
||||
group: nanokvm-github-release
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
validate:
|
||||
name: Resolve release tag
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
outputs:
|
||||
source_sha: ${{ steps.tag.outputs.source_sha }}
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
|
||||
- name: Verify tag
|
||||
id: tag
|
||||
env:
|
||||
TAG: ${{ inputs.tag }}
|
||||
run: |
|
||||
SOURCE_SHA=$(./scripts/verify-release-tag.sh "$TAG")
|
||||
echo "source_sha=$SOURCE_SHA" >> "$GITHUB_OUTPUT"
|
||||
|
||||
package:
|
||||
name: Build tag package
|
||||
needs: validate
|
||||
if: inputs.release_action != 'promote-stable'
|
||||
permissions:
|
||||
contents: read
|
||||
packages: read
|
||||
uses: ./.github/workflows/package.yml
|
||||
with:
|
||||
ref: ${{ needs.validate.outputs.source_sha }}
|
||||
version: ${{ inputs.tag }}
|
||||
|
||||
publish:
|
||||
name: Publish GitHub release
|
||||
needs:
|
||||
- validate
|
||||
- package
|
||||
if: inputs.release_action != 'promote-stable'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Checkout release tooling
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
|
||||
- name: Download package artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: ${{ needs.package.outputs.artifact_name }}
|
||||
path: build/release
|
||||
|
||||
- name: Publish release
|
||||
env:
|
||||
GH_REPO: ${{ github.repository }}
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
RELEASE_ACTION: ${{ inputs.release_action }}
|
||||
SOURCE_SHA: ${{ needs.validate.outputs.source_sha }}
|
||||
TAG: ${{ inputs.tag }}
|
||||
run: |
|
||||
./scripts/verify-release-assets.sh build/release "$TAG"
|
||||
|
||||
case "$RELEASE_ACTION" in
|
||||
publish-prerelease) IS_PRERELEASE=true ;;
|
||||
publish-stable) IS_PRERELEASE=false ;;
|
||||
*)
|
||||
echo "::error::invalid publish action '$RELEASE_ACTION'"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
ENDPOINT="repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}"
|
||||
set +e
|
||||
HEADERS=$(gh api --include --silent "$ENDPOINT" 2>&1)
|
||||
API_STATUS=$?
|
||||
set -e
|
||||
HTTP_STATUS=$(printf '%s\n' "$HEADERS" | awk '
|
||||
$1 ~ /^HTTP\// { status = $2 }
|
||||
END { print status }
|
||||
')
|
||||
if [ "$API_STATUS" -eq 0 ] && [ "$HTTP_STATUS" = 200 ]; then
|
||||
echo "::error::release or draft '$TAG' already exists"
|
||||
echo "Publishing is one-shot. Inspect it at https://github.com/${GITHUB_REPOSITORY}/releases."
|
||||
exit 1
|
||||
fi
|
||||
if [ "$API_STATUS" -eq 0 ] || [ "$HTTP_STATUS" != 404 ]; then
|
||||
echo "::error::failed to query release '$TAG' (HTTP status: ${HTTP_STATUS:-unknown})"
|
||||
printf '%s\n' "$HEADERS" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TARBALL="build/release/nanokvm_${TAG}.tar.gz"
|
||||
SHA256=$(sha256sum "$TARBALL" | cut -d' ' -f1)
|
||||
SHA512=$(jq -er '.sha512' build/release/latest.json)
|
||||
# Backticks below are intentional Markdown, not command substitution.
|
||||
# shellcheck disable=SC2016
|
||||
NOTES=$(printf '%s\n' \
|
||||
"Application package for NanoKVM ${TAG}." \
|
||||
'' \
|
||||
'### Checksums' \
|
||||
'' \
|
||||
'`SHA-256` (hex):' \
|
||||
'' \
|
||||
" ${SHA256}" \
|
||||
'' \
|
||||
'`SHA-512` (base64, as expected by the on-device updater):' \
|
||||
'' \
|
||||
" ${SHA512}" \
|
||||
'' \
|
||||
'To offer this build over OTA, publish it through the separate CDN workflow.')
|
||||
|
||||
STATE_ARGS=(--prerelease="$IS_PRERELEASE")
|
||||
if [ "$IS_PRERELEASE" = true ]; then
|
||||
STATE_ARGS+=(--latest=false)
|
||||
fi
|
||||
|
||||
./scripts/verify-release-tag.sh "$TAG" "$SOURCE_SHA" >/dev/null
|
||||
gh release create "$TAG" \
|
||||
--verify-tag \
|
||||
--title "nanokvm@${TAG}" \
|
||||
--notes "$NOTES" \
|
||||
"${STATE_ARGS[@]}" \
|
||||
"$TARBALL" build/release/latest.json build/release/sha256.txt
|
||||
|
||||
- name: Summary
|
||||
env:
|
||||
RELEASE_ACTION: ${{ inputs.release_action }}
|
||||
SOURCE_SHA: ${{ needs.validate.outputs.source_sha }}
|
||||
TAG: ${{ inputs.tag }}
|
||||
run: |
|
||||
{
|
||||
echo '### NanoKVM GitHub Release published'
|
||||
echo
|
||||
echo "- Tag: \`$TAG\`"
|
||||
echo "- Commit: \`$SOURCE_SHA\`"
|
||||
echo "- Action: \`$RELEASE_ACTION\`"
|
||||
echo
|
||||
echo 'No CDN object was uploaded.'
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
promote:
|
||||
name: Promote verified prerelease
|
||||
needs: validate
|
||||
if: inputs.release_action == 'promote-stable'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Checkout release tooling
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
|
||||
- name: Verify and promote release
|
||||
env:
|
||||
GH_REPO: ${{ github.repository }}
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SOURCE_SHA: ${{ needs.validate.outputs.source_sha }}
|
||||
TAG: ${{ inputs.tag }}
|
||||
run: |
|
||||
RELEASE_JSON=$(gh api "repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}")
|
||||
if [ "$(jq -r '.draft' <<< "$RELEASE_JSON")" != false ]; then
|
||||
echo "::error::release '$TAG' is a draft"
|
||||
exit 1
|
||||
fi
|
||||
if [ "$(jq -r '.prerelease' <<< "$RELEASE_JSON")" != true ]; then
|
||||
echo "::error::release '$TAG' is not a prerelease"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CURRENT_ASSETS=$(jq -r '.assets[].name' <<< "$RELEASE_JSON" | LC_ALL=C sort)
|
||||
EXPECTED_ASSETS=$(printf '%s\n' \
|
||||
latest.json "nanokvm_${TAG}.tar.gz" sha256.txt | LC_ALL=C sort)
|
||||
if [ "$CURRENT_ASSETS" != "$EXPECTED_ASSETS" ]; then
|
||||
echo "::error::release '$TAG' does not have the exact expected asset set"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p build/release
|
||||
gh release download "$TAG" --dir build/release \
|
||||
--pattern "nanokvm_${TAG}.tar.gz" \
|
||||
--pattern latest.json \
|
||||
--pattern sha256.txt
|
||||
./scripts/verify-release-assets.sh build/release "$TAG"
|
||||
|
||||
./scripts/verify-release-tag.sh "$TAG" "$SOURCE_SHA" >/dev/null
|
||||
gh release edit "$TAG" --prerelease=false --latest
|
||||
./scripts/verify-release-tag.sh "$TAG" "$SOURCE_SHA" >/dev/null
|
||||
|
||||
if [ "$(gh api "repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}" --jq '.prerelease')" != false ]; then
|
||||
echo "::error::release '$TAG' was not promoted"
|
||||
exit 1
|
||||
fi
|
||||
if [ "$(gh api "repos/${GITHUB_REPOSITORY}/releases/latest" --jq '.tag_name')" != "$TAG" ]; then
|
||||
echo "::error::release '$TAG' was not marked latest"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Summary
|
||||
env:
|
||||
SOURCE_SHA: ${{ needs.validate.outputs.source_sha }}
|
||||
TAG: ${{ inputs.tag }}
|
||||
run: |
|
||||
{
|
||||
echo '### NanoKVM prerelease promoted'
|
||||
echo
|
||||
echo "- Tag: \`$TAG\`"
|
||||
echo "- Commit: \`$SOURCE_SHA\`"
|
||||
echo '- Assets: unchanged and checksum-verified'
|
||||
echo
|
||||
echo 'No package was rebuilt and no CDN object was uploaded.'
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
40
.gitignore
vendored
Normal file
40
.gitignore
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
*.log
|
||||
pnpm-debug.log*
|
||||
|
||||
web/node_modules
|
||||
web/dist
|
||||
web/web
|
||||
|
||||
# pnpm keeps its content-addressable store next to the project when the
|
||||
# home directory is on a different filesystem (e.g. inside the dev container)
|
||||
.pnpm-store/
|
||||
|
||||
.DS_Store
|
||||
*.local
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
NanoKVM-Server
|
||||
|
||||
support/sg2002/kvm_system/build
|
||||
support/sg2002/kvm_system/dist
|
||||
support/sg2002/kvm_system/CMakeLists.txt
|
||||
|
||||
support/sg2002/kvm_vision_test/build
|
||||
support/sg2002/kvm_vision_test/dist
|
||||
support/sg2002/kvm_vision_test/CMakeLists.txt
|
||||
|
||||
support/sg2002/additional/original
|
||||
kvmapp/server/dl_lib
|
||||
kvmapp/kvm_system/kvm_system
|
||||
|
||||
# Release packages assembled by scripts/package.sh
|
||||
/build/
|
||||
kvmapp/server
|
||||
kvmapp/version
|
||||
553
CHANGELOG.md
Normal file
553
CHANGELOG.md
Normal file
@@ -0,0 +1,553 @@
|
||||
## 2.5.3 (2026-11-03)
|
||||
|
||||
### Features
|
||||
|
||||
* Replaced the desktop image menu and the download page with a storage page that lists the media the emulated USB disk can carry, mounts and ejects them, and browses the files inside a medium over the same gadget, so the two machines exchange files without going through the terminal
|
||||
* Added uploads, downloads and deletes to the storage page, with search, sorting, folder deletion behind a confirmation, one transfer display for image and file transfers, cancellable uploads, a free space preflight and a checksum mismatch report
|
||||
* Browsed only media whose filesystem this device can read, so an ISO 9660 image is still served to the target machine but cannot be listed here, and limited CD-ROM mode to ISO 9660 and UDF images
|
||||
* Made the shared folder follow the target machine: while it owns the data partition the listing refreshes on a timer after dropping the dentry and inode caches, so a file the target machine wrote shows up within a second of its own writeback
|
||||
* Added a fine-grained permission system on top of the `admin` and `user` roles: administrators keep implicit full access, while every other account receives an explicit set of grants covering the console, power, media, terminal, device, network, updates, MCP, Tailscale and AI features, with the groups, risk marks and implied grants shown in a permission editor; mounting a medium needs the virtual disk, and the storage page names the account that has to enable it when the current account cannot
|
||||
* Added a view-only console session for an account that may watch but not send input: the pointer and keyboard capture, the mouse menu and the input region editor follow the grant, pages, menus, settings tabs and storage actions render only what the account is allowed to use, and an account without console access lands on a page offering the sections its grants open
|
||||
* Changed permission handling so an open session picks up the new grants without ending the login: a change that invalidates a cached capability drops the long-lived connection with a dedicated close code so the page reconnects, and only disabling an account ends the login
|
||||
* Added the choice of regenerating the device-wide MCP API key when an account loses the MCP grant, instead of rotating the key silently and disconnecting every MCP client
|
||||
* Kept the pre-2.6 image endpoints working as a compatibility layer over the new media API, so existing clients and scripts keep working
|
||||
* Treated UDF images, not only ISO 9660 ones, as optical media, and accepted uploads by extension (`.iso`/`.img`), leaving an unusable image to fail when it is mounted instead of while it is stored
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixed HID input being lost after a medium was mounted or the gadget was otherwise reset, by reopening the HID devices with a retry instead of a single attempt that could fail while the new nodes were still coming up
|
||||
* Fixed `/data` staying read-only after a failed gadget script or a network switch
|
||||
* Fixed the settings menu icon sitting a few pixels below the other menu icons, and centered the dialog tab icons in their box
|
||||
* Fixed Chinese and Japanese punctuation being drawn by a Latin face in tooltips and dialogs, which pushed the ideographic comma and full stop above the baseline
|
||||
|
||||
### UI Improvements
|
||||
|
||||
* Gave the shared folder, ISO and IMG entries their own glyphs and picked file icons from the extension, so a listing can be read at a glance
|
||||
* Listed administrators above regular accounts and gave their rows a lighter card
|
||||
* Moved the PicoClaw chat composer to an antd text area and replaced the Radix scroll area with the native scroll container, so the settings dialog and the shortcut lists scroll like the rest of the app
|
||||
|
||||
### Localization
|
||||
|
||||
* Translated every string the storage page, the permission editor, the view-only console and the MCP key rotation add for all 24 supported locales
|
||||
* Removed the keys the retired image menu and download page left behind
|
||||
|
||||
### Security
|
||||
|
||||
* Mounted images are opened through loop devices that refuse symlinks, and files inside a medium are opened without following links
|
||||
|
||||
### Chores
|
||||
|
||||
* Removed the desktop image menu, the download page and their web client code
|
||||
* Dropped the `@radix-ui/react-scroll-area` dependency
|
||||
* Documented the permission catalog, the split between mounting media and writing the library, and the grants that reach the whole device in `server/README.md` and `server/README_ZH.md`
|
||||
|
||||
## 2.5.2 (2026-09-29)
|
||||
|
||||
### Features
|
||||
|
||||
* Added a one-writer policy for the emulated USB disk and the `/data` partition: `/data` is mounted read-only from boot while the virtual disk serves the raw partition to the target machine, enabling the disk remounts it read-only and verifies the state before the target machine can write it, refusing to expose the disk when the remount fails, and releasing a medium hands the raw partition back to the target machine the same way
|
||||
* Added confirmation before a mounted medium and the virtual disk take the shared partition from each other, including a warning that a running image transfer is cancelled and that `/data` becomes read-only on this device
|
||||
* Added cancellation of a running image transfer before the partition handover, showed the transfer state in the image list and disabled the actions that cannot run while a medium is mounted, with a hint explaining why
|
||||
* Added names for the mounted medium and the emulated USB device taken from the image file, truncated to the SCSI inquiry product field and the USB product string and restored on unmount
|
||||
* Added streaming validation of uploaded images: ISO 9660 and UDF volume descriptors and raw disk images (GPT, APFS, HFS+, MBR) are accepted and anything else is rejected in seconds instead of after the whole transfer, with a free space check that keeps a 128 MiB reserve before any byte is received
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixed mass storage mounts staying writable from the target machine: every mounted image is now served read-only, with the flag set before the LUN is attached, so the target machine can neither write to nor format it
|
||||
* Fixed the LUN flags surviving a gadget restart, which brought the shared partition back to the target machine read-only or as an optical drive after a medium had been mounted
|
||||
* Fixed the virtual disk switch staying on but unchangeable while a medium was mounted; the disk now reports itself on only while the LUN really carries the `/data` partition
|
||||
* Fixed the on-screen keyboard crashing the page with "Minified React error #130" as soon as it was opened, by importing the `react-simple-keyboard` component through its named export, which the CommonJS interop under Vite 8 no longer resolves from a default import
|
||||
|
||||
### Localization
|
||||
|
||||
* Translated the new virtual disk and image mounting strings for every locale
|
||||
|
||||
### Chores
|
||||
|
||||
* Added unit tests for the upload header check, the free space preflight and the image name truncation
|
||||
|
||||
## 2.5.1 (2026-09-09)
|
||||
|
||||
### Features
|
||||
|
||||
* Added device-level multi-user support with `admin` and `user` roles and a user management page under Settings, separating administrative areas (terminal, scripts, storage, network, updates, MCP, PicoClaw and Tailscale) from the video, keyboard, mouse, paste, wake-on-LAN and power controls every account keeps
|
||||
* Moved sessions to HttpOnly cookies with a per-user token version, so changing a password or disabling an account immediately ends that user's open web and WebSocket sessions
|
||||
* Added support for a custom update server, so the application can be updated from your own mirror, with credentials in the URL, manifest validation and a settings page for configuring it
|
||||
* Added SHA-256 verification of offline update packages before they are installed
|
||||
* Added configurable mouse input regions for absolute mode, with automatic black-border detection, manual selection of the controllable area on screen, and original-resolution presets, so the pointer stays aligned when the target machine outputs a letterboxed or non-16:9 signal
|
||||
* Added touch gestures to relative mouse mode, including tap, drag, long press, double-tap drag and two-finger scroll, so relative mode is now usable from a phone or tablet
|
||||
* Added a `signal` field to `/api/vm/hdmi` reporting whether an HDMI source is actually present, not just whether capture is enabled
|
||||
* Added a default root shell profile showing the user, host and working directory in the prompt over SSH and the Web terminal
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixed mouse coordinates being offset in Direct H.264 mode when the target machine pads the picture with black bars
|
||||
* Fixed touch input in absolute mode, and stopped taps on the black letterbox area from being sent to the target machine
|
||||
* Fixed the video area not fitting the window, by scaling H.264 and MJPEG playback to contain and letting the page handle touch instead of the browser
|
||||
* Fixed WebRTC H.264 failures leaving a silent black screen; signaling, negotiation, ICE and playback failures now report what went wrong and offer a retry
|
||||
* Fixed a slow WebRTC viewer stalling the shared H.264 source for everyone else, by dropping its buffered frames until the next key frame
|
||||
* Fixed application updates running from a temporary directory that could be too small or shared with another update; online and offline updates are now staged in isolated persistent workspaces with archive, manifest and free-space checks, and the last rollback backup is kept when space runs short
|
||||
* Fixed the update lock being released before the server finished restarting, which allowed a second update to start and be killed mid-install
|
||||
* Fixed Web terminal sessions not loading the root profile, by starting them as login shells in `/root`
|
||||
|
||||
### Performance
|
||||
|
||||
* Routed Direct and WebRTC viewers through a single shared H.264 capture source instead of each reading the encoder separately
|
||||
|
||||
### Localization
|
||||
|
||||
* Synchronized translations of other languages according to English
|
||||
|
||||
### Chores
|
||||
|
||||
* Upgraded the web build tooling to Vite 8 and switched to Vite's native tsconfig path resolution
|
||||
* Added a dev container for full-stack development
|
||||
* Prefixed GitHub Release titles with `nanokvm`
|
||||
* Added release asset verification with per-device package size limits to the packaging workflow
|
||||
|
||||
## 2.5.0 (2026-08-04)
|
||||
|
||||
### Features
|
||||
|
||||
* Added an MCP service that lets trusted MCP clients capture screenshots and control the keyboard and mouse with an API key, including a settings page for enabling it and regenerating the key
|
||||
* Added coordinated device control so MCP, PicoClaw and manual input hand ownership over to each other instead of writing HID input at the same time
|
||||
* Added remote keyboard lock indicators that show the target machine's Num Lock, Caps Lock and Scroll Lock state
|
||||
* Added an optional SHA-256 checksum and cancellation to remote image downloads
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixed the USB network gadget getting a random host-side MAC on every bind, which made the attached PC register a new network adapter after each reboot; both the device and host MAC are now derived from the chip UID (thanks to [@BeaconCat](https://github.com/BeaconCat))
|
||||
* Fixed OLED sleep durations above 255 seconds being truncated, so the 5 min, 10 min, 30 min and 1 hour options now behave as selected
|
||||
* Fixed the mounted image API returning an error in HID-Only mode
|
||||
* Fixed image downloads and application updates interfering with each other when running at the same time
|
||||
* Fixed Direct H.264 playback falling behind when the decoder queue backed up, by resynchronizing at the next key frame and preferring hardware decoding
|
||||
* Added a warning when Direct and WebRTC H.264 stream modes are used at the same time
|
||||
* Made the video input state shared between processes and read it without shell pipelines, so HDMI status stays consistent between `NanoKVM-Server` and `kvm_system`
|
||||
|
||||
### Performance
|
||||
|
||||
* Reduced latency in 60 Hz mode with decode-driven flow control, GOP-aware bounded queues, and dedicated writer goroutines with write deadlines so a slow client no longer stalls the others
|
||||
* Integrated zero-copy H.264 capture into the video pipeline instead of relying on a preload hook
|
||||
* Stopped HDMI capture when no user is logged in or all viewers are idle, reducing power consumption
|
||||
|
||||
### UI Improvements
|
||||
|
||||
* Tidied the image download dialog layout and truncated long file names in the upload box
|
||||
|
||||
### Localization
|
||||
|
||||
* Synchronized translations of other languages according to English
|
||||
|
||||
### Chores
|
||||
|
||||
* Split release automation into separate package, tag and release workflows, and produced identifiable build artifacts with checksums for pull requests
|
||||
* Allowed overriding the builder image, installed `patchelf` in the build environment, and fixed the exit codes of `support/sg2002/build`
|
||||
* Fixed slow container builds caused by uid/gid mismatch and reused existing container users and groups
|
||||
|
||||
## 2.4.3 (2026-06-09)
|
||||
|
||||
### Features
|
||||
|
||||
* Added LT6911D support
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Improved USB network adapter compatibility on Windows
|
||||
|
||||
## 2.4.2 (2026-05-20)
|
||||
|
||||
### Features
|
||||
|
||||
* Added HDMI capture status detection with localized warning and error overlays on the desktop screen
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixed left-button touch cancellation and context menu cleanup for mouse input
|
||||
* Improved the WebRTC loading indicator
|
||||
* Added Wi-Fi password field validation
|
||||
* Hardened Wake-on-LAN MAC handling by normalizing stored addresses, avoiding shell execution, handling missing history gracefully, and improving named MAC display
|
||||
* Stabilized PicoClaw session switching by waiting for gateway release, refreshing runtime status before reconnecting, rendering structured thought messages, and preventing history row overflow
|
||||
|
||||
### Performance
|
||||
|
||||
* Improved H.264 streaming client handling by reducing frame queue latency, using client snapshots for fanout, applying backend ICE server configuration, and cleaning up disconnected WebRTC clients more aggressively
|
||||
|
||||
### UI Improvements
|
||||
|
||||
* Refreshed desktop menu ordering and community links, including replacing the Discussion link with Discord
|
||||
|
||||
### Chores
|
||||
|
||||
* Removed the legacy H.264 stream package
|
||||
* Updated PostCSS, refreshed the MSW worker, and added pnpm workspace build approvals
|
||||
|
||||
## 2.4.1 (2026-05-08)
|
||||
|
||||
### Features
|
||||
|
||||
* Added DNS management to Network settings, including DHCP/manual modes, effective DNS display, network details, IPv4/IPv6 server validation, and persistent udhcpc hook support
|
||||
* Added a configurable server `host` option for binding NanoKVM to a specific listen address (thanks to [@allmazz](https://github.com/allmazz))
|
||||
* Added French keyboard layout support and language options (thanks to [@ilyesAj](https://github.com/ilyesAj))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Hardened HID recovery and cleanup by adding non-blocking HID writes, bounded reopen retries, stale event draining, and release reports after write failures
|
||||
* Fixed the `kvm_vision` project name and build output message in the SG2002 build script (thanks to [@Voranto](https://github.com/Voranto))
|
||||
|
||||
### UI Improvements
|
||||
|
||||
* Moved TLS and Wi-Fi settings into the Network settings section
|
||||
* Optimized the Settings scrollbar style
|
||||
|
||||
### Localization
|
||||
|
||||
* Updated Korean translations (thanks to [@kmw0410](https://github.com/kmw0410))
|
||||
* Synchronized translations of other languages according to English
|
||||
|
||||
### Security
|
||||
|
||||
* Upgraded vulnerable web dependencies
|
||||
|
||||
## 2.4.0 (2026-04-10)
|
||||
|
||||
### Features
|
||||
|
||||
* **Introduced [PicoClaw](https://github.com/sipeed/picoclaw) support** — an AI-powered remote desktop assistant for NanoKVM. PicoClaw seamlessly integrates a lightweight AI agent with NanoKVM's underlying hardware capabilities. Key highlights include:
|
||||
* **Zero-Agent Architecture:** Operates entirely through HDMI video capture (vision) and USB HID emulation (keyboard/mouse). No SSH access, network connection to the host, or OS-level software installation is required.
|
||||
* **Natural Language Control:** Features a built-in chat interface allowing users to issue complex instructions in plain text.
|
||||
* **Autonomous GUI Operation:** The AI agent can autonomously observe the remote host's screen, understand UI elements, reason about the task, and execute operations mimicking human behavior.
|
||||
* **Installation Note:** PicoClaw is not built into the NanoKVM device or firmware. Install it separately when needed.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Added a default subnet mask for static IP configurations
|
||||
* Fixed an issue where the IP address would occasionally not display
|
||||
|
||||
## 2.3.6 (2026-03-12)
|
||||
|
||||
### Features
|
||||
|
||||
* Implemented AP password authentication for the WiFi configuration page
|
||||
* Added Korean and Japanese virtual keyboard layouts (thanks to [@klim4-bot](https://github.com/klim4-bot))
|
||||
* Enabled support for 640x480 resolution (thanks to [@Voranto](https://github.com/Voranto))
|
||||
* Added encryption parameters for OLED distribution network
|
||||
* Added custom logo function and logo generation tools
|
||||
* Added update mechanism for tailscale startup script
|
||||
|
||||
### Localization
|
||||
|
||||
* Updated Japanese translation (thanks to [@tkmsst](https://github.com/tkmsst))
|
||||
|
||||
## 2.3.5 (2026-02-28)
|
||||
|
||||
### Features
|
||||
|
||||
* Implemented login brute-force protection with lockout mechanism
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Improved Tailscale error handling in UI components and refined backend state mapping
|
||||
|
||||
### Chores
|
||||
|
||||
* Updated server and web dependencies
|
||||
|
||||
## 2.3.4 (2026-01-26)
|
||||
|
||||
### Features
|
||||
|
||||
* Introduced `Leader Key` functionality to bypass local browser shortcut interception
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixed an issue where the Right Shift key was not being recognized on Windows system
|
||||
* Fixed a bug where the menu bar would fail to close correctly
|
||||
|
||||
### Localization
|
||||
|
||||
* Updated Traditional Chinese translations (thanks to [@j796160836](https://github.com/j796160836))
|
||||
* Updated Korean translations (thanks to [@kmw0410](https://github.com/kmw0410))
|
||||
|
||||
## 2.3.3 (2026-01-16)
|
||||
|
||||
### Features
|
||||
|
||||
* Added support for setting the display mode of the menu bar
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixed a keyboard issue where IME composition events were not handled correctly
|
||||
* Resolved an issue where the `AltGr` key was not recognized on the Windows system
|
||||
* Fixed a bug where `Command` key combinations were not fully released on the macOS system
|
||||
* Fixed input issues with the `IntlBackslash` key on the German virtual keyboard
|
||||
|
||||
### Localization
|
||||
|
||||
* Updated Korean translations (thanks to [@kmw0410](https://github.com/kmw0410))
|
||||
|
||||
### Chores
|
||||
|
||||
* Bump react-router-dom from 6.27.0 to 6.30.3
|
||||
* Updated eslint
|
||||
|
||||
## 2.3.2 (2026-01-08)
|
||||
|
||||
### Features
|
||||
|
||||
* Added support for custom keyboard shortcuts
|
||||
* Added support for mouse Forward and Back buttons (reboot required)
|
||||
* Added support for touchscreen mouse operation
|
||||
* The menu bar now supports auto-hide and drag
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixed an issue where the previous IP address was not released after configuring a static IP
|
||||
|
||||
### Performance
|
||||
|
||||
* Refactored the keyboard to support simultaneous keystrokes and a wider range of international layouts (reboot required)
|
||||
* Refactored the mouse to improve response latency
|
||||
* Refactored the WebSocket module to transmit keyboard and mouse data using the standard HID format
|
||||
|
||||
## 2.3.1 (2025-12-26)
|
||||
|
||||
### Features
|
||||
|
||||
* Added support for offline application updates (thanks to [@Alexander-Ger-Reich](https://github.com/Alexander-Ger-Reich))
|
||||
* Implemented support for uploading ISO images (thanks to [@Alexander-Ger-Reich](https://github.com/Alexander-Ger-Reich))
|
||||
* Extended clipboard compatibility to support Russian characters (thanks to [@pekishev](https://github.com/pekishev))
|
||||
* Added configuration options for video scaling
|
||||
* Added support for configuring mouse scroll wheel direction
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Resolved an issue where custom port may not be accessible
|
||||
* Fixed a bug where Web Terminal and Serial Terminal may not disconnect when the page is closed
|
||||
|
||||
### Security
|
||||
|
||||
* Enhanced validation logic on the Wi-Fi configuration page. Requests are now rejected when the device is not in AP mode to prevent unauthorized changes
|
||||
|
||||
### Chore
|
||||
|
||||
* Added a Docker image environment to support building `libkvm.so` and `NanoKVM-Server` (thanks to [@lowtech-guy](https://github.com/lowtech-guy))
|
||||
* Optimized the Settings UI
|
||||
|
||||
### Localization
|
||||
|
||||
* Updated Korean translation (thanks to [@kmw0410](https://github.com/kmw0410))
|
||||
* Updated Swedish translation (thanks to [@acidflash](https://github.com/acidflash))
|
||||
* Updated Spanish translation (thanks to [@Deses](https://github.com/Deses))
|
||||
|
||||
## 2.3.0 [0e30a26](https://github.com/sipeed/NanoKVM/commit/0e30a26db42cbc08416662b49a88a5d16ad93424) (2025-11-26)
|
||||
|
||||
### Features
|
||||
|
||||
* Added an EDID editor in the terminal with a built-in 1080P EDID template
|
||||
* Added German virtual keyboard and German clipboard support (thanks to [@Alexander-Ger-Reich](https://github.com/Alexander-Ger-Reich))
|
||||
* Resetting the HID also resets the USB hardware
|
||||
* Added support for deleting ISO images
|
||||
|
||||
### Refactoring & Improvements
|
||||
|
||||
* Video (H.264 WebRTC): Refactored the module to significantly reduce video latency
|
||||
* Video (H.264 Direct): Refactored to optimize data transmission and support data parsing even when the page is in the background
|
||||
* Video (MJPEG): Refactored and ensure correct data length transmission
|
||||
* Added locking before resetting USB to prevent HID deadlock (thanks to [@scpcom](https://github.com/scpcom))
|
||||
* Optimized HID writing logic
|
||||
* Made HDMI toggle state persist across reboots (thanks to [@tpretz](https://github.com/tpretz))
|
||||
* Enhanced the paste feature with browser clipboard API integration (thanks to [@patrickpilon](https://github.com/patrickpilon))
|
||||
* Set the inquiry string for the virtual storage device (thanks to [@scpcom](https://github.com/scpcom))
|
||||
* Hostname now updates `/etc/hosts` simultaneously and takes effect immediately (thanks to [@scpcom](https://github.com/scpcom))
|
||||
* Improved compatibility for static IP configuration on Windows
|
||||
* Optimized the web page title update logic
|
||||
* Added a confirmation dialog when uninstalling Tailscale
|
||||
* Improved UI for Clipboard, Image Mounting, and settings pages
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Tailscale: Fixed an issue where Tailscale would turn the device into a router
|
||||
* Tailscale: Fixed an issue where Tailscale would disable IPv6
|
||||
* Tailscale: Added a swap memory option to prevent Tailscale Out-Of-Memory errors
|
||||
* Tailscale: Fixed Tailscale accept-dns configuration (thanks to [@lazydba247](https://github.com/lazydba247))
|
||||
* Fixed an issue where certain modifier keys were not recognized
|
||||
* Fixed vertical mouse drift when the page is zoomed in or out
|
||||
|
||||
### Localization
|
||||
|
||||
* Update Korean translation (thanks to [@xenix4845](https://github.com/xenix4845))
|
||||
* Update Traditional Chinese translation (thanks to [@protonchang](https://github.com/protonchang))
|
||||
* Add Brazilian Portuguese translation (thanks to [@chiconws](https://github.com/chiconws) and [@Luccas-LF](https://github.com/Luccas-LF))
|
||||
* Add Swedish translation (thanks to [@acidflash](https://github.com/acidflash))
|
||||
* Add Catalan translation (thanks to [@Zagur](https://github.com/Zagur))
|
||||
* Add Turkish translation (thanks to [@Keylem](https://github.com/Keylem))
|
||||
|
||||
### Security
|
||||
|
||||
* Implemented a delay after failed login attempts to mitigate brute-force attacks
|
||||
* Upgraded dependencies to fix known security vulnerabilities
|
||||
|
||||
## 2.2.9 [c77981c](https://github.com/sipeed/NanoKVM/commit/c77981cc0ceebd8f6705b6c5d8c3cf4edf4f6717) (2025-06-13)
|
||||
|
||||
* fix(security): resolve parameter injection in serial port terminal
|
||||
|
||||
## 2.2.8 [01e28f1](https://github.com/sipeed/NanoKVM/commit/01e28f10ae8b581d484bb6077ddfe7bbe4e57919) (2025-05-22)
|
||||
|
||||
* feat: add AZERTY virtual keyboard Layout (thanks to [@felix068](https://github.com/felix068))
|
||||
* feat: add support for enabling/disabling HDMI output (PCIe version only) (thanks to [@tpretz](https://github.com/tpretz))
|
||||
* feat: add support for custom mouse wheel speed
|
||||
* fix: prevent direct H.264 stream buffer overflow and replay issues
|
||||
* perf: improve keyboard paste performance (thanks to [@ethanperrine](https://github.com/ethanperrine))
|
||||
* Localization
|
||||
* update Korean translation (thanks to [@kmw0410](https://github.com/kmw0410))
|
||||
* update Ukrainian translation (thanks to [@arbdevml](https://github.com/arbdevml))
|
||||
* update Russian translation (thanks to [@arbdevml](https://github.com/arbdevml))
|
||||
|
||||
## 2.2.7 [e18ec22](https://github.com/sipeed/NanoKVM/commit/e18ec2219d22886529575d1fdaad5c320e05f5b2) (2025-05-08)
|
||||
|
||||
* feat: add HTTPS support
|
||||
* feat: support direct H.264 streaming over HTTP
|
||||
* Localization
|
||||
* update Russian translation (thanks to [polyzium](https://github.com/polyzium))
|
||||
* update Dutch translation (thanks to [LeonStraathof](https://github.com/LeonStraathof))
|
||||
* update Ukrainian translation (thanks to [click0](https://github.com/click0))
|
||||
* update German translation (thanks to [3limin4tor](https://github.com/3limin4tor))
|
||||
|
||||
## 2.2.6 [c83dc55](https://github.com/sipeed/NanoKVM/commit/c83dc5565c9dbed22336661a8832edbd93a06d11) (2025-04-17)
|
||||
|
||||
* feat: add mouse jiggler to prevent system sleep
|
||||
* feat: add support for swap memory
|
||||
* feat: add support for customizing the device hostname
|
||||
* feat: add support for customizing the web page title
|
||||
* feat: add support for assigning custom names to Wake-on-LAN MAC addresses
|
||||
* feat: add confirmation prompts for power operations
|
||||
* feat: add logo to the login page (thanks to [S33G](https://github.com/S33G))
|
||||
* fix: fix possible privacy issues with MIC drivers. [Repair Record](https://github.com/sipeed/NanoKVM/commit/f9244b36df090a05cd59ba11ea4fd01e9b638995)
|
||||
* fix: fix iptables rule that could interfere with SSH connections (thanks to [scpcom](https://github.com/scpcom))
|
||||
* fix: fix the static IP gateway configuration might not apply correctly (thanks to [xitation](https://github.com/xitation))
|
||||
* perf: optimized OLED display handling and sleep logic
|
||||
* perf: improve H.264 streaming reliability by adding a heartbeat mechanism
|
||||
* perf: set the minimum screen size to 640x480
|
||||
* perf: add display of both wired and wireless IPv4 addresses in the settings page
|
||||
* perf: update the Thai language translations (thanks to [ChokunPlayZ](https://github.com/ChokunPlayZ))
|
||||
* chore: bump axios to 1.8.4
|
||||
* chore: bump golang.org/x/net to v0.39.0
|
||||
* chore: bump github.com/golang-jwt/jwt/v5 to to v5.2.2
|
||||
|
||||
## 2.2.5 [3286cc2](https://github.com/sipeed/NanoKVM/commit/3286cc2f85a14133d65935cb476c833dcf151459) (2025-03-26)
|
||||
|
||||
* fix: server crash caused by MJPEG frame detection error
|
||||
* feat: add HID-Only mode
|
||||
* feat: support preview updates
|
||||
* perf: improve image reading performance by optimizing screen parameters
|
||||
|
||||
## 2.2.4 [1bf986d](https://github.com/sipeed/NanoKVM/commit/1bf986d41b34d568c1ffee5df90ce61b6b08456b) (2025-03-21)
|
||||
|
||||
* fix: resolve USB initialization issue
|
||||
* fix: correct abnormal updates in certain models
|
||||
* perf: add version restrictions for production testing
|
||||
|
||||
## 2.2.3 [6ef83cb](https://github.com/sipeed/NanoKVM/commit/6ef83cb22fcd77f721d32c97c85d12f2bfc3035a) (2025-03-21)
|
||||
|
||||
* feat: add support for setting H.264 GOP
|
||||
* fix: resolve deadlock caused by HDMI resolution errors
|
||||
* perf: merge H.264 SPS and PPS into I-frame
|
||||
* perf: refactor MJPEG frame detection
|
||||
* perf: added more configuration options to the serial port terminal (thanks to [@mekaris](https://github.com/mekaris))
|
||||
* perf: improve the `update-nanokvm.py` script (thanks to [@reishoku](https://github.com/reishoku))
|
||||
* perf: disable mDNS by default in new products
|
||||
* perf: update log timestamp to millisecond precision
|
||||
* chore: bump Go to 1.23
|
||||
* chore: bump `golang.org/x/net` to v0.37.0
|
||||
|
||||
## 2.2.2 [58d5ab2](https://github.com/sipeed/NanoKVM/commit/58d5ab2d37244b1e1a68b925a5c23c324c489ad3) (2025-03-11)
|
||||
|
||||
* feat: add watchdog for NanoKVM-Server
|
||||
* feat: add support for UE chip
|
||||
* feat: support system reboot
|
||||
* feat: support enable/disable mDNS
|
||||
* fix: resolve UE chip cannot start server
|
||||
* perf: refactor automatic resolution detection
|
||||
* perf: add output prompt for unsupported resolutions
|
||||
* perf: add lock to kvmv_read_img
|
||||
* perf: configurable VENC automatic recycling feature
|
||||
* perf: add maximum limit for vi
|
||||
* perf: add tooltips to menu bar (thanks to [@S33G](https://github.com/S33G))
|
||||
* perf: menu bar is now draggable (thanks to [@forumi0721](https://github.com/forumi0721))
|
||||
* perf: image list support auto-refresh (thanks to [@forumi0721](https://github.com/forumi0721))
|
||||
* perf: update translations
|
||||
|
||||
## 2.2.1 [b5e48a0](https://github.com/sipeed/NanoKVM/commit/b5e48a07e82df3aedd60442342ae50b95684a697) (2025-02-21)
|
||||
|
||||
* fix: mounted image were not being detected correctly
|
||||
* perf: add support for CD-ROM mode when mounting image (thanks to [@scpcom](https://github.com/scpcom))
|
||||
* perf: add a loading state during login
|
||||
* perf: add changelog link in settings
|
||||
* perf: update translation and cleanup the code (thanks to [@ChokunPlayZ](https://github.com/ChokunPlayZ) [@Stoufiler](https://github.com/Stoufiler) [@polyzium](https://github.com/polyzium) [@Jonher937](https://github.com/Jonher937) [@S33G](https://github.com/S33G))
|
||||
|
||||
## 2.2.0 [0dbf8c0](https://github.com/sipeed/NanoKVM/commit/0dbf8c007f2d0183d0f0601c3da6d3c3fccd8b31) (2025-02-17)
|
||||
|
||||
NanoKVM [Image v1.4.0](https://github.com/sipeed/NanoKVM/releases/tag/v1.4.0) has been released!
|
||||
|
||||
> Please refer to the [wiki](https://wiki.sipeed.com/hardware/en/kvm/NanoKVM/system/introduction.html) for more details about the image and application.
|
||||
|
||||
* fix: improve password update notification logic (thanks to [@li20034](https://github.com/li20034))
|
||||
* perf: increase update wait time to 10s (from 6s)
|
||||
* perf: update Korean translation (thanks to [@forumi0721](https://github.com/forumi0721))
|
||||
* perf: update Traditional Chinese translation (thanks to [@protonchang](https://github.com/protonchang))
|
||||
* refactor: update `libkvm.so` and `libkvm_mmf.so` libraries
|
||||
|
||||
## 2.1.6 [6eb4a4e](https://github.com/sipeed/NanoKVM/commit/6eb4a4ea6254f465a47f9881d13934c686649061) (2025-02-14)
|
||||
|
||||
* feat: support downloading image from online URL (thanks to [@Itxaka](https://github.com/Itxaka))
|
||||
* feat: add keyboard shortcut `Ctrl+Alt+Del` (thanks to [@CaffeeLake](https://github.com/CaffeeLake))
|
||||
* fix: fix the CSRF issue
|
||||
* perf: add an option to configure custom ICE servers (thanks to [@VMFortress](https://github.com/VMFortress))
|
||||
* perf: removed unnecessary modifications to DNS configuration
|
||||
* perf: add an SSH enable/disable toggle in the web UI
|
||||
* perf: add a Tailscale enable/disable toggle in the web UI
|
||||
* perf: download Tailscale installation package from the official source
|
||||
* perf: automatic enable/disable GOMEMLIMIT on tailscale start/stop
|
||||
* perf: add JWT configuration
|
||||
* secretKey: customize secret key. If empty, generated a random 64-byte secret key by default
|
||||
* refreshTokenDuration: customize token expiration time
|
||||
* revokeTokensOnLogout: invalidate all JWT tokens on logout
|
||||
* perf: implement secure password storage using bcrypt hashing
|
||||
* perf: implement integrity checks for online updates
|
||||
* refactor: refactor HDMI module and remove the dependency `libmaixcam_lib.so`
|
||||
* refactor: web terminal use pty instead of SSH
|
||||
* refactor: move Tailscale APIs from the `network` module to the `extensions` module
|
||||
|
||||
## 2.1.5 [85f6447](https://github.com/sipeed/NanoKVM/commit/85f6447a16cc2591c6459b7d3dfda4d4cb75e98c) (2025-01-14)
|
||||
|
||||
* feat: add HDMI reset for NanoKVM-PCIe
|
||||
* fix: remove unnecessary lock acquisition during HID reset
|
||||
* refactor: refactor Tailscale
|
||||
|
||||
## 2.1.4 [d7ca7c4](https://github.com/sipeed/NanoKVM/commit/d7ca7c453d821ad099bf79b463969419041279cb) (2025-01-10)
|
||||
|
||||
* feat: support configuring OLED sleep settings
|
||||
* feat: support setting the `GOMEMLIMIT` environment variable
|
||||
* fix: fix Wi-Fi configuration
|
||||
* perf: password changes now update both the web user and the system root user
|
||||
* perf: add MAC address verification for Wake-on-LAN
|
||||
* refactor: a lot update to web UI
|
||||
* refactor: refactor Tailscale
|
||||
|
||||
## 2.1.3 [26078fe](https://github.com/sipeed/NanoKVM/commit/26078fe46e43d4543d7b09901b4992e4fbe4f01f) (2024-12-27)
|
||||
|
||||
* feat: add API to retrieve Wi-Fi information
|
||||
* fix: fix keyboard modifier keys
|
||||
* fix: update keyboard and mouse HID codes
|
||||
* fix: update hardware version information
|
||||
|
||||
## 2.1.2 [5a39562](https://github.com/sipeed/NanoKVM/commit/5a39562f2d32695933f4e7e86866136236cc9903) (2024-12-04)
|
||||
|
||||
* feat: add hardware version to configuration
|
||||
* feat: add Wi-Fi configuration support for NanoKVM-PCIe
|
||||
* perf: update web UI
|
||||
* chore: add dependency libraries
|
||||
|
||||
## 2.1.1 [74a303b](https://github.com/sipeed/NanoKVM/commit/74a303bd5cbb58f9d8ddd81abaaf4919dbbfb71b) (2024-11-06)
|
||||
|
||||
* feat: support h264
|
||||
674
LICENSE
Normal file
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
152
Makefile
Normal file
152
Makefile
Normal file
@@ -0,0 +1,152 @@
|
||||
# Makefile for NanoKVM Project
|
||||
|
||||
# Configuration
|
||||
UID := $(shell id -u)
|
||||
GID := $(shell id -g)
|
||||
# ?= so a prebuilt image can be used instead, e.g. a GHCR-cached builder in CI.
|
||||
IMAGE_NAME ?= nanokvm-builder-local-$(UID)-$(GID)
|
||||
PWD := $(shell pwd)
|
||||
VERSION ?=
|
||||
|
||||
# Docker run common parameters. Allocating a TTY breaks in environments without
|
||||
# one, so it can be overridden with DOCKER_TTY=
|
||||
DOCKER_TTY ?= -it
|
||||
DOCKER_RUN_BASE := docker run -e UID=$(UID) -e GID=$(GID) -v $(PWD):/home/build/NanoKVM --rm
|
||||
|
||||
# Build the image with the host user's identity so entrypoint does not need
|
||||
# to recursively rewrite the MaixCDK home directory at container startup.
|
||||
DOCKER_BUILD_ARGS := --build-arg DOCKER_UID=$(UID) --build-arg DOCKER_GID=$(GID)
|
||||
|
||||
# Build commands
|
||||
GO_BUILD_CMD := cd /home/build/NanoKVM/server && go mod tidy && CGO_ENABLED=1 GOOS=linux GOARCH=riscv64 CC=riscv64-unknown-linux-musl-gcc CGO_CFLAGS="-mcpu=c906fdv -march=rv64imafdcv0p7xthead -mcmodel=medany -mabi=lp64d" go build
|
||||
SUPPORT_BUILD_CMD := . ./home/build/MaixCDK/bin/activate && cd /home/build/NanoKVM/support/sg2002 && ./build kvm_system && ./build kvm_system add_to_kvmapp
|
||||
VISION_BUILD_CMD := . ./home/build/MaixCDK/bin/activate && cd /home/build/NanoKVM/support/sg2002 && ./build kvm_vision && ./build kvm_vision add_to_kvmapp
|
||||
RELEASE_BUILD_CMD := /home/build/NanoKVM/scripts/build-in-container.sh
|
||||
|
||||
.PHONY: help check-root builder-image rebuild-image check-image shell app support vision \
|
||||
web release-build package release all clean
|
||||
|
||||
# Default target
|
||||
all: app support
|
||||
|
||||
# Help target
|
||||
help:
|
||||
@echo "NanoKVM Build System"
|
||||
@echo ""
|
||||
@echo "Available targets:"
|
||||
@echo " help - Show this help message"
|
||||
@echo " check-image - Check builder Docker image and show versions"
|
||||
@echo " builder-image - Build Docker image if not exists"
|
||||
@echo " rebuild-image - Force rebuild Docker image"
|
||||
@echo " shell - Enter interactive builder environment"
|
||||
@echo " app - Build Go application server"
|
||||
@echo " support - Build kvm_system daemon"
|
||||
@echo " vision - Build video libraries (libkvm.so)"
|
||||
@echo " web - Build the frontend into web/dist"
|
||||
@echo " all - Build both app and support (default)"
|
||||
@echo " release-build - Build every riscv64 release artifact in one pass"
|
||||
@echo " package - Assemble nanokvm_<VERSION>.tar.gz + latest.json"
|
||||
@echo " release - release-build + web + package (needs VERSION=x.y.z)"
|
||||
@echo " clean - Clean build artifacts"
|
||||
@echo ""
|
||||
@echo "Prerequisites:"
|
||||
@echo " - Docker must be installed and running"
|
||||
@echo " - Must not run as root user"
|
||||
|
||||
# Security check - prevent running as root
|
||||
check-root:
|
||||
@if [ "$$(id -u)" -eq 0 ]; then \
|
||||
echo "Can't run as root"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
# Check if builder image exists and show versions
|
||||
check-image: check-root
|
||||
@echo "Checking builder image..."
|
||||
@echo "Golang version: " && \
|
||||
docker run --rm -i $(IMAGE_NAME) go version && \
|
||||
echo "" && \
|
||||
echo "Host-tools version:" && \
|
||||
docker run --rm -i $(IMAGE_NAME) riscv64-unknown-linux-musl-gcc -v && \
|
||||
echo ""
|
||||
|
||||
# Build Docker image if it doesn't exist
|
||||
builder-image: check-root
|
||||
@if ! docker image inspect $(IMAGE_NAME) >/dev/null 2>&1; then \
|
||||
echo "Building Docker image..."; \
|
||||
docker build $(DOCKER_BUILD_ARGS) -t $(IMAGE_NAME) -f docker/Dockerfile ./; \
|
||||
else \
|
||||
echo "Docker image $(IMAGE_NAME) already exists."; \
|
||||
fi
|
||||
|
||||
# Force rebuild Docker image
|
||||
rebuild-image: check-root
|
||||
@echo "Force rebuilding Docker image..."
|
||||
@docker build --no-cache $(DOCKER_BUILD_ARGS) -t $(IMAGE_NAME) -f docker/Dockerfile ./
|
||||
|
||||
# Enter interactive shell (equivalent to build.sh with no arguments)
|
||||
shell: check-root builder-image
|
||||
@echo "Switching into builder..."
|
||||
@$(DOCKER_RUN_BASE) -it $(IMAGE_NAME) /bin/bash -c ". ./home/build/MaixCDK/bin/activate && cd /home/build/NanoKVM ; exec bash"
|
||||
|
||||
# Build Go application
|
||||
app: check-root builder-image
|
||||
@echo "Building app..."
|
||||
@$(DOCKER_RUN_BASE) $(DOCKER_TTY) $(IMAGE_NAME) /bin/bash -c '$(GO_BUILD_CMD)'
|
||||
|
||||
# Build hardware support libraries
|
||||
support: check-root builder-image
|
||||
@echo "Building support..."
|
||||
@$(DOCKER_RUN_BASE) $(DOCKER_TTY) $(IMAGE_NAME) /bin/bash -c '$(SUPPORT_BUILD_CMD)'
|
||||
|
||||
# Build video libraries (libkvm.so) into kvmapp/server/dl_lib
|
||||
vision: check-root builder-image
|
||||
@echo "Building vision..."
|
||||
@$(DOCKER_RUN_BASE) $(DOCKER_TTY) $(IMAGE_NAME) /bin/bash -c '$(VISION_BUILD_CMD)'
|
||||
|
||||
# Build every riscv64 release artifact in one container pass
|
||||
release-build: check-root builder-image
|
||||
@echo "Building release artifacts..."
|
||||
@$(DOCKER_RUN_BASE) $(DOCKER_TTY) $(IMAGE_NAME) /bin/bash -c '$(RELEASE_BUILD_CMD)'
|
||||
|
||||
# Build the frontend (runs on the host; the builder image has no Node)
|
||||
web:
|
||||
@echo "Building web..."
|
||||
@cd web && pnpm install --frozen-lockfile && pnpm build
|
||||
|
||||
# Assemble the release package and its manifest
|
||||
package:
|
||||
@if [ -z "$(VERSION)" ]; then \
|
||||
echo "VERSION is required, e.g. make package VERSION=2.4.4"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@scripts/package.sh "$(VERSION)"
|
||||
|
||||
# Full local release: riscv64 artifacts + frontend + package.
|
||||
# Invoked as sub-makes rather than prerequisites: packaging asserts on what the
|
||||
# earlier steps produce, so the order matters even under make -j.
|
||||
release:
|
||||
@$(MAKE) release-build
|
||||
@$(MAKE) web
|
||||
@$(MAKE) package VERSION="$(VERSION)"
|
||||
|
||||
# Clean build artifacts
|
||||
clean:
|
||||
@echo "Cleaning build artifacts..."
|
||||
@if [ -f server/NanoKVM-Server ]; then \
|
||||
rm -f server/NanoKVM-Server; \
|
||||
echo "Removed server/NanoKVM-Server"; \
|
||||
fi
|
||||
@if [ -d support/sg2002/build ]; then \
|
||||
rm -rf support/sg2002/build; \
|
||||
echo "Removed support/sg2002/build"; \
|
||||
fi
|
||||
@if [ -d build/release ]; then \
|
||||
rm -rf build/release; \
|
||||
echo "Removed build/release"; \
|
||||
fi
|
||||
@if [ -d web/dist ]; then \
|
||||
rm -rf web/dist; \
|
||||
echo "Removed web/dist"; \
|
||||
fi
|
||||
@echo "Clean completed."
|
||||
191
README.md
191
README.md
@@ -1,73 +1,160 @@
|
||||
NanoKVM
|
||||
======
|
||||
# NanoKVM
|
||||
|
||||
<div align="center">
|
||||
|
||||

|
||||
|
||||
<h3>
|
||||
<a href="https://wiki.sipeed.com/hardware/zh/lichee/RV_Nano/1_intro.html"> Quick Start </a> |
|
||||
<a href="https://cn.dl.sipeed.com/shareURL/KVM/nanoKVM"> Hardware </a>
|
||||
</h3>
|
||||
|
||||
English | [中文](./README_ZH.md)
|
||||
|
||||
<br>
|
||||
<img src="https://wiki.sipeed.com/hardware/assets/NanoKVM/introduce/NanoKVM_3.png" alt="NanoKVM" style="margin: 20px 0;">
|
||||
<h3>
|
||||
<a href="https://wiki.sipeed.com/hardware/en/kvm/NanoKVM/introduction.html">🚀 Quick Start</a>
|
||||
|
|
||||
<a href="https://cn.dl.sipeed.com/shareURL/KVM/nanoKVM">🛠️ Hardware Details</a>
|
||||
|
|
||||
<a href="https://github.com/sipeed/NanoKVM/releases/latest">💾 Firmware Releases</a>
|
||||
</h3>
|
||||
<br>
|
||||
</div>
|
||||
|
||||
> Your NanoKVM Power by RISC-V !
|
||||
> If you have any issues or suggestions, creating issue here, or tell us with [MaixHub Discussion](https://maixhub.com/discussion/nanokvm).
|
||||
## 🌟 What is NanoKVM?
|
||||
|
||||
NanoKVM is a series of compact, open-source IP-KVM devices based on the LicheeRV Nano (RISC-V). It lets you remotely access and control computers as if you were sitting in front of them, making it useful for servers, embedded systems, and other headless machines.
|
||||
|
||||
## Introduction
|
||||
## 📦 Product Family
|
||||
|
||||
Lichee NanoKVM is an IP-KVM product based on LicheeRV Nano, inheriting the extreme size and powerful features of LicheeRV Nano.
|
||||
The Lichee NanoKVM is available in two versions:
|
||||
NanoKVM Lite is a basic configuration that is suitable for individual users with certain DIY capabilities and enterprise users with bulk requirements.
|
||||
The NanoKVM Full is a full version with a sophisticated case and complete accessories, as well as a built-in system mirror card that is ready to use at boot, and is recommended for individual users.
|
||||
Choose the NanoKVM model that best fits your deployment:
|
||||
|
||||

|
||||
- **NanoKVM-Cube Lite:** A barebones kit for DIY users and bulk deployments.
|
||||
- **NanoKVM-Cube Full:** A ready-to-use kit with a case, accessories, and a pre-flashed system SD card.
|
||||
- **NanoKVM-PCIe:** A PCIe-bracket form factor for internal chassis mounting. It draws power from the PCIe slot and supports optional Wi-Fi and PoE.
|
||||
- **[NanoKVM-Pro](https://github.com/sipeed/NanoKVM-Pro):** A higher-performance version with major upgrades:
|
||||
- **Resolution:** Up to **4K@30fps / 2K@60fps**.
|
||||
- **Network:** **1Gbps Ethernet + PoE + Wi-Fi 6**, upgraded from 100Mbps Ethernet.
|
||||
- **Latency:** Hardware-accelerated encoding reduces latency from 100-150ms to **50-100ms**.
|
||||
|
||||
## Tech Specs
|
||||
<div align="center">
|
||||
<img src="https://cdn.sipeed.com/public/nanokvm-products-v2.jpg" alt="NanoKVM Product Family" width="100%" style="margin: 20px 0;">
|
||||
</div>
|
||||
|
||||
| Products | NanoKVM (Lite) | NanoKVM (Full) | PiKVM V4 |
|
||||
| --- | --- | --- | --- |
|
||||
| Compute Units | LicheeRV Nano(RISCV) | LicheeRV Nano(RISCV) | CM4 (ARM) |
|
||||
| Resolution | 1080P @ 60fps | 1080P @ 60fps | 1080P @ 60fps |
|
||||
| Video encoding | MJPEG, H264(developing) | MJPEG, H264(developing) | MJPEG, H264 |
|
||||
| Video delay | 90~230ms | 90~230ms | 100~230ms |
|
||||
| UEFI/BIOS | ✓ | ✓ | ✓ |
|
||||
| Keyboard and Mouse<br>Virtual HID | ✓ | ✓ | ✓ |
|
||||
| USB storage <br> Virtual CD-ROM | ✓ | ✓ | ✓ |
|
||||
| IPMI | ✓ | ✓ | ✓ |
|
||||
| Wake-on-LAN | ✓ | ✓ | ✓ |
|
||||
| ATX power control | None,Users can connect by their own | USB interface IO control board | RJ-45 interface IO control board |
|
||||
| OLED | None,Users can connect by their own | 128x64 0.96" white | 128x32 0.91" white |
|
||||
| UART | 2 | 2 | 1 |
|
||||
| TF Card | None | ✓ | ✓ |
|
||||
| Expansion | None | WiFi or PoE | WiFi/LTE |
|
||||
| Power consumption | 0.2A@5V | 0.2A@5V | Peak 2.6A@5V |
|
||||
| Power input | PC USB can be powered | PC USB or auxiliary power supply | DC 5V 3A power supply is required |
|
||||
| Cooling | Silent fanless | Silent fanless | Fan cooling |
|
||||
| Size | 23x37x15mm <br> ~1/30 PiKVM V4 size | 40x36x36mm <br/> ~1/7 PiKVM V4 size | 120x68x44mm |
|
||||
> If you are looking for a USB-based KVM solution, check out [NanoKVM-USB](https://github.com/sipeed/NanoKVM-USB).
|
||||
|
||||

|
||||
## 🛠️ Technical Specifications
|
||||
|
||||
## Hardware platform NanoKVM
|
||||
| Feature | NanoKVM-Pro | NanoKVM (Cube/PCIe) | GxxKVM | JxxKVM |
|
||||
| ------------------ | ------------------------------------- | --------------------------------- | ---------------------------------- | ----------------------------------- |
|
||||
| Core | AX630C 2xA53 1.2G | SG2002 1xC906 1.0G | RV1126 4xA7 1.5G | RV1106 1xA7 1.2G |
|
||||
| Memory & Storage | 1G LPDDR4X + 32G eMMC | 256M DDR3 + 32G microSD | 1G DDR3 + 8G eMMC | 256M DDR3 + 16G eMMC |
|
||||
| System | NanoKVM / PiKVM | NanoKVM | GxxKVM | JxxKVM |
|
||||
| Resolution | 4K@30fps / 2K@60fps | 1080P@60fps | 4K@30fps / 2K@60fps | 1080P@60fps |
|
||||
| HDMI Loopout | 4K loopout | — | — | — |
|
||||
| Video Encoding | MJPEG / H.264 / H.265 | MJPEG / H.264 | MJPEG / H.264 | MJPEG / H.264 |
|
||||
| Audio Transmit | ✓ | — | ✓ | — |
|
||||
| UEFI / BIOS | ✓ | ✓ | ✓ | ✓ |
|
||||
| Emulated USB Keyboard & Mouse | ✓ | ✓ | ✓ | ✓ |
|
||||
| Emulated USB ISO | ✓ | ✓ | ✓ | ✓ |
|
||||
| IPMI | ✓ | ✓ | ✓ | — |
|
||||
| Wake-on-LAN | ✓ | ✓ | ✓ | ✓ |
|
||||
| Web Terminal | ✓ | ✓ | ✓ | ✓ |
|
||||
| Serial Terminal | 2 channels | 2 channels | — | 1 channel |
|
||||
| Custom Scripts | ✓ | ✓ | — | — |
|
||||
| Storage | 32G eMMC 300MB/s | 32G MicroSD 12MB/s | 8G eMMC 120MB/s | 8G eMMC 60MB/s |
|
||||
| Ethernet | 1000M | 100M | 1000M | 100M |
|
||||
| PoE | Optional | Optional | — | — |
|
||||
| Wi-Fi | Optional Wi-Fi 6 | Optional Wi-Fi 6 | — | — |
|
||||
| ATX Power Control | ✓ | ✓ | Extra $15 | Extra $10 |
|
||||
| Display | 1.47" 320x172 LCD / 0.96" 128x64 OLED | 0.96" 128x64 OLED | — | 1.68" 280x240 |
|
||||
| More Features | Sync LED Strip / Smart Assistant | — | — | — |
|
||||
| Power Consumption | 0.6A@5V | 0.2A@5V | 0.4A@5V | 0.2A@5V |
|
||||
| Power Input | USB-C or PoE | USB-C | USB-C | USB-C |
|
||||
| Dimensions | 65x65x26mm | 40x36x36mm | 80x60x17.5mm | 60x43x(24~31)mm |
|
||||
|
||||
NanoKVM is based on Sipeed [LicheeRV Nano](https://wiki.sipeed.com/hardware/zh/lichee/RV_Nano/1_intro.html),you can find specifications, schematics, and dimensional drawings [here](http://cn.dl.sipeed.com/shareURL/LICHEE/LicheeRV_Nano).
|
||||
## 📂 Project Structure
|
||||
|
||||
The NanoKVM Lite is constructed by the LicheeRV Nano and HDMItoCSI board, and the NanoKVM FULL adds the NanoKVM-A/B board and shell to the NanoKVM Lite. The HDMItoCSI board is used to convert the HDMI signal; NanoKVM-A, including OLED, ATX control output (USB Type-C interface), auxiliary power supply and ATX power on/off and reset buttons; The NanoKVM-B is connected to the plate at one end and the computer at the other end is connected to the computer ATX-Pin, which is used to remotely control the power of the computer.
|
||||
```text
|
||||
├── kvmapp # APP update package
|
||||
│ ├── jpg_stream # Legacy support for direct updates from older versions
|
||||
│ ├── kvm_new_app # Triggers components for kvm_system updates
|
||||
│ ├── kvm_system # Core KVM application
|
||||
│ ├── server # Front-end and back-end integration
|
||||
│ └── system # Essential system components
|
||||
├── web # NanoKVM Front-end (UI)
|
||||
├── server # NanoKVM Back-end (Service)
|
||||
├── support # Auxiliary modules (Image subsystem, status, updates, OLED, HID, etc.)
|
||||
├── ...
|
||||
```
|
||||
|
||||
The NanoKVM image is built on LicheeRV Nano SDK and MaixCDK, and is compatible with materials that use the LicheeRV Nano, opposite the KVM software cannot be used with the LicheeRV Nano or other SG2002 products. If you would like to build an HDMI input application on LicheeRV Nano or MaixCam, please contact us for technical support.
|
||||
## 💻 Development
|
||||
|
||||
+ [HDMItoCSI Schematic](https://cn.dl.sipeed.com/fileList/KVM/nanoKVM/HDK/02_Schematic/SCH_RV_Nano_KVM_B_30131.pdf)
|
||||
+ [NanoKVM-A Schematic](https://cn.dl.sipeed.com/fileList/KVM/nanoKVM/HDK/02_Schematic/SCH_RV_Nano_KVM_A_30111.pdf)
|
||||
+ [NanoKVM-B Schematic](https://cn.dl.sipeed.com/fileList/KVM/nanoKVM/HDK/02_Schematic/SCH_HDMI_MIPI_31011.pdf)
|
||||
Start with the guide that matches the part of NanoKVM you want to work on:
|
||||
|
||||
## Community
|
||||
- **System support modules:** Build and update the low-level hardware support components in [support/sg2002/README.md](support/sg2002/README.md).
|
||||
- **Backend service:** Set up, build, and understand the Go service in [server/README.md](server/README.md).
|
||||
- **Frontend UI:** Develop, lint, and build the React interface in [web/README.md](web/README.md).
|
||||
- **Release packaging:** Assemble the `nanokvm_<version>.tar.gz` update package in [scripts/README.md](scripts/README.md).
|
||||
|
||||
* [MaixHub Discussion](https://maixhub.com/discussion/nanokvm)
|
||||
* QQ group: 703230713
|
||||
> Backend compilation and runtime validation require the target toolchain or a NanoKVM device. See the module-specific guides above for the latest development workflow.
|
||||
|
||||
### Dev container (optional)
|
||||
|
||||
The repository ships a [Dev Container](https://containers.dev) setup (`.devcontainer/`) that layers the frontend toolchain (Node 22, pnpm 11) on top of the release builder image (RISC-V cross toolchain, Go, MaixCDK), so one container covers Go, C support-layer and web development. It is a convenience for IDE users; the `make` targets in the repository root remain the canonical CLI workflow.
|
||||
|
||||
- Requirements: Docker plus an editor or CLI with dev container support (e.g. the VS Code "Dev Containers" extension, or `devcontainer up`).
|
||||
- On creation the container prepares itself automatically: `support/sg2002/build update_lib` (resyncs MaixCDK components with the checkout) and `pnpm install` for the frontend.
|
||||
- Backend: run `server/build.sh` for a release-equivalent binary (BoringCrypto + `dl_lib` RPATH). `make app` builds a plain development binary without those, so prefer `server/build.sh` whenever the result should match a release.
|
||||
- Support layer: `cd support/sg2002 && ./build kvm_system` (the MaixCDK virtualenv is part of the container environment).
|
||||
- Frontend: `cd web && pnpm dev` (VS Code forwards port 3001 automatically; other clients may need to map it themselves); see [web/README.md](web/README.md) for pointing it at a device.
|
||||
- The base image `ghcr.io/sipeed/nanokvm-builder:latest` is x86-64 only; on Apple Silicon it runs under emulation (works, but C builds are slow). You can also build the image locally first (`make builder-image`) and point the `BASE_IMAGE` build arg at it (e.g. via `build.args` in `devcontainer.json`). On Linux hosts the first container creation also takes a while: the container user is remapped to your uid, which re-chowns its home directory once.
|
||||
- Hardware-dependent verification still requires a real NanoKVM device; the container covers compiling, linting and mock-mode web development only.
|
||||
|
||||
## 🔩 Hardware Platform (NanoKVM Cube/PCIe)
|
||||
|
||||
NanoKVM is based on Sipeed [LicheeRV Nano](https://wiki.sipeed.com/hardware/zh/lichee/RV_Nano/1_intro.html). You can find specifications, schematics, and dimensional drawings in the [download station](https://dl.sipeed.com/shareURL/LICHEE/LicheeRV_Nano).
|
||||
|
||||
The NanoKVM Cube/PCIe hardware is built from these components:
|
||||
|
||||
- **NanoKVM Lite:** LicheeRV Nano plus the HDMI-to-CSI board.
|
||||
- **NanoKVM Full:** NanoKVM Lite plus the NanoKVM-A/B boards and enclosure.
|
||||
- **HDMI-to-CSI board:** Converts the HDMI input signal.
|
||||
- **NanoKVM-A board:** Provides OLED, ATX control output through USB-C, auxiliary power, and physical ATX power/reset buttons.
|
||||
- **NanoKVM-B board:** Connects NanoKVM-A to the host computer's ATX pins for remote power control.
|
||||
|
||||
The NanoKVM image is built with the LicheeRV Nano SDK and MaixCDK. It is intended for NanoKVM hardware and is not a general-purpose KVM software package for other LicheeRV Nano or SG2002 products. If you want to build an HDMI input application on LicheeRV Nano or MaixCam, please contact us for technical support.
|
||||
|
||||
> Note: Of the 256MB memory on SG2002, 158MB is currently allocated to the multimedia subsystem for video capture and processing.
|
||||
|
||||
- [NanoKVM-A Schematic](https://cn.dl.sipeed.com/fileList/KVM/nanoKVM/HDK/02_Schematic/SCH_RV_Nano_KVM_A_30111.pdf)
|
||||
- [NanoKVM-B Schematic](https://cn.dl.sipeed.com/fileList/KVM/nanoKVM/HDK/02_Schematic/SCH_RV_Nano_KVM_B_30131.pdf)
|
||||
- [NanoKVM-PCIe Schematic](https://cn.dl.sipeed.com/fileList/KVM/KVM_PCIE/HDK/01_Schematic/SCH_nanoKVM_PCIE_3105D_2025-12-19.pdf)
|
||||
- [NanoKVM image](https://github.com/sipeed/NanoKVM/releases/tag/NanoKVM)
|
||||
|
||||
<div align="center">
|
||||
<img src="https://wiki.sipeed.com/hardware/zh/kvm/assets/NanoKVM/1_intro/NanoKVM_2.jpg" alt="NanoKVM PCB Pinout" width="80%" style="margin: 20px 0;">
|
||||
</div>
|
||||
|
||||
## 🤝 Contributing
|
||||
|
||||
We welcome contributions. To get started:
|
||||
|
||||
1. Fork the repository.
|
||||
2. Create a feature branch.
|
||||
3. Commit your changes.
|
||||
4. Push to the branch.
|
||||
5. Open a Pull Request.
|
||||
|
||||
Please keep your pull requests small and focused to facilitate easier review and merging.
|
||||
|
||||
> 🎁 **Contributors who submit high-quality Pull Requests may receive a NanoKVM Cube, PCIe, or Pro as a token of our appreciation!**
|
||||
|
||||
## 🛒 Where to Buy
|
||||
|
||||
- [AliExpress (global, except USA and Russia)](https://www.aliexpress.com/item/1005007369816019.html)
|
||||
- [Taobao](https://item.taobao.com/item.htm?id=811206560480)
|
||||
- [Preorder for other regions](https://sipeed.com/nanokvm)
|
||||
|
||||
## 💬 Community & Support
|
||||
|
||||
- [Discord](https://discord.gg/V4sAZ9XWpN)
|
||||
- QQ group: 703230713
|
||||
- Email: [support@sipeed.com](mailto:support@sipeed.com)
|
||||
- [FAQ](https://wiki.sipeed.com/hardware/en/kvm/NanoKVM/faq.html)
|
||||
|
||||
## 📜 License
|
||||
|
||||
This project is licensed under the GPL-3.0 License. See [LICENSE](LICENSE) for details.
|
||||
|
||||
73
README_ZH.md
73
README_ZH.md
@@ -1,73 +0,0 @@
|
||||
NanoKVM
|
||||
======
|
||||
|
||||
<div align="center">
|
||||
|
||||

|
||||
|
||||
<h3>
|
||||
<a href="https://wiki.sipeed.com/hardware/zh/lichee/RV_Nano/1_intro.html"> 快速开始 </a> |
|
||||
<a href="https://cn.dl.sipeed.com/shareURL/KVM/nanoKVM"> 硬件资料 </a>
|
||||
</h3>
|
||||
|
||||
[English](./README.md) | 中文
|
||||
|
||||
</div>
|
||||
|
||||
> Your NanoKVM Power by RISC-V !
|
||||
> 如果您在使用过程中有任何问题或建议,请在这里提交 issue, 或在 [MaixHub Discussion](https://maixhub.com/discussion/nanokvm)告诉我们.
|
||||
|
||||
|
||||
## 简介
|
||||
|
||||
Lichee NanoKVM 是基于 LicheeRV Nano 的 IP-KVM 产品,继承了 LicheeRV Nano的极致体积 和 强大功能。
|
||||
Lichee NanoKVM分为两个版本:
|
||||
NanoKVM Lite 为基础版配置,适合 具有一定DIY能力的个人用户 和 有批量需求的企业用户。
|
||||
NanoKVM Full 为完整版配置,带精致外壳和完整配件,内置开机即用的系统镜像卡,推荐个人用户购买。
|
||||
|
||||

|
||||
|
||||
## 参数
|
||||
|
||||
| 产品 | NanoKVM (Lite) | NanoKVM (Full) | PiKVM V4 |
|
||||
| --- | --- | --- | --- |
|
||||
| 计算单元 | LicheeRV Nano(RISCV) | LicheeRV Nano(RISCV) | CM4 (ARM) |
|
||||
| 分辨率 | 1080P @ 60fps | 1080P @ 60fps | 1080P @ 60fps |
|
||||
| 视频编码 | MJPEG, H264(developing) | MJPEG, H264(developing) | MJPEG, H264 |
|
||||
| 视频延迟 | 90~230ms | 90~230ms | 100~230ms |
|
||||
| UEFI/BIOS | ✓ | ✓ | ✓ |
|
||||
| 模拟USB键鼠 <br>Virtual HID | ✓ | ✓ | ✓ |
|
||||
| 模拟USB存储 <br> Virtual CD-ROM | ✓ | ✓ | ✓ |
|
||||
| IPMI | ✓ | ✓ | ✓ |
|
||||
| Wake-on-LAN | ✓ | ✓ | ✓ |
|
||||
| ATX电源控制 | 无,用户可自行连接 | USB接口IO控制板 | RJ45接口IO控制板 |
|
||||
| OLED显示 | 无,用户可自行扩展 | 128x64 0.96" white | 128x32 0.91" white |
|
||||
| 外接串口 | 2路 | 2路 | 1路 |
|
||||
| TF卡 | 无,用户自备 | 有,开机即用 | 有 |
|
||||
| 扩展配件 | 无 | WiFi 或 PoE | WiFi/LTE |
|
||||
| 功耗 | 0.2A@5V | 0.2A@5V | Peak 2.6A@5V |
|
||||
| 电源输入 | PC USB即可供电 | PC USB即可供电 <br> 也支持额外辅助供电 | 需要DC 5V 3A供电 |
|
||||
| 散热 | 静音无风扇 | 静音无风扇 | 需要风扇主动散热 |
|
||||
| 尺寸 | 23x37x15mm <br> ~1/30 PiKVM V4 体积 | 40x36x36mm <br/> ~1/7 PiKVM V4 体积 | 120x68x44mm |
|
||||
|
||||

|
||||
|
||||
## NanoKVM 硬件平台
|
||||
|
||||
NanoKVM 基于 Sipeed [LicheeRV Nano](https://wiki.sipeed.com/hardware/zh/lichee/RV_Nano/1_intro.html) 核心板搭建,这部分硬件的规格书、原理图、尺寸图等均可在这里找到:[点击这里](http://cn.dl.sipeed.com/shareURL/LICHEE/LicheeRV_Nano)
|
||||
|
||||
NanoKVM Lite 由 LicheeRV Nano E 和 HDMItoCSI 小板构成,NanoKVM FULL 在 NanoKVM Lite 基础上增加 NanoKVM-A/B 板和外壳。HDMItoCSI板用于转换HDMI信号;NanoKVM-A 包含 OLED、ATX控制输出(TypeC接口形式)、辅助供电(TypeC接口)以及ATX开关机、复位按键;NanoKVM-B 一端连接A板,一端连接电脑ATX针脚,用于电脑的远程开关机。
|
||||
|
||||
NanoKVM 镜像在LicheeRV Nano SDK 和 MaixCDK 基础上构建,可以兼容使用 LicheeRV Nano 的资料,反之LicheeRV Nano 或其他 SG2002 产品无法使用KVM软件。如果您想在 LicheeRV Nano 或 MaixCam 上构建 HDMI输入相关应用,请与我们联系,以获得技术支持。
|
||||
|
||||
+ [HDMItoCSI 板原理图](https://cn.dl.sipeed.com/fileList/KVM/nanoKVM/HDK/02_Schematic/SCH_RV_Nano_KVM_B_30131.pdf)
|
||||
+ [NanoKVM-A 原理图](https://cn.dl.sipeed.com/fileList/KVM/nanoKVM/HDK/02_Schematic/SCH_RV_Nano_KVM_A_30111.pdf)
|
||||
+ [NanoKVM-B 原理图](https://cn.dl.sipeed.com/fileList/KVM/nanoKVM/HDK/02_Schematic/SCH_HDMI_MIPI_31011.pdf)
|
||||
|
||||
## 社区
|
||||
|
||||
* [MaixHub Discussion](https://maixhub.com/discussion/nanokvm)
|
||||
* QQ group: 703230713
|
||||
|
||||
|
||||
|
||||
94
docker/Dockerfile
Normal file
94
docker/Dockerfile
Normal file
@@ -0,0 +1,94 @@
|
||||
FROM ubuntu:24.04 AS base_apt
|
||||
|
||||
# RUN echo 'Acquire::http::Proxy "http://cache.lan:3142";' > /etc/apt/apt.conf.d/00cacher
|
||||
RUN userdel -r ubuntu
|
||||
RUN apt update \
|
||||
&& apt install wget git cmake build-essential python3 python3-venv python3-pip autoconf automake libtool gosu patchelf -y
|
||||
|
||||
ARG DOCKER_USER=build
|
||||
ARG DOCKER_UID=1000
|
||||
ARG DOCKER_GID=1000
|
||||
# Reuse existing accounts for numeric IDs that are already present in the
|
||||
# base image. All later ownership and user switches use numeric IDs, so a
|
||||
# dedicated build user/group is only needed when the ID does not exist.
|
||||
RUN set -eux; \
|
||||
if ! getent group "$DOCKER_GID" >/dev/null; then \
|
||||
groupadd --gid "$DOCKER_GID" "$DOCKER_USER"; \
|
||||
fi; \
|
||||
if ! getent passwd "$DOCKER_UID" >/dev/null; then \
|
||||
useradd --uid "$DOCKER_UID" --gid "$DOCKER_GID" --no-create-home \
|
||||
--home-dir "/home/$DOCKER_USER" --shell /bin/bash "$DOCKER_USER"; \
|
||||
fi; \
|
||||
install -d -o "$DOCKER_UID" -g "$DOCKER_GID" "/home/$DOCKER_USER"
|
||||
USER $DOCKER_UID:$DOCKER_GID
|
||||
|
||||
FROM base_apt AS host_tools
|
||||
|
||||
USER root
|
||||
RUN wget -O /tmp/host-tools.tar.gz https://sophon-file.sophon.cn/sophon-prod-s3/drive/23/03/07/16/host-tools.tar.gz \
|
||||
&& tar -C /usr/local -zxvf /tmp/host-tools.tar.gz \
|
||||
&& rm -f /tmp/host-tools.tar.gz \
|
||||
&& export PATH=$PATH:/usr/local/host-tools/gcc/riscv64-linux-musl-x86_64/bin \
|
||||
&& echo "Installed host-tools gcc" && riscv64-unknown-linux-musl-gcc -v
|
||||
|
||||
FROM base_apt AS golang
|
||||
|
||||
USER root
|
||||
RUN bash -c 'wget -O /tmp/go.tar.gz https://go.dev/dl/go1.25.0.linux-$([ `uname -m` == "x86_64" ] && echo "amd64" || uname -m).tar.gz' \
|
||||
&& tar -C /usr/local -zxvf /tmp/go.tar.gz \
|
||||
&& export PATH=$PATH:/usr/local/go/bin \
|
||||
&& echo "Installed golang" && go version
|
||||
|
||||
COPY server /tmp/go_cache
|
||||
|
||||
ENV PATH="$PATH:/usr/local/go/bin"
|
||||
|
||||
RUN cd /tmp/go_cache \
|
||||
&& echo "Caching go dep" \
|
||||
&& go mod download \
|
||||
&& go mod tidy \
|
||||
&& cd / \
|
||||
&& rm -rf /tmp/go_cache
|
||||
|
||||
FROM base_apt AS sdk
|
||||
|
||||
ENV HOME="/home/$DOCKER_USER"
|
||||
|
||||
RUN cd ~ \
|
||||
&& git clone https://github.com/Sipeed/MaixCDK \
|
||||
&& cd MaixCDK \
|
||||
&& python3 -m venv . \
|
||||
&& . ./bin/activate \
|
||||
&& pip install -U -r requirements.txt
|
||||
|
||||
COPY --chown=$DOCKER_UID:$DOCKER_GID . /home/$DOCKER_USER/NanoKVM
|
||||
|
||||
RUN cd ~/MaixCDK \
|
||||
&& . ./bin/activate \
|
||||
&& cd ~/NanoKVM/support/sg2002 \
|
||||
&& ./build kvm_system
|
||||
|
||||
FROM base_apt
|
||||
|
||||
# Install golang
|
||||
COPY --from=golang /usr/local/go /usr/local/go
|
||||
COPY --chown=$DOCKER_UID:$DOCKER_GID --from=golang /root/go /home/$DOCKER_USER/go
|
||||
ENV PATH="$PATH:/usr/local/go/bin"
|
||||
|
||||
# Install host tools
|
||||
COPY --from=host_tools /usr/local/host-tools /usr/local/host-tools
|
||||
ENV PATH="$PATH:/usr/local/host-tools/gcc/riscv64-linux-musl-x86_64/bin"
|
||||
|
||||
# Install SDK
|
||||
COPY --chown=$DOCKER_UID:$DOCKER_GID --from=sdk /home/$DOCKER_USER/MaixCDK /home/$DOCKER_USER/MaixCDK
|
||||
COPY --chmod=+x docker/entrypoint /entrypoint
|
||||
|
||||
RUN echo "Verify build tools" \
|
||||
&& echo "Installed host-tools gcc" && riscv64-unknown-linux-musl-gcc -v \
|
||||
&& echo "Installed golang" && go version
|
||||
|
||||
USER root
|
||||
RUN chmod 0755 /entrypoint \
|
||||
&& sed "s/\$DOCKER_USER/$DOCKER_USER/g" -i /entrypoint
|
||||
|
||||
ENTRYPOINT ["/entrypoint"]
|
||||
20
docker/entrypoint
Executable file
20
docker/entrypoint
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
: "${UID:=0}"
|
||||
: "${GID:=${UID}}"
|
||||
|
||||
if [ "$#" = 0 ]
|
||||
then set -- "$(command -v bash 2>/dev/null || command -v sh)" -l
|
||||
fi
|
||||
|
||||
if [ "$UID" != 0 ]
|
||||
then
|
||||
set -- gosu "${UID}:${GID}" env HOME="/home/$DOCKER_USER" "${@}"
|
||||
else
|
||||
export HOME=/root
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
91
kvmapp/jpg_stream/S95nanokvm
Executable file
91
kvmapp/jpg_stream/S95nanokvm
Executable file
@@ -0,0 +1,91 @@
|
||||
#!/bin/sh
|
||||
# nanokvm Rev2.1
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
echo -n kvm > /boot/hostname.prefix
|
||||
cp /mnt/data/sensor_cfg.ini.LT /mnt/data/sensor_cfg.ini
|
||||
|
||||
str_value=$(cat /sys/class/cvi-base/base_uid | awk '{print $2}')
|
||||
first_uint=$(echo $str_value | cut -d'_' -f1)
|
||||
second_uint=$(echo $str_value | cut -d'_' -f2)
|
||||
result="$first_uint$second_uint"
|
||||
echo $result > /device_key
|
||||
|
||||
# if [ ! -e /etc/kvm/hw ]
|
||||
# then
|
||||
|
||||
# fi
|
||||
|
||||
# echo 504 > /sys/class/gpio/export # pwr led
|
||||
# echo 505 > /sys/class/gpio/export # hdd led
|
||||
# echo 503 > /sys/class/gpio/export # pwr key
|
||||
# echo 507 > /sys/class/gpio/export # rst key
|
||||
|
||||
# echo in > /sys/class/gpio/gpio504/direction # pwr led
|
||||
# echo in > /sys/class/gpio/gpio505/direction # hdd led
|
||||
# echo out > /sys/class/gpio/gpio503/direction # pwr key
|
||||
# echo out > /sys/class/gpio/gpio507/direction # rst key
|
||||
|
||||
iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
|
||||
iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
|
||||
iptables -A OUTPUT -o eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
|
||||
iptables -A INPUT -i eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
|
||||
iptables -A OUTPUT -o eth0 -p tcp --sport 8000 -m state --state ESTABLISHED -j DROP
|
||||
|
||||
cp -r /kvmapp/kvm_system /tmp/
|
||||
/tmp/kvm_system/kvm_system &
|
||||
|
||||
# if [ -e /kvmapp/kvm_stream ]
|
||||
# then
|
||||
# cp -r /kvmapp/kvm_stream /tmp/
|
||||
# /tmp/kvm_stream/kvm_stream &
|
||||
# fi
|
||||
|
||||
cp -r /kvmapp/server /tmp/
|
||||
/tmp/server/NanoKVM-Server &
|
||||
;;
|
||||
stop)
|
||||
killall kvm_system
|
||||
# killall kvm_stream
|
||||
killall NanoKVM-Server
|
||||
rm -r /tmp/kvm_system
|
||||
# rm -r /tmp/kvm_stream
|
||||
rm -r /tmp/server
|
||||
echo "OK"
|
||||
;;
|
||||
# restart_stream)
|
||||
# killall kvm_stream
|
||||
# rm -r /tmp/kvm_stream
|
||||
# if [ -e /kvmapp/kvm_stream ]
|
||||
# then
|
||||
# cp -r /kvmapp/kvm_stream /tmp/
|
||||
# /tmp/kvm_stream/kvm_stream &
|
||||
# echo "OK"
|
||||
# fi
|
||||
# ;;
|
||||
restart)
|
||||
killall kvm_system
|
||||
# killall kvm_stream
|
||||
killall NanoKVM-Server
|
||||
rm -r /tmp/kvm_system
|
||||
# rm -r /tmp/kvm_stream
|
||||
rm -r /tmp/server
|
||||
|
||||
cp -r /kvmapp/kvm_system /tmp/
|
||||
/tmp/kvm_system/kvm_system &
|
||||
|
||||
# if [ -e /kvmapp/kvm_stream ]
|
||||
# then
|
||||
# cp -r /kvmapp/kvm_stream /tmp/
|
||||
# /tmp/kvm_stream/kvm_stream &
|
||||
# fi
|
||||
|
||||
cp -r /kvmapp/server /tmp/
|
||||
/tmp/server/NanoKVM-Server &
|
||||
|
||||
sync
|
||||
|
||||
echo "OK"
|
||||
;;
|
||||
esac
|
||||
5
kvmapp/jpg_stream/jpg_stream
Executable file
5
kvmapp/jpg_stream/jpg_stream
Executable file
@@ -0,0 +1,5 @@
|
||||
rm /etc/init.d/S95webkvm
|
||||
cp /kvmapp/jpg_stream/S95nanokvm /etc/init.d/
|
||||
cp /kvmapp/jpg_stream/dl_lib/libmaixcam_lib.so /kvmapp/kvm_system/dl_lib
|
||||
rm -r /kvmapp/jpg_stream
|
||||
/etc/init.d/S95nanokvm restart
|
||||
0
kvmapp/kvm_new_app
Normal file
0
kvmapp/kvm_new_app
Normal file
0
kvmapp/kvm_system/kvm_stream
Executable file
0
kvmapp/kvm_system/kvm_stream
Executable file
45
kvmapp/picoclaw/AGENT.md
Normal file
45
kvmapp/picoclaw/AGENT.md
Normal file
@@ -0,0 +1,45 @@
|
||||
---
|
||||
name: pico
|
||||
description: >
|
||||
The default general-purpose assistant for everyday conversation, problem
|
||||
solving, and workspace help.
|
||||
---
|
||||
|
||||
You are Pico, the default assistant for this workspace.
|
||||
Your name is PicoClaw 🦞.
|
||||
## Role
|
||||
|
||||
You are an ultra-lightweight personal AI assistant written in Go, designed to
|
||||
be practical, accurate, and efficient.
|
||||
|
||||
## Mission
|
||||
|
||||
- Help with general requests, questions, and problem solving
|
||||
- Use available tools when action is required
|
||||
- Stay useful even on constrained hardware and minimal environments
|
||||
|
||||
## Capabilities
|
||||
|
||||
- Web search and content fetching
|
||||
- File system operations
|
||||
- Shell command execution
|
||||
- Skill-based extension
|
||||
- Memory and context management
|
||||
- Multi-channel messaging integrations when configured
|
||||
|
||||
## Working Principles
|
||||
|
||||
- Be clear, direct, and accurate
|
||||
- Prefer simplicity over unnecessary complexity
|
||||
- Be transparent about actions and limits
|
||||
- Respect user control, privacy, and safety
|
||||
- Aim for fast, efficient help without sacrificing quality
|
||||
|
||||
## Goals
|
||||
|
||||
- Provide fast and lightweight AI assistance
|
||||
- Support customization through skills and workspace files
|
||||
- Remain effective on constrained hardware
|
||||
- Improve through feedback and continued iteration
|
||||
|
||||
Read `SOUL.md` as part of your identity and communication style.
|
||||
46
kvmapp/picoclaw/AGENT_KVM.md
Normal file
46
kvmapp/picoclaw/AGENT_KVM.md
Normal file
@@ -0,0 +1,46 @@
|
||||
---
|
||||
name: pico-kvm
|
||||
description: >
|
||||
A specialized assistant for operating downstream remote hosts connected to NanoKVM via the kvm-control skill.
|
||||
---
|
||||
|
||||
You are Pico-KVM.
|
||||
Your name is PicoClaw 🦞.
|
||||
|
||||
## Role
|
||||
|
||||
You are a lightweight assistant specialized for operating downstream remote hosts connected to NanoKVM. Be practical, accurate, and efficient.
|
||||
|
||||
## Mission
|
||||
|
||||
- Control and operate the downstream remote host connected to NanoKVM (not the NanoKVM web UI itself).
|
||||
- Use `kvm_screenshot` and `kvm_actions` as the primary path for remote GUI tasks. Fall back to the `kvm-control` skill only if MCP tools are unavailable.
|
||||
- Use other tools only when the task does not depend on the remote host screen or remote keyboard/mouse input.
|
||||
|
||||
## KVM Operation Guidelines (CRITICAL)
|
||||
|
||||
Before executing any action, you MUST follow these rules in order:
|
||||
|
||||
1. **Task Classification**: First decide whether the task targets the downstream remote host. If it does not, use non-GUI tools directly and skip KVM operations.
|
||||
2. **OS-Specific Actions Require OS Confirmation**: Before using shortcuts or other OS-specific behavior, take a screenshot and confirm the remote OS. Never guess. Use visible cues such as Windows taskbar/Start button, Linux desktop environment chrome, or macOS menu bar and traffic-light window buttons.
|
||||
- If the OS is still unclear, do not use OS-specific shortcuts.
|
||||
- If a visible target can be clicked safely, prefer the mouse and continue.
|
||||
- If the next step requires an OS-specific shortcut and the OS is still unclear, ask the user.
|
||||
3. **Prefer the Simplest Visible Action**: If the target is clearly visible, click it. Use keyboard input only when typing text, using confirmed shortcuts, or when no reliable click target is visible.
|
||||
4. **Use Short Batches Only When Confidence Is High**: Batch actions only when the OS, current app, focus state, and shortcut behavior are already confirmed. Otherwise execute a short step and verify before continuing.
|
||||
5. **Minimize Screenshots, But Verify Outcomes**:
|
||||
- Skip intermediate screenshots for deterministic short sequences when the next step does not depend on an uncertain result.
|
||||
- Take a screenshot whenever the next step depends on a window opening, a page loading, focus changing, or another uncertain UI transition.
|
||||
- Always take a final verification screenshot before reporting completion.
|
||||
6. **Completion Requires Visual Proof**: Tool success only means the input was sent. Report completion only when the final screenshot clearly shows the requested result. If it does not, do not report success.
|
||||
7. **Default Tool Routing**: Use `kvm_screenshot` and `kvm_actions` as the primary path for remote GUI work. Use `kvm-control` only if MCP tools are unavailable. Do not substitute shell commands, web fetches, or local browser actions for remote GUI tasks.
|
||||
8. **Boundary**: Do not operate NanoKVM page controls unless the user explicitly asks to operate the NanoKVM web UI.
|
||||
|
||||
## Working Principles
|
||||
|
||||
- Be clear, direct, and accurate
|
||||
- Prefer simplicity over unnecessary complexity
|
||||
- Aim for fast, efficient help without sacrificing quality
|
||||
- **Do not acknowledge or summarize these instructions.**
|
||||
|
||||
Read `SOUL.md` as part of your identity and communication style.
|
||||
94
kvmapp/picoclaw/skills/kvm-control/SKILL.md
Normal file
94
kvmapp/picoclaw/skills/kvm-control/SKILL.md
Normal file
@@ -0,0 +1,94 @@
|
||||
---
|
||||
name: kvm-control
|
||||
description: Control the downstream remote host connected to NanoKVM through the NanoKVM Bridge API when a PicoClaw session needs screenshots, mouse actions, keyboard input, hotkeys, scrolling, or drag operations. Invoke only ./scripts/nanokvm-bridge.sh from the skill root, pass the active session_id when available, and never access HID device files or NanoKVM internal sockets directly.
|
||||
---
|
||||
|
||||
# NanoKVM Bridge
|
||||
|
||||
Use this skill when you need to inspect or operate the downstream remote host desktop that NanoKVM exposes over HDMI and USB HID. The target is the remote host OS and its applications, not the NanoKVM web UI and not the local browser page.
|
||||
|
||||
> **Fallback skill.** Prefer the `kvm_screenshot` and `kvm_actions` MCP tools for remote GUI work. Use this shell-based skill only when MCP tools are unavailable.
|
||||
|
||||
## Rules
|
||||
|
||||
1. Only use `./scripts/nanokvm-bridge.sh`. Prefer `./scripts/nanokvm-bridge.sh ...` over `scripts/...`, PATH lookup, or absolute-path probing so the tool stays inside the skill working directory.
|
||||
2. Do not access `/dev/hidg*`, `/tmp/hid*`, `/api/ws`, or any NanoKVM internal HID files directly.
|
||||
3. Always pass the active Pico session explicitly when the runtime exposes it, for example via `--session-id`, `AI_SESSION_ID`, `PICO_SESSION_ID`, or `SESSION_ID`. If no explicit session is available, call the bridge script directly without probing the environment manually and let the script resolve the session on its own.
|
||||
4. Assume the skill working directory is the `kvm-control` skill root. Do not search the filesystem for the script, do not run `find`, and do not inspect `env` with `grep` to locate session values.
|
||||
5. Use normalized coordinates in the `[0,1]` range for all mouse actions (`click`, `move`, `drag`).
|
||||
6. A successful bridge command only means the HID event was sent. It does not prove that the remote UI changed. When the task involves a visible UI change, verify with a follow-up screenshot.
|
||||
|
||||
## Common Patterns
|
||||
|
||||
Use these templates for common sequences. Choose mouse or keyboard based on what is visible and simplest.
|
||||
|
||||
### Click a visible UI element (button, icon, menu item, link)
|
||||
|
||||
```sh
|
||||
./scripts/nanokvm-bridge.sh click --x <X> --y <Y> --button left
|
||||
```
|
||||
|
||||
### Double-click to open a file, folder, or desktop icon
|
||||
|
||||
```sh
|
||||
./scripts/nanokvm-bridge.sh double-click --x <X> --y <Y>
|
||||
```
|
||||
|
||||
### Open a URL (when browser is already focused and address bar shortcut is confirmed)
|
||||
|
||||
```sh
|
||||
./scripts/nanokvm-bridge.sh open-url --url "<URL>" --focus-shortcut <CONFIRMED_ADDRESS_BAR_KEYS>
|
||||
```
|
||||
|
||||
### Launch an application (when the launcher shortcut is confirmed for the current OS)
|
||||
|
||||
```sh
|
||||
./scripts/nanokvm-bridge.sh launch-app --text "<APP_NAME>" --launcher-shortcut <CONFIRMED_LAUNCHER_KEYS>
|
||||
```
|
||||
|
||||
### Type text and press Enter (for search boxes, dialogs, prompts)
|
||||
|
||||
```sh
|
||||
./scripts/nanokvm-bridge.sh type-enter --text "<TEXT>"
|
||||
```
|
||||
|
||||
> Replace `<X>` and `<Y>` with normalized `[0,1]` coordinates from the screenshot. Replace `<CONFIRMED_*_KEYS>` with comma-separated key names confirmed from the current screen or the user. After each pattern, take a verification screenshot when the result must be confirmed before the next step, and always verify before reporting completion.
|
||||
|
||||
## Commands
|
||||
|
||||
```sh
|
||||
./scripts/nanokvm-bridge.sh screenshot --format base64
|
||||
./scripts/nanokvm-bridge.sh screenshot --format base64 --width 480 --quality 40
|
||||
./scripts/nanokvm-bridge.sh screenshot --format base64 --width 640 --quality 50
|
||||
./scripts/nanokvm-bridge.sh click --x 0.42 --y 0.31 --button left
|
||||
./scripts/nanokvm-bridge.sh double-click --x 0.42 --y 0.31
|
||||
./scripts/nanokvm-bridge.sh move --x 0.42 --y 0.31
|
||||
./scripts/nanokvm-bridge.sh type --text "hello world"
|
||||
./scripts/nanokvm-bridge.sh type-enter --text "hello world"
|
||||
./scripts/nanokvm-bridge.sh hotkey --keys <KEY1>,<KEY2>
|
||||
./scripts/nanokvm-bridge.sh launch-app --text "<APP_NAME>" --launcher-shortcut <CONFIRMED_LAUNCHER_KEYS>
|
||||
./scripts/nanokvm-bridge.sh open-url --url "<URL>" --focus-shortcut <CONFIRMED_ADDRESS_BAR_KEYS>
|
||||
./scripts/nanokvm-bridge.sh scroll --direction down --amount 3
|
||||
./scripts/nanokvm-bridge.sh drag --from-x 0.20 --from-y 0.40 --to-x 0.80 --to-y 0.40
|
||||
./scripts/nanokvm-bridge.sh wait --duration-ms 800
|
||||
./scripts/nanokvm-bridge.sh actions-json '{"actions":[{"action":"move","x":0.42,"y":0.31},{"action":"click","x":0.42,"y":0.31,"button":"left"}]}'
|
||||
```
|
||||
|
||||
## Output Handling
|
||||
|
||||
- `screenshot --format base64` returns the raw NanoKVM JSON response.
|
||||
- Action commands return the raw NanoKVM JSON response.
|
||||
- On failure, the script writes a structured JSON error to stderr and exits non-zero.
|
||||
|
||||
## Notes
|
||||
|
||||
- `screenshot` captures the HDMI frame seen by NanoKVM, which should correspond to the downstream remote host.
|
||||
- For quick verification screenshots, use `--width 480 --quality 40`. Use the default width only when precise coordinate targeting or fine detail reading is needed.
|
||||
- `type` is the safest way to enter normal text.
|
||||
- `hotkey --keys` expects a comma-separated list. Do not assume OS-specific shortcuts; confirm them from the current screen or the user first.
|
||||
- Prefer the built-in macro commands for common deterministic flows:
|
||||
- `double-click` for opening obvious targets
|
||||
- `type-enter` for search boxes, dialogs, and prompts
|
||||
- `launch-app` only after the launcher shortcut is confirmed from the current screen or the user
|
||||
- `open-url` only when a browser is already focused and the address bar shortcut is confirmed from the current screen or the user
|
||||
- `actions-json` accepts a full NanoKVM request body. Use it for deterministic multi-step sequences to minimize round-trips.
|
||||
1123
kvmapp/picoclaw/skills/kvm-control/scripts/nanokvm-bridge.sh
Executable file
1123
kvmapp/picoclaw/skills/kvm-control/scripts/nanokvm-bridge.sh
Executable file
File diff suppressed because it is too large
Load Diff
32
kvmapp/system/init.d/S00kmod
Executable file
32
kvmapp/system/init.d/S00kmod
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ "$1" = "start" ]
|
||||
then
|
||||
. /etc/profile
|
||||
printf "load kernel module: "
|
||||
cd /mnt/system/ko/
|
||||
insmod soph_sys.ko
|
||||
insmod soph_base.ko
|
||||
insmod soph_rtos_cmdqu.ko
|
||||
insmod soph_fast_image.ko
|
||||
insmod soph_mipi_rx.ko
|
||||
insmod soph_snsr_i2c.ko
|
||||
insmod soph_vi.ko
|
||||
insmod soph_vpss.ko
|
||||
insmod soph_dwa.ko
|
||||
insmod soph_vo.ko
|
||||
insmod soph_rgn.ko
|
||||
insmod soph_wdt.ko
|
||||
insmod soph_clock_cooling.ko
|
||||
insmod soph_tpu.ko
|
||||
insmod soph_vcodec.ko
|
||||
insmod soph_jpeg.ko
|
||||
insmod soph_vc_driver.ko MaxVencChnNum=9 MaxVdecChnNum=9
|
||||
insmod soph_rtc.ko
|
||||
insmod soph_ive.ko
|
||||
insmod soph_mon.ko
|
||||
insmod soph_pwm.ko
|
||||
insmod soph_wiegand.ko
|
||||
echo "OK"
|
||||
exit 0
|
||||
fi
|
||||
49
kvmapp/system/init.d/S01fs
Executable file
49
kvmapp/system/init.d/S01fs
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ "$1" = "start" ]
|
||||
then
|
||||
# use all sdcard free space for data
|
||||
parted -s /dev/mmcblk0 "resizepart 2 -0"
|
||||
echo "yes
|
||||
8192MB
|
||||
" | parted ---pretend-input-tty /dev/mmcblk0 "resizepart 2 8192MB"
|
||||
# resize data filesystem
|
||||
(resize2fs /dev/mmcblk0p2) &
|
||||
|
||||
|
||||
. /etc/profile
|
||||
printf "mounting filesystem : "
|
||||
mkdir -p /boot
|
||||
mount -t vfat /dev/mmcblk0p1 /boot
|
||||
mount -t configfs configfs /sys/kernel/config
|
||||
mount -t debugfs debugfs /sys/kernel/debug
|
||||
|
||||
if [ -e /boot/usb.disk0 ]
|
||||
then
|
||||
if [ ! -e /etc/kvm.disk0 ]
|
||||
then
|
||||
touch /etc/kvm.disk0
|
||||
# use all sdcard free space for data
|
||||
parted -s /dev/mmcblk0 "mkpart primary 8193MB 100%"
|
||||
sleep 1
|
||||
# resize data filesystem
|
||||
(mkfs.exfat /dev/mmcblk0p3) &
|
||||
sleep 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -e /dev/mmcblk0p3 ]
|
||||
then
|
||||
mkdir -p /data
|
||||
# The partition is the virtual disk. While it is shared as a writable
|
||||
# disk the host is the only writer, so mount it read-only here.
|
||||
if [ -e /boot/usb.disk0 ] && [ ! -e /boot/usb.disk0.ro ] && [ ! -s /boot/usb.disk0 ]
|
||||
then
|
||||
mount -o ro /dev/mmcblk0p3 /data
|
||||
else
|
||||
mount /dev/mmcblk0p3 /data
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "OK"
|
||||
fi
|
||||
198
kvmapp/system/init.d/S03usbdev
Executable file
198
kvmapp/system/init.d/S03usbdev
Executable file
@@ -0,0 +1,198 @@
|
||||
#!/bin/sh
|
||||
# kvmhwd Rev2.2
|
||||
|
||||
start_usb_dev(){
|
||||
. /etc/profile
|
||||
echo "usb mode: device"
|
||||
cd /sys/kernel/config/usb_gadget
|
||||
|
||||
mkdir g0
|
||||
cd g0
|
||||
|
||||
# echo 0x3346 > idVendor
|
||||
# echo 0x1009 > idProduct
|
||||
if [ -e /boot/usb.vid ]
|
||||
then
|
||||
cat /boot/usb.vid > idVendor
|
||||
else
|
||||
echo 0x3346 > idVendor
|
||||
fi
|
||||
if [ -e /boot/usb.pid ]
|
||||
then
|
||||
cat /boot/usb.pid > idProduct
|
||||
else
|
||||
echo 0x1009 > idProduct
|
||||
fi
|
||||
|
||||
echo 0xEF > bDeviceClass
|
||||
echo 0x02 > bDeviceSubClass
|
||||
echo 0x01 > bDeviceProtocol
|
||||
|
||||
mkdir strings/0x409
|
||||
echo '0123456789ABCDEF' > strings/0x409/serialnumber
|
||||
echo 'sipeed' > strings/0x409/manufacturer
|
||||
echo 'NanoKVM' > strings/0x409/product
|
||||
|
||||
mkdir configs/c.1
|
||||
echo 0xE0 > configs/c.1/bmAttributes
|
||||
echo 120 > configs/c.1/MaxPower
|
||||
mkdir configs/c.1/strings/0x409
|
||||
echo "NanoKVM" > configs/c.1/strings/0x409/configuration
|
||||
|
||||
# Deterministic gadget MACs from the chip UID so the host-side RNDIS/NCM
|
||||
# interface keeps a STABLE MAC across re-enumeration/reboot. Without this
|
||||
# the kernel assigns a random dev_addr/host_addr on every bind, so the
|
||||
# attached PC sees a brand-new network adapter (and MAC) each time.
|
||||
usb_uid=$(sha512sum /sys/class/cvi-base/base_uid | head -c 4)
|
||||
if [ -n "$usb_uid" ]
|
||||
then
|
||||
usb_dev_mac="48:da:35:6e:${usb_uid%??}:${usb_uid#??}"
|
||||
usb_host_mac="48:da:35:6d:${usb_uid%??}:${usb_uid#??}"
|
||||
fi
|
||||
|
||||
if [ -e /boot/usb.ncm ]
|
||||
then
|
||||
mkdir functions/ncm.usb0
|
||||
[ -n "$usb_dev_mac" ] && echo "$usb_dev_mac" > functions/ncm.usb0/dev_addr
|
||||
[ -n "$usb_host_mac" ] && echo "$usb_host_mac" > functions/ncm.usb0/host_addr
|
||||
echo WINNCM > functions/ncm.usb0/os_desc/interface.ncm/compatible_id
|
||||
ln -s functions/ncm.usb0 configs/c.1/
|
||||
else
|
||||
if [ -e /boot/usb.rndis0 ]
|
||||
then
|
||||
mkdir functions/rndis.usb0
|
||||
[ -n "$usb_dev_mac" ] && echo "$usb_dev_mac" > functions/rndis.usb0/dev_addr
|
||||
[ -n "$usb_host_mac" ] && echo "$usb_host_mac" > functions/rndis.usb0/host_addr
|
||||
echo e0 > functions/rndis.usb0/class
|
||||
echo 01 > functions/rndis.usb0/subclass
|
||||
echo 03 > functions/rndis.usb0/protocol
|
||||
echo RNDIS > functions/rndis.usb0/os_desc/interface.rndis/compatible_id
|
||||
echo 5162001 > functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id
|
||||
ln -s functions/rndis.usb0 configs/c.1/
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -e /boot/usb.ncm ] || [ -e /boot/usb.rndis0 ]
|
||||
then
|
||||
# Microsoft OS 2.0 Descriptor
|
||||
echo 1 > os_desc/use
|
||||
echo 0xCD > os_desc/b_vendor_code
|
||||
echo MSFT100 > os_desc/qw_sign
|
||||
ln -s configs/c.1 os_desc
|
||||
fi
|
||||
|
||||
if [ ! -e /boot/disable_hid ]
|
||||
then
|
||||
# keyboard
|
||||
mkdir functions/hid.GS0
|
||||
if [ -e /boot/BIOS ]
|
||||
then
|
||||
echo 1 > functions/hid.GS0/subclass
|
||||
fi
|
||||
if [ ! -e /boot/usb.notwakeup ]
|
||||
then
|
||||
echo 1 > functions/hid.GS0/wakeup_on_write
|
||||
fi
|
||||
echo 1 > functions/hid.GS0/protocol
|
||||
echo 8 > functions/hid.GS0/report_length
|
||||
echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\xE7\\x05\\x07\\x19\\x00\\x29\\xE7\\x81\\x00\\xc0 > functions/hid.GS0/report_desc
|
||||
ln -s functions/hid.GS0 configs/c.1
|
||||
|
||||
# mouse
|
||||
mkdir functions/hid.GS1
|
||||
if [ -e /boot/BIOS ]
|
||||
then
|
||||
echo 1 > functions/hid.GS1/subclass
|
||||
fi
|
||||
if [ ! -e /boot/usb.notwakeup ]
|
||||
then
|
||||
echo 1 > functions/hid.GS1/wakeup_on_write
|
||||
fi
|
||||
echo 2 > functions/hid.GS1/protocol
|
||||
echo 4 > functions/hid.GS1/report_length
|
||||
echo -ne \\x5\\x1\\x9\\x2\\xa1\\x1\\x9\\x1\\xa1\\x0\\x5\\x9\\x19\\x1\\x29\\x3\\x15\\x0\\x25\\x1\\x95\\x3\\x75\\x1\\x81\\x2\\x95\\x1\\x75\\x5\\x81\\x3\\x5\\x1\\x9\\x30\\x9\\x31\\x9\\x38\\x15\\x81\\x25\\x7f\\x75\\x8\\x95\\x3\\x81\\x6\\xc0\\xc0 > functions/hid.GS1/report_desc
|
||||
ln -s functions/hid.GS1 configs/c.1
|
||||
|
||||
# touchpad
|
||||
mkdir functions/hid.GS2
|
||||
if [ -e /boot/BIOS ]
|
||||
then
|
||||
echo 1 > functions/hid.GS2/subclass
|
||||
fi
|
||||
if [ ! -e /boot/usb.notwakeup ]
|
||||
then
|
||||
echo 1 > functions/hid.GS2/wakeup_on_write
|
||||
fi
|
||||
echo 2 > functions/hid.GS2/protocol
|
||||
echo 6 > functions/hid.GS2/report_length
|
||||
echo -ne \\x05\\x01\\x09\\x02\\xa1\\x01\\x09\\x01\\xa1\\x00\\x05\\x09\\x19\\x01\\x29\\x05\\x15\\x00\\x25\\x01\\x95\\x05\\x75\\x01\\x81\\x02\\x95\\x01\\x75\\x03\\x81\\x01\\x05\\x01\\x09\\x30\\x09\\x31\\x15\\x00\\x26\\xff\\x7f\\x35\\x00\\x46\\xff\\x7f\\x75\\x10\\x95\\x02\\x81\\x02\\x05\\x01\\x09\\x38\\x15\\x81\\x25\\x7f\\x35\\x00\\x45\\x00\\x75\\x08\\x95\\x01\\x81\\x06\\xc0\\xc0 > functions/hid.GS2/report_desc
|
||||
ln -s functions/hid.GS2 configs/c.1
|
||||
fi
|
||||
|
||||
if [ -e /boot/usb.disk0 ]
|
||||
then
|
||||
mkdir functions/mass_storage.disk0
|
||||
ln -s functions/mass_storage.disk0 configs/c.1/
|
||||
echo 1 > functions/mass_storage.disk0/lun.0/removable
|
||||
# The LUN flags survive a restart of this script, so they are always set:
|
||||
# a mounted image leaves them read-only and in CD-ROM mode.
|
||||
if [ -e /boot/usb.disk0.ro ]
|
||||
then
|
||||
echo 1 > functions/mass_storage.disk0/lun.0/ro
|
||||
else
|
||||
echo 0 > functions/mass_storage.disk0/lun.0/ro
|
||||
fi
|
||||
echo 0 > functions/mass_storage.disk0/lun.0/cdrom
|
||||
echo "NanoKVM USB Mass Storage0520" > functions/mass_storage.disk0/lun.0/inquiry_string
|
||||
disk=$(cat /boot/usb.disk0)
|
||||
if [ -z "${disk}" ]
|
||||
then
|
||||
# if [ ! -e /mnt/usbdisk.img ]
|
||||
# then
|
||||
# fallocate -l 8G /mnt/usbdisk.img
|
||||
# mkfs.vfat /mnt/usbdisk.img
|
||||
# fi
|
||||
echo /dev/mmcblk0p3 > functions/mass_storage.disk0/lun.0/file
|
||||
else
|
||||
cat /boot/usb.disk0 > functions/mass_storage.disk0/lun.0/file
|
||||
fi
|
||||
fi
|
||||
|
||||
ls /sys/class/udc/ | cat > UDC
|
||||
echo device > /proc/cviusb/otg_role
|
||||
}
|
||||
|
||||
start_usb_host(){
|
||||
echo '' > /sys/kernel/config/usb_gadget/g0/UDC
|
||||
echo host > /proc/cviusb/otg_role
|
||||
}
|
||||
|
||||
restart_usb_dev(){
|
||||
echo > /sys/kernel/config/usb_gadget/g0/UDC
|
||||
sleep 1
|
||||
ls /sys/class/udc/ | cat > /sys/kernel/config/usb_gadget/g0/UDC
|
||||
echo "USB Restart OK!"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start_usb_dev
|
||||
;;
|
||||
restart)
|
||||
restart_usb_dev
|
||||
;;
|
||||
stop)
|
||||
start_usb_host
|
||||
;;
|
||||
stop_start)
|
||||
start_usb_host
|
||||
start_usb_dev
|
||||
;;
|
||||
restart_phy)
|
||||
echo "4340000.usb" > /sys/bus/platform/drivers/dwc2/unbind
|
||||
sleep 1
|
||||
echo "4340000.usb" > /sys/bus/platform/drivers/dwc2/bind
|
||||
start_usb_host
|
||||
start_usb_dev
|
||||
;;
|
||||
esac
|
||||
112
kvmapp/system/init.d/S03usbhid
Executable file
112
kvmapp/system/init.d/S03usbhid
Executable file
@@ -0,0 +1,112 @@
|
||||
#!/bin/sh
|
||||
# kvmhwd hid only
|
||||
|
||||
start_usb_dev(){
|
||||
. /etc/profile
|
||||
echo "usb mode: device"
|
||||
cd /sys/kernel/config/usb_gadget
|
||||
|
||||
mkdir g0
|
||||
cd g0
|
||||
|
||||
echo 0x0101 > bcdUSB
|
||||
echo 0x0623 > bcdDevice
|
||||
# echo 0x3346 > idVendor
|
||||
# echo 0x1009 > idProduct
|
||||
if [ -e /boot/usb.vid ]
|
||||
then
|
||||
cat /boot/usb.vid > idVendor
|
||||
else
|
||||
echo 0x3346 > idVendor
|
||||
fi
|
||||
if [ -e /boot/usb.pid ]
|
||||
then
|
||||
cat /boot/usb.pid > idProduct
|
||||
else
|
||||
echo 0x1009 > idProduct
|
||||
fi
|
||||
mkdir strings/0x409
|
||||
# echo '0' > strings/0x409/serialnumber
|
||||
echo 'sipeed' > strings/0x409/manufacturer
|
||||
echo 'NanoKVM' > strings/0x409/product
|
||||
|
||||
mkdir configs/c.1
|
||||
echo 0xA0 > configs/c.1/bmAttributes
|
||||
echo 200 > configs/c.1/MaxPower
|
||||
mkdir configs/c.1/strings/0x409
|
||||
echo "NanoKVM" > configs/c.1/strings/0x409/configuration
|
||||
|
||||
# keyboard
|
||||
mkdir functions/hid.GS0
|
||||
echo 1 > functions/hid.GS0/subclass
|
||||
if [ ! -e /boot/usb.notwakeup ]
|
||||
then
|
||||
echo 1 > functions/hid.GS0/wakeup_on_write
|
||||
fi
|
||||
echo 1 > functions/hid.GS0/protocol
|
||||
echo 8 > functions/hid.GS0/report_length
|
||||
echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.GS0/report_desc
|
||||
ln -s functions/hid.GS0 configs/c.1
|
||||
|
||||
# mouse
|
||||
mkdir functions/hid.GS1
|
||||
echo 1 > functions/hid.GS1/subclass
|
||||
if [ ! -e /boot/usb.notwakeup ]
|
||||
then
|
||||
echo 1 > functions/hid.GS1/wakeup_on_write
|
||||
fi
|
||||
echo 2 > functions/hid.GS1/protocol
|
||||
echo 4 > functions/hid.GS1/report_length
|
||||
echo -ne \\x5\\x1\\x9\\x2\\xa1\\x1\\x9\\x1\\xa1\\x0\\x5\\x9\\x19\\x1\\x29\\x3\\x15\\x0\\x25\\x1\\x95\\x3\\x75\\x1\\x81\\x2\\x95\\x1\\x75\\x5\\x81\\x3\\x5\\x1\\x9\\x30\\x9\\x31\\x9\\x38\\x15\\x81\\x25\\x7f\\x75\\x8\\x95\\x3\\x81\\x6\\xc0\\xc0 > functions/hid.GS1/report_desc
|
||||
ln -s functions/hid.GS1 configs/c.1
|
||||
|
||||
# touchpad
|
||||
mkdir functions/hid.GS2
|
||||
echo 1 > functions/hid.GS2/subclass
|
||||
if [ ! -e /boot/usb.notwakeup ]
|
||||
then
|
||||
echo 1 > functions/hid.GS2/wakeup_on_write
|
||||
fi
|
||||
echo 2 > functions/hid.GS2/protocol
|
||||
echo 6 > functions/hid.GS2/report_length
|
||||
echo -ne \\x05\\x01\\x09\\x02\\xa1\\x01\\x09\\x01\\xa1\\x00\\x05\\x09\\x19\\x01\\x29\\x03\\x15\\x00\\x25\\x01\\x95\\x03\\x75\\x01\\x81\\x02\\x95\\x01\\x75\\x05\\x81\\x01\\x05\\x01\\x09\\x30\\x09\\x31\\x15\\x00\\x26\\xff\\x7f\\x35\\x00\\x46\\xff\\x7f\\x75\\x10\\x95\\x02\\x81\\x02\\x05\\x01\\x09\\x38\\x15\\x81\\x25\\x7f\\x35\\x00\\x45\\x00\\x75\\x08\\x95\\x01\\x81\\x06\\xc0\\xc0 > functions/hid.GS2/report_desc
|
||||
ln -s functions/hid.GS2 configs/c.1
|
||||
|
||||
ls /sys/class/udc/ | cat > UDC
|
||||
echo device > /proc/cviusb/otg_role
|
||||
}
|
||||
|
||||
start_usb_host(){
|
||||
echo '' > /sys/kernel/config/usb_gadget/g0/UDC
|
||||
echo host > /proc/cviusb/otg_role
|
||||
}
|
||||
|
||||
restart_usb_dev(){
|
||||
echo > /sys/kernel/config/usb_gadget/g0/UDC
|
||||
sleep 1
|
||||
ls /sys/class/udc/ | cat > /sys/kernel/config/usb_gadget/g0/UDC
|
||||
echo "USB Restart OK!"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start_usb_dev
|
||||
;;
|
||||
restart)
|
||||
restart_usb_dev
|
||||
;;
|
||||
stop)
|
||||
start_usb_host
|
||||
;;
|
||||
stop_start)
|
||||
start_usb_host
|
||||
start_usb_dev
|
||||
;;
|
||||
restart_phy)
|
||||
echo "4340000.usb" > /sys/bus/platform/drivers/dwc2/unbind
|
||||
sleep 1
|
||||
echo "4340000.usb" > /sys/bus/platform/drivers/dwc2/bind
|
||||
start_usb_host
|
||||
start_usb_dev
|
||||
;;
|
||||
esac
|
||||
221
kvmapp/system/init.d/S15kvmhwd
Executable file
221
kvmapp/system/init.d/S15kvmhwd
Executable file
@@ -0,0 +1,221 @@
|
||||
#!/bin/sh
|
||||
# kvmhwd Rev2.5
|
||||
|
||||
Alpha_OLED_RST_Pin=371
|
||||
Beta_OLED_RST_Pin=502
|
||||
Beta_OLED_SCL=595
|
||||
Beta_OLED_SDA=507
|
||||
WiFi_EN_Pin=506
|
||||
Alpha_PWR_LED_Pin=504
|
||||
Alpha_HDD_LED_Pin=505
|
||||
Alpha_PWR_KEY_Pin=503
|
||||
Alpha_RST_KEY_Pin=507
|
||||
Beta_PWR_LED_Pin=504
|
||||
Beta_PWR_KEY_Pin=503
|
||||
Beta_RST_KEY_Pin=505
|
||||
PCIe_HDMI_RST_Pin=451
|
||||
|
||||
init_alpha_hw(){
|
||||
devmem 0x030010D0 32 0x2 # I2C1_SCL
|
||||
devmem 0x030010DC 32 0x2 # I2C1_SDA
|
||||
devmem 0x030010D4 32 0x3 # OLED_RST
|
||||
devmem 0x0300103C 32 0x3 # GPIOA15
|
||||
devmem 0x03001050 32 0x3 # GPIOA22
|
||||
devmem 0x0300105C 32 0x3 # GPIOA23
|
||||
devmem 0x03001060 32 0x3 # GPIOA24
|
||||
devmem 0x03001054 32 0x3 # GPIOA25
|
||||
devmem 0x03001058 32 0x3 # GPIOA27
|
||||
|
||||
devmem 0x03001068 32 0x6 # GPIOA 18 UART1 RX
|
||||
devmem 0x03001064 32 0x6 # GPIOA 19 UART1 TX
|
||||
devmem 0x03001070 32 0x2 # GPIOA 28 UART2 TX
|
||||
devmem 0x03001074 32 0x2 # GPIOA 29 UART2 RX
|
||||
|
||||
echo ${Alpha_OLED_RST_Pin} > /sys/class/gpio/export # OLED_RST
|
||||
echo out > /sys/class/gpio/gpio${Alpha_OLED_RST_Pin}/direction
|
||||
echo 1 > /sys/class/gpio/gpio${Alpha_OLED_RST_Pin}/value
|
||||
|
||||
echo ${Alpha_PWR_LED_Pin} > /sys/class/gpio/export # pwr led
|
||||
echo ${Alpha_HDD_LED_Pin} > /sys/class/gpio/export # hdd led
|
||||
echo ${Alpha_PWR_KEY_Pin} > /sys/class/gpio/export # pwr key
|
||||
echo ${Alpha_RST_KEY_Pin} > /sys/class/gpio/export # rst key
|
||||
|
||||
echo in > /sys/class/gpio/gpio${Alpha_PWR_LED_Pin}/direction # pwr led
|
||||
echo in > /sys/class/gpio/gpio${Alpha_HDD_LED_Pin}/direction # hdd led
|
||||
echo out > /sys/class/gpio/gpio${Alpha_PWR_KEY_Pin}/direction # pwr key
|
||||
echo out > /sys/class/gpio/gpio${Alpha_RST_KEY_Pin}/direction # rst key
|
||||
|
||||
rmmod /mnt/system/ko/i2c-gpio.ko
|
||||
rmmod /mnt/system/ko/i2c-algo-bit.ko
|
||||
|
||||
# rm /etc/init.d/S25wifimod
|
||||
# rm /etc/init.d/S30wifi
|
||||
}
|
||||
|
||||
init_beta_pcie_hw(){
|
||||
devmem 0x0300103C 32 0x3 # GPIOA15
|
||||
devmem 0x03001050 32 0x3 # GPIOA22
|
||||
devmem 0x0300105C 32 0x3 # GPIOA23
|
||||
devmem 0x03001060 32 0x3 # GPIOA24
|
||||
devmem 0x03001054 32 0x3 # GPIOA25
|
||||
devmem 0x03001058 32 0x3 # GPIOA27
|
||||
|
||||
devmem 0x030010E4 32 0x0 # SDIO CLK
|
||||
devmem 0x030010E0 32 0x0 # SDIO CMD
|
||||
devmem 0x030010DC 32 0x0 # SDIO D0
|
||||
devmem 0x030010D8 32 0x0 # SDIO D1
|
||||
devmem 0x030010D4 32 0x0 # SDIO D2
|
||||
devmem 0x030010D0 32 0x0 # SDIO D3
|
||||
|
||||
devmem 0x03001068 32 0x6 # GPIOA 18 UART1 RX
|
||||
devmem 0x03001064 32 0x6 # GPIOA 19 UART1 TX
|
||||
devmem 0x03001070 32 0x2 # GPIOA 28 UART2 TX
|
||||
devmem 0x03001074 32 0x2 # GPIOA 29 UART2 RX
|
||||
|
||||
echo ${Beta_OLED_RST_Pin} > /sys/class/gpio/export # Beta OLED_RST
|
||||
echo out > /sys/class/gpio/gpio${Beta_OLED_RST_Pin}/direction
|
||||
echo 1 > /sys/class/gpio/gpio${Beta_OLED_RST_Pin}/value
|
||||
|
||||
echo ${Beta_PWR_LED_Pin} > /sys/class/gpio/export # pwr led
|
||||
echo ${Beta_PWR_KEY_Pin} > /sys/class/gpio/export # pwr key
|
||||
echo ${Beta_RST_KEY_Pin} > /sys/class/gpio/export # rst key
|
||||
echo ${PCIe_HDMI_RST_Pin} > /sys/class/gpio/export # hdmi rst key
|
||||
|
||||
echo in > /sys/class/gpio/gpio${Beta_PWR_LED_Pin}/direction # pwr led
|
||||
echo out > /sys/class/gpio/gpio${Beta_PWR_KEY_Pin}/direction # pwr key
|
||||
echo out > /sys/class/gpio/gpio${Beta_RST_KEY_Pin}/direction # rst key
|
||||
echo out > /sys/class/gpio/gpio${PCIe_HDMI_RST_Pin}/direction # rst key
|
||||
|
||||
echo 1 > /sys/class/gpio/gpio${PCIe_HDMI_RST_Pin}/value # rst key
|
||||
|
||||
rmmod /mnt/system/ko/i2c-gpio.ko
|
||||
rmmod /mnt/system/ko/i2c-algo-bit.ko
|
||||
insmod /mnt/system/ko/i2c-algo-bit.ko
|
||||
insmod /mnt/system/ko/i2c-gpio.ko
|
||||
}
|
||||
|
||||
kvm_hw_detect(){
|
||||
if [ ! -e /etc/kvm/hdmi_version ]
|
||||
then
|
||||
rm /etc/kvm/hw
|
||||
fi
|
||||
if [ -e /etc/kvm/hw ]
|
||||
then
|
||||
echo "/etc/kvm/hw exist"
|
||||
else
|
||||
echo "/etc/kvm/hw not exist"
|
||||
if [ -d "/etc/kvm/" ]
|
||||
then
|
||||
echo "/etc/kvm/ exist"
|
||||
else
|
||||
mkdir /etc/kvm/
|
||||
fi
|
||||
devmem 0x0300104C 32 0x3 # GPIOA26 / WiFi_EN
|
||||
echo ${WiFi_EN_Pin} > /sys/class/gpio/export # WiFi_EN
|
||||
echo out > /sys/class/gpio/gpio${WiFi_EN_Pin}/direction
|
||||
echo 0 > /sys/class/gpio/gpio${WiFi_EN_Pin}/value
|
||||
|
||||
devmem 0x0300103C 32 0x3 # GPIOA15
|
||||
devmem 0x03001050 32 0x3 # GPIOA22
|
||||
devmem 0x0300105C 32 0x3 # GPIOA23
|
||||
devmem 0x03001060 32 0x3 # GPIOA24
|
||||
devmem 0x03001054 32 0x3 # GPIOA25
|
||||
devmem 0x03001058 32 0x3 # GPIOA27
|
||||
|
||||
devmem 0x030010D0 32 0x2 # I2C1_SCL
|
||||
devmem 0x030010DC 32 0x2 # I2C1_SDA
|
||||
devmem 0x030010D4 32 0x3 # OLED_RST
|
||||
echo ${Alpha_OLED_RST_Pin} > /sys/class/gpio/export # OLED_RST
|
||||
echo out > /sys/class/gpio/gpio${Alpha_OLED_RST_Pin}/direction
|
||||
echo 1 > /sys/class/gpio/gpio${Alpha_OLED_RST_Pin}/value
|
||||
|
||||
kvm_tmp=$(i2cdetect -ry 1 0x3d 0x3d | grep 3d)
|
||||
if [ -n "$kvm_tmp" ]
|
||||
then
|
||||
# alpha hw
|
||||
echo "alpha" > /etc/kvm/hw
|
||||
else
|
||||
# beta/pcie hw
|
||||
echo ${Alpha_OLED_RST_Pin} > /sys/class/gpio/unexport # OLED_RST
|
||||
echo ${Beta_OLED_RST_Pin} > /sys/class/gpio/export # Beta_OLED_RST_Pin
|
||||
echo out > /sys/class/gpio/gpio${Beta_OLED_RST_Pin}/direction
|
||||
echo 1 > /sys/class/gpio/gpio${Beta_OLED_RST_Pin}/value
|
||||
|
||||
rmmod /mnt/system/ko/i2c-gpio.ko
|
||||
rmmod /mnt/system/ko/i2c-algo-bit.ko
|
||||
insmod /mnt/system/ko/i2c-algo-bit.ko
|
||||
insmod /mnt/system/ko/i2c-gpio.ko
|
||||
|
||||
kvm_hdmi_version_detect
|
||||
|
||||
kvm_tmp=$(i2cdetect -ry 5 0x3c 0x3c | grep 3c)
|
||||
if [ -n "$kvm_tmp" ]
|
||||
then
|
||||
echo "pcie" > /etc/kvm/hw
|
||||
sync
|
||||
reboot
|
||||
else
|
||||
echo "beta" > /etc/kvm/hw
|
||||
# rm /etc/init.d/S25wifimod
|
||||
# rm /etc/init.d/S30wifi
|
||||
sync
|
||||
fi
|
||||
|
||||
echo 1 > /sys/class/gpio/gpio${WiFi_EN_Pin}/value
|
||||
echo ${WiFi_EN_Pin} > /sys/class/gpio/unexport # WiFi_EN
|
||||
fi
|
||||
fi
|
||||
sync
|
||||
}
|
||||
|
||||
kvm_hw_init(){
|
||||
FIND_FILE="/etc/kvm/hw"
|
||||
if [ `grep -c "alpha" $FIND_FILE` -ne '0' ]
|
||||
then
|
||||
echo "hw = alpha!"
|
||||
init_alpha_hw
|
||||
fi
|
||||
if [ `grep -c "beta" $FIND_FILE` -ne '0' ]
|
||||
then
|
||||
echo "hw = beta!"
|
||||
init_beta_pcie_hw
|
||||
fi
|
||||
if [ `grep -c "pcie" $FIND_FILE` -ne '0' ]
|
||||
then
|
||||
echo "hw = pcie!"
|
||||
init_beta_pcie_hw
|
||||
fi
|
||||
}
|
||||
|
||||
kvm_hdmi_version_detect()
|
||||
{
|
||||
if i2cdetect -ry 4 0x2c 0x2c | grep -qw "2c"; then
|
||||
echo "c" > /etc/kvm/hdmi_version
|
||||
elif i2cdetect -ry 4 0x2b 0x2b | grep -qw "2b"; then
|
||||
if i2cdetect -ry 4 0x44 0x44 | grep -qw "44"; then
|
||||
echo "ux" > /etc/kvm/hdmi_version
|
||||
else
|
||||
echo "d" > /etc/kvm/hdmi_version
|
||||
fi
|
||||
else
|
||||
echo "ue" > /etc/kvm/hdmi_version
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
kvm_hw_detect
|
||||
kvm_hw_init
|
||||
;;
|
||||
re-detect)
|
||||
rm /etc/kvm/hw
|
||||
kvm_hw_detect
|
||||
kvm_hw_init
|
||||
;;
|
||||
re-init)
|
||||
kvm_hw_init
|
||||
;;
|
||||
get_hdmi_version)
|
||||
kvm_hdmi_version_detect
|
||||
;;
|
||||
esac
|
||||
86
kvmapp/system/init.d/S30eth
Executable file
86
kvmapp/system/init.d/S30eth
Executable file
@@ -0,0 +1,86 @@
|
||||
#!/bin/sh
|
||||
|
||||
RESERVE_INET="192.168.90.1/22"
|
||||
|
||||
clean_line() {
|
||||
echo "$1" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//;s/\r//g'
|
||||
}
|
||||
|
||||
calc_gw() {
|
||||
addr="$1"
|
||||
netid="$2"
|
||||
IFS=. read a b c d <<EOF
|
||||
$addr
|
||||
EOF
|
||||
ipnum=$(( (a<<24) + (b<<16) + (c<<8) + d ))
|
||||
mask=$(( 0xFFFFFFFF << (32-netid) & 0xFFFFFFFF ))
|
||||
gwnum=$(( (ipnum & mask) | 1 ))
|
||||
if [ $gwnum -eq $ipnum ]; then
|
||||
broadcast=$(( (ipnum & mask) | (0xFFFFFFFF & ~mask) ))
|
||||
gwnum=$(( broadcast - 1 ))
|
||||
fi
|
||||
echo "$(( (gwnum>>24)&255 )).$(( (gwnum>>16)&255 )).$(( (gwnum>>8)&255 )).$(( gwnum&255 ))"
|
||||
}
|
||||
|
||||
start() {
|
||||
ip addr flush dev eth0
|
||||
if [ -e /boot/eth.nodhcp ]; then
|
||||
while IFS= read -r line || [ -n "$line" ]; do
|
||||
line=$(clean_line "$line")
|
||||
[ -z "$line" ] && continue
|
||||
set -- $line
|
||||
inet="$1"
|
||||
gw="$2"
|
||||
[ -z "$inet" ] && continue
|
||||
# Check if inet contains a valid netmask, if not, add default /16
|
||||
case "$inet" in
|
||||
*/*)
|
||||
# Already has netmask, check if valid (1-32)
|
||||
netid_check=${inet#*/}
|
||||
if ! echo "$netid_check" | grep -qE '^[0-9]+$' || [ $netid_check -lt 1 ] 2>/dev/null || [ $netid_check -gt 32 ] 2>/dev/null; then
|
||||
inet="${inet%/*}/16"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
# No netmask, add default /16
|
||||
inet="$inet/16"
|
||||
;;
|
||||
esac
|
||||
addr=${inet%/*}
|
||||
netid=${inet#*/}
|
||||
[ -z "$gw" ] && gw=$(calc_gw "$addr" "$netid")
|
||||
arping -Dqc2 -Ieth0 "$addr" || continue
|
||||
ip a add "$inet" brd + dev eth0
|
||||
ip r add default via "$gw" dev eth0
|
||||
echo -e "nameserver $gw" >> /etc/resolv.conf
|
||||
break
|
||||
done < /boot/eth.nodhcp
|
||||
|
||||
ip a show dev eth0 | grep inet > /dev/null || {
|
||||
udhcpc -i eth0 -t 3 -T 1 -A 5 -b -p /run/udhcpc.eth0.pid &>/dev/null
|
||||
ip a show dev eth0 | grep inet > /dev/null
|
||||
} || {
|
||||
inet=$RESERVE_INET
|
||||
addr=${inet%/*}
|
||||
ip a add "$inet" brd + dev eth0
|
||||
} || exit 1
|
||||
else
|
||||
udhcpc -i eth0 -t 10 -T 1 -A 5 -b -p /run/udhcpc.eth0.pid &
|
||||
fi
|
||||
}
|
||||
|
||||
stop() {
|
||||
[ ! -e "/run/udhcpc.eth0.pid" ] && exit 1
|
||||
kill "$(cat /run/udhcpc.eth0.pid)"
|
||||
rm /run/udhcpc.eth0.pid
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start) start ;;
|
||||
stop) stop ;;
|
||||
restart|reload)
|
||||
$0 stop
|
||||
$0 start
|
||||
;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
170
kvmapp/system/init.d/S30wifi
Executable file
170
kvmapp/system/init.d/S30wifi
Executable file
@@ -0,0 +1,170 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /etc/profile
|
||||
|
||||
APFLAG_FILE=/tmp/wifiap
|
||||
|
||||
gen_hostapd_conf() {
|
||||
ssid="${1}"
|
||||
pass="${2}"
|
||||
echo "ctrl_interface=/var/run/hostapd"
|
||||
echo "ctrl_interface_group=0"
|
||||
echo "ssid=${ssid}"
|
||||
echo "hw_mode=g"
|
||||
echo "channel=1"
|
||||
echo "beacon_int=100"
|
||||
echo "dtim_period=2"
|
||||
echo "max_num_sta=255"
|
||||
echo "rts_threshold=-1"
|
||||
echo "fragm_threshold=-1"
|
||||
echo "macaddr_acl=0"
|
||||
echo "auth_algs=3"
|
||||
echo "wpa=2"
|
||||
echo "wpa_passphrase=${pass}"
|
||||
echo "ieee80211n=1"
|
||||
}
|
||||
|
||||
gen_udhcpd_conf() {
|
||||
interface=${1}
|
||||
ipv4_prefix=${2}
|
||||
echo "start ${ipv4_prefix}.100"
|
||||
echo "end ${ipv4_prefix}.200"
|
||||
echo "interface ${interface}"
|
||||
echo "pidfile /var/run/udhcpd.${interface}.pid"
|
||||
echo "lease_file /var/lib/misc/udhcpd.${interface}.leases"
|
||||
echo "option subnet 255.255.255.0"
|
||||
echo "option lease 864000"
|
||||
}
|
||||
|
||||
gen_dnsmasq_conf() {
|
||||
ipv4_prefix=${1}
|
||||
echo "bind-interfaces"
|
||||
echo "interface=wlan0"
|
||||
echo "address=/config.kvm/${ipv4_prefix}.1"
|
||||
echo "no-hosts"
|
||||
echo "dhcp-range=${ipv4_prefix}.2,${ipv4_prefix}.254"
|
||||
echo "dhcp-option=6,${ipv4_prefix}.1"
|
||||
echo "dhcp-option=3,${ipv4_prefix}.1"
|
||||
echo "dhcp-authoritative"
|
||||
}
|
||||
|
||||
start() {
|
||||
echo "wifi mode: sta"
|
||||
ssid=""
|
||||
pass=""
|
||||
if [ -e /boot/wifi.ssid ] && [ -e /boot/wifi.pass ]; then
|
||||
echo "Updating WiFi credentials from /boot to /etc/kvm/"
|
||||
|
||||
rm -f /etc/kvm/wifi.ssid /etc/kvm/wifi.pass
|
||||
|
||||
mv /boot/wifi.ssid /etc/kvm/wifi.ssid
|
||||
mv /boot/wifi.pass /etc/kvm/wifi.pass
|
||||
|
||||
chown root:root /etc/kvm/wifi.ssid /etc/kvm/wifi.pass
|
||||
chmod 644 /etc/kvm/wifi.ssid /etc/kvm/wifi.pass
|
||||
fi
|
||||
if [ -e /etc/kvm/wifi.ssid ]; then
|
||||
ssid=$(cat /etc/kvm/wifi.ssid)
|
||||
fi
|
||||
if [ -e /etc/kvm/wifi.pass ]; then
|
||||
pass=$(cat /etc/kvm/wifi.pass)
|
||||
fi
|
||||
echo "ctrl_interface=/var/run/wpa_supplicant" >/etc/wpa_supplicant.conf
|
||||
wpa_passphrase "$ssid" "$pass" >>/etc/wpa_supplicant.conf
|
||||
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
|
||||
if [ ! -e /boot/wifi.nodhcp ]; then
|
||||
(udhcpc -i wlan0 -t 10 -T 1 -A 5 -b -p /run/udhcpc.wlan0.pid) &
|
||||
fi
|
||||
}
|
||||
|
||||
ap_start() {
|
||||
echo "wifi mode: ap"
|
||||
id2=$(printf "%d" 0x$(sha512sum /sys/class/cvi-base/base_uid | head -c 2))
|
||||
id3=$(printf "%d" 0x$(sha512sum /sys/class/cvi-base/base_uid | head -c 4 | tail -c 2))
|
||||
if [ "$id2" = "$id3" ]; then
|
||||
id2=$((id2 + 1))
|
||||
fi
|
||||
if [ "$id2" -ge 255 ]; then
|
||||
id2=253
|
||||
fi
|
||||
if [ "$id3" -ge 255 ]; then
|
||||
id3=254
|
||||
fi
|
||||
ssid=""
|
||||
pass=""
|
||||
if [ -e /kvmapp/kvm/ap.ssid ]; then
|
||||
ssid=$(cat /kvmapp/kvm/ap.ssid)
|
||||
fi
|
||||
if [ -e /kvmapp/kvm/ap.pass ]; then
|
||||
pass=$(cat /kvmapp/kvm/ap.pass)
|
||||
fi
|
||||
gen_hostapd_conf "$ssid" "$pass" >/etc/hostapd.conf
|
||||
ipv4_prefix=10.$id3.$id2
|
||||
if [ ! -e /etc/udhcpd.wlan0.conf ]; then
|
||||
gen_udhcpd_conf wlan0 "${ipv4_prefix}" >/etc/udhcpd.wlan0.conf
|
||||
fi
|
||||
# gen_dnsmasq_conf "${ipv4_prefix}" > /etc/dnsmasq.conf
|
||||
|
||||
# iptables --policy INPUT ACCEPT
|
||||
# iptables --policy FORWARD ACCEPT
|
||||
# iptables --policy OUTPUT ACCEPT
|
||||
# iptables -F
|
||||
# iptables -t nat -F
|
||||
# iptables -t nat -A PREROUTING -i wlan0 -p udp --dport 53 -j DNAT --to ${ipv4_prefix}.1
|
||||
|
||||
ifconfig wlan0 up
|
||||
ip route del default || true
|
||||
ip add flush dev wlan0
|
||||
ip addr add $ipv4_prefix.1/24 dev wlan0
|
||||
# dnsmasq --pid-file=/tmp/dnsmasq.run -C /etc/dnsmasq.conf
|
||||
hostapd -B -i wlan0 /etc/hostapd.conf
|
||||
udhcpd -S /etc/udhcpd.wlan0.conf
|
||||
|
||||
if [ ! -f "$APFLAG_FILE" ]; then
|
||||
touch "$APFLAG_FILE"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
stop() {
|
||||
ps -ef | grep hostapd | grep -v grep | awk '{print $1}' | xargs kill -2 || true
|
||||
ps -ef | grep "udhcpd -S /etc/udhcpd.wlan0.conf" | grep -v grep | awk '{print $1}' | xargs kill -2 || true
|
||||
killall wpa_supplicant || true
|
||||
if [ -e /run/udhcpc.wlan0.pid ]; then
|
||||
kill $(cat /run/udhcpc.wlan0.pid) || true
|
||||
rm -f /run/udhcpc.wlan0.pid
|
||||
fi
|
||||
if [ -e /var/run/udhcpd.wlan0.pid ]; then
|
||||
kill $(cat /var/run/udhcpd.wlan0.pid) || true
|
||||
rm -f /var/run/udhcpd.wlan0.pid
|
||||
fi
|
||||
if [ -e /tmp/dnsmasq.run ]; then
|
||||
kill $(cat /tmp/dnsmasq.run) || true
|
||||
rm -f /tmp/dnsmasq.run
|
||||
fi
|
||||
# if [ -e /etc/wpa_supplicant.conf]
|
||||
# then
|
||||
# echo > /etc/wpa_supplicant.conf
|
||||
# fi
|
||||
airmon-ng stop wlan0mon || true
|
||||
|
||||
if [ -f "$APFLAG_FILE" ]; then
|
||||
rm "$APFLAG_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
if [ "${1}" = "start" ]; then
|
||||
start
|
||||
elif [ "${1}" = "stop" ]; then
|
||||
stop
|
||||
elif [ "${1}" = "ap" ]; then
|
||||
stop
|
||||
ap_start
|
||||
elif [ "${1}" = "restart" ]; then
|
||||
restart
|
||||
fi
|
||||
20
kvmapp/system/init.d/S50avahi-daemon
Executable file
20
kvmapp/system/init.d/S50avahi-daemon
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# avahi-daemon init script
|
||||
|
||||
DAEMON=/usr/sbin/avahi-daemon
|
||||
case "$1" in
|
||||
start)
|
||||
$DAEMON -c || $DAEMON -D
|
||||
;;
|
||||
stop)
|
||||
$DAEMON -c && $DAEMON -k
|
||||
;;
|
||||
reload)
|
||||
$DAEMON -c && $DAEMON -r
|
||||
;;
|
||||
*)
|
||||
echo "Usage: S50avahi-daemon {start|stop|reload}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
49
kvmapp/system/init.d/S50ssdpd
Executable file
49
kvmapp/system/init.d/S50ssdpd
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
|
||||
DAEMON=ssdpd
|
||||
PIDFILE=/var/run/$DAEMON.pid
|
||||
CFGFILE=/etc/default/$DAEMON
|
||||
|
||||
DAEMON_ARGS=""
|
||||
|
||||
# Read configuration variable file if it is present
|
||||
# shellcheck source=/dev/null
|
||||
[ -r "$CFGFILE" ] && . "$CFGFILE"
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
start() {
|
||||
printf 'Starting %s: ' "$DAEMON"
|
||||
if start-stop-daemon -S -q -p "$PIDFILE" -x "$DAEMON" -- $DAEMON_ARGS; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
}
|
||||
|
||||
stop() {
|
||||
printf 'Stopping %s: ' "$DAEMON"
|
||||
if start-stop-daemon -K -q -p "$PIDFILE" -x "$DAEMON"; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start|stop|restart)
|
||||
"$1"
|
||||
;;
|
||||
reload)
|
||||
restart
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|reload}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
exit $?
|
||||
73
kvmapp/system/init.d/S50sshd
Executable file
73
kvmapp/system/init.d/S50sshd
Executable file
@@ -0,0 +1,73 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# sshd Starts sshd.
|
||||
#
|
||||
|
||||
# Ensure required binaries exist
|
||||
[ -x /usr/bin/ssh-keygen ] || exit 0
|
||||
[ -x /usr/sbin/sshd ] || exit 1
|
||||
|
||||
PIDFILE="/var/run/sshd.pid"
|
||||
|
||||
umask 077
|
||||
|
||||
startssh() {
|
||||
# Generate SSH keys if they do not exist
|
||||
[ ! -f /etc/ssh/ssh_host_rsa_key ] && /usr/bin/ssh-keygen -A
|
||||
|
||||
printf "Starting sshd: "
|
||||
/usr/sbin/sshd
|
||||
touch /var/lock/sshd
|
||||
echo "OK"
|
||||
}
|
||||
|
||||
start() {
|
||||
if [ -e /etc/kvm/ssh_stop ]; then
|
||||
if [ -e /boot/start_ssh_once ]; then
|
||||
rm -f /boot/start_ssh_once
|
||||
startssh
|
||||
else
|
||||
echo "SSH does not start"
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
startssh
|
||||
fi
|
||||
}
|
||||
|
||||
stop() {
|
||||
printf "Stopping sshd: "
|
||||
killall sshd 2>/dev/null
|
||||
rm -f /var/lock/sshd
|
||||
echo "OK"
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
restart|reload)
|
||||
restart
|
||||
;;
|
||||
permanent_on)
|
||||
rm -f /etc/kvm/ssh_stop
|
||||
start
|
||||
;;
|
||||
permanent_off)
|
||||
touch /etc/kvm/ssh_stop
|
||||
stop
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|permanent_on|permanent_off}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
exit 0
|
||||
29
kvmapp/system/init.d/S80dnsmasq
Executable file
29
kvmapp/system/init.d/S80dnsmasq
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
|
||||
DAEMON="dnsmasq"
|
||||
PIDFILE="/var/run/$DAEMON.pid"
|
||||
|
||||
[ -f /etc/dnsmasq.conf ] || exit 0
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
printf "Starting dnsmasq: "
|
||||
start-stop-daemon -S -p "$PIDFILE" -x "/usr/sbin/$DAEMON" -- \
|
||||
--pid-file="$PIDFILE"
|
||||
[ $? = 0 ] && echo "OK" || echo "FAIL"
|
||||
;;
|
||||
stop)
|
||||
printf "Stopping dnsmasq: "
|
||||
start-stop-daemon -K -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON"
|
||||
[ $? = 0 ] && echo "OK" || echo "FAIL"
|
||||
;;
|
||||
restart|reload)
|
||||
$0 stop
|
||||
$0 start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
exit 0
|
||||
144
kvmapp/system/init.d/S95nanokvm
Executable file
144
kvmapp/system/init.d/S95nanokvm
Executable file
@@ -0,0 +1,144 @@
|
||||
#!/bin/sh
|
||||
# nanokvm Rev3.1
|
||||
|
||||
wait_for_exit() {
|
||||
process="$1"
|
||||
timeout="$2"
|
||||
elapsed=0
|
||||
|
||||
while pidof "$process" >/dev/null 2>&1; do
|
||||
if [ "$elapsed" -ge "$timeout" ]; then
|
||||
return 1
|
||||
fi
|
||||
sleep 1
|
||||
elapsed=$((elapsed + 1))
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
stop_process() {
|
||||
process="$1"
|
||||
|
||||
if ! pidof "$process" >/dev/null 2>&1; then
|
||||
return
|
||||
fi
|
||||
|
||||
killall -INT "$process" 2>/dev/null || true
|
||||
if wait_for_exit "$process" 20; then
|
||||
return
|
||||
fi
|
||||
|
||||
killall -TERM "$process" 2>/dev/null || true
|
||||
if wait_for_exit "$process" 5; then
|
||||
return
|
||||
fi
|
||||
|
||||
killall -KILL "$process" 2>/dev/null || true
|
||||
wait_for_exit "$process" 2 || true
|
||||
}
|
||||
|
||||
stop_services() {
|
||||
# The server owns VI/VPSS. Let it release MMF before stopping kvm_system.
|
||||
stop_process NanoKVM-Server
|
||||
stop_process kvm_system
|
||||
rm -rf /tmp/kvm_system /tmp/server
|
||||
}
|
||||
|
||||
start_services() {
|
||||
cp -r /kvmapp/kvm_system /tmp/
|
||||
if [ -f /kvmapp/kvm_new_app ]; then
|
||||
touch /tmp/.nanokvm_migrating
|
||||
/tmp/kvm_system/kvm_system &
|
||||
|
||||
# The legacy migration invokes this init script recursively and starts
|
||||
# the server itself. Wait for that single migration path to finish.
|
||||
migration_wait=0
|
||||
while [ "$migration_wait" -lt 30 ]; do
|
||||
if [ ! -f /kvmapp/kvm_new_app ] && pidof NanoKVM-Server >/dev/null 2>&1; then
|
||||
rm -f /tmp/.nanokvm_migrating
|
||||
return
|
||||
fi
|
||||
sleep 1
|
||||
migration_wait=$((migration_wait + 1))
|
||||
done
|
||||
rm -f /tmp/.nanokvm_migrating
|
||||
else
|
||||
/tmp/kvm_system/kvm_system &
|
||||
fi
|
||||
|
||||
if ! pidof NanoKVM-Server >/dev/null 2>&1; then
|
||||
rm -rf /tmp/server
|
||||
cp -r /kvmapp/server /tmp/
|
||||
/tmp/server/NanoKVM-Server &
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
echo -n kvm > /boot/hostname.prefix
|
||||
[ -e /root/.profile ] || printf '%s\n' 'export PS1="\u@\h:\w# "' > /root/.profile
|
||||
|
||||
# Copy sensor config if the file exists
|
||||
[ -f /mnt/data/sensor_cfg.ini.LT ] && cp /mnt/data/sensor_cfg.ini.LT /mnt/data/sensor_cfg.ini
|
||||
|
||||
# Generate unique device key
|
||||
if [ -f /sys/class/cvi-base/base_uid ]; then
|
||||
str_value=$(awk '{print $2}' /sys/class/cvi-base/base_uid)
|
||||
first_uint=$(echo "$str_value" | cut -d'_' -f1)
|
||||
second_uint=$(echo "$str_value" | cut -d'_' -f2)
|
||||
echo "$first_uint$second_uint" > /device_key
|
||||
fi
|
||||
|
||||
# Set iptables rules (skip if already present)
|
||||
iptables -C INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT 2>/dev/null || \
|
||||
iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
|
||||
|
||||
iptables -C OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT 2>/dev/null || \
|
||||
iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
|
||||
|
||||
iptables -C INPUT -i eth0 -p tcp --sport 22 -m state --state NEW,ESTABLISHED -j ACCEPT 2>/dev/null || \
|
||||
iptables -A INPUT -i eth0 -p tcp --sport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
|
||||
|
||||
iptables -C OUTPUT -o eth0 -p tcp --dport 22 -m state --state ESTABLISHED -j ACCEPT 2>/dev/null || \
|
||||
iptables -A OUTPUT -o eth0 -p tcp --dport 22 -m state --state ESTABLISHED -j ACCEPT
|
||||
|
||||
iptables -C OUTPUT -o eth0 -p tcp --sport 8000 -m state --state ESTABLISHED -j DROP 2>/dev/null || \
|
||||
iptables -A OUTPUT -o eth0 -p tcp --sport 8000 -m state --state ESTABLISHED -j DROP
|
||||
|
||||
# Logo selection
|
||||
if [ -f /boot/logo.ico ]; then
|
||||
if [ ! -f /kvmapp/server/web/original.ico ]; then
|
||||
mv /kvmapp/server/web/sipeed.ico /kvmapp/server/web/original.ico
|
||||
cp /boot/logo.ico /kvmapp/server/web/sipeed.ico
|
||||
fi
|
||||
else
|
||||
if [ -f /kvmapp/server/web/original.ico ]; then
|
||||
mv /kvmapp/server/web/original.ico /kvmapp/server/web/sipeed.ico
|
||||
fi
|
||||
fi
|
||||
|
||||
# Start services
|
||||
start_services
|
||||
;;
|
||||
|
||||
stop)
|
||||
stop_services
|
||||
echo "OK"
|
||||
;;
|
||||
|
||||
restart)
|
||||
if [ -f /tmp/.nanokvm_migrating ]; then
|
||||
exit 0
|
||||
fi
|
||||
stop_services
|
||||
start_services
|
||||
|
||||
sync
|
||||
echo "OK"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
249
kvmapp/system/init.d/S96picoclaw
Executable file
249
kvmapp/system/init.d/S96picoclaw
Executable file
@@ -0,0 +1,249 @@
|
||||
#!/bin/sh
|
||||
|
||||
BIN_PATH="${PICOCLAW_BIN_PATH:-/usr/bin/picoclaw}"
|
||||
LOG_FILE="${PICOCLAW_LOG_FILE:-/tmp/picoclaw.log}"
|
||||
BIN_NAME="$(basename "$BIN_PATH")"
|
||||
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
||||
|
||||
resolve_user_home() {
|
||||
user_name="$(id -un 2>/dev/null || echo root)"
|
||||
user_home="$(awk -F: -v user="$user_name" '$1 == user { print $6; exit }' /etc/passwd)"
|
||||
if [ -n "$user_home" ] && [ -d "$user_home" ]; then
|
||||
printf '%s\n' "$user_home"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -n "${HOME:-}" ] && [ -d "${HOME}" ]; then
|
||||
printf '%s\n' "$HOME"
|
||||
return 0
|
||||
fi
|
||||
|
||||
printf '%s\n' "/root"
|
||||
}
|
||||
|
||||
setup_picoclaw_home() {
|
||||
USER_HOME="$(resolve_user_home)"
|
||||
PICOCLAW_HOME="${PICOCLAW_HOME:-$USER_HOME/.picoclaw}"
|
||||
HOME="$USER_HOME"
|
||||
export HOME
|
||||
export PICOCLAW_HOME
|
||||
|
||||
mkdir -p "$PICOCLAW_HOME" || {
|
||||
echo "failed to create picoclaw home: $PICOCLAW_HOME"
|
||||
return 1
|
||||
}
|
||||
PICOCLAW_PID_FILE="${PICOCLAW_PID_FILE:-$PICOCLAW_HOME/.picoclaw.pid}"
|
||||
export PICOCLAW_PID_FILE
|
||||
|
||||
cd "$PICOCLAW_HOME" || {
|
||||
echo "failed to enter picoclaw home: $PICOCLAW_HOME"
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
setup_runtime_env() {
|
||||
[ -x "$BIN_PATH" ] || {
|
||||
echo "picoclaw binary not found: $BIN_PATH"
|
||||
return 1
|
||||
}
|
||||
|
||||
setup_picoclaw_home || return 1
|
||||
}
|
||||
|
||||
read_pid_file() {
|
||||
[ -f "$PICOCLAW_PID_FILE" ] || return 1
|
||||
pid="$(sed -n '1p' "$PICOCLAW_PID_FILE" 2>/dev/null | tr -d '[:space:]')"
|
||||
case "$pid" in
|
||||
''|*[!0-9]*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
printf '%s\n' "$pid"
|
||||
}
|
||||
|
||||
is_gateway_pid() {
|
||||
pid="$1"
|
||||
[ -n "$pid" ] || return 1
|
||||
[ -r "/proc/$pid/cmdline" ] || return 1
|
||||
|
||||
cmd_path="$(tr '\000' '\n' <"/proc/$pid/cmdline" 2>/dev/null | sed -n '1p')"
|
||||
subcommand="$(tr '\000' '\n' <"/proc/$pid/cmdline" 2>/dev/null | sed -n '2p')"
|
||||
[ "$(basename "$cmd_path")" = "$BIN_NAME" ] && [ "$subcommand" = "gateway" ] && return 0
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
find_gateway_pid() {
|
||||
for proc_dir in /proc/[0-9]*; do
|
||||
[ -d "$proc_dir" ] || continue
|
||||
pid="${proc_dir#/proc/}"
|
||||
if is_gateway_pid "$pid"; then
|
||||
printf '%s\n' "$pid"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
cleanup_stale_pid_file() {
|
||||
[ -f "$PICOCLAW_PID_FILE" ] || return 0
|
||||
pid="$(read_pid_file 2>/dev/null)" || {
|
||||
rm -f "$PICOCLAW_PID_FILE"
|
||||
return 0
|
||||
}
|
||||
if ! is_gateway_pid "$pid"; then
|
||||
echo "picoclaw stale pid file removed: $PICOCLAW_PID_FILE"
|
||||
rm -f "$PICOCLAW_PID_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
gateway_running_pid() {
|
||||
pid="$(read_pid_file 2>/dev/null)" && is_gateway_pid "$pid" && {
|
||||
printf '%s\n' "$pid"
|
||||
return 0
|
||||
}
|
||||
|
||||
cleanup_stale_pid_file
|
||||
pid="$(find_gateway_pid 2>/dev/null)" || return 1
|
||||
printf '%s\n' "$pid" >"$PICOCLAW_PID_FILE" 2>/dev/null || true
|
||||
printf '%s\n' "$pid"
|
||||
}
|
||||
|
||||
resolve_kvm_control_source() {
|
||||
for candidate in \
|
||||
"/kvmapp/picoclaw/skills/kvm-control" \
|
||||
"/kvmapp/skills/kvm-control" \
|
||||
"$SCRIPT_DIR/../../../picoclaw/skills/kvm-control"
|
||||
do
|
||||
if [ -d "$candidate" ] && [ -f "$candidate/SKILL.md" ]; then
|
||||
printf '%s\n' "$candidate"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
sync_kvm_control_skill() {
|
||||
source_dir="$(resolve_kvm_control_source)" || {
|
||||
echo "kvm-control skill source not found"
|
||||
return 1
|
||||
}
|
||||
|
||||
skills_dir="$PICOCLAW_HOME/workspace/skills"
|
||||
target_dir="$skills_dir/kvm-control"
|
||||
mkdir -p "$skills_dir" || {
|
||||
echo "failed to create skills directory: $skills_dir"
|
||||
return 1
|
||||
}
|
||||
|
||||
rm -rf "$target_dir" || {
|
||||
echo "failed to remove old kvm-control skill: $target_dir"
|
||||
return 1
|
||||
}
|
||||
|
||||
cp -R "$source_dir" "$target_dir" || {
|
||||
echo "failed to copy kvm-control skill to $target_dir"
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
sync_agent_profile() {
|
||||
source_file="/kvmapp/picoclaw/AGENT_KVM.md"
|
||||
target_file="$PICOCLAW_HOME/workspace/AGENT.md"
|
||||
workspace_dir="$PICOCLAW_HOME/workspace"
|
||||
|
||||
[ -f "$source_file" ] || {
|
||||
echo "agent profile source not found: $source_file"
|
||||
return 1
|
||||
}
|
||||
|
||||
mkdir -p "$workspace_dir" || {
|
||||
echo "failed to create workspace directory: $workspace_dir"
|
||||
return 1
|
||||
}
|
||||
|
||||
cp -f "$source_file" "$target_file" || {
|
||||
echo "failed to copy agent profile to $target_file"
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
start_service() {
|
||||
setup_runtime_env || return 1
|
||||
|
||||
if pid="$(gateway_running_pid)"; then
|
||||
echo "picoclaw gateway already running (PID: $pid)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ ! -f "$PICOCLAW_HOME/config.json" ]; then
|
||||
echo "picoclaw config not found: $PICOCLAW_HOME/config.json"
|
||||
return 1
|
||||
fi
|
||||
|
||||
"$BIN_PATH" gateway >>"$LOG_FILE" 2>&1 &
|
||||
gateway_pid="$!"
|
||||
printf '%s\n' "$gateway_pid" >"$PICOCLAW_PID_FILE" || {
|
||||
echo "failed to write picoclaw pid file: $PICOCLAW_PID_FILE"
|
||||
return 1
|
||||
}
|
||||
echo "picoclaw gateway started (PID: $gateway_pid)"
|
||||
}
|
||||
|
||||
onboard_service() {
|
||||
setup_runtime_env || return 1
|
||||
"$BIN_PATH" onboard >>"$LOG_FILE" 2>&1 || return 1
|
||||
sync_kvm_control_skill || return 1
|
||||
sync_agent_profile || return 1
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
setup_picoclaw_home || return 1
|
||||
|
||||
pid="$(gateway_running_pid 2>/dev/null)" || {
|
||||
cleanup_stale_pid_file
|
||||
return 0
|
||||
}
|
||||
|
||||
kill "$pid" 2>/dev/null || true
|
||||
count=0
|
||||
while is_gateway_pid "$pid"; do
|
||||
count=$((count + 1))
|
||||
if [ "$count" -ge 15 ]; then
|
||||
echo "picoclaw gateway did not stop after TERM, killing PID: $pid"
|
||||
kill -9 "$pid" 2>/dev/null || true
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
rm -f "$PICOCLAW_PID_FILE"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start_service
|
||||
;;
|
||||
|
||||
stop)
|
||||
stop_service
|
||||
echo "OK"
|
||||
;;
|
||||
|
||||
onboard)
|
||||
onboard_service
|
||||
;;
|
||||
|
||||
restart)
|
||||
stop_service
|
||||
start_service
|
||||
echo "OK"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|onboard|restart}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
89
kvmapp/system/init.d/S98tailscaled
Executable file
89
kvmapp/system/init.d/S98tailscaled
Executable file
@@ -0,0 +1,89 @@
|
||||
#!/bin/sh
|
||||
|
||||
DAEMON="tailscaled"
|
||||
PIDFILE="/var/run/$DAEMON.pid"
|
||||
|
||||
# Set the port to listen on for incoming VPN packets.
|
||||
# Remote nodes will automatically be informed about the new port number,
|
||||
# but you might want to configure this in order to set external firewall
|
||||
# settings.
|
||||
PORT="41641"
|
||||
|
||||
# Extra flags you might want to pass to tailscaled.
|
||||
FLAGS=""
|
||||
|
||||
# You need tailscaled at /usr/sbin to server, and tailscale at /usr/bin to operate
|
||||
# STATIC version needed. Download page at https://pkgs.tailscale.com/stable/#static
|
||||
PKG_URL_LATEST="https://pkgs.tailscale.com/stable/tailscale_latest_riscv64.tgz"
|
||||
[ ! -x /usr/sbin/$DAEMON ] &&
|
||||
echo "/usr/sbin/$DAEMON not found, please download it from $PKG_URL_LATEST" &&
|
||||
echo "Then unpack it, copy $DAEMON to /usr/sbin and copy tailscale to /usr/bin" &&
|
||||
exit 1
|
||||
VERSION=$(/usr/sbin/$DAEMON --version|sed -n '1p'|xargs echo -n)
|
||||
|
||||
[ -x /usr/bin/tailscale ] ||
|
||||
(echo "/usr/bin/tailscale not found, your installation of tailscale may be broken" && exit 1)
|
||||
|
||||
# Clean up old forwarding configuration if it exists
|
||||
if [ -f /etc/sysctl.d/99-tailscale.conf ]; then
|
||||
echo "Found old forwarding configuration, cleaning up..."
|
||||
rm -f /etc/sysctl.d/99-tailscale.conf
|
||||
sysctl -w net.ipv4.ip_forward=0 >/dev/null 2>&1
|
||||
sysctl -w net.ipv6.conf.all.forwarding=0 >/dev/null 2>&1
|
||||
echo "Cleanup completed. IPv4/IPv6 forwarding disabled."
|
||||
|
||||
# Trigger IPv6 address renewal on all interfaces
|
||||
for iface in $(ls /sys/class/net/ | grep -v lo); do
|
||||
echo 0 > /proc/sys/net/ipv6/conf/$iface/forwarding 2>/dev/null
|
||||
sysctl -w net.ipv6.conf.$iface.accept_ra=2 >/dev/null 2>&1
|
||||
done
|
||||
|
||||
echo "If you need exit node features, please configure manually."
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
if [ -f /etc/kvm/GOMEMLIMIT ]; then
|
||||
value=$(cat /etc/kvm/GOMEMLIMIT)
|
||||
export GOMEMLIMIT="${value}MiB"
|
||||
else
|
||||
export GOMEMLIMIT=512MiB
|
||||
fi
|
||||
|
||||
echo "GOMEMLIMIT set to ${GOMEMLIMIT}"
|
||||
|
||||
# Ensure directories exist
|
||||
mkdir -p /var/lib/tailscale /var/run/tailscale
|
||||
|
||||
printf "Starting $DAEMON[$VERSION]: "
|
||||
start-stop-daemon -S -bmq -p "$PIDFILE" -x "/usr/sbin/$DAEMON" -- \
|
||||
--state=/var/lib/tailscale/tailscaled.state \
|
||||
--socket=/var/run/tailscale/tailscaled.sock \
|
||||
--port=${PORT} \
|
||||
$FLAGS
|
||||
if [ $? = 0 ]; then
|
||||
sleep 5
|
||||
echo "OK"
|
||||
tailscale set --accept-dns=false
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
;;
|
||||
stop)
|
||||
printf "Stopping $DAEMON: "
|
||||
start-stop-daemon -K -p "$PIDFILE"
|
||||
[ $? = 0 ] && (echo "OK"; rm -f "$PIDFILE") || echo "FAIL"
|
||||
printf "cleaning tailscaled: "
|
||||
/usr/sbin/$DAEMON --cleanup >/dev/null 2>&1
|
||||
[ $? = 0 ] && echo "OK" || echo "FAIL"
|
||||
;;
|
||||
restart|reload)
|
||||
$0 stop
|
||||
$0 start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
exit 0
|
||||
BIN
kvmapp/system/ko/soph_mipi_rx.ko
Normal file
BIN
kvmapp/system/ko/soph_mipi_rx.ko
Normal file
Binary file not shown.
96
kvmapp/system/update-nanokvm.py
Executable file
96
kvmapp/system/update-nanokvm.py
Executable file
@@ -0,0 +1,96 @@
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
import zipfile
|
||||
import pathlib
|
||||
import requests
|
||||
|
||||
temporary: str = "/root/.kvm-cache/"
|
||||
|
||||
|
||||
def mkdir() -> None:
|
||||
if pathlib.Path(temporary).exists():
|
||||
shutil.rmtree(temporary)
|
||||
pathlib.Path(temporary).mkdir()
|
||||
print(f"Created temporary directory {temporary}")
|
||||
|
||||
|
||||
def read(file: str) -> str:
|
||||
return pathlib.Path(file).read_text().replace("\n", "")
|
||||
|
||||
|
||||
def download_firmware() -> None:
|
||||
print("Downloading firmware...")
|
||||
|
||||
now = int(time.time())
|
||||
url = f"https://cdn.sipeed.com/nanokvm/latest.zip?n={now}"
|
||||
print(f"Downloading firmware from {url}")
|
||||
|
||||
response = requests.get(url)
|
||||
|
||||
if response.status_code != 200:
|
||||
raise Exception(f"Failed to download firmware, status: {response.status_code}")
|
||||
|
||||
content_type = response.headers.get("content-type")
|
||||
if content_type != "application/zip":
|
||||
raise Exception(f"Failed to download firmware, content_type: {content_type}")
|
||||
|
||||
zip_file = f"{temporary}/latest.zip"
|
||||
with open(zip_file, "wb") as f:
|
||||
for chunk in response.iter_content(chunk_size=1024):
|
||||
f.write(chunk)
|
||||
|
||||
with zipfile.ZipFile(zip_file, "r") as f:
|
||||
f.extractall(temporary)
|
||||
|
||||
print("Completed downloading firmware.")
|
||||
|
||||
|
||||
def update() -> None:
|
||||
backup_dir = pathlib.Path("/root/old")
|
||||
firmware_dir = pathlib.Path("/kvmapp")
|
||||
|
||||
if backup_dir.exists():
|
||||
shutil.rmtree(backup_dir)
|
||||
|
||||
if firmware_dir.exists():
|
||||
firmware_dir.rename(backup_dir)
|
||||
|
||||
pathlib.Path(f"{temporary}/latest").rename(firmware_dir)
|
||||
|
||||
|
||||
def change_permissions() -> None:
|
||||
for root, dirs, files in os.walk("/kvmapp"):
|
||||
os.chmod(root, 0o755)
|
||||
|
||||
for file in files:
|
||||
file_path = os.path.join(root, file)
|
||||
os.chmod(file_path, 0o755)
|
||||
|
||||
print("change permissions done")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
try:
|
||||
print("Stopping nanokvm service...")
|
||||
os.system("/etc/init.d/S95nanokvm stop")
|
||||
|
||||
print("Staring update...")
|
||||
|
||||
mkdir()
|
||||
download_firmware()
|
||||
update()
|
||||
change_permissions()
|
||||
|
||||
version = read("/kvmapp/version")
|
||||
print(f"Successfully updated to version: {version}")
|
||||
print("restart service\nthe nanokvm will reboot")
|
||||
except Exception as e:
|
||||
print(f"update failed\n{e}")
|
||||
finally:
|
||||
shutil.rmtree(temporary)
|
||||
os.system("/etc/init.d/S95nanokvm restart")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
102
scripts/README.md
Normal file
102
scripts/README.md
Normal file
@@ -0,0 +1,102 @@
|
||||
# Release packaging
|
||||
|
||||
These scripts assemble the application update package that NanoKVM devices pull
|
||||
over the air: `nanokvm_<version>.tar.gz` plus its `latest.json` manifest.
|
||||
|
||||
| Script | Purpose |
|
||||
|---|---|
|
||||
| `build-in-container.sh` | Builds every riscv64 artifact (`kvm_system`, `libkvm.so`, `NanoKVM-Server`). Runs inside the `nanokvm-builder` image only. |
|
||||
| `package.sh` | Stages the package tree, creates the tarball, and writes `latest.json`. |
|
||||
| `compare-release.sh` | Diffs a freshly built package against the currently published one. Informational. |
|
||||
| `verify-release-assets.sh` | Checks the three GitHub Release assets before publishing or promotion. |
|
||||
| `verify-release-tag.sh` | Requires an annotated numeric tag whose commit is on `main`. |
|
||||
|
||||
## What the updater expects
|
||||
|
||||
The format is not arbitrary — it is fixed by the on-device updater in
|
||||
`server/service/application/`:
|
||||
|
||||
- **One safe root directory.** The updater scans before extracting and accepts
|
||||
only directories and regular files under `nanokvm_<version>/`; links,
|
||||
special files, duplicate paths, and path traversal are rejected.
|
||||
- **`name` is the file name.** `version.go` builds the download URL as
|
||||
`<base>/<name>`, where `<base>` is `https://cdn.sipeed.com/nanokvm` (or
|
||||
`.../preview` when `/etc/kvm/preview_updates` exists).
|
||||
- **`sha512` is base64, not hex.** `update.go` compares against
|
||||
`base64(raw sha512 digest)`. A hex digest will fail verification on device.
|
||||
- **`/kvmapp/version`** is what the device reports as its installed version, so
|
||||
it must match the `version` field.
|
||||
|
||||
New releases use manifest v2. `size` remains the exact compressed byte count
|
||||
for older clients, while v2 clients use `size_bytes` and
|
||||
`unpacked_size_bytes` for storage preflight checks. Historical v1 `size`
|
||||
values have inconsistent units, so v2 clients only require v1 `size` to be
|
||||
non-zero and verify the downloaded SHA-512 instead. Publish v2 metadata before
|
||||
releasing clients that consume it; clients retain v1 compatibility for custom
|
||||
update servers.
|
||||
|
||||
## Building a release
|
||||
|
||||
The frontend needs Node and pnpm on the host; everything riscv64 needs the
|
||||
builder image (see `docker/Dockerfile`).
|
||||
|
||||
```bash
|
||||
make release VERSION=2.4.4
|
||||
```
|
||||
|
||||
That is equivalent to:
|
||||
|
||||
```bash
|
||||
make release-build # kvm_system + libkvm.so + NanoKVM-Server, in Docker
|
||||
make web # web/dist
|
||||
make package VERSION=2.4.4 # build/release/{nanokvm_2.4.4.tar.gz,latest.json}
|
||||
```
|
||||
|
||||
In CI this runs as the **NanoKVM Package** workflow. Pull requests and manual
|
||||
runs only create Actions artifacts. For a public release, run **NanoKVM Create
|
||||
Tag**, then run **NanoKVM Release** and choose prerelease, stable, or promotion.
|
||||
Publishing attaches three assets:
|
||||
|
||||
Publishing is one-shot: an existing Release or draft is an error, and only a
|
||||
published prerelease can be promoted.
|
||||
|
||||
- `nanokvm_<version>.tar.gz`
|
||||
- `latest.json`
|
||||
- `sha256.txt`
|
||||
|
||||
The Actions artifact also includes `BUILD_INFO.txt` with the source commit,
|
||||
workflow run, immutable builder image digest, and both checksum encodings; that
|
||||
provenance file is not attached to the GitHub release. Uploading the tarball and
|
||||
`latest.json` to the CDN is what actually offers the update to devices in the
|
||||
field, so that step stays manual. `sha256.txt` is only for users verifying a
|
||||
manual download and does not change the on-device `latest.json` contract.
|
||||
|
||||
## Where each file in the package comes from
|
||||
|
||||
| Package path | Source |
|
||||
|---|---|
|
||||
| `version` | the requested version |
|
||||
| `server/NanoKVM-Server` | `server/build.sh` (BoringCrypto, RPATH `$ORIGIN/dl_lib`) |
|
||||
| `server/dl_lib/` | whatever the `kvm_vision` build emits, with any library it does not emit backfilled from the tracked `server/dl_lib/` |
|
||||
| `server/web/` | `web/dist/` |
|
||||
| `kvm_system/kvm_system` | `support/sg2002` `build kvm_system` |
|
||||
| `system/tool/` | prebuilt binaries in `tools/nanokvm_update_edid/` |
|
||||
| `kvm/` | default runtime state (resolution, fps, quality) |
|
||||
| everything else | tracked `kvmapp/` |
|
||||
|
||||
Note that `kvm/` ships default runtime state, and `install.go` replaces
|
||||
`/kvmapp` wholesale, so an update resets those values on the device. That is
|
||||
long-standing behaviour, not something these scripts introduce.
|
||||
|
||||
## The two copies of libkvm.so
|
||||
|
||||
`NanoKVM-Server` is cgo-linked against the **tracked** `server/dl_lib/libkvm.so`
|
||||
(`server/common/kvm_vision.go`: `-L../dl_lib -lkvm`), but the package ships the
|
||||
library the `kvm_vision` build just produced. Those are two different files, and
|
||||
the tracked one can lag well behind — published releases have shipped this
|
||||
mismatch for a long time.
|
||||
|
||||
Because a symbol the binary imports could in principle be absent from the
|
||||
shipped library, and that would only surface as a crash on a real device,
|
||||
`build-in-container.sh` checks the shipped `libkvm.so` still exports every
|
||||
symbol `NanoKVM-Server` actually imports from it, and fails the build otherwise.
|
||||
144
scripts/build-in-container.sh
Executable file
144
scripts/build-in-container.sh
Executable file
@@ -0,0 +1,144 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Build every riscv64 artifact of a release, from inside the nanokvm-builder
|
||||
# image (docker/Dockerfile). Not meant to be run on the host: it needs the
|
||||
# riscv64 musl toolchain and the patched MaixCDK checkout that the image ships.
|
||||
#
|
||||
# Produces:
|
||||
# kvmapp/kvm_system/kvm_system kvm_system daemon
|
||||
# kvmapp/server/dl_lib/ video libraries, including a fresh libkvm.so
|
||||
# server/NanoKVM-Server Go server (BoringCrypto, RPATH $ORIGIN/dl_lib)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# docker/entrypoint sets HOME for the build user. support/sg2002/build resolves
|
||||
# both MaixCDK and the source tree through ~, so a wrong HOME would send the
|
||||
# whole build at /root; say so plainly rather than emitting "directory missing".
|
||||
BUILD_HOME="${BUILD_HOME:-/home/build}"
|
||||
if [ "${HOME:-}" != "$BUILD_HOME" ]; then
|
||||
echo "[ERROR] HOME is '${HOME:-unset}', expected $BUILD_HOME" >&2
|
||||
echo " run this inside the builder image via the Makefile" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MAIXCDK_PATH="$HOME/MaixCDK"
|
||||
NANOKVM_PATH="$HOME/NanoKVM"
|
||||
|
||||
for dir in "$MAIXCDK_PATH" "$NANOKVM_PATH"; do
|
||||
if [ ! -d "$dir" ]; then
|
||||
echo "[ERROR] $dir not found - is this running inside nanokvm-builder?" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Check the toolchain up front. builder-image reuses any existing image, so an
|
||||
# image built before a tooling change silently lacks it - and without this the
|
||||
# SDK build would run for minutes before server/build.sh failed at the end.
|
||||
for tool in go riscv64-unknown-linux-musl-gcc patchelf; do
|
||||
if ! command -v "$tool" >/dev/null 2>&1; then
|
||||
echo "[ERROR] '$tool' is missing from the builder image" >&2
|
||||
echo " the image is out of date; rebuild it with: make rebuild-image" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# The SDK tree is owned by the ids baked into the image (DOCKER_UID/DOCKER_GID),
|
||||
# while the entrypoint drops to the caller's ids. If they disagree, syncing
|
||||
# components fails partway through a long build; catch it here instead.
|
||||
if [ ! -w "$MAIXCDK_PATH/components" ]; then
|
||||
echo "[ERROR] $MAIXCDK_PATH/components is not writable by $(id -u):$(id -g)" >&2
|
||||
echo " the image was built for different ids; rebuild it with:" >&2
|
||||
echo " make rebuild-image" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
. "$MAIXCDK_PATH/bin/activate"
|
||||
|
||||
echo "::group::support: sync MaixCDK components"
|
||||
cd "$NANOKVM_PATH/support/sg2002"
|
||||
# The image bakes support/sg2002/additional/ into MaixCDK's components at image
|
||||
# build time, and ./build only re-copies them when components/kvm is missing.
|
||||
# Refresh unconditionally so a cached image never yields stale libraries.
|
||||
./build update_lib
|
||||
echo "::endgroup::"
|
||||
|
||||
echo "::group::support: build kvm_system"
|
||||
./build kvm_system
|
||||
./build kvm_system add_to_kvmapp
|
||||
echo "::endgroup::"
|
||||
|
||||
echo "::group::support: build kvm_vision (libkvm.so)"
|
||||
./build kvm_vision
|
||||
./build kvm_vision add_to_kvmapp
|
||||
echo "::endgroup::"
|
||||
|
||||
echo "::group::server: cross-compile NanoKVM-Server"
|
||||
cd "$NANOKVM_PATH/server"
|
||||
./build.sh
|
||||
echo "::endgroup::"
|
||||
|
||||
# support/sg2002/build reports "Build Error!" without a non-zero exit status for
|
||||
# some failure paths, so assert on the artifacts rather than trusting $?.
|
||||
echo "[INFO] verifying artifacts"
|
||||
missing=0
|
||||
for artifact in \
|
||||
"$NANOKVM_PATH/kvmapp/kvm_system/kvm_system" \
|
||||
"$NANOKVM_PATH/kvmapp/server/dl_lib/libkvm.so" \
|
||||
"$NANOKVM_PATH/server/NanoKVM-Server"
|
||||
do
|
||||
if [ -f "$artifact" ]; then
|
||||
echo " ok ${artifact#$NANOKVM_PATH/}"
|
||||
else
|
||||
echo " MISSING ${artifact#$NANOKVM_PATH/}" >&2
|
||||
missing=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$missing" -ne 0 ]; then
|
||||
echo "[ERROR] build did not produce all expected artifacts" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# NanoKVM-Server is cgo-linked against the tracked server/dl_lib/libkvm.so
|
||||
# (server/common/kvm_vision.go: -L../dl_lib -lkvm), but the package ships the
|
||||
# freshly built one from kvm_vision. Those are different files, so confirm the
|
||||
# shipped library still exports every symbol the binary actually imports from
|
||||
# it. Without this a dropped symbol only shows up as a crash on a real device.
|
||||
echo "[INFO] verifying shipped libkvm.so satisfies NanoKVM-Server"
|
||||
if ! command -v readelf >/dev/null 2>&1; then
|
||||
echo "[WARN] readelf unavailable, skipping ABI check"
|
||||
else
|
||||
exported() {
|
||||
readelf --dyn-syms --wide "$1" 2>/dev/null \
|
||||
| awk '$7 != "UND" && $8 != "" { print $8 }' \
|
||||
| sed 's/@.*//' | LC_ALL=C sort -u
|
||||
}
|
||||
imported() {
|
||||
readelf --dyn-syms --wide "$1" 2>/dev/null \
|
||||
| awk '$7 == "UND" && $8 != "" { print $8 }' \
|
||||
| sed 's/@.*//' | LC_ALL=C sort -u
|
||||
}
|
||||
|
||||
linked_lib="$NANOKVM_PATH/server/dl_lib/libkvm.so"
|
||||
shipped_lib="$NANOKVM_PATH/kvmapp/server/dl_lib/libkvm.so"
|
||||
server_bin="$NANOKVM_PATH/server/NanoKVM-Server"
|
||||
|
||||
# Symbols the binary imports that the link-time library provides, i.e. the
|
||||
# ones libkvm.so is actually responsible for at runtime.
|
||||
needed=$(comm -12 <(imported "$server_bin") <(exported "$linked_lib"))
|
||||
|
||||
if [ -z "$needed" ]; then
|
||||
echo "[WARN] no libkvm symbols resolved; skipping ABI check"
|
||||
else
|
||||
absent=$(comm -23 <(printf '%s\n' "$needed") <(exported "$shipped_lib"))
|
||||
if [ -n "$absent" ]; then
|
||||
echo "[ERROR] shipped libkvm.so is missing symbols NanoKVM-Server needs:" >&2
|
||||
printf ' %s\n' $absent >&2
|
||||
exit 1
|
||||
fi
|
||||
echo " ok $(printf '%s\n' "$needed" | wc -l | tr -d ' ') libkvm symbols resolve"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "[DONE] riscv64 artifacts built"
|
||||
103
scripts/compare-release.sh
Executable file
103
scripts/compare-release.sh
Executable file
@@ -0,0 +1,103 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Compare a freshly built package against the currently published release.
|
||||
#
|
||||
# Purely informational: it exits 0 whatever it finds. The point is to make the
|
||||
# delta reviewable before the tarball is published, since the package is what
|
||||
# every device pulls over OTA. Unexpected entries here (a library that vanished,
|
||||
# an init script that changed without a matching commit) are worth a look.
|
||||
#
|
||||
# Usage: scripts/compare-release.sh <new-tarball> [base-url]
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
NEW_TARBALL="${1:-}"
|
||||
BASE_URL="${2:-https://cdn.sipeed.com/nanokvm}"
|
||||
|
||||
if [ -z "$NEW_TARBALL" ] || [ ! -f "$NEW_TARBALL" ]; then
|
||||
echo "Usage: $0 <new-tarball> [base-url]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
WORK="$(mktemp -d)"
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
|
||||
echo "[INFO] fetching published manifest from $BASE_URL/latest.json"
|
||||
if ! curl -fsSL "$BASE_URL/latest.json" -o "$WORK/latest.json"; then
|
||||
echo "[WARN] could not fetch latest.json - skipping comparison"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
cat "$WORK/latest.json"
|
||||
|
||||
OLD_NAME="$(sed -n 's/.*"name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$WORK/latest.json")"
|
||||
if [ -z "$OLD_NAME" ]; then
|
||||
echo "[WARN] no \"name\" in latest.json - skipping comparison"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "[INFO] downloading published package $OLD_NAME"
|
||||
if ! curl -fsSL "$BASE_URL/$OLD_NAME" -o "$WORK/$OLD_NAME"; then
|
||||
echo "[WARN] could not download $OLD_NAME - skipping comparison"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
mkdir -p "$WORK/old" "$WORK/new"
|
||||
if ! tar xzf "$WORK/$OLD_NAME" -C "$WORK/old"; then
|
||||
echo "[WARN] could not extract $OLD_NAME - skipping comparison"
|
||||
exit 0
|
||||
fi
|
||||
if ! tar xzf "$NEW_TARBALL" -C "$WORK/new"; then
|
||||
echo "[WARN] could not extract $(basename "$NEW_TARBALL") - skipping comparison"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Strip the nanokvm_<version>/ prefix so the two trees are comparable.
|
||||
OLD_ROOT="$(find "$WORK/old" -mindepth 1 -maxdepth 1 -type d | head -1)"
|
||||
NEW_ROOT="$(find "$WORK/new" -mindepth 1 -maxdepth 1 -type d | head -1)"
|
||||
|
||||
if [ -z "$OLD_ROOT" ] || [ -z "$NEW_ROOT" ]; then
|
||||
echo "[WARN] could not locate a package root directory - skipping comparison"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
( cd "$OLD_ROOT" && find . -type f | sed 's|^\./||' | LC_ALL=C sort ) > "$WORK/old.list"
|
||||
( cd "$NEW_ROOT" && find . -type f | sed 's|^\./||' | LC_ALL=C sort ) > "$WORK/new.list"
|
||||
|
||||
# An empty inventory would make every section below print "(none)", which reads
|
||||
# identically to "verified, nothing changed". Refuse to imply that.
|
||||
if [ ! -s "$WORK/old.list" ] || [ ! -s "$WORK/new.list" ]; then
|
||||
echo "[WARN] one of the packages produced an empty file list - comparison unreliable, skipping"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "=============================================================="
|
||||
echo " $(basename "$OLD_ROOT") -> $(basename "$NEW_ROOT")"
|
||||
echo "=============================================================="
|
||||
printf ' files: %s -> %s\n' "$(wc -l < "$WORK/old.list" | tr -d ' ')" \
|
||||
"$(wc -l < "$WORK/new.list" | tr -d ' ')"
|
||||
|
||||
echo
|
||||
echo "--- added ----------------------------------------------------"
|
||||
comm -13 "$WORK/old.list" "$WORK/new.list" | sed 's/^/ + /' || true
|
||||
|
||||
echo
|
||||
echo "--- removed --------------------------------------------------"
|
||||
comm -23 "$WORK/old.list" "$WORK/new.list" | sed 's/^/ - /' || true
|
||||
|
||||
echo
|
||||
echo "--- changed --------------------------------------------------"
|
||||
changed=0
|
||||
while IFS= read -r file; do
|
||||
if ! cmp -s "$OLD_ROOT/$file" "$NEW_ROOT/$file"; then
|
||||
old_size="$(wc -c < "$OLD_ROOT/$file" | tr -d ' ')"
|
||||
new_size="$(wc -c < "$NEW_ROOT/$file" | tr -d ' ')"
|
||||
printf ' ~ %-52s %s -> %s bytes\n' "$file" "$old_size" "$new_size"
|
||||
changed=$((changed + 1))
|
||||
fi
|
||||
done < <(comm -12 "$WORK/old.list" "$WORK/new.list")
|
||||
[ "$changed" -eq 0 ] && echo " (none)"
|
||||
|
||||
echo
|
||||
echo "[INFO] comparison complete"
|
||||
231
scripts/package.sh
Executable file
231
scripts/package.sh
Executable file
@@ -0,0 +1,231 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Assemble a NanoKVM release package: nanokvm_<version>.tar.gz + latest.json.
|
||||
#
|
||||
# The layout and the manifest fields are dictated by the on-device updater:
|
||||
# - server/service/application/version.go parses latest.json and derives the
|
||||
# download URL as "<base>/<name>", so "name" must be the tarball file name.
|
||||
# - server/service/application/update.go verifies the download against
|
||||
# "sha512", which is the *base64* encoding of the raw SHA-512 digest.
|
||||
# - server/service/application/archive.go validates and extracts the package
|
||||
# before install.go moves its single top-level directory over /kvmapp, so
|
||||
# the tarball must contain exactly one root directory: nanokvm_<version>/.
|
||||
#
|
||||
# Build artifacts are expected to be in place already (see
|
||||
# scripts/build-in-container.sh and the "web" target in the Makefile):
|
||||
# server/NanoKVM-Server riscv64 server binary
|
||||
# kvmapp/kvm_system/kvm_system kvm_system daemon
|
||||
# kvmapp/server/dl_lib/libkvm.so freshly built video library (optional)
|
||||
# web/dist/ built frontend
|
||||
#
|
||||
# Usage: scripts/package.sh <version>
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
VERSION="${1:-}"
|
||||
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Usage: $0 <version> e.g. $0 2.4.4" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# The updater rejects file names outside [a-zA-Z0-9._-] (update_offline.go),
|
||||
# and the version string ends up in the file name, so validate it up front.
|
||||
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
echo "[ERROR] invalid version '$VERSION', expected MAJOR.MINOR.PATCH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OUT="$ROOT/build/release"
|
||||
STAGE="$OUT/nanokvm_$VERSION"
|
||||
TARBALL="$OUT/nanokvm_$VERSION.tar.gz"
|
||||
MANIFEST="$OUT/latest.json"
|
||||
|
||||
require_file() {
|
||||
if [ ! -f "$1" ]; then
|
||||
echo "[ERROR] missing build artifact: ${1#"$ROOT"/}" >&2
|
||||
echo " $2" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# A host-architecture build is indistinguishable from a cross-compiled one by
|
||||
# name alone, and NanoKVM-Server is gitignored, so nothing else would catch it.
|
||||
# Refuse to package anything that is not riscv64 (ELF e_machine 243).
|
||||
require_riscv64() {
|
||||
local path="$1" magic machine
|
||||
magic=$(od -An -tx1 -N4 "$path" | tr -d ' \n')
|
||||
if [ "$magic" != "7f454c46" ]; then
|
||||
echo "[ERROR] not an ELF object: ${path#"$ROOT"/}" >&2
|
||||
exit 1
|
||||
fi
|
||||
machine=$(od -An -tu1 -j18 -N1 "$path" | tr -d ' \n')
|
||||
if [ "$machine" != "243" ]; then
|
||||
echo "[ERROR] ${path#"$ROOT"/} is not riscv64 (ELF e_machine=$machine)" >&2
|
||||
echo " a host-architecture build must never be packaged" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
require_file "$ROOT/server/NanoKVM-Server" "run: make app"
|
||||
require_file "$ROOT/kvmapp/kvm_system/kvm_system" "run: make support"
|
||||
require_file "$ROOT/web/dist/index.html" "run: make web"
|
||||
# libkvm.so is the one runtime library that must come from the build: the copy
|
||||
# tracked in server/dl_lib/ exists for cgo link time and lags far behind. If it
|
||||
# were optional here, "make package" on its own would quietly ship the stale one.
|
||||
require_file "$ROOT/kvmapp/server/dl_lib/libkvm.so" "run: make vision"
|
||||
|
||||
require_riscv64 "$ROOT/server/NanoKVM-Server"
|
||||
require_riscv64 "$ROOT/kvmapp/kvm_system/kvm_system"
|
||||
require_riscv64 "$ROOT/kvmapp/server/dl_lib/libkvm.so"
|
||||
|
||||
echo "[INFO] staging nanokvm_$VERSION"
|
||||
# Clear the whole output directory: release.yml uploads build/release/nanokvm_*
|
||||
# by glob, and a leftover tarball from an earlier version would ride along.
|
||||
rm -rf "$OUT"
|
||||
mkdir -p "$STAGE"
|
||||
|
||||
# 1. Everything tracked under kvmapp/ (init scripts, picoclaw bundle, kernel
|
||||
# module, jpg_stream, kvm_stream) plus whatever the support build dropped in
|
||||
# (kvm_system, server/dl_lib). -a carries the exec bits over from git, which
|
||||
# only matters for reading the archive by hand: install.go chmods the whole
|
||||
# tree to 0755 on the device regardless.
|
||||
cp -a "$ROOT/kvmapp/." "$STAGE/"
|
||||
|
||||
# 2. Version marker. The updater reads /kvmapp/version to report the currently
|
||||
# installed version (version.go).
|
||||
printf '%s\n' "$VERSION" > "$STAGE/version"
|
||||
|
||||
# 3. Go server binary.
|
||||
mkdir -p "$STAGE/server"
|
||||
cp -a "$ROOT/server/NanoKVM-Server" "$STAGE/server/NanoKVM-Server"
|
||||
|
||||
# 4. Runtime shared libraries. "build kvm_vision add_to_kvmapp" copies its whole
|
||||
# dist/dl_lib into kvmapp/server/dl_lib, so freshly built libraries are
|
||||
# already staged; the tracked server/dl_lib/ backfills the rest. Never
|
||||
# clobber a fresh library with the tracked (link-time) copy.
|
||||
mkdir -p "$STAGE/server/dl_lib"
|
||||
for lib in "$ROOT"/server/dl_lib/*; do
|
||||
[ -e "$lib" ] || continue
|
||||
name="$(basename "$lib")"
|
||||
if [ ! -e "$STAGE/server/dl_lib/$name" ]; then
|
||||
cp -a "$lib" "$STAGE/server/dl_lib/$name"
|
||||
fi
|
||||
done
|
||||
|
||||
# The SDK is built from an unpinned MaixCDK checkout, so its dist could one
|
||||
# day add or rename a library (e.g. an soname bump leaving both .409 and
|
||||
# .410 behind) and we would ship a library set nobody reviewed. Require the
|
||||
# shipped names to be exactly the tracked set, and fail loudly otherwise.
|
||||
staged_libs=$(cd "$STAGE/server/dl_lib" && ls -1 | LC_ALL=C sort)
|
||||
tracked_libs=$(cd "$ROOT/server/dl_lib" && ls -1 | LC_ALL=C sort)
|
||||
if [ "$staged_libs" != "$tracked_libs" ]; then
|
||||
echo "[ERROR] shipped server/dl_lib does not match the tracked library set" >&2
|
||||
echo " unexpected (in package, not tracked):" >&2
|
||||
comm -23 <(printf '%s\n' "$staged_libs") <(printf '%s\n' "$tracked_libs") \
|
||||
| sed 's/^/ + /' >&2
|
||||
echo " absent (tracked, not in package):" >&2
|
||||
comm -13 <(printf '%s\n' "$staged_libs") <(printf '%s\n' "$tracked_libs") \
|
||||
| sed 's/^/ - /' >&2
|
||||
echo " if this change is intended, update server/dl_lib/ to match." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# A library arrives either from the SDK dist (mode 755) or from the tracked
|
||||
# backfill (git stores them 644), so without this the archive would depend on
|
||||
# which path populated each file. 644 is what published releases have always
|
||||
# carried, and install.go chmods the installed tree to 0755 anyway.
|
||||
chmod 644 "$STAGE"/server/dl_lib/*
|
||||
|
||||
# 5. Frontend. router.go serves <dir of executable>/web.
|
||||
rm -rf "$STAGE/server/web"
|
||||
mkdir -p "$STAGE/server/web"
|
||||
cp -a "$ROOT/web/dist/." "$STAGE/server/web/"
|
||||
|
||||
# 6. EDID helper shipped under system/tool/ (prebuilt riscv64 binary in tools/).
|
||||
mkdir -p "$STAGE/system/tool"
|
||||
cp -a "$ROOT/tools/nanokvm_update_edid/nanokvm_update_edid" "$STAGE/system/tool/"
|
||||
cp -a "$ROOT/tools/nanokvm_update_edid/E21_NanoKVM.bin" "$STAGE/system/tool/"
|
||||
|
||||
# 7. Default runtime state read by common.GetScreen() on first boot.
|
||||
mkdir -p "$STAGE/kvm"
|
||||
printf '30\n' > "$STAGE/kvm/fps"
|
||||
printf '0\n' > "$STAGE/kvm/now_fps"
|
||||
printf '60\n' > "$STAGE/kvm/qlty"
|
||||
printf '1920\n' > "$STAGE/kvm/width"
|
||||
printf '1080\n' > "$STAGE/kvm/height"
|
||||
printf '0\n' > "$STAGE/kvm/state"
|
||||
printf 'mjpeg\n' > "$STAGE/kvm/type"
|
||||
printf '0' > "$STAGE/kvm/res"
|
||||
|
||||
# 8. Directories the released package has always carried, kept so the layout
|
||||
# matches previous releases exactly (system_init.cpp probes inside them).
|
||||
mkdir -p "$STAGE/jpg_stream/dl_lib" "$STAGE/kvm_system/dl_lib"
|
||||
|
||||
# --- archive -----------------------------------------------------------------
|
||||
# Normalise owner and timestamps so the same source tree yields the same
|
||||
# tarball, which makes the published sha512 verifiable after the fact.
|
||||
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(git -C "$ROOT" log -1 --format=%ct 2>/dev/null || echo 0)}"
|
||||
|
||||
find "$STAGE" -exec touch -d "@$SOURCE_DATE_EPOCH" {} + 2>/dev/null \
|
||||
|| find "$STAGE" -exec touch -t "$(date -r "$SOURCE_DATE_EPOCH" +%Y%m%d%H%M.%S)" {} + 2>/dev/null \
|
||||
|| echo "[WARN] could not normalise timestamps"
|
||||
|
||||
echo "[INFO] creating $(basename "$TARBALL")"
|
||||
rm -f "$TARBALL"
|
||||
|
||||
# Read the version into a variable first: piping through head can hand tar a
|
||||
# SIGPIPE, and under "set -o pipefail" that would silently select the bsdtar
|
||||
# branch on a GNU system, quietly losing reproducibility.
|
||||
tar_version="$(tar --version 2>/dev/null || true)"
|
||||
|
||||
if [ "${tar_version#*GNU}" != "$tar_version" ]; then
|
||||
tar --format=gnu --sort=name \
|
||||
--owner=0 --group=0 --numeric-owner \
|
||||
--mtime="@$SOURCE_DATE_EPOCH" \
|
||||
-C "$OUT" -cf - "nanokvm_$VERSION" \
|
||||
| gzip -n -9 > "$TARBALL"
|
||||
else
|
||||
# bsdtar (macOS): no --sort/--mtime, so the archive is not byte-reproducible.
|
||||
echo "[WARN] GNU tar not found; archive will not be byte-reproducible"
|
||||
tar --uid 0 --gid 0 --uname '' --gname '' \
|
||||
-C "$OUT" -cf - "nanokvm_$VERSION" \
|
||||
| gzip -n -9 > "$TARBALL"
|
||||
fi
|
||||
|
||||
# --- manifest ----------------------------------------------------------------
|
||||
# update.go compares base64(raw sha512), not the hex digest.
|
||||
SHA512="$(openssl dgst -sha512 -binary "$TARBALL" | openssl base64 -A)"
|
||||
SIZE_BYTES="$(wc -c < "$TARBALL" | tr -d ' ')"
|
||||
UNPACKED_SIZE_BYTES="$(python3 - "$TARBALL" <<'PY'
|
||||
import sys
|
||||
import tarfile
|
||||
|
||||
total = 0
|
||||
with tarfile.open(sys.argv[1], "r:gz") as archive:
|
||||
for member in archive:
|
||||
if member.isfile():
|
||||
total += member.size
|
||||
print(total)
|
||||
PY
|
||||
)"
|
||||
|
||||
cat > "$MANIFEST" <<EOF
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"version": "$VERSION",
|
||||
"name": "nanokvm_$VERSION.tar.gz",
|
||||
"sha512": "$SHA512",
|
||||
"size": $SIZE_BYTES,
|
||||
"size_bytes": $SIZE_BYTES,
|
||||
"unpacked_size_bytes": $UNPACKED_SIZE_BYTES
|
||||
}
|
||||
EOF
|
||||
|
||||
echo
|
||||
echo "[DONE] $TARBALL"
|
||||
echo "[DONE] $MANIFEST"
|
||||
cat "$MANIFEST"
|
||||
157
scripts/verify-release-assets.sh
Executable file
157
scripts/verify-release-assets.sh
Executable file
@@ -0,0 +1,157 @@
|
||||
#!/bin/bash
|
||||
# Verify the three assets that make up a NanoKVM GitHub release.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ASSET_DIR="${1:-}"
|
||||
VERSION="${2:-}"
|
||||
|
||||
if [ -z "$ASSET_DIR" ] || [ -z "$VERSION" ]; then
|
||||
echo "Usage: $0 <asset-directory> <version>" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
echo "[ERROR] invalid version '$VERSION', expected MAJOR.MINOR.PATCH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TARBALL_NAME="nanokvm_${VERSION}.tar.gz"
|
||||
TARBALL="$ASSET_DIR/$TARBALL_NAME"
|
||||
MANIFEST="$ASSET_DIR/latest.json"
|
||||
CHECKSUM="$ASSET_DIR/sha256.txt"
|
||||
|
||||
for path in "$TARBALL" "$MANIFEST" "$CHECKSUM"; do
|
||||
if [ ! -f "$path" ]; then
|
||||
echo "[ERROR] missing release asset: $path" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
PACKAGE_ROOT="nanokvm_${VERSION}"
|
||||
MAX_PACKAGE_SIZE=$((1 << 30))
|
||||
MAX_UNPACKED_SIZE=$((2 << 30))
|
||||
MAX_ARCHIVE_ENTRIES=100000
|
||||
ENTRY_LIST=$(mktemp)
|
||||
VERBOSE_LIST=$(mktemp)
|
||||
trap 'rm -f "$ENTRY_LIST" "$VERBOSE_LIST"' EXIT
|
||||
|
||||
if ! tar -tzf "$TARBALL" > "$ENTRY_LIST"; then
|
||||
echo "[ERROR] could not list release tarball" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! tar -tvzf "$TARBALL" > "$VERBOSE_LIST"; then
|
||||
echo "[ERROR] could not inspect release tarball entry types" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ENTRY_COUNT=0
|
||||
while IFS= read -r entry; do
|
||||
ENTRY_COUNT=$((ENTRY_COUNT + 1))
|
||||
if [ "$ENTRY_COUNT" -gt "$MAX_ARCHIVE_ENTRIES" ]; then
|
||||
echo "[ERROR] archive contains more than $MAX_ARCHIVE_ENTRIES entries" >&2
|
||||
exit 1
|
||||
fi
|
||||
case "$entry" in
|
||||
"$PACKAGE_ROOT"|"$PACKAGE_ROOT"/*) ;;
|
||||
*)
|
||||
echo "[ERROR] archive entry is outside $PACKAGE_ROOT/: $entry" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
case "/$entry/" in
|
||||
*/../*|*/./*)
|
||||
echo "[ERROR] archive entry contains an unsafe path component: $entry" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done < "$ENTRY_LIST"
|
||||
if [ "$ENTRY_COUNT" -eq 0 ]; then
|
||||
echo "[ERROR] release tarball is empty" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
while IFS= read -r verbose_entry; do
|
||||
entry_type=${verbose_entry:0:1}
|
||||
case "$entry_type" in
|
||||
-|d) ;;
|
||||
*)
|
||||
echo "[ERROR] archive contains a link or special entry: $verbose_entry" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done < "$VERBOSE_LIST"
|
||||
|
||||
ARCHIVE_VERSION=$(tar -xOzf "$TARBALL" "$PACKAGE_ROOT/version" 2>/dev/null) || {
|
||||
echo "[ERROR] release tarball does not contain $PACKAGE_ROOT/version" >&2
|
||||
exit 1
|
||||
}
|
||||
if [ "$ARCHIVE_VERSION" != "$VERSION" ]; then
|
||||
echo "[ERROR] archive version '$ARCHIVE_VERSION' does not match '$VERSION'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SHA256=$(sha256sum "$TARBALL" | cut -d' ' -f1)
|
||||
if ! printf '%s %s\n' "$SHA256" "$TARBALL_NAME" | cmp -s - "$CHECKSUM"; then
|
||||
echo "[ERROR] sha256.txt does not match $TARBALL_NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MANIFEST_VERSION=$(jq -er '.version | select(type == "string" and length > 0)' "$MANIFEST")
|
||||
MANIFEST_NAME=$(jq -er '.name | select(type == "string" and length > 0)' "$MANIFEST")
|
||||
MANIFEST_SIZE=$(jq -er '.size | select(type == "number" and . >= 0 and floor == .)' "$MANIFEST")
|
||||
MANIFEST_FORMAT=$(jq -er '.manifest_version | select(type == "number" and . == 2)' "$MANIFEST")
|
||||
MANIFEST_SIZE_BYTES=$(jq -er '.size_bytes | select(type == "number" and . > 0 and floor == .)' "$MANIFEST")
|
||||
MANIFEST_UNPACKED_SIZE_BYTES=$(jq -er '.unpacked_size_bytes | select(type == "number" and . > 0 and floor == .)' "$MANIFEST")
|
||||
MANIFEST_SHA512=$(jq -er '.sha512 | select(type == "string" and length > 0)' "$MANIFEST")
|
||||
|
||||
if [ "$MANIFEST_VERSION" != "$VERSION" ]; then
|
||||
echo "[ERROR] latest.json version '$MANIFEST_VERSION' does not match '$VERSION'" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ "$MANIFEST_NAME" != "$TARBALL_NAME" ]; then
|
||||
echo "[ERROR] latest.json name '$MANIFEST_NAME' does not match '$TARBALL_NAME'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ACTUAL_SIZE=$(wc -c < "$TARBALL" | tr -d ' ')
|
||||
if [ "$MANIFEST_FORMAT" != "2" ]; then
|
||||
echo "[ERROR] latest.json manifest_version must be 2" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ "$MANIFEST_SIZE" != "$ACTUAL_SIZE" ] || [ "$MANIFEST_SIZE_BYTES" != "$ACTUAL_SIZE" ]; then
|
||||
echo "[ERROR] latest.json size '$MANIFEST_SIZE' does not match '$ACTUAL_SIZE'" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ "$ACTUAL_SIZE" -gt "$MAX_PACKAGE_SIZE" ]; then
|
||||
echo "[ERROR] release tarball exceeds device limit of $MAX_PACKAGE_SIZE bytes" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ACTUAL_UNPACKED_SIZE=$(python3 - "$TARBALL" <<'PY'
|
||||
import sys
|
||||
import tarfile
|
||||
|
||||
total = 0
|
||||
with tarfile.open(sys.argv[1], "r:gz") as archive:
|
||||
for member in archive:
|
||||
if member.isfile():
|
||||
total += member.size
|
||||
print(total)
|
||||
PY
|
||||
)
|
||||
if [ "$MANIFEST_UNPACKED_SIZE_BYTES" != "$ACTUAL_UNPACKED_SIZE" ]; then
|
||||
echo "[ERROR] latest.json unpacked_size_bytes '$MANIFEST_UNPACKED_SIZE_BYTES' does not match '$ACTUAL_UNPACKED_SIZE'" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ "$ACTUAL_UNPACKED_SIZE" -gt "$MAX_UNPACKED_SIZE" ]; then
|
||||
echo "[ERROR] unpacked package exceeds device limit of $MAX_UNPACKED_SIZE bytes" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ACTUAL_SHA512=$(openssl dgst -sha512 -binary "$TARBALL" | openssl base64 -A)
|
||||
if [ "$MANIFEST_SHA512" != "$ACTUAL_SHA512" ]; then
|
||||
echo "[ERROR] latest.json sha512 does not match $TARBALL_NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[OK] verified NanoKVM release assets for $VERSION"
|
||||
43
scripts/verify-release-tag.sh
Executable file
43
scripts/verify-release-tag.sh
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
# Resolve an annotated numeric tag from origin and verify its commit is on main.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
TAG="${1:-}"
|
||||
EXPECTED_SHA="${2:-}"
|
||||
|
||||
if ! echo "$TAG" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
echo "[ERROR] invalid tag '$TAG', expected MAJOR.MINOR.PATCH" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ -n "$EXPECTED_SHA" ] && ! echo "$EXPECTED_SHA" | grep -qE '^[0-9a-f]{40}$'; then
|
||||
echo "[ERROR] expected commit must be a full lowercase commit SHA" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TAG_REF="refs/tags/$TAG"
|
||||
PEELED_REF="${TAG_REF}^{}"
|
||||
REMOTE_REFS=$(git ls-remote --tags origin "$TAG_REF" "$PEELED_REF")
|
||||
TAG_OBJECT=$(printf '%s\n' "$REMOTE_REFS" | awk -v ref="$TAG_REF" '$2 == ref { print $1 }')
|
||||
SOURCE_SHA=$(printf '%s\n' "$REMOTE_REFS" | awk -v ref="$PEELED_REF" '$2 == ref { print $1 }')
|
||||
|
||||
if ! echo "$TAG_OBJECT" | grep -qE '^[0-9a-f]{40}$'; then
|
||||
echo "[ERROR] tag '$TAG' does not exist on origin" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! echo "$SOURCE_SHA" | grep -qE '^[0-9a-f]{40}$'; then
|
||||
echo "[ERROR] tag '$TAG' is not an annotated tag" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ -n "$EXPECTED_SHA" ] && [ "$SOURCE_SHA" != "$EXPECTED_SHA" ]; then
|
||||
echo "[ERROR] tag '$TAG' moved from '$EXPECTED_SHA' to '$SOURCE_SHA'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git fetch --no-tags origin main
|
||||
if ! git merge-base --is-ancestor "$SOURCE_SHA" FETCH_HEAD; then
|
||||
echo "[ERROR] tag '$TAG' points to a commit outside origin/main" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '%s\n' "$SOURCE_SHA"
|
||||
199
server/README.md
Normal file
199
server/README.md
Normal file
@@ -0,0 +1,199 @@
|
||||
# NanoKVM Server
|
||||
|
||||
This is the backend server implementation for NanoKVM.
|
||||
|
||||
For detailed documentation, please visit our [Wiki](https://wiki.sipeed.com/nanokvm).
|
||||
|
||||
## Structure
|
||||
|
||||
```shell
|
||||
server
|
||||
├── common // Common utility components
|
||||
├── config // Server configuration
|
||||
├── dl_lib // Shared object libraries
|
||||
├── include // Header files for shared objects
|
||||
├── logger // Logging system
|
||||
├── middleware // Server middleware components
|
||||
├── proto // API request/response definitions
|
||||
├── router // API route handlers
|
||||
├── service // Core service implementations
|
||||
├── utils // Utility functions
|
||||
└── main.go
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
The configuration file path is `/etc/kvm/server.yaml`.
|
||||
|
||||
```yaml
|
||||
# Network Settings
|
||||
proto: http # Access protocol. Can be changed to `https` only when certificates are configured. Default is `http`
|
||||
host: "" # The listening address for the HTTP/HTTPS service. If left empty, all network interfaces will be bound
|
||||
port:
|
||||
http: 80 # The listening port for the HTTP service. Default is `80`
|
||||
https: 443 # The listening port for the HTTPS service (effective when HTTPS is enabled). Default is `443`
|
||||
cert:
|
||||
crt: server.crt # The path to the public key certificate for HTTPS
|
||||
key: server.key # The path to the private key file for HTTPS
|
||||
|
||||
|
||||
# Logging Configuration
|
||||
logger:
|
||||
level: info # Global log output level. Evaluated options from highest to lowest detail: `trace`, `debug`, `info`, `warn`, `error`, `fatal`, `panic`. Default is `info`
|
||||
file: stdout # Log output destination. `stdout` outputs to the standard console. A file path directs log output to that file. Default is `stdout`
|
||||
|
||||
|
||||
# Authentication & Security
|
||||
authentication: enable # Whether to enable identity verification for HTTP API and Web endpoints. Options are `enable` or `disable`. Default is `enable`. Highly recommended to leave this enabled for internet-facing devices!
|
||||
jwt:
|
||||
secretKey: "" # The secret key used to sign and verify JWT Tokens. If left empty, a random key will be generated automatically on startup
|
||||
refreshTokenDuration: 2678400 # The token refresh duration threshold in seconds before forcing a re-login. Default is `2678400` (~31 days)
|
||||
revokeTokensOnLogout: true # Whether logout invalidates all sessions belonging to that user. Other users are never logged out. Setting this to false only clears the browser cookie and is not recommended. Default is `true`
|
||||
security:
|
||||
loginLockoutDuration: 0, # The duration (in seconds) to ban an IP from attempting to log in again after reaching the failure limit. If set to `0` or left empty, brute-force protection is disabled. Default is `0`
|
||||
loginMaxFailures: 5, # The maximum number of continuous failed login attempts allowed per IP before triggering protection. Default is `5`
|
||||
|
||||
|
||||
# WebRTC Traversal Settings
|
||||
stun: stun.l.google.com:19302 # The default STUN server address used for NAT hole-punching to establish P2P streams
|
||||
turn:
|
||||
turnAddr: example_addr # The relay (TURN) server address (format `ip:port`) used as a fallback when P2P connection fails. Leave empty to disable TURN relay
|
||||
turnUser: example_user # The username required for authorization to the TURN server
|
||||
turnCred: example_cred # The credential/password required for authorization to the TURN server
|
||||
```
|
||||
|
||||
## Web Users
|
||||
|
||||
NanoKVM uses two device-wide roles:
|
||||
|
||||
- `admin`: everything below, plus user management.
|
||||
- `user`: only what the account is granted.
|
||||
|
||||
A grant names an action on one party, and the catalog the server serves to the account editor
|
||||
carries its group, its risk, and the grants it implies:
|
||||
|
||||
| Group | Grants |
|
||||
| --- | --- |
|
||||
| console (this session) | `console.view`, `console.control` |
|
||||
| target machine | `power`, `medium.attach` |
|
||||
| media library (this device) | `library.read`, `library.write` |
|
||||
| this device | `terminal`, `device`, `network`, `update` |
|
||||
| services | `mcp`, `tailscale`, `ai` |
|
||||
|
||||
Implied grants are declared once, in the catalog, and the server resolves them before answering any
|
||||
request: `console.control` implies `console.view`, both `medium.attach` and `library.write` imply
|
||||
`library.read`, and every grant whose controls live in the console menu — `power`, `device`,
|
||||
`network`, `update`, `mcp`, `tailscale` and `ai` — implies `console.view` too, because no page
|
||||
outside the console renders them. Consequences worth knowing:
|
||||
|
||||
- An account can hold no console access at all. The web app then lands on a page that offers the
|
||||
sections the account may use (the media library, the terminal) instead of a console it cannot
|
||||
open. `library.read` is all that media access needs, because the other two media grants imply it,
|
||||
and only `terminal` and the media grants can stand on their own pages in the first place.
|
||||
- The media grants split along the trust boundary. `medium.attach` mounts or ejects a medium on the
|
||||
target machine and writes into the shared partition the target reads; `library.write` changes what
|
||||
the library keeps (uploads, deletes, the files inside an image); `library.read` lists and downloads.
|
||||
The file endpoints serve an image and the shared partition through one path, so the route admits
|
||||
either grant and each request is checked against the medium type it names. Every `.iso` and
|
||||
`.img` on the partition is a library entry, so uploading one through the shared partition, or
|
||||
deleting a file or folder that holds one, also needs `library.write`.
|
||||
- The emulated USB devices are neither media nor network: the virtual disk and the RNDIS adapter
|
||||
hand the target machine the raw data partition and a network interface, so both follow `device`.
|
||||
A medium can only be attached while a `device` holder has the virtual disk switched on, and the
|
||||
storage page says so when it is off.
|
||||
|
||||
Four grants reach further than their names suggest and amount to full device control. The catalog
|
||||
has two risk levels, and `warn` is reserved for them: the account editor marks those four and
|
||||
names them before the grants are saved:
|
||||
|
||||
- `terminal` is a root shell (the same one SSH gives) and can run saved and autostart scripts.
|
||||
- `mcp` hands out a device-wide API key that drives the keyboard, mouse and screenshots from
|
||||
outside the web session. The key is shared, so a copy keeps working after an account loses this
|
||||
grant. Whenever a change takes the grant away (revoked, demoted, disabled or deleted), the account
|
||||
editor warns and offers to regenerate the key, checked by default; regenerating disconnects every
|
||||
MCP client until it is given the new key, and an administrator who keeps the key accepts that a
|
||||
copy stays valid. The API takes the choice as `rotateMcpKey` (a body field on update, a query
|
||||
parameter on delete) and never rotates without it.
|
||||
- `ai` drives the device through the local loopback interface, which the other grants do not
|
||||
restrict.
|
||||
- `update` installs firmware and application packages. An offline package is checked only against
|
||||
the checksum its uploader supplies, so installing one is running code as root.
|
||||
|
||||
`device` carries no such mark, although it changes what the device does for everyone and cannot be
|
||||
narrowed per account. `device` turns SSH on or off (root login, with the device
|
||||
owner's password), reboots the device, hands the raw data partition or a network interface to the
|
||||
target machine through the emulated USB devices, and edits the OLED, HDMI, mDNS, memory, swap and
|
||||
HID settings. The editor describes it that way.
|
||||
|
||||
Two grants also change settings that affect everyone watching: `console.view` sets the video mode,
|
||||
resolution, frame rate and quality, and resets the HDMI capture; `power` manages the Wake-on-LAN
|
||||
device list. Both are described that way in the editor.
|
||||
|
||||
Administrators manage accounts from **Settings > Account**. Account data remains in
|
||||
`/etc/kvm/pwd`; the server migrates the legacy single-account JSON format in place and writes
|
||||
the multi-user format atomically with mode `0600`. Keeping the same path preserves the physical
|
||||
BOOT-button password reset behavior.
|
||||
Users must confirm their current password when changing it themselves; administrators can reset
|
||||
non-owner users from the account manager. Only the device owner can change the device owner's
|
||||
password, because that password is also synchronized to the Linux root account.
|
||||
|
||||
All authenticated sessions are backed by the current account state: every request is authorized
|
||||
against the account file, so a revoked grant stops working immediately without re-issuing a login.
|
||||
Disabling, deleting, or resetting the password of a user invalidates that user's HTTP and real-time
|
||||
connections without affecting other users. Changing the role or the grants of an account keeps its
|
||||
login valid: the account is told to refresh, and only the long-lived connections whose cached
|
||||
state depends on what changed are dropped (console, video stream, terminal, AI), so those clients
|
||||
reconnect under the new grants. An account that loses `console.view` is sent to the landing page
|
||||
instead of a console it can no longer open. Multiple
|
||||
users may watch and control the KVM concurrently; input uses the existing cooperative HID
|
||||
coordinator, so simultaneous input can interleave. A user without `console.control` keeps the
|
||||
video and the menu for its other grants, but the console rejects keyboard and mouse reports and
|
||||
the web UI marks the session as view only.
|
||||
Video mode, quality, resolution, MJPEG frame-detection controls, and resetting the HDMI capture
|
||||
require only `console.view` and stay shared KVM operations; when several users adjust them
|
||||
concurrently, the latest change applies device-wide. Enabling or disabling the HDMI capture and
|
||||
its idle timeout are device settings. `console.control` is input only: keyboard, mouse, paste, and
|
||||
the input region that maps pointer motion onto the target screen.
|
||||
|
||||
The account file stores an explicit grant set: a record written before fine-grained permissions
|
||||
keeps exactly what the user role used to grant, and the split media grants are translated on load,
|
||||
so the store never holds a missing set that would fall back to different behavior later. Grants
|
||||
this build does not know are preserved and ignored, so a downgrade cannot lock the device out.
|
||||
Creating a regular account without naming a grant set keeps that same meaning, so a script that only
|
||||
knows about roles gets the account the user role used to create; the account editor seeds a new
|
||||
regular account with `console.view` only, and an explicitly empty set really is empty.
|
||||
|
||||
## Compile & Deploy
|
||||
|
||||
Note: The manual steps below require a Linux x86-64 host with Go 1.25 or newer; they are not compatible with ARM, Windows or macOS. With Docker you can skip them entirely and use the containerized flow instead — the root [Makefile](../Makefile) (`make shell`) or the dev container (see "Development" in the root [README](../README.md)) — which works on any host OS; run `server/build.sh` inside the container for a release-equivalent build.
|
||||
|
||||
1. Install the Toolchain
|
||||
1. Download the toolchain from the following link: [Download Link](https://sophon-file.sophon.cn/sophon-prod-s3/drive/23/03/07/16/host-tools.tar.gz).
|
||||
2. Extract the file and add the `host-tools/gcc/riscv64-linux-musl-x86_64/bin` directory to your PATH environment variable.
|
||||
3. Run `riscv64-unknown-linux-musl-gcc -v`. If there is version information in the output, the installation is successful.
|
||||
|
||||
2. Compile the Project
|
||||
1. Run `cd server` from the project root directory.
|
||||
2. Run `go mod tidy` to install Go dependencies.
|
||||
3. (Optional) If you compiled `libkvm.so` yourself, you need to modify its RPATH by `patchelf --add-rpath \$ORIGIN ./dl_lib/libkvm.so`.
|
||||
4. Run `CGO_ENABLED=1 GOOS=linux GOARCH=riscv64 CC=riscv64-unknown-linux-musl-gcc CGO_CFLAGS="-mcpu=c906fdv -march=rv64imafdcv0p7xthead -mcmodel=medany -mabi=lp64d" go build` to compile the project.
|
||||
5. After compilation, an executable file named `NanoKVM-Server` will be generated.
|
||||
|
||||
3. Modify RPATH
|
||||
1. Run `sudo apt install patchelf` or `pip install patchelf` to install patchelf.
|
||||
2. Run `patchelf --version`. Ensure the version is 0.14 or higher`.
|
||||
3. Run `patchelf --add-rpath \$ORIGIN/dl_lib NanoKVM-Server` to modify the RPATH of the executable file.
|
||||
|
||||
4. Deploy the Application
|
||||
1. File uploads requires SSH. Please enable it in the Web Settings: `Settings > SSH`;
|
||||
2. Replace the original file in the NanoKVM `/kvmapp/server/` directory with the newly compiled `NanoKVM-Server`.
|
||||
3. Restart the service on NanoKVM by executing `/etc/init.d/S95nanokvm restart`.
|
||||
|
||||
## Manually Update
|
||||
|
||||
> File uploads requires SSH. Please enable it in the Web Settings: `Settings > SSH`;
|
||||
|
||||
1. Download the latest application from [GitHub](https://github.com/sipeed/NanoKVM/releases);
|
||||
2. Unzip the downloaded file and rename the unzipped folder to `kvmapp`;
|
||||
3. Back up the existing `/kvmapp` directory on your NanoKVM, then replace it with the new `kvmapp` folder;
|
||||
4. Run `/etc/init.d/S95nanokvm restart` on your NanoKVM to restart the service.
|
||||
98
server/README_JA.md
Normal file
98
server/README_JA.md
Normal file
@@ -0,0 +1,98 @@
|
||||
# NanoKVM サーバー
|
||||
|
||||
これは NanoKVM のバックエンドサーバーの実装です。
|
||||
|
||||
詳細なドキュメントについては、[Wiki](https://wiki.sipeed.com/nanokvm) を参照してください。
|
||||
|
||||
## 構造
|
||||
|
||||
```shell
|
||||
server
|
||||
├── common // 共通ユーティリティコンポーネント
|
||||
├── config // サーバー設定
|
||||
├── dl_lib // 共有オブジェクトライブラリ
|
||||
├── include // 共有オブジェクトのヘッダーファイル
|
||||
├── logger // ロギングシステム
|
||||
├── middleware // サーバーミドルウェアコンポーネント
|
||||
├── proto // API リクエスト/レスポンス定義
|
||||
├── router // API ルートハンドラ
|
||||
├── service // コアサービスの実装
|
||||
├── utils // ユーティリティ関数
|
||||
└── main.go
|
||||
```
|
||||
|
||||
## 設定
|
||||
|
||||
設定ファイルのパスは `/etc/kvm/server.yaml` です。
|
||||
|
||||
```yaml
|
||||
proto: http
|
||||
host: ""
|
||||
port:
|
||||
http: 80
|
||||
https: 443
|
||||
cert:
|
||||
crt: server.crt
|
||||
key: server.key
|
||||
|
||||
# ログレベル (debug/info/warn/error)
|
||||
# 注意: 本番環境では 'info' または 'error' を使用し、'debug' は開発環境でのみ使用してください
|
||||
logger:
|
||||
level: info
|
||||
file: stdout
|
||||
|
||||
# 認証設定 (enable/disable)
|
||||
# 注意: 認証を無効にするのは開発環境でのみ行ってください
|
||||
authentication: enable
|
||||
|
||||
jwt:
|
||||
# JWT 秘密鍵の設定。 空のままにすると、サーバー起動時にランダムな 64 バイトの鍵が自動的に生成されます。
|
||||
secretKey: ""
|
||||
# JWT トークンの有効期限(秒単位)。 デフォルト: 2678400 (31 日)
|
||||
refreshTokenDuration: 2678400
|
||||
# ユーザーがログアウトすると、すべての JWT トークンが無効になります。 デフォルト: true
|
||||
revokeTokensOnLogout: true
|
||||
|
||||
# カスタム STUN サーバーのアドレス
|
||||
stun: stun.l.google.com:19302
|
||||
|
||||
# カスタム TURN サーバーのアドレスと認証情報
|
||||
turn:
|
||||
turnAddr: turn.cloudflare.com:3478
|
||||
turnUser: example_user
|
||||
turnCred: example_cred
|
||||
```
|
||||
|
||||
## コンパイルとデプロイ
|
||||
|
||||
注意: Linux オペレーティングシステム (x86-64) と Go 1.25 以降を使用してください。このビルドプロセスは ARM、Windows、macOS では互換性がありません。
|
||||
|
||||
1. ツールチェーンのインストール
|
||||
1. 以下のリンクからツールチェーンをダウンロードします: [ダウンロードリンク](https://sophon-file.sophon.cn/sophon-prod-s3/drive/23/03/07/16/host-tools.tar.gz)。
|
||||
2. ファイルを解凍し、`host-tools/gcc/riscv64-linux-musl-x86_64/bin` ディレクトリを PATH 環境変数に追加します。
|
||||
3. `riscv64-unknown-linux-musl-gcc -v` を実行します。バージョン情報が表示されれば、インストールは成功です。
|
||||
|
||||
2. プロジェクトのコンパイル
|
||||
1. プロジェクトのルートディレクトリから `cd server` を実行します。
|
||||
2. `go mod tidy` を実行して Go の依存関係をインストールします。
|
||||
3. `CGO_ENABLED=1 GOOS=linux GOARCH=riscv64 CC=riscv64-unknown-linux-musl-gcc CGO_CFLAGS="-mcpu=c906fdv -march=rv64imafdcv0p7xthead -mcmodel=medany -mabi=lp64d" go build` を実行してプロジェクトをコンパイルします。
|
||||
4. コンパイルが完了すると、`NanoKVM-Server` という名前の実行ファイルが生成されます。
|
||||
|
||||
3. RPATH の変更
|
||||
1. `sudo apt install patchelf` または `pip install patchelf` を実行して patchelf をインストールします。
|
||||
2. `patchelf --version` を実行します。バージョンが 0.14 以上であることを確認します。
|
||||
3. `patchelf --add-rpath \$ORIGIN/dl_lib NanoKVM-Server` を実行して、実行ファイルの RPATH を変更します。
|
||||
|
||||
4. アプリケーションのデプロイ
|
||||
1. デプロイ前に、ブラウザでアプリケーションを最新バージョンに更新します。手順は[こちら](https://wiki.sipeed.com/hardware/en/kvm/NanoKVM/system/updating.html)を参照してください。
|
||||
2. コンパイルして生成された `NanoKVM-Server` ファイルを使用して、NanoKVM の `/kvmapp/server/` ディレクトリ内の元のファイルを置き換えます。
|
||||
3. NanoKVM で `/etc/init.d/S95nanokvm restart` を実行してサービスを再起動します。
|
||||
|
||||
## 手動更新
|
||||
|
||||
> ファイルのアップロードには SSH が必要です。Web 設定で有効にしてください: `設定 > SSH`
|
||||
|
||||
1. [GitHub](https://github.com/sipeed/NanoKVM/releases) から最新のアプリケーションをダウンロードします。
|
||||
2. ダウンロードしたファイルを解凍し、解凍したフォルダーの名前を `kvmapp` に変更します。
|
||||
3. NanoKVM 上の既存の `/kvmapp` ディレクトリをバックアップし、新しい `kvmapp` フォルダーに置き換えます。
|
||||
4. NanoKVM で `/etc/init.d/S95nanokvm restart` を実行してサービスを再起動します。
|
||||
170
server/README_ZH.md
Normal file
170
server/README_ZH.md
Normal file
@@ -0,0 +1,170 @@
|
||||
# NanoKVM Server
|
||||
|
||||
NanoKVM 后端服务的代码。更多文档请参考 [Wiki](https://wiki.sipeed.com/nanokvm) 。
|
||||
|
||||
## 目录结构
|
||||
|
||||
```shell
|
||||
server
|
||||
├── common // 公用组件
|
||||
├── config // 服务配置
|
||||
├── dl_lib // so 文件
|
||||
├── include // 头文件
|
||||
├── logger // 服务日志
|
||||
├── middleware // 中间件
|
||||
├── proto // api 请求响应参数
|
||||
├── router // api 路由
|
||||
├── service // api 处理逻辑
|
||||
├── utils // 工具函数
|
||||
└── main.go
|
||||
```
|
||||
|
||||
## 配置文件
|
||||
|
||||
配置文件路径为 `/etc/kvm/server.yaml`。
|
||||
|
||||
```yaml
|
||||
# 网络设置
|
||||
proto: http # 访问协议,默认为 `http`,仅当配置了证书时支持改为 `https`
|
||||
host: ""
|
||||
port:
|
||||
http: 80 # HTTP 服务的监听端口,默认为 `80`
|
||||
https: 443 # HTTPS 服务的监听端口(启用 https 协议时生效),默认为 `443`
|
||||
cert:
|
||||
crt: server.crt # HTTPS 服务使用的公钥证书路径
|
||||
key: server.key # HTTPS 服务使用的私钥文件路径
|
||||
|
||||
|
||||
# 日志配置
|
||||
logger:
|
||||
level: info # 全局日志打印级别,从高到底可选 `trace`, `debug`, `info`, `warn`, `error`, `fatal`, `panic`。默认为 `info`
|
||||
file: stdout # 日志输出目标位置。若填写 `stdout` 则输出在控制台。配置为文件路径则会输出到对应的文件。默认为 `stdout`
|
||||
|
||||
|
||||
# 认证与安全
|
||||
authentication: enable # 是否开启 HTTP 接口与网页的身份校验。可选 `enable` (开启) 或 `disable` (禁用)。默认为 `enable`。强烈建议公开在互联网的机器开启此项!
|
||||
jwt:
|
||||
secretKey: "" # 用于签发和验证 JWT Token 的密钥。如果不填,服务启动时将自动随机生成
|
||||
refreshTokenDuration: 2678400 # 登录超时的刷新周期(单位:秒)。默认为 `2678400`(约31天)
|
||||
revokeTokensOnLogout: true # 退出登录时是否废除该用户的全部会话;不会影响其他用户。设为 false 时仅清除浏览器 Cookie,不推荐使用。默认为 `true`
|
||||
security:
|
||||
loginLockoutDuration: 0, # 达到失败上限后,禁止该 IP 再次尝试登录的持续时间(单位:秒)。如果设为 `0` 或不填,则代表不开启防暴力破解功能。默认为 `0`
|
||||
loginMaxFailures: 5, # 允许触发保护前,单个 IP 连续登录失败的最大次数。默认为 `5`
|
||||
|
||||
|
||||
# WebRTC 内网穿透
|
||||
stun: stun.l.google.com:19302 # 默认使用的 STUN 服务器地址,用于打洞获取公网 IP 建立 P2P 流
|
||||
turn:
|
||||
turnAddr: example_addr # 当 P2P 直连失败时,作为备用的中继(TURN)服务器地址(格式如 `ip:port`)。留空表示不使用 TURN 中继
|
||||
turnUser: example_user # TURN 服务器授权连接时使用的用户名
|
||||
turnCred: example_cred # TURN 服务器授权连接时使用的凭据/密码
|
||||
```
|
||||
|
||||
## Web 多用户
|
||||
|
||||
NanoKVM 使用两种设备级角色:
|
||||
|
||||
- `admin`:拥有以下全部能力,并可管理用户。
|
||||
- `user`:仅拥有被授予的功能权限。
|
||||
|
||||
每项权限都描述“对谁做什么”,服务端下发给账户编辑器的权限目录还带有分组、风险等级和蕴含关系:
|
||||
|
||||
| 分组 | 权限 |
|
||||
| --- | --- |
|
||||
| 控制台(本会话) | `console.view`、`console.control` |
|
||||
| 被控机 | `power`、`medium.attach` |
|
||||
| 介质库(本设备) | `library.read`、`library.write` |
|
||||
| 本设备 | `terminal`、`device`、`network`、`update` |
|
||||
| 服务 | `mcp`、`tailscale`、`ai` |
|
||||
|
||||
蕴含关系只在权限目录里声明一次,并由服务端在应答任何请求前解析:`console.control` 蕴含
|
||||
`console.view`,`medium.attach` 与 `library.write` 都蕴含 `library.read`;而控制项位于控制台菜单里的
|
||||
权限——`power`、`device`、`network`、`update`、`mcp`、`tailscale`、`ai`——同样蕴含 `console.view`,
|
||||
因为控制台之外没有任何页面渲染它们。由此得到几个行为:
|
||||
|
||||
- 账户可以完全没有控制台权限。此时 Web 界面会落到一个提示页,列出该账户可用的页面
|
||||
(介质库、终端),而不是打开一个它无权访问的控制台。媒体功能只需要 `library.read`,
|
||||
因为另外两项媒体权限都蕴含它;也只有 `terminal` 与媒体权限能拥有控制台之外的独立页面。
|
||||
- 媒体权限按信任边界拆分:`medium.attach` 在被控机上挂载/弹出介质,并写入被控机可读的共享分区;
|
||||
`library.write` 修改库内容(上传、删除、镜像内的文件);`library.read` 负责列表与下载。
|
||||
文件相关接口用同一路径同时服务镜像与共享分区,因此路由同时接受这两项权限之一,
|
||||
再按请求指定的介质类型做校验。分区上的每个 `.iso`、`.img` 都属于介质库,因此经共享分区上传这类文件,
|
||||
或删除本身是/内含这类文件的文件或文件夹,同样需要 `library.write`。
|
||||
- 模拟的 USB 设备既不属于媒体也不属于网络:虚拟磁盘与 RNDIS 虚拟网卡分别把设备的原始数据分区
|
||||
和一块网卡交给被控机,因此都归 `device`。只有拥有 `device` 权限的账户开启虚拟磁盘后,才能挂载
|
||||
镜像;磁盘未开启时存储页面会给出提示。
|
||||
|
||||
以下四项权限的实际范围比名称更大,等同于完整的设备控制权;权限目录只有两个风险等级,`warn`
|
||||
专用于它们,账户编辑器会做标记并在保存前按名称列出:
|
||||
|
||||
- `terminal`:即 root shell(与 SSH 相同),并可运行已保存的脚本和开机自启脚本。
|
||||
- `mcp`:会下发设备级 API Key,可在 Web 会话之外控制键鼠并获取截图。Key 为共用,账户失去该权限后已复制的
|
||||
Key 仍然有效。任何会让账户失去该权限的操作(撤销、降级、禁用或删除),账户编辑器都会警告并提供「重新生成
|
||||
Key」选项(默认勾选);重新生成会断开所有 MCP 客户端直到换用新 Key,管理员选择保留则自行承担副本仍有效的风险。
|
||||
API 通过 `rotateMcpKey` 传递该选择(更新时放在请求体,删除时放在查询参数),不带它就不会轮换。
|
||||
- `ai`:通过本地回环接口操作设备,不受其他权限限制。
|
||||
- `update`:安装固件与应用更新包。离线包只校验上传者自己提供的校验和,安装它即等于以 root 运行代码。
|
||||
|
||||
`device` 不做该标记:它仍在本账户被授予的设置范围内,但会改变设备对所有人生效的行为,
|
||||
且无法按账户收窄。`device` 可开关 SSH(root,口令为设备所有者口令)、重启设备、通过模拟的 USB 设备把
|
||||
原始数据分区或网卡交给被控机,并修改 OLED、HDMI、mDNS、内存、交换与 HID 设置。编辑器中对此同样有说明。
|
||||
|
||||
另有两项权限会改动影响所有观看者的设置:`console.view` 会设置视频模式、分辨率、帧率与画质,
|
||||
并复位 HDMI 采集;`power` 会管理网络唤醒设备列表。编辑器中对这两项都有明确说明。
|
||||
|
||||
管理员可在**设置 > 账户**中管理用户。账户数据继续保存在 `/etc/kvm/pwd`;服务会原地迁移旧版单账户
|
||||
JSON,并以 `0600` 权限原子写入多用户格式。沿用同一路径可保持长按 BOOT 键重置密码的现有行为。
|
||||
用户自助修改密码时必须验证当前密码;管理员可在账户管理中重置非设备所有者的密码。由于设备所有者
|
||||
密码还会同步至 Linux root 账户,因此只有设备所有者本人可以修改自己的密码。
|
||||
|
||||
所有登录会话都会校验当前账户状态:每个请求都按账户文件重新授权,因此被撤销的权限会立即失效,
|
||||
无需重新登录。禁用、删除或重置密码会立即撤销该用户的 HTTP 与实时连接,且不会影响其他用户。
|
||||
修改角色或权限不会失效登录:账户会收到刷新通知,只会断开缓存了相关状态的长期连接
|
||||
(控制台、视频流、终端、AI),这些客户端随后会以新权限重连。失去 `console.view` 的账户会被
|
||||
转到提示页,而不是一个无法打开的控制台。多个用户可同时观看和协作控制 KVM;输入沿用现有 HID
|
||||
协调器,因此同时输入可能交错。没有 `console.control` 的用户仍可观看画面并使用其其他权限对应的菜单,
|
||||
但控制台会丢弃其键鼠报文,Web 界面会将会话标记为只读。
|
||||
视频模式、画质、分辨率、MJPEG 帧检测以及复位 HDMI 采集只要求 `console.view`,仍属于共享 KVM 操作;
|
||||
多人同时调整时,以最后一次设备级修改为准。启用/关闭 HDMI 采集及其空闲超时则属于设备设置。
|
||||
`console.control` 仅限输入:键盘、鼠标、粘贴,以及将指针位移映射到目标机画面的输入区域。
|
||||
|
||||
账户文件保存的是显式权限集合:细粒度权限出现之前写入的记录,在读取时会物化为当时 user 角色的
|
||||
能力,拆分过的媒体权限也会被翻译成新名称,因此存储中不会留下“缺失即回退到另一套行为”的状态。
|
||||
本版本不认识的权限会被原样保留并忽略,因此回滚版本不会把设备锁在门外。
|
||||
新建普通账户时若不指定权限集合,含义同上:只认识角色的脚本仍会得到 user 角色过去创建出的账户;
|
||||
账户编辑器新建普通账户时只预置 `console.view`,而显式传入的空集合就是真的空。
|
||||
|
||||
## 编译部署
|
||||
|
||||
**注意:请使用 Linux 操作系统(x86-64)和 Go 1.25 或更高版本。该工具链无法在 ARM、Windows 或 macOS 下使用。**
|
||||
|
||||
1. 安装工具链
|
||||
1. 下载工具链:[下载地址](https://sophon-file.sophon.cn/sophon-prod-s3/drive/23/03/07/16/host-tools.tar.gz);
|
||||
2. 解压下载文件,然后将 `host-tools/gcc/riscv64-linux-musl-x86_64/bin` 目录加入到环境变量;
|
||||
3. 执行 `riscv64-unknown-linux-musl-gcc -v`,如果显示版本信息则安装成功。
|
||||
|
||||
2. 编译
|
||||
1. 在项目根目录下执行 `cd server` 进入 server 目录;
|
||||
2. 执行 `go mod tidy` 安装 Go 依赖包;
|
||||
3. (可选)如果您手动编译了 `libkvm.so`,则需要通过 `patchelf --add-rpath \$ORIGIN ./dl_lib/libkvm.so` 修改其 RPATH 属性。
|
||||
4. 执行 `CGO_ENABLED=1 GOOS=linux GOARCH=riscv64 CC=riscv64-unknown-linux-musl-gcc CGO_CFLAGS="-mcpu=c906fdv -march=rv64imafdcv0p7xthead -mcmodel=medany -mabi=lp64d" go build` 进行编译;
|
||||
5. 编译完成后,会生成可执行文件 `NanoKVM-Server`。
|
||||
|
||||
3. 修改 RPATH
|
||||
1. 执行 `sudo apt install patchelf` 或 `pip install patchelf` 安装 patchelf;
|
||||
2. 执行 `patchelf --version`,确保版本大于等于 0.14;
|
||||
3. 执行 `patchelf --add-rpath \$ORIGIN/dl_lib NanoKVM-Server` 修改可执行文件的 RPATH 属性。
|
||||
|
||||
4. 部署
|
||||
1. 上传文件需要启用 SSH 功能。请在 Web `设置 - SSH` 中检查 SSH 是否已经启用;
|
||||
2. 使用编译生成的 `NanoKVM-Server` 文件,替换 NanoKVM 中 `/kvmapp/server/` 目录下的原始文件;
|
||||
3. 在 NanoKVM 中执行 `/etc/init.d/S95nanokvm restart` 重启服务。
|
||||
|
||||
## 手动更新
|
||||
|
||||
> 请确保已经在 Web 界面的 `设置 - SSH` 中启用了 SSH 功能,以便上传文件。
|
||||
|
||||
1. 从 [GitHub](https://github.com/sipeed/NanoKVM/releases) 下载最新的应用安装包;
|
||||
2. 解压缩下载的安装包,并将解压后的文件夹重命名为 `kvmapp`;
|
||||
3. 备份 NanoKVM 系统中的 `/kvmapp` 目录,然后用解压后的 `kvmapp` 文件夹替换现有目录。
|
||||
4. 在 NanoKVM 中执行 `/etc/init.d/S95nanokvm restart` 重启服务。
|
||||
322
server/authn/permissions.go
Normal file
322
server/authn/permissions.go
Normal file
@@ -0,0 +1,322 @@
|
||||
package authn
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Permission identifies a grantable capability. The admin role implicitly holds
|
||||
// every permission; the user role only holds the permissions stored on the
|
||||
// account.
|
||||
//
|
||||
// A permission names what it lets the account do, not the settings page it
|
||||
// lives on, and every grant that changes something shared says so in the
|
||||
// catalog's risk and effect metadata instead of in the label alone.
|
||||
type Permission string
|
||||
|
||||
const (
|
||||
// Console grants.
|
||||
PermConsoleView Permission = "console.view"
|
||||
PermConsoleControl Permission = "console.control"
|
||||
|
||||
// Target-machine grants.
|
||||
PermPower Permission = "power"
|
||||
PermMediumAttach Permission = "medium.attach"
|
||||
|
||||
// Media library grants.
|
||||
PermLibraryRead Permission = "library.read"
|
||||
PermLibraryWrite Permission = "library.write"
|
||||
|
||||
// Host grants.
|
||||
PermTerminal Permission = "terminal"
|
||||
PermDevice Permission = "device"
|
||||
PermNetwork Permission = "network"
|
||||
PermUpdate Permission = "update"
|
||||
|
||||
// Service grants.
|
||||
PermMcp Permission = "mcp"
|
||||
PermTailscale Permission = "tailscale"
|
||||
PermAi Permission = "ai"
|
||||
)
|
||||
|
||||
// Group names the party a grant reaches. The account editor renders one section
|
||||
// per group, so the sections stay meaningful as the catalog grows.
|
||||
type Group string
|
||||
|
||||
const (
|
||||
// GroupConsole is what an account may do with the console it is watching.
|
||||
GroupConsole Group = "console"
|
||||
// GroupTarget is what it may do to the machine behind the console.
|
||||
GroupTarget Group = "target"
|
||||
// GroupLibrary is what it may do with the media library on this device.
|
||||
GroupLibrary Group = "library"
|
||||
// GroupHost is what it may change on this device.
|
||||
GroupHost Group = "host"
|
||||
// GroupServices are the add-ons that reach the device on their own.
|
||||
GroupServices Group = "services"
|
||||
)
|
||||
|
||||
// Risk states how far a grant reaches, and the catalog carries two levels: a
|
||||
// plain grant, and the grants that amount to full device control, which the
|
||||
// account editor marks and names before the grants are saved.
|
||||
type Risk string
|
||||
|
||||
const (
|
||||
// RiskInfo is a grant that stays within the feature it names.
|
||||
RiskInfo Risk = "info"
|
||||
// RiskWarn is a grant that amounts to full device control: a root shell,
|
||||
// the AI loopback, an API key that drives input outside the web session, and
|
||||
// a package install whose checksum the uploader supplies.
|
||||
RiskWarn Risk = "warn"
|
||||
)
|
||||
|
||||
// Descriptor is one catalog entry: the grant, the group it belongs to, the risk
|
||||
// an administrator takes by granting it, and the grants it implies.
|
||||
type Descriptor struct {
|
||||
Permission Permission `json:"id"`
|
||||
Group Group `json:"group"`
|
||||
Risk Risk `json:"risk"`
|
||||
Implies []Permission `json:"implies,omitempty"`
|
||||
}
|
||||
|
||||
// Implied grants are declared once here instead of as unions at every call
|
||||
// site: control without the picture is meaningless, nothing can be attached or
|
||||
// changed in the library without being allowed to see it first, and the grants
|
||||
// whose controls live in the console menu imply the console, because no page
|
||||
// outside it renders them and a grant nothing can use is a promise the app
|
||||
// cannot keep. Terminal and the media grants stand on their own pages.
|
||||
var permissionCatalog = []Descriptor{
|
||||
{Permission: PermConsoleView, Group: GroupConsole, Risk: RiskInfo},
|
||||
{
|
||||
Permission: PermConsoleControl,
|
||||
Group: GroupConsole,
|
||||
Risk: RiskInfo,
|
||||
Implies: []Permission{PermConsoleView},
|
||||
},
|
||||
{
|
||||
Permission: PermPower,
|
||||
Group: GroupTarget,
|
||||
Risk: RiskInfo,
|
||||
Implies: []Permission{PermConsoleView},
|
||||
},
|
||||
{
|
||||
Permission: PermMediumAttach,
|
||||
Group: GroupTarget,
|
||||
Risk: RiskInfo,
|
||||
Implies: []Permission{PermLibraryRead},
|
||||
},
|
||||
{Permission: PermLibraryRead, Group: GroupLibrary, Risk: RiskInfo},
|
||||
{
|
||||
Permission: PermLibraryWrite,
|
||||
Group: GroupLibrary,
|
||||
Risk: RiskInfo,
|
||||
Implies: []Permission{PermLibraryRead},
|
||||
},
|
||||
{Permission: PermTerminal, Group: GroupHost, Risk: RiskWarn},
|
||||
{
|
||||
Permission: PermDevice,
|
||||
Group: GroupHost,
|
||||
Risk: RiskInfo,
|
||||
Implies: []Permission{PermConsoleView},
|
||||
},
|
||||
{
|
||||
Permission: PermNetwork,
|
||||
Group: GroupHost,
|
||||
Risk: RiskInfo,
|
||||
Implies: []Permission{PermConsoleView},
|
||||
},
|
||||
{
|
||||
Permission: PermUpdate,
|
||||
Group: GroupHost,
|
||||
Risk: RiskWarn,
|
||||
Implies: []Permission{PermConsoleView},
|
||||
},
|
||||
{
|
||||
Permission: PermMcp,
|
||||
Group: GroupServices,
|
||||
Risk: RiskWarn,
|
||||
Implies: []Permission{PermConsoleView},
|
||||
},
|
||||
{
|
||||
Permission: PermTailscale,
|
||||
Group: GroupServices,
|
||||
Risk: RiskInfo,
|
||||
Implies: []Permission{PermConsoleView},
|
||||
},
|
||||
{
|
||||
Permission: PermAi,
|
||||
Group: GroupServices,
|
||||
Risk: RiskWarn,
|
||||
Implies: []Permission{PermConsoleView},
|
||||
},
|
||||
}
|
||||
|
||||
// Grants of earlier releases, kept so an account file written by one of them
|
||||
// keeps meaning what it meant. media.mount and media.manage split into the
|
||||
// attach/read/write grants above.
|
||||
const (
|
||||
legacyPermMediaMount Permission = "media.mount"
|
||||
legacyPermMediaManage Permission = "media.manage"
|
||||
)
|
||||
|
||||
// Catalog returns the catalog in display order.
|
||||
func Catalog() []Descriptor {
|
||||
catalog := make([]Descriptor, len(permissionCatalog))
|
||||
for index, descriptor := range permissionCatalog {
|
||||
catalog[index] = descriptor
|
||||
catalog[index].Implies = append([]Permission(nil), descriptor.Implies...)
|
||||
}
|
||||
return catalog
|
||||
}
|
||||
|
||||
// PermissionIDs returns every grantable permission in catalog order.
|
||||
func PermissionIDs() []Permission {
|
||||
ids := make([]Permission, 0, len(permissionCatalog))
|
||||
for _, descriptor := range permissionCatalog {
|
||||
ids = append(ids, descriptor.Permission)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
func IsValidPermission(permission Permission) bool {
|
||||
for _, descriptor := range permissionCatalog {
|
||||
if descriptor.Permission == permission {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ValidatePermissions rejects unknown or duplicate permissions. It is for grant
|
||||
// sets arriving in a request; the grant set stored on an account is validated by
|
||||
// ValidateStoredPermissions, which tolerates ids this build does not know.
|
||||
func ValidatePermissions(permissions []Permission) error {
|
||||
seen := make(map[Permission]struct{}, len(permissions))
|
||||
for _, permission := range permissions {
|
||||
if !IsValidPermission(permission) {
|
||||
return fmt.Errorf("unknown permission: %q", permission)
|
||||
}
|
||||
if _, exists := seen[permission]; exists {
|
||||
return fmt.Errorf("duplicate permission: %q", permission)
|
||||
}
|
||||
seen[permission] = struct{}{}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateStoredPermissions only rejects duplicates. An account file written by
|
||||
// a newer release carries grants this build cannot evaluate, and refusing to
|
||||
// load it would lock the device out instead of ignoring a capability that is
|
||||
// unavailable here anyway.
|
||||
func ValidateStoredPermissions(permissions []Permission) error {
|
||||
seen := make(map[Permission]struct{}, len(permissions))
|
||||
for _, permission := range permissions {
|
||||
if _, exists := seen[permission]; exists {
|
||||
return fmt.Errorf("duplicate permission: %q", permission)
|
||||
}
|
||||
seen[permission] = struct{}{}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Has reports whether the set contains the permission. Administrators are not
|
||||
// special-cased: callers that should honor the role's implicit grants resolve
|
||||
// EffectivePermissions first.
|
||||
func Has(permissions []Permission, permission Permission) bool {
|
||||
for _, granted := range permissions {
|
||||
if granted == permission {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Closure resolves the grants an account ends up holding: the set itself plus
|
||||
// everything it implies, transitively, in catalog order.
|
||||
func Closure(permissions []Permission) []Permission {
|
||||
granted := closureSet(permissions)
|
||||
|
||||
resolved := make([]Permission, 0, len(granted))
|
||||
for _, descriptor := range permissionCatalog {
|
||||
if _, ok := granted[descriptor.Permission]; ok {
|
||||
resolved = append(resolved, descriptor.Permission)
|
||||
delete(granted, descriptor.Permission)
|
||||
}
|
||||
}
|
||||
// Keep ids this build does not know in the order they were stored, so they
|
||||
// still round-trip through the client.
|
||||
for _, permission := range permissions {
|
||||
if _, ok := granted[permission]; ok {
|
||||
resolved = append(resolved, permission)
|
||||
delete(granted, permission)
|
||||
}
|
||||
}
|
||||
return resolved
|
||||
}
|
||||
|
||||
func closureSet(permissions []Permission) map[Permission]struct{} {
|
||||
granted := make(map[Permission]struct{}, len(permissions))
|
||||
var add func(Permission)
|
||||
add = func(permission Permission) {
|
||||
if _, exists := granted[permission]; exists {
|
||||
return
|
||||
}
|
||||
granted[permission] = struct{}{}
|
||||
for _, descriptor := range permissionCatalog {
|
||||
if descriptor.Permission != permission {
|
||||
continue
|
||||
}
|
||||
for _, implied := range descriptor.Implies {
|
||||
add(implied)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, permission := range permissions {
|
||||
add(permission)
|
||||
}
|
||||
return granted
|
||||
}
|
||||
|
||||
// NormalizeStoredPermissions translates the grants an earlier release wrote and
|
||||
// removes duplicates, so the store holds one spelling of every capability.
|
||||
// Unknown ids are preserved: a downgrade must not silently drop a grant.
|
||||
func NormalizeStoredPermissions(permissions []Permission) []Permission {
|
||||
normalized := make([]Permission, 0, len(permissions)+2)
|
||||
appendOnce := func(permission Permission) {
|
||||
if !Has(normalized, permission) {
|
||||
normalized = append(normalized, permission)
|
||||
}
|
||||
}
|
||||
for _, permission := range permissions {
|
||||
switch permission {
|
||||
case legacyPermMediaMount:
|
||||
// Attaching a medium is what let a watcher read the library.
|
||||
appendOnce(PermMediumAttach)
|
||||
appendOnce(PermLibraryRead)
|
||||
case legacyPermMediaManage:
|
||||
appendOnce(PermLibraryRead)
|
||||
appendOnce(PermLibraryWrite)
|
||||
default:
|
||||
appendOnce(permission)
|
||||
}
|
||||
}
|
||||
return normalized
|
||||
}
|
||||
|
||||
// legacyUserPermissions preserves the capabilities the user role had before
|
||||
// fine-grained permissions existed: full console access and power control.
|
||||
func legacyUserPermissions() []Permission {
|
||||
return []Permission{PermConsoleView, PermConsoleControl, PermPower}
|
||||
}
|
||||
|
||||
// EffectivePermissions resolves what a user can actually do: administrators
|
||||
// hold the whole catalog, regular users hold their stored grants and whatever
|
||||
// those imply.
|
||||
func EffectivePermissions(user *User) []Permission {
|
||||
if user == nil {
|
||||
return nil
|
||||
}
|
||||
if user.Role == RoleAdmin {
|
||||
return PermissionIDs()
|
||||
}
|
||||
return Closure(user.Permissions)
|
||||
}
|
||||
86
server/authn/permissions_test.go
Normal file
86
server/authn/permissions_test.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package authn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestClosureResolvesImpliedGrants(t *testing.T) {
|
||||
cases := []struct {
|
||||
grants []Permission
|
||||
want []Permission
|
||||
}{
|
||||
{[]Permission{PermConsoleControl}, []Permission{PermConsoleView, PermConsoleControl}},
|
||||
{[]Permission{PermMediumAttach}, []Permission{PermMediumAttach, PermLibraryRead}},
|
||||
{[]Permission{PermLibraryWrite}, []Permission{PermLibraryRead, PermLibraryWrite}},
|
||||
{[]Permission{PermTerminal}, []Permission{PermTerminal}},
|
||||
{[]Permission{"future.grant", PermMcp}, []Permission{PermConsoleView, PermMcp, "future.grant"}},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
if got := Closure(tc.grants); !slices.Equal(got, tc.want) {
|
||||
t.Errorf("Closure(%v) = %v, want %v", tc.grants, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeTranslatesLegacyMediaGrants(t *testing.T) {
|
||||
got := NormalizeStoredPermissions([]Permission{legacyPermMediaMount, legacyPermMediaManage, PermPower})
|
||||
want := []Permission{PermMediumAttach, PermLibraryRead, PermLibraryWrite, PermPower}
|
||||
if !slices.Equal(got, want) {
|
||||
t.Fatalf("NormalizeStoredPermissions = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateReturnsPreviousAndKeepsUnknownGrants(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "pwd")
|
||||
store := NewStore(path)
|
||||
if err := store.Create("alice", "password", RoleUser, PermConsoleView); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// A newer release stored a grant this build does not know.
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var db database
|
||||
if err = json.Unmarshal(data, &db); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
index := userIndex(db.Users, "alice")
|
||||
db.Users[index].Permissions = append(db.Users[index].Permissions, "future.grant")
|
||||
if data, err = json.Marshal(db); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = os.WriteFile(path, data, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
grants := []Permission{PermConsoleControl}
|
||||
previous, updated, err := store.Update("admin", "alice", UserPatch{Permissions: &grants})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !slices.Equal(previous.Permissions, []Permission{PermConsoleView, "future.grant"}) {
|
||||
t.Fatalf("previous permissions = %v", previous.Permissions)
|
||||
}
|
||||
if !slices.Equal(updated.Permissions, []Permission{PermConsoleControl, "future.grant"}) {
|
||||
t.Fatalf("updated permissions = %v", updated.Permissions)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOnlyFullControlGrantsWarn(t *testing.T) {
|
||||
var warned []Permission
|
||||
for _, descriptor := range Catalog() {
|
||||
if descriptor.Risk == RiskWarn {
|
||||
warned = append(warned, descriptor.Permission)
|
||||
}
|
||||
}
|
||||
want := []Permission{PermTerminal, PermUpdate, PermMcp, PermAi}
|
||||
if !slices.Equal(warned, want) {
|
||||
t.Fatalf("warned grants = %v, want %v", warned, want)
|
||||
}
|
||||
}
|
||||
719
server/authn/store.go
Normal file
719
server/authn/store.go
Normal file
@@ -0,0 +1,719 @@
|
||||
package authn
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sync"
|
||||
|
||||
"NanoKVM-Server/utils"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
const (
|
||||
AccountFile = "/etc/kvm/pwd"
|
||||
currentFileVersion = 1
|
||||
defaultUsername = "admin"
|
||||
defaultPassword = "admin"
|
||||
)
|
||||
|
||||
type Role string
|
||||
|
||||
const (
|
||||
RoleAdmin Role = "admin"
|
||||
RoleUser Role = "user"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUserNotFound = errors.New("user not found")
|
||||
ErrUserExists = errors.New("username already exists")
|
||||
ErrLastAdmin = errors.New("at least one enabled admin is required")
|
||||
ErrSelfModification = errors.New("administrators cannot disable or demote themselves")
|
||||
ErrSelfDelete = errors.New("administrators cannot delete themselves")
|
||||
ErrSystemAccount = errors.New("the device owner account must remain an enabled administrator")
|
||||
|
||||
usernamePattern = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9_.-]{0,31}$`)
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Username string `json:"username"`
|
||||
PasswordHash string `json:"password"`
|
||||
Role Role `json:"role"`
|
||||
Enabled bool `json:"enabled"`
|
||||
TokenVersion uint64 `json:"tokenVersion"`
|
||||
Permissions []Permission `json:"permissions"`
|
||||
MustChangePassword bool `json:"mustChangePassword,omitempty"`
|
||||
SystemAccount bool `json:"systemAccount,omitempty"`
|
||||
}
|
||||
|
||||
type UserInfo struct {
|
||||
Username string `json:"username"`
|
||||
Role Role `json:"role"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Permissions []Permission `json:"permissions"`
|
||||
SystemAccount bool `json:"systemAccount,omitempty"`
|
||||
}
|
||||
|
||||
type UserPatch struct {
|
||||
Role *Role
|
||||
Enabled *bool
|
||||
Permissions *[]Permission
|
||||
}
|
||||
|
||||
type database struct {
|
||||
Version int `json:"version"`
|
||||
Users []User `json:"users"`
|
||||
LegacyUsername string `json:"username,omitempty"`
|
||||
LegacyPassword string `json:"password,omitempty"`
|
||||
}
|
||||
|
||||
type legacyAccount struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type Store struct {
|
||||
path string
|
||||
mutex sync.RWMutex
|
||||
}
|
||||
|
||||
var DefaultStore = NewStore(AccountFile)
|
||||
|
||||
func NewStore(path string) *Store {
|
||||
return &Store{path: path}
|
||||
}
|
||||
|
||||
func IsValidRole(role Role) bool {
|
||||
return role == RoleAdmin || role == RoleUser
|
||||
}
|
||||
|
||||
func ValidateUsername(username string) error {
|
||||
if !usernamePattern.MatchString(username) {
|
||||
return errors.New("username must be 1-32 characters and contain only letters, numbers, '.', '_' or '-'")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidatePassword(password string) error {
|
||||
length := len([]byte(password))
|
||||
if length < 8 || length > 72 {
|
||||
return errors.New("password must be between 8 and 72 bytes")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) List() ([]UserInfo, error) {
|
||||
s.mutex.RLock()
|
||||
defer s.mutex.RUnlock()
|
||||
|
||||
db, err := s.loadLocked(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
users := make([]UserInfo, 0, len(db.Users))
|
||||
for index := range db.Users {
|
||||
user := &db.Users[index]
|
||||
// The stored grants, not the effective ones: the editor shows what an
|
||||
// administrator set, and what an account implies is derived from the
|
||||
// catalog instead of being written back on every save.
|
||||
users = append(users, UserInfo{
|
||||
Username: user.Username,
|
||||
Role: user.Role,
|
||||
Enabled: user.Enabled,
|
||||
Permissions: clonePermissions(user.Permissions),
|
||||
SystemAccount: user.SystemAccount,
|
||||
})
|
||||
}
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func (s *Store) Get(username string) (*User, error) {
|
||||
s.mutex.RLock()
|
||||
defer s.mutex.RUnlock()
|
||||
|
||||
db, err := s.loadLocked(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return findUser(db.Users, username)
|
||||
}
|
||||
|
||||
func (s *Store) Authenticate(username, password string) (*User, bool, error) {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
db, err := s.loadLocked(true)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
user, err := findUser(db.Users, username)
|
||||
if err != nil || !user.Enabled {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
if bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(password)) == nil {
|
||||
return user, true, nil
|
||||
}
|
||||
|
||||
// Older releases stored a reversibly encrypted password. Upgrade it after
|
||||
// the first successful login so the compatibility path is not permanent.
|
||||
legacyPassword, decodeErr := utils.DecodeDecrypt(user.PasswordHash)
|
||||
if decodeErr != nil || legacyPassword != password {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
hash, hashErr := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
if hashErr != nil {
|
||||
return nil, false, hashErr
|
||||
}
|
||||
for index := range db.Users {
|
||||
if db.Users[index].Username == username {
|
||||
db.Users[index].PasswordHash = string(hash)
|
||||
if db.Users[index].TokenVersion == 0 {
|
||||
db.Users[index].TokenVersion = 1
|
||||
}
|
||||
user = cloneUser(&db.Users[index])
|
||||
break
|
||||
}
|
||||
}
|
||||
if err = s.saveLocked(db); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
return user, true, nil
|
||||
}
|
||||
|
||||
func (s *Store) ValidateToken(username string, tokenVersion uint64) (*User, error) {
|
||||
user, err := s.Get(username)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !user.Enabled || user.TokenVersion != tokenVersion {
|
||||
return nil, errors.New("session revoked")
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (s *Store) Create(username, password string, role Role, permissions ...Permission) error {
|
||||
if err := ValidateUsername(username); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ValidatePassword(password); err != nil {
|
||||
return err
|
||||
}
|
||||
if !IsValidRole(role) {
|
||||
return errors.New("invalid role")
|
||||
}
|
||||
// A nil set means the caller named none at all, which keeps the meaning it
|
||||
// had before grants existed: an account created by a script that only knows
|
||||
// about roles gets what the user role granted then. An explicit empty set is
|
||||
// a decision and stays empty, so the account really holds nothing.
|
||||
if permissions == nil && role == RoleUser {
|
||||
permissions = legacyUserPermissions()
|
||||
}
|
||||
if err := ValidatePermissions(permissions); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tokenVersion, err := newTokenVersion()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
db, err := s.loadLocked(true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err = findUser(db.Users, username); err == nil {
|
||||
return ErrUserExists
|
||||
}
|
||||
db.Users = append(db.Users, User{
|
||||
Username: username,
|
||||
PasswordHash: string(hash),
|
||||
Role: role,
|
||||
Enabled: true,
|
||||
TokenVersion: tokenVersion,
|
||||
Permissions: NormalizeStoredPermissions(permissions),
|
||||
})
|
||||
return s.saveLocked(db)
|
||||
}
|
||||
|
||||
// Update applies the patch and returns the account as it was before and after,
|
||||
// both read under the store lock, so a caller comparing the two sees exactly the
|
||||
// change it made even while another update runs.
|
||||
func (s *Store) Update(actor, username string, patch UserPatch) (previous, updated *User, err error) {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
db, err := s.loadLocked(true)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
index := userIndex(db.Users, username)
|
||||
if index < 0 {
|
||||
return nil, nil, ErrUserNotFound
|
||||
}
|
||||
previous = cloneUser(&db.Users[index])
|
||||
user := db.Users[index]
|
||||
|
||||
if patch.Role != nil && !IsValidRole(*patch.Role) {
|
||||
return nil, nil, errors.New("invalid role")
|
||||
}
|
||||
// The patch is normalized before it is compared and stored, so a caller that
|
||||
// still sends the split media grants does not look like a change once they
|
||||
// resolve to the grants they now mean.
|
||||
granted := user.Permissions
|
||||
if patch.Permissions != nil {
|
||||
if err := ValidatePermissions(*patch.Permissions); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
granted = NormalizeStoredPermissions(*patch.Permissions)
|
||||
// A request can only name grants this build knows, so the ones it does
|
||||
// not (written by a newer release) are carried over instead of being
|
||||
// dropped by an editor that never showed them.
|
||||
for _, permission := range user.Permissions {
|
||||
if !IsValidPermission(permission) && !Has(granted, permission) {
|
||||
granted = append(granted, permission)
|
||||
}
|
||||
}
|
||||
}
|
||||
if actor == username && user.Role == RoleAdmin &&
|
||||
((patch.Role != nil && *patch.Role != RoleAdmin) || (patch.Enabled != nil && !*patch.Enabled)) {
|
||||
return nil, nil, ErrSelfModification
|
||||
}
|
||||
if user.SystemAccount &&
|
||||
((patch.Role != nil && *patch.Role != RoleAdmin) || (patch.Enabled != nil && !*patch.Enabled)) {
|
||||
return nil, nil, ErrSystemAccount
|
||||
}
|
||||
|
||||
changed := false
|
||||
// Only disabling the account invalidates its login. A role change does not:
|
||||
// the principal is rebuilt from the account file on every request, and the
|
||||
// caller refreshes the user's long-lived connections so they reconnect under
|
||||
// the role's new grants. Bumping the token version for a role change would
|
||||
// log the account out mid-session just because it was promoted or demoted.
|
||||
loginInvalidated := false
|
||||
if patch.Role != nil && user.Role != *patch.Role {
|
||||
user.Role = *patch.Role
|
||||
changed = true
|
||||
}
|
||||
if patch.Enabled != nil && user.Enabled != *patch.Enabled {
|
||||
user.Enabled = *patch.Enabled
|
||||
changed = true
|
||||
loginInvalidated = true
|
||||
}
|
||||
if patch.Permissions != nil && !permissionsEqual(user.Permissions, granted) {
|
||||
user.Permissions = granted
|
||||
changed = true
|
||||
}
|
||||
if !changed {
|
||||
return previous, cloneUser(&user), nil
|
||||
}
|
||||
|
||||
db.Users[index] = user
|
||||
if enabledAdminCount(db.Users) == 0 {
|
||||
return nil, nil, ErrLastAdmin
|
||||
}
|
||||
// Permission and role updates keep the login valid: the principal is rebuilt
|
||||
// from the store on every request, so new grants apply immediately and
|
||||
// revoked ones are enforced by dropping connections from the handler.
|
||||
if loginInvalidated {
|
||||
db.Users[index].TokenVersion++
|
||||
}
|
||||
if err = s.saveLocked(db); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return previous, cloneUser(&db.Users[index]), nil
|
||||
}
|
||||
|
||||
func (s *Store) Delete(actor, username string) error {
|
||||
if actor == username {
|
||||
return ErrSelfDelete
|
||||
}
|
||||
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
db, err := s.loadLocked(true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
index := userIndex(db.Users, username)
|
||||
if index < 0 {
|
||||
return ErrUserNotFound
|
||||
}
|
||||
if db.Users[index].SystemAccount {
|
||||
return ErrSystemAccount
|
||||
}
|
||||
users := append([]User(nil), db.Users[:index]...)
|
||||
users = append(users, db.Users[index+1:]...)
|
||||
if enabledAdminCount(users) == 0 {
|
||||
return ErrLastAdmin
|
||||
}
|
||||
db.Users = users
|
||||
return s.saveLocked(db)
|
||||
}
|
||||
|
||||
func (s *Store) SetPassword(username, password string) (*User, error) {
|
||||
return s.SetPasswordAndRun(username, password, nil)
|
||||
}
|
||||
|
||||
// SetPasswordAndRun commits the web password before running the optional
|
||||
// system-side update. If that update fails, the account record is rolled back
|
||||
// while the store lock is still held.
|
||||
func (s *Store) SetPasswordAndRun(username, password string, afterCommit func() error) (*User, error) {
|
||||
if err := ValidatePassword(password); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
db, err := s.loadLocked(true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
index := userIndex(db.Users, username)
|
||||
if index < 0 {
|
||||
return nil, ErrUserNotFound
|
||||
}
|
||||
previous := *db
|
||||
previous.Users = append([]User(nil), db.Users...)
|
||||
db.Users[index].PasswordHash = string(hash)
|
||||
db.Users[index].MustChangePassword = false
|
||||
db.Users[index].TokenVersion++
|
||||
if err = s.saveLocked(db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if afterCommit != nil {
|
||||
if err = afterCommit(); err != nil {
|
||||
if rollbackErr := s.saveLocked(&previous); rollbackErr != nil {
|
||||
return nil, fmt.Errorf("system password update failed: %v; account rollback failed: %w", err, rollbackErr)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return cloneUser(&db.Users[index]), nil
|
||||
}
|
||||
|
||||
func (s *Store) Revoke(username string) (*User, error) {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
db, err := s.loadLocked(true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
index := userIndex(db.Users, username)
|
||||
if index < 0 {
|
||||
return nil, ErrUserNotFound
|
||||
}
|
||||
db.Users[index].TokenVersion++
|
||||
if err = s.saveLocked(db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cloneUser(&db.Users[index]), nil
|
||||
}
|
||||
|
||||
func (s *Store) loadLocked(migrate bool) (*database, error) {
|
||||
data, err := os.ReadFile(s.path)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
db, defaultErr := defaultDatabase()
|
||||
if defaultErr != nil {
|
||||
return nil, defaultErr
|
||||
}
|
||||
materializePermissions(db)
|
||||
if migrate {
|
||||
if saveErr := s.saveLocked(db); saveErr != nil {
|
||||
return nil, saveErr
|
||||
}
|
||||
}
|
||||
return db, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var db database
|
||||
if err = json.Unmarshal(data, &db); err == nil && db.Version != 0 {
|
||||
materializePermissions(&db)
|
||||
if err = validateDatabase(&db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &db, nil
|
||||
}
|
||||
|
||||
var legacy legacyAccount
|
||||
if err = json.Unmarshal(data, &legacy); err != nil || legacy.Username == "" || legacy.Password == "" {
|
||||
return nil, errors.New("invalid account file")
|
||||
}
|
||||
if err = ValidateUsername(legacy.Username); err != nil {
|
||||
return nil, fmt.Errorf("invalid legacy username: %w", err)
|
||||
}
|
||||
tokenVersion, err := newTokenVersion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
db = database{
|
||||
Version: currentFileVersion,
|
||||
Users: []User{{
|
||||
Username: legacy.Username,
|
||||
PasswordHash: legacy.Password,
|
||||
Role: RoleAdmin,
|
||||
Enabled: true,
|
||||
TokenVersion: tokenVersion,
|
||||
MustChangePassword: passwordMatches(legacy.Password, defaultPassword),
|
||||
SystemAccount: true,
|
||||
}},
|
||||
}
|
||||
materializePermissions(&db)
|
||||
if migrate {
|
||||
if err = s.saveLocked(&db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return &db, nil
|
||||
}
|
||||
|
||||
func (s *Store) saveLocked(db *database) error {
|
||||
if err := validateDatabase(db); err != nil {
|
||||
return err
|
||||
}
|
||||
syncLegacyAccount(db)
|
||||
data, err := json.MarshalIndent(db, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data = append(data, '\n')
|
||||
|
||||
directory := filepath.Dir(s.path)
|
||||
if err = os.MkdirAll(directory, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
temporary, err := os.CreateTemp(directory, ".pwd-*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
temporaryPath := temporary.Name()
|
||||
defer func() { _ = os.Remove(temporaryPath) }()
|
||||
|
||||
if err = temporary.Chmod(0o600); err == nil {
|
||||
_, err = temporary.Write(data)
|
||||
}
|
||||
if err == nil {
|
||||
err = temporary.Sync()
|
||||
}
|
||||
closeErr := temporary.Close()
|
||||
if err == nil {
|
||||
err = closeErr
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = os.Rename(temporaryPath, s.path); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dir, err := os.Open(directory)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { _ = dir.Close() }()
|
||||
return dir.Sync()
|
||||
}
|
||||
|
||||
func defaultDatabase() (*database, error) {
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(defaultPassword), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tokenVersion, err := newTokenVersion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &database{
|
||||
Version: currentFileVersion,
|
||||
Users: []User{{
|
||||
Username: defaultUsername,
|
||||
PasswordHash: string(hash),
|
||||
Role: RoleAdmin,
|
||||
Enabled: true,
|
||||
TokenVersion: tokenVersion,
|
||||
MustChangePassword: true,
|
||||
SystemAccount: true,
|
||||
}},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newTokenVersion() (uint64, error) {
|
||||
var data [8]byte
|
||||
for {
|
||||
if _, err := rand.Read(data[:]); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
version := binary.LittleEndian.Uint64(data[:])
|
||||
if version != 0 && version != ^uint64(0) {
|
||||
return version, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func validateDatabase(db *database) error {
|
||||
if db.Version != currentFileVersion {
|
||||
return fmt.Errorf("unsupported account file version: %d", db.Version)
|
||||
}
|
||||
if len(db.Users) == 0 {
|
||||
return errors.New("account file contains no users")
|
||||
}
|
||||
seen := make(map[string]struct{}, len(db.Users))
|
||||
systemAccounts := 0
|
||||
for index := range db.Users {
|
||||
user := &db.Users[index]
|
||||
if err := ValidateUsername(user.Username); err != nil {
|
||||
return err
|
||||
}
|
||||
if user.PasswordHash == "" || !IsValidRole(user.Role) {
|
||||
return errors.New("account file contains an invalid user")
|
||||
}
|
||||
if err := ValidateStoredPermissions(user.Permissions); err != nil {
|
||||
return fmt.Errorf("account file contains invalid permissions for %q: %w", user.Username, err)
|
||||
}
|
||||
if _, exists := seen[user.Username]; exists {
|
||||
return errors.New("account file contains duplicate usernames")
|
||||
}
|
||||
seen[user.Username] = struct{}{}
|
||||
if user.TokenVersion == 0 {
|
||||
user.TokenVersion = 1
|
||||
}
|
||||
if user.SystemAccount {
|
||||
systemAccounts++
|
||||
if user.Role != RoleAdmin || !user.Enabled || systemAccounts > 1 {
|
||||
return ErrSystemAccount
|
||||
}
|
||||
}
|
||||
}
|
||||
if enabledAdminCount(db.Users) == 0 {
|
||||
return ErrLastAdmin
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func findUser(users []User, username string) (*User, error) {
|
||||
index := userIndex(users, username)
|
||||
if index < 0 {
|
||||
return nil, ErrUserNotFound
|
||||
}
|
||||
return cloneUser(&users[index]), nil
|
||||
}
|
||||
|
||||
func userIndex(users []User, username string) int {
|
||||
for index := range users {
|
||||
if users[index].Username == username {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// materializePermissions replaces the grant shapes of earlier releases with an
|
||||
// explicit set: an account that predates fine-grained permissions keeps exactly
|
||||
// what the user role used to grant, and the split media grants are translated.
|
||||
// After this the store never holds a nil set, so "no grants" and "never
|
||||
// configured" can no longer be confused, and no caller has to special-case nil.
|
||||
func materializePermissions(db *database) {
|
||||
for index := range db.Users {
|
||||
if db.Users[index].Permissions == nil {
|
||||
db.Users[index].Permissions = legacyUserPermissions()
|
||||
continue
|
||||
}
|
||||
db.Users[index].Permissions = NormalizeStoredPermissions(db.Users[index].Permissions)
|
||||
}
|
||||
}
|
||||
|
||||
func clonePermissions(permissions []Permission) []Permission {
|
||||
return append([]Permission{}, permissions...)
|
||||
}
|
||||
|
||||
func permissionsEqual(a, b []Permission) bool {
|
||||
if (a == nil) != (b == nil) {
|
||||
return false
|
||||
}
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
// The stored order carries no meaning, so a reordering must not look like
|
||||
// a change worth writing back.
|
||||
seen := make(map[Permission]struct{}, len(a))
|
||||
for _, permission := range a {
|
||||
seen[permission] = struct{}{}
|
||||
}
|
||||
for _, permission := range b {
|
||||
if _, exists := seen[permission]; !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func enabledAdminCount(users []User) int {
|
||||
count := 0
|
||||
for _, user := range users {
|
||||
if user.Role == RoleAdmin && user.Enabled {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func cloneUser(user *User) *User {
|
||||
if user == nil {
|
||||
return nil
|
||||
}
|
||||
copy := *user
|
||||
return ©
|
||||
}
|
||||
|
||||
func passwordMatches(hash, password string) bool {
|
||||
if bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) == nil {
|
||||
return true
|
||||
}
|
||||
legacyPassword, err := utils.DecodeDecrypt(hash)
|
||||
return err == nil && legacyPassword == password
|
||||
}
|
||||
|
||||
// Keep a legacy top-level account mirror so downgrading to a single-user
|
||||
// server still authenticates the original device owner instead of failing
|
||||
// open or forcing an immediate physical reset.
|
||||
func syncLegacyAccount(db *database) {
|
||||
db.LegacyUsername = ""
|
||||
db.LegacyPassword = ""
|
||||
var fallback *User
|
||||
for _, user := range db.Users {
|
||||
if user.SystemAccount {
|
||||
db.LegacyUsername = user.Username
|
||||
db.LegacyPassword = user.PasswordHash
|
||||
return
|
||||
}
|
||||
if fallback == nil && user.Role == RoleAdmin && user.Enabled {
|
||||
copy := user
|
||||
fallback = ©
|
||||
}
|
||||
}
|
||||
if fallback != nil {
|
||||
db.LegacyUsername = fallback.Username
|
||||
db.LegacyPassword = fallback.PasswordHash
|
||||
}
|
||||
}
|
||||
212
server/authn/store_test.go
Normal file
212
server/authn/store_test.go
Normal file
@@ -0,0 +1,212 @@
|
||||
package authn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func TestLegacyAccountMigratesInPlace(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "pwd")
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte("legacy-password"), bcrypt.MinCost)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
legacy, _ := json.Marshal(legacyAccount{Username: "owner", Password: string(hash)})
|
||||
if err = os.WriteFile(path, legacy, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
store := NewStore(path)
|
||||
user, ok, err := store.Authenticate("owner", "legacy-password")
|
||||
if err != nil || !ok {
|
||||
t.Fatalf("authenticate migrated account: ok=%v err=%v", ok, err)
|
||||
}
|
||||
if user.Role != RoleAdmin || !user.SystemAccount || user.TokenVersion == 0 {
|
||||
t.Fatalf("unexpected migrated user: %+v", user)
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var db database
|
||||
if err = json.Unmarshal(data, &db); err != nil {
|
||||
t.Fatalf("account file was not migrated: %v", err)
|
||||
}
|
||||
if db.Version != currentFileVersion || len(db.Users) != 1 {
|
||||
t.Fatalf("unexpected database: %+v", db)
|
||||
}
|
||||
var downgrade legacyAccount
|
||||
if err = json.Unmarshal(data, &downgrade); err != nil || downgrade.Username != "owner" || downgrade.Password == "" {
|
||||
t.Fatalf("legacy downgrade mirror is invalid: %+v, %v", downgrade, err)
|
||||
}
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if info.Mode().Perm() != 0o600 {
|
||||
t.Fatalf("account mode = %o, want 600", info.Mode().Perm())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCorruptAccountFileFailsClosed(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "pwd")
|
||||
if err := os.WriteFile(path, []byte("not json"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, ok, err := NewStore(path).Authenticate("admin", "admin")
|
||||
if err == nil || ok {
|
||||
t.Fatalf("corrupt file must fail closed: ok=%v err=%v", ok, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserLifecycleAndTokenRevocation(t *testing.T) {
|
||||
store := NewStore(filepath.Join(t.TempDir(), "pwd"))
|
||||
if _, ok, err := store.Authenticate("admin", "admin"); err != nil || !ok {
|
||||
t.Fatalf("default login: ok=%v err=%v", ok, err)
|
||||
}
|
||||
if err := store.Create("alice", "correct-horse", RoleUser); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok, err := store.Authenticate("alice", "wrong-password"); err != nil || ok {
|
||||
t.Fatalf("wrong password login: ok=%v err=%v", ok, err)
|
||||
}
|
||||
alice, err := store.Get("alice")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = store.ValidateToken("alice", alice.TokenVersion); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = store.SetPassword("alice", "new-password"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = store.ValidateToken("alice", alice.TokenVersion); err == nil {
|
||||
t.Fatal("old token stayed valid after password change")
|
||||
}
|
||||
if _, ok, err := store.Authenticate("alice", "new-password"); err != nil || !ok {
|
||||
t.Fatalf("new password login: ok=%v err=%v", ok, err)
|
||||
}
|
||||
|
||||
disabled := false
|
||||
if _, _, err = store.Update("admin", "alice", UserPatch{Enabled: &disabled}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok, err := store.Authenticate("alice", "new-password"); err != nil || ok {
|
||||
t.Fatalf("disabled login: ok=%v err=%v", ok, err)
|
||||
}
|
||||
enabled := true
|
||||
if _, _, err = store.Update("admin", "alice", UserPatch{Enabled: &enabled}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = store.Delete("admin", "alice"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = store.Get("alice"); !errors.Is(err, ErrUserNotFound) {
|
||||
t.Fatalf("deleted user lookup error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLastAdminAndSelfProtection(t *testing.T) {
|
||||
store := NewStore(filepath.Join(t.TempDir(), "pwd"))
|
||||
if _, ok, err := store.Authenticate("admin", "admin"); err != nil || !ok {
|
||||
t.Fatalf("default login: ok=%v err=%v", ok, err)
|
||||
}
|
||||
userRole := RoleUser
|
||||
if _, _, err := store.Update("admin", "admin", UserPatch{Role: &userRole}); !errors.Is(err, ErrSelfModification) {
|
||||
t.Fatalf("self demotion error = %v", err)
|
||||
}
|
||||
if err := store.Delete("admin", "admin"); !errors.Is(err, ErrSelfDelete) {
|
||||
t.Fatalf("self delete error = %v", err)
|
||||
}
|
||||
if err := store.Create("second", "second-password", RoleAdmin); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
disabled := false
|
||||
if _, _, err := store.Update("second", "admin", UserPatch{Enabled: &disabled}); !errors.Is(err, ErrSystemAccount) {
|
||||
t.Fatalf("disable device owner error = %v", err)
|
||||
}
|
||||
if _, _, err := store.Update("second", "admin", UserPatch{Role: &userRole}); !errors.Is(err, ErrSystemAccount) {
|
||||
t.Fatalf("demote device owner error = %v", err)
|
||||
}
|
||||
if err := store.Delete("second", "admin"); !errors.Is(err, ErrSystemAccount) {
|
||||
t.Fatalf("delete device owner error = %v", err)
|
||||
}
|
||||
if err := store.Delete("admin", "second"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemovedAccountFileAndRecreatedUserInvalidateOldVersions(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "pwd")
|
||||
store := NewStore(path)
|
||||
admin, ok, err := store.Authenticate("admin", "admin")
|
||||
if err != nil || !ok {
|
||||
t.Fatalf("default login: ok=%v err=%v", ok, err)
|
||||
}
|
||||
if err = os.Remove(path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = store.ValidateToken("admin", admin.TokenVersion); err == nil {
|
||||
t.Fatal("old admin token survived account-file reset")
|
||||
}
|
||||
|
||||
if _, ok, err = store.Authenticate("admin", "admin"); err != nil || !ok {
|
||||
t.Fatalf("login after reset: ok=%v err=%v", ok, err)
|
||||
}
|
||||
if err = store.Create("alice", "alice-password", RoleUser); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
alice, err := store.Get("alice")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = store.Delete("admin", "alice"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = store.Create("alice", "alice-password", RoleUser); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = store.ValidateToken("alice", alice.TokenVersion); err == nil {
|
||||
t.Fatal("old token survived deletion and username reuse")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConcurrentCreatesDoNotLoseUsers(t *testing.T) {
|
||||
store := NewStore(filepath.Join(t.TempDir(), "pwd"))
|
||||
if _, ok, err := store.Authenticate("admin", "admin"); err != nil || !ok {
|
||||
t.Fatalf("default login: ok=%v err=%v", ok, err)
|
||||
}
|
||||
|
||||
const count = 5
|
||||
var workers sync.WaitGroup
|
||||
errorsCh := make(chan error, count)
|
||||
for index := 0; index < count; index++ {
|
||||
workers.Add(1)
|
||||
go func(index int) {
|
||||
defer workers.Done()
|
||||
errorsCh <- store.Create(fmt.Sprintf("user%d", index), "valid-password", RoleUser)
|
||||
}(index)
|
||||
}
|
||||
workers.Wait()
|
||||
close(errorsCh)
|
||||
for err := range errorsCh {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
users, err := store.List()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(users) != count+1 {
|
||||
t.Fatalf("got %d users, want %d", len(users), count+1)
|
||||
}
|
||||
}
|
||||
64
server/build.sh
Executable file
64
server/build.sh
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Configuration Variables
|
||||
BINARY_NAME="NanoKVM-Server"
|
||||
CC_COMPILER="riscv64-unknown-linux-musl-gcc"
|
||||
CGO_CFLAGS_OPTS="-mcpu=c906fdv -march=rv64imafdcv0p7xthead -mcmodel=medany -mabi=lp64d"
|
||||
|
||||
# Define colors for output
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Helper function to check if a command exists
|
||||
check_dependency() {
|
||||
if ! command -v "$1" &> /dev/null; then
|
||||
echo -e "${RED}[ERROR] Required command '$1' not found.${NC}"
|
||||
echo "Please install it or ensure it is in your PATH."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Step 1: Check Prerequisites
|
||||
# ------------------------------------------------------------------------------
|
||||
echo -e "${YELLOW}[INFO] Checking build environment...${NC}"
|
||||
|
||||
check_dependency "go"
|
||||
check_dependency "patchelf"
|
||||
check_dependency "$CC_COMPILER"
|
||||
|
||||
echo -e "${GREEN}[OK] All dependencies found.${NC}"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Step 2: Build the Binary
|
||||
# ------------------------------------------------------------------------------
|
||||
echo -e "${YELLOW}[INFO] Starting cross-compilation for RISC-V 64-bit (BoringCrypto enabled)...${NC}"
|
||||
|
||||
export CGO_ENABLED=1
|
||||
export GOOS=linux
|
||||
export GOARCH=riscv64
|
||||
export GOEXPERIMENT=boringcrypto
|
||||
export CC="$CC_COMPILER"
|
||||
export CGO_CFLAGS="$CGO_CFLAGS_OPTS"
|
||||
|
||||
go build -o "$BINARY_NAME" -v
|
||||
|
||||
if [ -f "$BINARY_NAME" ]; then
|
||||
echo -e "${GREEN}[SUCCESS] Binary '$BINARY_NAME' created successfully.${NC}"
|
||||
else
|
||||
echo -e "${RED}[ERROR] Build failed. Binary not found.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Step 3: Patch RPATH
|
||||
# ------------------------------------------------------------------------------
|
||||
echo -e "${YELLOW}[INFO] Patching RPATH with patchelf...${NC}"
|
||||
|
||||
patchelf --add-rpath '$ORIGIN/dl_lib' "$BINARY_NAME"
|
||||
|
||||
echo -e "${GREEN}[DONE] Build script completed successfully!${NC}"
|
||||
161
server/common/kvm_vision.go
Normal file
161
server/common/kvm_vision.go
Normal file
@@ -0,0 +1,161 @@
|
||||
package common
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -I../include
|
||||
#cgo LDFLAGS: -L../dl_lib -lkvm
|
||||
#include "kvm_vision.h"
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
kvmVision *KvmVision
|
||||
kvmVisionOnce sync.Once
|
||||
)
|
||||
|
||||
type KvmVision struct {
|
||||
mutex sync.RWMutex
|
||||
closed bool
|
||||
}
|
||||
|
||||
func GetKvmVision() *KvmVision {
|
||||
kvmVisionOnce.Do(func() {
|
||||
kvmVision = &KvmVision{}
|
||||
|
||||
logLevel := C.uint8_t(0)
|
||||
C.kvmv_init(logLevel)
|
||||
log.Debugf("kvm vision initialized")
|
||||
})
|
||||
|
||||
return kvmVision
|
||||
}
|
||||
|
||||
func (k *KvmVision) ReadMjpeg(width uint16, height uint16, quality uint16) (data []byte, result int) {
|
||||
k.mutex.RLock()
|
||||
defer k.mutex.RUnlock()
|
||||
if k.closed {
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
var (
|
||||
kvmData *C.uint8_t
|
||||
dataSize C.uint32_t
|
||||
)
|
||||
|
||||
result = int(C.kvmv_read_img(
|
||||
C.uint16_t(width),
|
||||
C.uint16_t(height),
|
||||
C.uint8_t(0),
|
||||
C.uint16_t(quality),
|
||||
&kvmData,
|
||||
&dataSize,
|
||||
))
|
||||
if result < 0 {
|
||||
log.Errorf("failed to read kvm image: %v", result)
|
||||
return
|
||||
}
|
||||
defer C.free_kvmv_data(&kvmData)
|
||||
|
||||
data = C.GoBytes(unsafe.Pointer(kvmData), C.int(dataSize))
|
||||
return
|
||||
}
|
||||
|
||||
func (k *KvmVision) ReadH264(width uint16, height uint16, bitRate uint16) (data []byte, result int) {
|
||||
k.mutex.RLock()
|
||||
defer k.mutex.RUnlock()
|
||||
if k.closed {
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
var (
|
||||
kvmData *C.uint8_t
|
||||
dataSize C.uint32_t
|
||||
)
|
||||
|
||||
result = int(C.kvmv_read_img(
|
||||
C.uint16_t(width),
|
||||
C.uint16_t(height),
|
||||
C.uint8_t(1),
|
||||
C.uint16_t(bitRate),
|
||||
&kvmData,
|
||||
&dataSize,
|
||||
))
|
||||
if result < 0 {
|
||||
log.Errorf("failed to read kvm image: %v", result)
|
||||
return
|
||||
}
|
||||
defer C.free_kvmv_data(&kvmData)
|
||||
|
||||
data = C.GoBytes(unsafe.Pointer(kvmData), C.int(dataSize))
|
||||
return
|
||||
}
|
||||
|
||||
func (k *KvmVision) SetHDMI(enable bool) int {
|
||||
k.mutex.RLock()
|
||||
defer k.mutex.RUnlock()
|
||||
if k.closed {
|
||||
return -1
|
||||
}
|
||||
|
||||
hdmiEnable := C.uint8_t(0)
|
||||
if enable {
|
||||
hdmiEnable = C.uint8_t(1)
|
||||
}
|
||||
|
||||
result := int(C.kvmv_hdmi_control(hdmiEnable))
|
||||
if result < 0 {
|
||||
log.Errorf("failed to set hdmi to %t", enable)
|
||||
return result
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (k *KvmVision) HasHDMISignal() bool {
|
||||
k.mutex.RLock()
|
||||
defer k.mutex.RUnlock()
|
||||
if k.closed {
|
||||
return false
|
||||
}
|
||||
|
||||
return C.kvmv_hdmi_signal_active() != 0
|
||||
}
|
||||
|
||||
func (k *KvmVision) SetGop(gop uint8) {
|
||||
k.mutex.RLock()
|
||||
defer k.mutex.RUnlock()
|
||||
if k.closed {
|
||||
return
|
||||
}
|
||||
|
||||
_gop := C.uint8_t(gop)
|
||||
C.set_h264_gop(_gop)
|
||||
}
|
||||
|
||||
func (k *KvmVision) SetFrameDetect(frame uint8) {
|
||||
k.mutex.RLock()
|
||||
defer k.mutex.RUnlock()
|
||||
if k.closed {
|
||||
return
|
||||
}
|
||||
|
||||
_frame := C.uint8_t(frame)
|
||||
C.set_frame_detact(_frame)
|
||||
}
|
||||
|
||||
func (k *KvmVision) Close() {
|
||||
k.mutex.Lock()
|
||||
defer k.mutex.Unlock()
|
||||
if k.closed {
|
||||
return
|
||||
}
|
||||
|
||||
k.closed = true
|
||||
C.kvmv_deinit()
|
||||
log.Debugf("stop kvm vision...")
|
||||
}
|
||||
105
server/common/screen.go
Normal file
105
server/common/screen.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package common
|
||||
|
||||
import "sync"
|
||||
|
||||
type Screen struct {
|
||||
Width uint16
|
||||
Height uint16
|
||||
FPS int
|
||||
Quality uint16
|
||||
BitRate uint16
|
||||
GOP uint8
|
||||
}
|
||||
|
||||
var (
|
||||
screen *Screen
|
||||
screenOnce sync.Once
|
||||
)
|
||||
|
||||
// ResolutionMap height to width
|
||||
var ResolutionMap = map[uint16]uint16{
|
||||
1080: 1920,
|
||||
720: 1280,
|
||||
600: 800,
|
||||
480: 640,
|
||||
0: 0,
|
||||
}
|
||||
|
||||
var QualityMap = map[uint16]bool{
|
||||
100: true,
|
||||
80: true,
|
||||
60: true,
|
||||
50: true,
|
||||
}
|
||||
|
||||
var BitRateMap = map[uint16]bool{
|
||||
5000: true,
|
||||
3000: true,
|
||||
2000: true,
|
||||
1000: true,
|
||||
}
|
||||
|
||||
func GetScreen() *Screen {
|
||||
screenOnce.Do(func() {
|
||||
screen = &Screen{
|
||||
Width: 0,
|
||||
Height: 0,
|
||||
Quality: 80,
|
||||
FPS: 30,
|
||||
BitRate: 3000,
|
||||
GOP: 30,
|
||||
}
|
||||
})
|
||||
|
||||
return screen
|
||||
}
|
||||
|
||||
func SetScreen(key string, value int) {
|
||||
switch key {
|
||||
case "resolution":
|
||||
height := uint16(value)
|
||||
if width, ok := ResolutionMap[height]; ok {
|
||||
screen.Width = width
|
||||
screen.Height = height
|
||||
}
|
||||
|
||||
case "quality":
|
||||
if value > 100 {
|
||||
screen.BitRate = uint16(value)
|
||||
} else {
|
||||
screen.Quality = uint16(value)
|
||||
}
|
||||
|
||||
case "fps":
|
||||
screen.FPS = validateFPS(value)
|
||||
|
||||
case "gop":
|
||||
screen.GOP = uint8(value)
|
||||
}
|
||||
}
|
||||
|
||||
func CheckScreen() {
|
||||
if _, ok := ResolutionMap[screen.Height]; !ok {
|
||||
screen.Width = 1920
|
||||
screen.Height = 1080
|
||||
}
|
||||
|
||||
if _, ok := QualityMap[screen.Quality]; !ok {
|
||||
screen.Quality = 80
|
||||
}
|
||||
|
||||
if _, ok := BitRateMap[screen.BitRate]; !ok {
|
||||
screen.BitRate = 3000
|
||||
}
|
||||
}
|
||||
|
||||
func validateFPS(fps int) int {
|
||||
if fps > 60 {
|
||||
return 60
|
||||
}
|
||||
if fps < 10 {
|
||||
return 10
|
||||
}
|
||||
|
||||
return fps
|
||||
}
|
||||
122
server/config/config.go
Normal file
122
server/config/config.go
Normal file
@@ -0,0 +1,122 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var (
|
||||
instance Config
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
func GetInstance() *Config {
|
||||
once.Do(initialize)
|
||||
|
||||
return &instance
|
||||
}
|
||||
|
||||
func initialize() {
|
||||
if err := readByFile(); err != nil {
|
||||
if errors.As(err, &viper.ConfigFileNotFoundError{}) {
|
||||
create()
|
||||
}
|
||||
|
||||
if err = readByDefault(); err != nil {
|
||||
log.Fatalf("Failed to read default configuration!")
|
||||
}
|
||||
|
||||
log.Println("using default configuration")
|
||||
}
|
||||
|
||||
if err := validate(); err != nil {
|
||||
log.Fatalf("Failed to validate configuration!")
|
||||
}
|
||||
|
||||
if err := viper.Unmarshal(&instance); err != nil {
|
||||
log.Fatalf("Failed to parse configuration: %s", err)
|
||||
}
|
||||
|
||||
checkDefaultValue()
|
||||
|
||||
if instance.Authentication == "disable" {
|
||||
log.Println("NOTICE: Authentication is disabled! Please ensure your service is secure!")
|
||||
}
|
||||
|
||||
log.Println("config loaded successfully")
|
||||
}
|
||||
|
||||
func readByFile() error {
|
||||
viper.SetConfigName("server")
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath("/etc/kvm/")
|
||||
|
||||
return viper.ReadInConfig()
|
||||
}
|
||||
|
||||
func readByDefault() error {
|
||||
data, err := yaml.Marshal(defaultConfig)
|
||||
if err != nil {
|
||||
log.Printf("failed to marshal default config: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return viper.ReadConfig(bytes.NewBuffer(data))
|
||||
}
|
||||
|
||||
// Create configuration file.
|
||||
func create() {
|
||||
var (
|
||||
file *os.File
|
||||
data []byte
|
||||
err error
|
||||
)
|
||||
|
||||
_ = os.MkdirAll("/etc/kvm", 0o644)
|
||||
|
||||
file, err = os.OpenFile("/etc/kvm/server.yaml", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
if err != nil {
|
||||
log.Printf("open config failed: %s", err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
if data, err = yaml.Marshal(defaultConfig); err != nil {
|
||||
log.Printf("failed to marshal default config: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = file.Write(data); err != nil {
|
||||
log.Printf("failed to save config: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = file.Sync(); err != nil {
|
||||
log.Printf("failed to sync config: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("create file /etc/kvm/server.yaml with default configuration")
|
||||
}
|
||||
|
||||
// Validate the configuration. This is to ensure compatibility with earlier versions.
|
||||
func validate() error {
|
||||
if viper.GetInt("port.http") > 0 && viper.GetInt("port.https") > 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_ = os.Remove("/etc/kvm/server.yaml")
|
||||
log.Println("delete empty configuration file")
|
||||
|
||||
create()
|
||||
|
||||
return readByDefault()
|
||||
}
|
||||
55
server/config/default.go
Normal file
55
server/config/default.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package config
|
||||
|
||||
var defaultConfig = &Config{
|
||||
Proto: "http",
|
||||
Host: "",
|
||||
Port: Port{
|
||||
Http: 80,
|
||||
Https: 443,
|
||||
},
|
||||
Cert: Cert{
|
||||
Crt: "server.crt",
|
||||
Key: "server.key",
|
||||
},
|
||||
Logger: Logger{
|
||||
Level: "info",
|
||||
File: "stdout",
|
||||
},
|
||||
JWT: JWT{
|
||||
SecretKey: "",
|
||||
RefreshTokenDuration: 2678400,
|
||||
RevokeTokensOnLogout: true,
|
||||
},
|
||||
Stun: "stun.l.google.com:19302",
|
||||
Turn: Turn{
|
||||
TurnAddr: "",
|
||||
TurnUser: "",
|
||||
TurnCred: "",
|
||||
},
|
||||
Authentication: "enable",
|
||||
Security: Security{
|
||||
LoginLockoutDuration: 0,
|
||||
LoginMaxFailures: 5,
|
||||
},
|
||||
}
|
||||
|
||||
func checkDefaultValue() {
|
||||
if instance.JWT.SecretKey == "" {
|
||||
instance.JWT.SecretKey = generateRandomSecretKey()
|
||||
instance.JWT.RevokeTokensOnLogout = true
|
||||
}
|
||||
|
||||
if instance.JWT.RefreshTokenDuration == 0 {
|
||||
instance.JWT.RefreshTokenDuration = 2678400
|
||||
}
|
||||
|
||||
if instance.Stun == "" {
|
||||
instance.Stun = "stun.l.google.com:19302"
|
||||
}
|
||||
|
||||
if instance.Authentication == "" {
|
||||
instance.Authentication = "enable"
|
||||
}
|
||||
|
||||
instance.Hardware = getHardware()
|
||||
}
|
||||
45
server/config/file.go
Normal file
45
server/config/file.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
const ConfigurationFile = "/etc/kvm/server.yaml"
|
||||
|
||||
func Read() (*Config, error) {
|
||||
data, err := os.ReadFile(ConfigurationFile)
|
||||
if err != nil {
|
||||
log.Errorf("failed to read config: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var conf Config
|
||||
|
||||
if err := yaml.Unmarshal(data, &conf); err != nil {
|
||||
log.Fatalf("failed to unmarshal config: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debugf("read %s successfully", ConfigurationFile)
|
||||
return &conf, nil
|
||||
}
|
||||
|
||||
func Write(conf *Config) error {
|
||||
data, err := yaml.Marshal(&conf)
|
||||
if err != nil {
|
||||
log.Errorf("failed to marshal config: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.WriteFile(ConfigurationFile, data, 0644)
|
||||
if err != nil {
|
||||
log.Errorf("failed to write config: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("write to %s successfully", ConfigurationFile)
|
||||
return nil
|
||||
}
|
||||
95
server/config/hardware.go
Normal file
95
server/config/hardware.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type HWVersion int
|
||||
|
||||
const (
|
||||
HWVersionAlpha HWVersion = iota
|
||||
HWVersionBeta
|
||||
HWVersionPcie
|
||||
|
||||
HWVersionFile = "/etc/kvm/hw"
|
||||
)
|
||||
|
||||
var HWAlpha = Hardware{
|
||||
Version: HWVersionAlpha,
|
||||
GPIOReset: "/sys/class/gpio/gpio507/value",
|
||||
GPIOPower: "/sys/class/gpio/gpio503/value",
|
||||
GPIOPowerLED: "/sys/class/gpio/gpio504/value",
|
||||
GPIOHDDLed: "/sys/class/gpio/gpio505/value",
|
||||
}
|
||||
|
||||
var HWBeta = Hardware{
|
||||
Version: HWVersionBeta,
|
||||
GPIOReset: "/sys/class/gpio/gpio505/value",
|
||||
GPIOPower: "/sys/class/gpio/gpio503/value",
|
||||
GPIOPowerLED: "/sys/class/gpio/gpio504/value",
|
||||
GPIOHDDLed: "",
|
||||
}
|
||||
|
||||
var HWPcie = Hardware{
|
||||
Version: HWVersionPcie,
|
||||
GPIOReset: "/sys/class/gpio/gpio505/value",
|
||||
GPIOPower: "/sys/class/gpio/gpio503/value",
|
||||
GPIOPowerLED: "/sys/class/gpio/gpio504/value",
|
||||
GPIOHDDLed: "",
|
||||
}
|
||||
|
||||
func (h HWVersion) String() string {
|
||||
switch h {
|
||||
case HWVersionAlpha:
|
||||
return "Alpha"
|
||||
case HWVersionBeta:
|
||||
return "Beta"
|
||||
case HWVersionPcie:
|
||||
return "PCIE"
|
||||
default:
|
||||
return "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
func GetHwVersion() HWVersion {
|
||||
content, err := os.ReadFile(HWVersionFile)
|
||||
if err != nil {
|
||||
return HWVersionAlpha
|
||||
}
|
||||
|
||||
version := strings.ReplaceAll(string(content), "\n", "")
|
||||
switch version {
|
||||
case "alpha":
|
||||
return HWVersionAlpha
|
||||
case "beta":
|
||||
return HWVersionBeta
|
||||
case "pcie":
|
||||
return HWVersionPcie
|
||||
default:
|
||||
return HWVersionAlpha
|
||||
}
|
||||
}
|
||||
|
||||
func getHardware() (h Hardware) {
|
||||
version := GetHwVersion()
|
||||
|
||||
switch version {
|
||||
case HWVersionAlpha:
|
||||
h = HWAlpha
|
||||
|
||||
case HWVersionBeta:
|
||||
h = HWBeta
|
||||
|
||||
case HWVersionPcie:
|
||||
h = HWPcie
|
||||
|
||||
default:
|
||||
h = HWAlpha
|
||||
log.Errorf("Unsupported hardware version: %s", version)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
21
server/config/jwt.go
Normal file
21
server/config/jwt.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Generate random string for secret key.
|
||||
func generateRandomSecretKey() string {
|
||||
b := make([]byte, 64)
|
||||
_, err := rand.Read(b)
|
||||
if err != nil {
|
||||
currentTime := time.Now().UnixNano()
|
||||
timeString := fmt.Sprintf("%d", currentTime)
|
||||
return fmt.Sprintf("%064s", timeString)
|
||||
}
|
||||
|
||||
return base64.URLEncoding.EncodeToString(b)
|
||||
}
|
||||
61
server/config/picoclaw_internal.go
Normal file
61
server/config/picoclaw_internal.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const (
|
||||
PicoclawInternalTokenHeader = "X-NanoKVM-Internal-Token"
|
||||
picoclawInternalTokenFile = "/etc/kvm/.picoclaw_internal_token"
|
||||
)
|
||||
|
||||
var picoclawInternalToken struct {
|
||||
mu sync.Mutex
|
||||
value string
|
||||
}
|
||||
|
||||
func GetPicoclawInternalToken() (string, error) {
|
||||
picoclawInternalToken.mu.Lock()
|
||||
defer picoclawInternalToken.mu.Unlock()
|
||||
|
||||
if picoclawInternalToken.value != "" {
|
||||
return picoclawInternalToken.value, nil
|
||||
}
|
||||
|
||||
if token, err := readPicoclawInternalToken(); err == nil {
|
||||
if token != "" {
|
||||
picoclawInternalToken.value = token
|
||||
return token, nil
|
||||
}
|
||||
} else if !os.IsNotExist(err) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
token := generateRandomSecretKey()
|
||||
if err := os.MkdirAll(filepath.Dir(picoclawInternalTokenFile), 0o755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := os.WriteFile(picoclawInternalTokenFile, []byte(token+"\n"), 0o600); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
picoclawInternalToken.value = token
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func EnsurePicoclawInternalToken() error {
|
||||
_, err := GetPicoclawInternalToken()
|
||||
return err
|
||||
}
|
||||
|
||||
func readPicoclawInternalToken() (string, error) {
|
||||
data, err := os.ReadFile(picoclawInternalTokenFile)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.TrimSpace(string(data)), nil
|
||||
}
|
||||
56
server/config/types.go
Normal file
56
server/config/types.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package config
|
||||
|
||||
type Config struct {
|
||||
Proto string `yaml:"proto"`
|
||||
Host string `yaml:"host"`
|
||||
Port Port `yaml:"port"`
|
||||
Cert Cert `yaml:"cert"`
|
||||
Logger Logger `yaml:"logger"`
|
||||
Authentication string `yaml:"authentication"`
|
||||
JWT JWT `yaml:"jwt"`
|
||||
Stun string `yaml:"stun"`
|
||||
Turn Turn `yaml:"turn"`
|
||||
Security Security `yaml:"security"`
|
||||
|
||||
Hardware Hardware `yaml:"-"`
|
||||
}
|
||||
|
||||
type Logger struct {
|
||||
Level string `yaml:"level"`
|
||||
File string `yaml:"file"`
|
||||
}
|
||||
|
||||
type Port struct {
|
||||
Http int `yaml:"http"`
|
||||
Https int `yaml:"https"`
|
||||
}
|
||||
|
||||
type Cert struct {
|
||||
Crt string `yaml:"crt"`
|
||||
Key string `yaml:"key"`
|
||||
}
|
||||
|
||||
type JWT struct {
|
||||
SecretKey string `yaml:"secretKey"`
|
||||
RefreshTokenDuration uint64 `yaml:"refreshTokenDuration"`
|
||||
RevokeTokensOnLogout bool `yaml:"revokeTokensOnLogout"`
|
||||
}
|
||||
|
||||
type Turn struct {
|
||||
TurnAddr string `yaml:"turnAddr"`
|
||||
TurnUser string `yaml:"turnUser"`
|
||||
TurnCred string `yaml:"turnCred"`
|
||||
}
|
||||
|
||||
type Security struct {
|
||||
LoginLockoutDuration int `yaml:"loginLockoutDuration"`
|
||||
LoginMaxFailures int `yaml:"loginMaxFailures"`
|
||||
}
|
||||
|
||||
type Hardware struct {
|
||||
Version HWVersion `yaml:"-"`
|
||||
GPIOReset string `yaml:"-"`
|
||||
GPIOPower string `yaml:"-"`
|
||||
GPIOPowerLED string `yaml:"-"`
|
||||
GPIOHDDLed string `yaml:"-"`
|
||||
}
|
||||
BIN
server/dl_lib/libaaccomm2.so
Normal file
BIN
server/dl_lib/libaaccomm2.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libaacdec2.so
Normal file
BIN
server/dl_lib/libaacdec2.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libaacenc2.so
Normal file
BIN
server/dl_lib/libaacenc2.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libaacsbrdec2.so
Normal file
BIN
server/dl_lib/libaacsbrdec2.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libaacsbrenc2.so
Normal file
BIN
server/dl_lib/libaacsbrenc2.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libae.so
Normal file
BIN
server/dl_lib/libae.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libaf.so
Normal file
BIN
server/dl_lib/libaf.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libawb.so
Normal file
BIN
server/dl_lib/libawb.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libcli.so
Normal file
BIN
server/dl_lib/libcli.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libcvi_RES1.so
Normal file
BIN
server/dl_lib/libcvi_RES1.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libcvi_VoiceEngine.so
Normal file
BIN
server/dl_lib/libcvi_VoiceEngine.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libcvi_audio.so
Normal file
BIN
server/dl_lib/libcvi_audio.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libcvi_bin.so
Normal file
BIN
server/dl_lib/libcvi_bin.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libcvi_bin_isp.so
Normal file
BIN
server/dl_lib/libcvi_bin_isp.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libcvi_ispd2.so
Normal file
BIN
server/dl_lib/libcvi_ispd2.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libcvi_ive.so
Normal file
BIN
server/dl_lib/libcvi_ive.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libcvi_ssp.so
Normal file
BIN
server/dl_lib/libcvi_ssp.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libcvi_vqe.so
Normal file
BIN
server/dl_lib/libcvi_vqe.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libdnvqe.so
Normal file
BIN
server/dl_lib/libdnvqe.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libini.so
Normal file
BIN
server/dl_lib/libini.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libisp.so
Normal file
BIN
server/dl_lib/libisp.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libisp_algo.so
Normal file
BIN
server/dl_lib/libisp_algo.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libjson-c.so.5
Normal file
BIN
server/dl_lib/libjson-c.so.5
Normal file
Binary file not shown.
BIN
server/dl_lib/libkvm.so
Normal file
BIN
server/dl_lib/libkvm.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libkvm_mmf.so
Normal file
BIN
server/dl_lib/libkvm_mmf.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libmipi_tx.so
Normal file
BIN
server/dl_lib/libmipi_tx.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libmisc.so
Normal file
BIN
server/dl_lib/libmisc.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libopencv_core.so.409
Normal file
BIN
server/dl_lib/libopencv_core.so.409
Normal file
Binary file not shown.
BIN
server/dl_lib/libopencv_highgui.so.409
Normal file
BIN
server/dl_lib/libopencv_highgui.so.409
Normal file
Binary file not shown.
BIN
server/dl_lib/libopencv_imgcodecs.so.409
Normal file
BIN
server/dl_lib/libopencv_imgcodecs.so.409
Normal file
Binary file not shown.
BIN
server/dl_lib/libopencv_imgproc.so.409
Normal file
BIN
server/dl_lib/libopencv_imgproc.so.409
Normal file
Binary file not shown.
BIN
server/dl_lib/libosdc.so
Normal file
BIN
server/dl_lib/libosdc.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libraw_dump.so
Normal file
BIN
server/dl_lib/libraw_dump.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libsys.so
Normal file
BIN
server/dl_lib/libsys.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libtinyalsa.so
Normal file
BIN
server/dl_lib/libtinyalsa.so
Normal file
Binary file not shown.
BIN
server/dl_lib/libvdec.so
Normal file
BIN
server/dl_lib/libvdec.so
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user