MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / installDependencies

Function installDependencies

speedlink/speedlink.ts:188–226  ·  view source on GitHub ↗
(msg: Api.Message)

Source from the content-addressed store, hash-verified

186} catch (e: any) {
187 dependenciesInstalled = false;
188}
189
190async function installDependencies(msg: Api.Message): Promise<void> {
191 isInstalling = true;
192 try {
193 console.log("SpeedLink Plugin: Starting async dependency installation...");
194 try {
195 require.resolve("better-sqlite3");
196 } catch (e: any) {
197 console.log("[INSTALLING] 'better-sqlite3' not found. Installing via npm...");
198 await execFileAsync("npm", ["install", "better-sqlite3"], { cwd: "/root/telebox" });
199 console.log("[SUCCESS] Installed 'better-sqlite3'.");
200 }
201 try {
202 execSync("command -v sshpass");
203 } catch (e: any) {
204 console.log("[INSTALLING] 'sshpass' not found. Installing via system package manager...");
205 if (fs.existsSync("/usr/bin/apt-get"))
206 await execFileAsync("sudo", ["apt-get", "update"], { timeout: 120000 }).then(() =>
207 execFileAsync("sudo", ["apt-get", "install", "-y", "sshpass"], { timeout: 120000 })
208 );
209 else if (fs.existsSync("/usr/bin/yum"))
210 await execFileAsync("sudo", ["yum", "install", "-y", "sshpass"], { timeout: 120000 });
211 else throw new Error("Unsupported package manager.");
212 console.log("[SUCCESS] Installed 'sshpass'.");
213 }
214 await msg.edit({
215 text: "✅ <b>依赖安装完成!</b>\n\n为了使插件生效,请现在<b>重启TeleBox</b>。",
216 parseMode: "html",
217 });
218 dependenciesInstalled = false;
219 } catch (error: any) {
220 console.error("[FATAL] Dependency installation failed:", error);
221 await msg.edit({
222 text: `❌ <b>依赖自动安装失败!</b>\n\n请检查服务器后台日志。`,
223 parseMode: "html",
224 });
225 } finally {
226 isInstalling = false;
227 }
228}
229

Callers 1

speedtestFunction · 0.85

Calls 3

execFileAsyncFunction · 0.85
errorMethod · 0.80
editMethod · 0.45

Tested by

no test coverage detected