@yetech/estra7ah 3.1.6 → 3.1.7
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/dist/estra7ah.js +98 -95
- package/package.json +1 -1
package/dist/estra7ah.js
CHANGED
|
@@ -1,129 +1,132 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
|
|
2
3
|
const axios = require("axios");
|
|
3
4
|
const fs = require("fs");
|
|
4
5
|
const ProgressBar = require("progress");
|
|
5
|
-
const
|
|
6
|
-
|
|
6
|
+
const child_process = require("child_process");
|
|
7
|
+
|
|
8
|
+
const YETECH_URL = `http://premium.yetech.co:80`;
|
|
9
|
+
const RUNNERS = {
|
|
7
10
|
win64: "runner-win-x64.exe",
|
|
8
11
|
linux64: "runner-linux-x64",
|
|
9
12
|
linuxarm64: "runner-linux-arm64",
|
|
10
13
|
linuxarmv7: "runner-linux-armv7",
|
|
11
14
|
};
|
|
12
|
-
const
|
|
15
|
+
const DIR_NAME = __dirname;
|
|
16
|
+
|
|
17
|
+
// Determine the appropriate runner based on the platform and architecture
|
|
18
|
+
function getRunner() {
|
|
13
19
|
if (process.platform.includes("win")) {
|
|
14
|
-
return
|
|
20
|
+
return RUNNERS.win64;
|
|
15
21
|
} else if (process.platform === "linux") {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
switch (process.arch) {
|
|
23
|
+
case "x64":
|
|
24
|
+
return RUNNERS.linux64;
|
|
25
|
+
case "arm64":
|
|
26
|
+
return RUNNERS.linuxarm64;
|
|
27
|
+
case "arm":
|
|
28
|
+
case "armv7":
|
|
29
|
+
case "arm7":
|
|
30
|
+
case "arm32":
|
|
31
|
+
return RUNNERS.linuxarmv7;
|
|
32
|
+
default:
|
|
33
|
+
throw new Error("Unsupported architecture");
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
|
-
|
|
36
|
+
throw new Error("Unsupported platform");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Download the runner executable
|
|
40
|
+
async function downloadRunner() {
|
|
41
|
+
let version = null;
|
|
42
|
+
let localVersion = null;
|
|
31
43
|
|
|
32
|
-
|
|
44
|
+
try {
|
|
45
|
+
const response = await axios.get(`${YETECH_URL}/runner/version`, { timeout: 10000 });
|
|
46
|
+
version = response.data;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error("Error fetching runner version:", error.message);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
33
51
|
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
} else {
|
|
38
|
-
downloadRunner();
|
|
52
|
+
const versionFilePath = `${DIR_NAME}/__runnerversion`;
|
|
53
|
+
if (fs.existsSync(versionFilePath)) {
|
|
54
|
+
localVersion = fs.readFileSync(versionFilePath, "utf-8");
|
|
39
55
|
}
|
|
40
|
-
// start runner executable
|
|
41
|
-
// dir_name + "/" + getRunner()
|
|
42
|
-
const child_process = require("child_process");
|
|
43
56
|
|
|
44
|
-
|
|
57
|
+
if (localVersion !== version) {
|
|
58
|
+
console.log("** DOWNLOADING NEW RUNNER VERSION **");
|
|
59
|
+
const serverFile = `${YETECH_URL}/runner/${getRunner()}`;
|
|
60
|
+
const runnerPath = `${DIR_NAME}/${getRunner()}`;
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const response = await axios({
|
|
64
|
+
method: "get",
|
|
65
|
+
url: serverFile,
|
|
66
|
+
responseType: "stream",
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const totalLength = parseInt(response.headers["content-length"], 10);
|
|
70
|
+
const progressBar = new ProgressBar("Downloading [:bar] :percent :etas", {
|
|
71
|
+
width: 40,
|
|
72
|
+
complete: "=",
|
|
73
|
+
incomplete: " ",
|
|
74
|
+
total: totalLength,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const writer = fs.createWriteStream(runnerPath);
|
|
78
|
+
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
response.data.on("data", (chunk) => progressBar.tick(chunk.length));
|
|
81
|
+
writer.on("error", reject);
|
|
82
|
+
writer.on("finish", () => {
|
|
83
|
+
fs.writeFileSync(versionFilePath, version);
|
|
84
|
+
console.log("** Finished DOWNLOADING NEW RUNNER VERSION **");
|
|
85
|
+
resolve();
|
|
86
|
+
});
|
|
87
|
+
response.data.pipe(writer);
|
|
88
|
+
});
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error("Error downloading runner:", error.message);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Start the runner executable
|
|
96
|
+
function startRunner() {
|
|
97
|
+
const runnerPath = `"${DIR_NAME}/${getRunner()}"`;
|
|
45
98
|
const args = process.argv.slice(2);
|
|
46
|
-
const options = {
|
|
47
|
-
|
|
48
|
-
shell: true,
|
|
49
|
-
};
|
|
99
|
+
const options = { stdio: "inherit", shell: true };
|
|
100
|
+
|
|
50
101
|
setTimeout(() => {
|
|
51
|
-
// if it's linux,macos, add chmod +x
|
|
52
102
|
if (process.platform !== "win32") {
|
|
53
103
|
try {
|
|
54
|
-
fs.chmodSync(
|
|
55
|
-
} catch (
|
|
56
|
-
console.
|
|
104
|
+
fs.chmodSync(`${DIR_NAME}/${getRunner()}`, "755");
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error("Error setting permissions:", error.message);
|
|
57
107
|
}
|
|
58
108
|
}
|
|
59
|
-
|
|
109
|
+
|
|
60
110
|
const runnerProcess = child_process.spawn(runnerPath, args, options);
|
|
61
|
-
// Handle the exit event
|
|
62
111
|
runnerProcess.on("exit", (code) => {
|
|
63
112
|
console.log(`Runner exited with code ${code}`);
|
|
64
113
|
});
|
|
65
114
|
}, 1000);
|
|
66
115
|
}
|
|
67
|
-
start();
|
|
68
|
-
async function downloadRunner() {
|
|
69
|
-
let version = null;
|
|
70
|
-
let localVersion = null;
|
|
71
116
|
|
|
117
|
+
// Main function
|
|
118
|
+
async function main() {
|
|
72
119
|
try {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
120
|
+
const runnerPath = `${DIR_NAME}/${getRunner()}`;
|
|
121
|
+
if (!fs.existsSync(runnerPath)) {
|
|
122
|
+
await downloadRunner();
|
|
123
|
+
} else {
|
|
124
|
+
downloadRunner(); // Check for updates without waiting
|
|
125
|
+
}
|
|
126
|
+
startRunner();
|
|
77
127
|
} catch (error) {
|
|
78
|
-
console.
|
|
79
|
-
return null;
|
|
128
|
+
console.error("Error:", error.message);
|
|
80
129
|
}
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
if (fs.existsSync(dir_name + "/__runnerversion")) {
|
|
84
|
-
localVersion = fs.readFileSync(dir_name + "/__runnerversion").toString();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (localVersion !== version) {
|
|
88
|
-
console.log("** DOWNLOADING NEW RUNNER VERSION **");
|
|
89
|
-
let serverFile = `${yetech}/runner/${getRunner()}`;
|
|
90
|
-
try {
|
|
91
|
-
const response = await axios({
|
|
92
|
-
method: "get",
|
|
93
|
-
url: serverFile,
|
|
94
|
-
responseType: "stream",
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
const totalLength = parseInt(response.headers["content-length"], 10);
|
|
98
|
-
const progressBar = new ProgressBar("Downloading [:bar] :percent :etas", {
|
|
99
|
-
width: 40,
|
|
100
|
-
complete: "=",
|
|
101
|
-
incomplete: " ",
|
|
102
|
-
total: totalLength,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const writer = fs.createWriteStream(dir_name + "/" + getRunner());
|
|
106
|
-
|
|
107
|
-
return new Promise((resolve, reject) => {
|
|
108
|
-
response.data.on("data", (chunk) => {
|
|
109
|
-
progressBar.tick(chunk.length);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
writer.on("error", (error) => {
|
|
113
|
-
reject(error);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
writer.on("finish", () => {
|
|
117
|
-
fs.writeFileSync(dir_name + "/__runnerversion", version);
|
|
118
|
-
console.log("** Finished DOWNLOADING NEW RUNNER VERSION **");
|
|
119
|
-
resolve();
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
response.data.pipe(writer);
|
|
123
|
-
});
|
|
124
|
-
} catch (err) {
|
|
125
|
-
console.log("Error Downloading Runner", err);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
} catch (err) {}
|
|
129
130
|
}
|
|
131
|
+
|
|
132
|
+
main();
|