@ghyper9023/u2secure 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/install.js +41 -37
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Linux 服务器安全加固工具(CLI + TUI 双模式),基于 Rust 构建
|
|
|
4
4
|
|
|
5
5
|
> Linux server security hardening tool (CLI + TUI) built with Rust. One run builds a complete security baseline: system updates, user creation, deep SSH hardening, firewall, intrusion prevention, auditing and automatic updates.
|
|
6
6
|
>
|
|
7
|
-
> 支持平台 / Supported
|
|
7
|
+
> 支持平台 / Supported platform: Linux x86_64 & ARM64 (Linux only)
|
|
8
8
|
>
|
|
9
9
|
> 详细文档与使用指南请访问 / For full documentation and usage guide, visit:
|
|
10
10
|
> [GitHub 主页](https://github.com/cherish-ltt/U2Secure)
|
package/bin/install.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const os = require('os');
|
|
6
|
+
const { pipeline } = require('stream');
|
|
6
7
|
const { https } = require('follow-redirects');
|
|
7
8
|
|
|
8
9
|
const pkgJson = require('../package.json');
|
|
@@ -25,37 +26,25 @@ if (repo.endsWith('.git')) {
|
|
|
25
26
|
|
|
26
27
|
const tag = `v${version}`;
|
|
27
28
|
|
|
29
|
+
// U2Secure 是 Linux 专用工具,只发布 Linux 二进制。
|
|
30
|
+
// 这里给出明确报错,而不是让 postinstall 去下载一个永远不存在的资产。
|
|
28
31
|
function getPlatformAsset() {
|
|
29
32
|
const platform = os.platform();
|
|
30
33
|
const arch = os.arch();
|
|
31
34
|
console.log(`Detected platform: ${platform}, arch: ${arch}`);
|
|
32
35
|
|
|
33
|
-
if (platform
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
} else if (
|
|
42
|
-
|
|
43
|
-
return 'u2secure-x86_64-unknown-linux-gnu';
|
|
44
|
-
} else if (arch === 'arm64') {
|
|
45
|
-
return 'u2secure-aarch64-unknown-linux-gnu';
|
|
46
|
-
} else {
|
|
47
|
-
throw new Error(`Unsupported Linux architecture: ${arch}`);
|
|
48
|
-
}
|
|
49
|
-
} else if (platform === 'darwin') {
|
|
50
|
-
if (arch === 'arm64') {
|
|
51
|
-
return 'u2secure-aarch64-apple-darwin';
|
|
52
|
-
} else if (arch === 'x64') {
|
|
53
|
-
return 'u2secure-x86_64-apple-darwin';
|
|
54
|
-
} else {
|
|
55
|
-
throw new Error(`Unsupported macOS architecture: ${arch}`);
|
|
56
|
-
}
|
|
36
|
+
if (platform !== 'linux') {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`U2Secure only supports Linux (detected: ${platform}). ` +
|
|
39
|
+
'On other platforms please use Docker or a Linux server / VM.'
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
if (arch === 'x64') {
|
|
43
|
+
return 'u2secure-x86_64-unknown-linux-gnu';
|
|
44
|
+
} else if (arch === 'arm64') {
|
|
45
|
+
return 'u2secure-aarch64-unknown-linux-gnu';
|
|
57
46
|
} else {
|
|
58
|
-
throw new Error(`Unsupported
|
|
47
|
+
throw new Error(`Unsupported Linux architecture: ${arch}`);
|
|
59
48
|
}
|
|
60
49
|
}
|
|
61
50
|
|
|
@@ -68,19 +57,34 @@ console.log(`Downloading from ${url} ...`);
|
|
|
68
57
|
|
|
69
58
|
if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });
|
|
70
59
|
|
|
71
|
-
const
|
|
60
|
+
const staging = fs.mkdtempSync(path.join(destDir, '.download-'));
|
|
61
|
+
const temporary = path.join(staging, 'binary');
|
|
62
|
+
function fail(error) {
|
|
63
|
+
console.error(`Download failed: ${error.message}`);
|
|
64
|
+
process.exitCode = 1;
|
|
65
|
+
fs.rmSync(staging, { recursive: true, force: true });
|
|
66
|
+
}
|
|
72
67
|
https.get(url, (response) => {
|
|
73
68
|
if (response.statusCode !== 200) {
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
response.resume();
|
|
70
|
+
fail(new Error(`HTTP ${response.statusCode}`));
|
|
71
|
+
return;
|
|
76
72
|
}
|
|
77
|
-
response.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
pipeline(response, fs.createWriteStream(temporary, { flags: 'wx' }), (error) => {
|
|
74
|
+
if (error) return fail(error);
|
|
75
|
+
try {
|
|
76
|
+
const expected = response.headers['content-length'];
|
|
77
|
+
const bytes = fs.statSync(temporary).size;
|
|
78
|
+
if (!response.complete || bytes === 0 ||
|
|
79
|
+
(expected !== undefined && Number(expected) !== bytes)) {
|
|
80
|
+
throw new Error('Incomplete binary response');
|
|
81
|
+
}
|
|
82
|
+
fs.chmodSync(temporary, 0o755);
|
|
83
|
+
fs.renameSync(temporary, destFile);
|
|
84
|
+
fs.rmdirSync(staging);
|
|
85
|
+
console.log(`Binary saved to ${destFile}`);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
fail(error);
|
|
88
|
+
}
|
|
82
89
|
});
|
|
83
|
-
}).on('error',
|
|
84
|
-
console.error(err);
|
|
85
|
-
process.exit(1);
|
|
86
|
-
});
|
|
90
|
+
}).on('error', fail);
|