@techsologic/unolock-agent 0.1.50 → 0.1.51
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/bin/install-binary.js +45 -5
- package/bin/unolock-agent-common.js +26 -5
- package/package.json +1 -1
package/bin/install-binary.js
CHANGED
|
@@ -3,21 +3,61 @@
|
|
|
3
3
|
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
|
+
const os = require("os");
|
|
7
|
+
const { spawnSync } = require("child_process");
|
|
6
8
|
|
|
7
9
|
const common = require("./unolock-agent-common");
|
|
8
10
|
|
|
11
|
+
function removeExistingPath(fsImpl, target) {
|
|
12
|
+
if (!fsImpl.existsSync(target)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
fsImpl.rmSync(target, { recursive: true, force: true });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function extractArchive(archivePath, destDir) {
|
|
19
|
+
if (process.platform === "win32") {
|
|
20
|
+
const result = spawnSync(
|
|
21
|
+
"powershell.exe",
|
|
22
|
+
[
|
|
23
|
+
"-NoProfile",
|
|
24
|
+
"-NonInteractive",
|
|
25
|
+
"-Command",
|
|
26
|
+
`Expand-Archive -LiteralPath '${archivePath.replace(/'/g, "''")}' -DestinationPath '${destDir.replace(/'/g, "''")}' -Force`,
|
|
27
|
+
],
|
|
28
|
+
{ stdio: "pipe" },
|
|
29
|
+
);
|
|
30
|
+
if (result.status !== 0) {
|
|
31
|
+
throw new Error((result.stderr && result.stderr.toString().trim()) || "Failed to extract UnoLock agent archive.");
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const result = spawnSync("tar", ["-xzf", archivePath, "-C", destDir], { stdio: "pipe" });
|
|
36
|
+
if (result.status !== 0) {
|
|
37
|
+
throw new Error((result.stderr && result.stderr.toString().trim()) || "Failed to extract UnoLock agent archive.");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
9
41
|
async function installBinary(options = {}) {
|
|
10
42
|
const fsImpl = options.fsImpl || fs;
|
|
11
43
|
const commonImpl = options.commonImpl || common;
|
|
44
|
+
const extractImpl = options.extractImpl || extractArchive;
|
|
12
45
|
const dest = commonImpl.installedBinaryPath();
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
commonImpl.ensureDir(path.dirname(dest));
|
|
46
|
+
const installDir = commonImpl.installedBinaryDir();
|
|
47
|
+
const tempRoot = fsImpl.mkdtempSync(path.join(os.tmpdir(), "unolock-agent-install-"));
|
|
48
|
+
const archivePath = path.join(tempRoot, commonImpl.platformAssetInfo().asset);
|
|
17
49
|
process.stderr.write(
|
|
18
50
|
`Installing UnoLock agent ${commonImpl.PACKAGE_VERSION} for ${process.platform}/${process.arch}...\n`,
|
|
19
51
|
);
|
|
20
|
-
|
|
52
|
+
try {
|
|
53
|
+
await commonImpl.fetchToFile(commonImpl.binaryUrl(commonImpl.PACKAGE_VERSION), archivePath);
|
|
54
|
+
removeExistingPath(fsImpl, installDir);
|
|
55
|
+
commonImpl.ensureDir(commonImpl.installRoot());
|
|
56
|
+
await extractImpl(archivePath, commonImpl.installRoot());
|
|
57
|
+
commonImpl.ensureExecutable(dest);
|
|
58
|
+
} finally {
|
|
59
|
+
removeExistingPath(fsImpl, tempRoot);
|
|
60
|
+
}
|
|
21
61
|
}
|
|
22
62
|
|
|
23
63
|
async function main() {
|
|
@@ -14,16 +14,32 @@ function platformAssetInfo() {
|
|
|
14
14
|
const platform = process.platform;
|
|
15
15
|
const arch = process.arch;
|
|
16
16
|
if (platform === "linux" && arch === "x64") {
|
|
17
|
-
return {
|
|
17
|
+
return {
|
|
18
|
+
asset: "unolock-agent-linux-x86_64.tar.gz",
|
|
19
|
+
installDir: "unolock-agent-linux-x86_64",
|
|
20
|
+
executable: "unolock-agent-linux-x86_64",
|
|
21
|
+
};
|
|
18
22
|
}
|
|
19
23
|
if (platform === "darwin" && arch === "arm64") {
|
|
20
|
-
return {
|
|
24
|
+
return {
|
|
25
|
+
asset: "unolock-agent-macos-arm64.tar.gz",
|
|
26
|
+
installDir: "unolock-agent-macos-arm64",
|
|
27
|
+
executable: "unolock-agent-macos-arm64",
|
|
28
|
+
};
|
|
21
29
|
}
|
|
22
30
|
if (platform === "darwin" && arch === "x64") {
|
|
23
|
-
return {
|
|
31
|
+
return {
|
|
32
|
+
asset: "unolock-agent-macos-x86_64.tar.gz",
|
|
33
|
+
installDir: "unolock-agent-macos-x86_64",
|
|
34
|
+
executable: "unolock-agent-macos-x86_64",
|
|
35
|
+
};
|
|
24
36
|
}
|
|
25
37
|
if (platform === "win32" && arch === "x64") {
|
|
26
|
-
return {
|
|
38
|
+
return {
|
|
39
|
+
asset: "unolock-agent-windows-amd64.zip",
|
|
40
|
+
installDir: "unolock-agent-windows-amd64",
|
|
41
|
+
executable: "unolock-agent-windows-amd64.exe",
|
|
42
|
+
};
|
|
27
43
|
}
|
|
28
44
|
throw new Error(`Unsupported platform for UnoLock agent binary: ${platform}/${arch}`);
|
|
29
45
|
}
|
|
@@ -32,9 +48,13 @@ function installRoot() {
|
|
|
32
48
|
return path.join(__dirname, "..", "vendor");
|
|
33
49
|
}
|
|
34
50
|
|
|
51
|
+
function installedBinaryDir() {
|
|
52
|
+
return path.join(installRoot(), platformAssetInfo().installDir);
|
|
53
|
+
}
|
|
54
|
+
|
|
35
55
|
function installedBinaryPath() {
|
|
36
56
|
const { executable } = platformAssetInfo();
|
|
37
|
-
return path.join(
|
|
57
|
+
return path.join(installedBinaryDir(), executable);
|
|
38
58
|
}
|
|
39
59
|
|
|
40
60
|
function binaryUrl(releaseVersion = PACKAGE_VERSION) {
|
|
@@ -102,6 +122,7 @@ module.exports = {
|
|
|
102
122
|
ensureExecutable,
|
|
103
123
|
fetchToFile,
|
|
104
124
|
installRoot,
|
|
125
|
+
installedBinaryDir,
|
|
105
126
|
installedBinaryPath,
|
|
106
127
|
platformAssetInfo,
|
|
107
128
|
};
|