Feat: delete pty install

This commit is contained in:
unitwk 2024-03-13 19:52:12 +08:00
parent be75b8de2d
commit 2dcacc6b6a
4 changed files with 2 additions and 64 deletions

View File

@ -51,7 +51,6 @@ import * as router from "./service/router";
import * as koa from "./service/http";
import * as protocol from "./service/protocol";
import InstanceSubsystem from "./service/system_instance";
import { initDependent } from "./service/install";
import "./service/async_task_service";
import "./service/async_task_service/quick_install";
import "./service/system_visual_data";
@ -86,9 +85,6 @@ const io = new Server(httpServer, {
}
});
// Initialize optional dependencies
initDependent();
// Initialize application instance system
try {
InstanceSubsystem.loadInstances();

View File

@ -1,58 +0,0 @@
import { $t } from "../i18n";
import os from "os";
import fs from "fs-extra";
import https from "https";
import path from "path";
import logger from "./log";
import { downloadFileToLocalFile } from "./download";
const PTY_NAME = `pty_${os.platform()}_${os.arch()}${os.platform() === "win32" ? ".exe" : ""}`;
const PTY_PATH = path.normalize(path.join(process.cwd(), "lib", PTY_NAME));
const PTY_DIR_PATH = path.join(process.cwd(), "lib");
function ptyChmod() {
try {
fs.chmodSync(PTY_PATH, 0o755);
return true;
} catch (error) {
logger.warn($t("TXT_CODE_install.changeModeErr", { path: PTY_PATH }));
fs.remove(PTY_PATH, () => {});
return false;
}
}
async function installPty(url: string): Promise<boolean> {
if (!fs.existsSync(PTY_DIR_PATH)) fs.mkdirsSync(PTY_DIR_PATH);
if (fs.existsSync(PTY_PATH) && fs.statSync(PTY_PATH)?.size > 1024) {
if (!ptyChmod()) throw new Error("ptyChmod error");
logger.info($t("TXT_CODE_install.ptySupport"));
return true;
}
await downloadFileToLocalFile(url, PTY_PATH);
return true;
}
// Emulate terminal-dependent programs, PTY programs based on Go/C++
// Reference: https://github.com/MCSManager/pty
export function initDependent() {
const ptyUrls = [`https://mcsmanager.oss-cn-guangzhou.aliyuncs.com/${PTY_NAME}`];
function setup(index = 0) {
installPty(ptyUrls[index])
.then(() => {
logger.info($t("TXT_CODE_install.installed"));
logger.info($t("TXT_CODE_install.guide"));
ptyChmod();
})
.catch((err: Error) => {
fs.remove(PTY_PATH, () => {});
if (index === ptyUrls.length - 1) {
logger.warn($t("TXT_CODE_install.installErr"));
if (err?.message) logger.warn(err.message);
return;
}
return setup(index + 1);
});
}
setup(0);
}

View File

@ -160,7 +160,7 @@
"TXT_CODE_pty_start.instanceUuid": "Instance UUID: [{{instanceUuid}}]",
"TXT_CODE_pty_start.mustAbsolutePath": "The working directory for emulated terminal must be an absolute path. Please go to the instance settings and set the working directory to an absolute path.",
"TXT_CODE_pty_start.notSupportPty": "Emulated terminal mode failed. Unsupported architecture or system. Downgraded to regular terminal mode...",
"TXT_CODE_pty_start.pidErr": "Detected instance process/container startup failure (PID is empty). Possible reasons include:\n1. Incorrect instance startup command. Please check the startup command and parameters in settings.\n2. Incorrect system host environment or missing dependencies, such as Java environment, etc.\n\nNative startup command:\n{{startCommand}}\n\nEmulated terminal relay command:\nProgram: {{path}}\nParameters: {{params}}\n\nPlease report this information to the administrator, technical support, or troubleshoot it yourself.\nIf you believe the issue is caused by the panel's emulated terminal, please disable the 'Emulated Terminal' option in the left-side of terminal settings. We will use the original input and output streams to monitor the program.",
"TXT_CODE_pty_start.pidErr": "It was detected that the process startup failed. The possible reasons are: \n1. The instance startup command was written incorrectly. Please go to the instance setting interface to check the startup command and parameters. \n2. The system host environment is incorrect or lacks an environment, such as a lack of Java environment, etc. \n\nStart command:\n{{startCommand}}\n\nPlease report this information to the administrator, technician or troubleshoot yourself.",
"TXT_CODE_pty_start.ptyCwd": "Working Directory: {{cwd}}",
"TXT_CODE_pty_start.ptyParams": "PTY Parameters: {{param}}",
"TXT_CODE_pty_start.ptyPath": "PTY Path: {{path}}",

View File

@ -160,7 +160,7 @@
"TXT_CODE_pty_start.instanceUuid": "实例标识符: [{{instanceUuid}}]",
"TXT_CODE_pty_start.mustAbsolutePath": "仿真终端启动工作目录必须使用绝对路径,请前往实例设置界面重新设置工作路径为绝对路径",
"TXT_CODE_pty_start.notSupportPty": "仿真终端模式失败,无法支持的架构或系统,已自动降级到普通终端模式...",
"TXT_CODE_pty_start.pidErr": "检测到实例进程/容器启动失败PID 为空),其可能的原因是:\n1. 实例启动命令编写错误,请前往实例设置界面检查启动命令与参数。\n2. 系统主机环境不正确或缺少环境,如 Java 环境等。\n\n原生启动命令:\n{{startCommand}}\n\n仿真终端中转命令:\n程序{{path}}\n参数{{params}}\n\n请将此信息报告给管理员,技术人员或自行排查故障。\n如果您认为是面板仿真终端导致的问题请在左侧终端设置中关闭“仿真终端”选项我们将会采用原始输入输出流的方式监听程序。",
"TXT_CODE_pty_start.pidErr": "检测到进程启动失败,其可能的原因是:\n1. 实例启动命令编写错误,请前往实例设置界面检查启动命令与参数。\n2. 系统主机环境不正确或缺少环境,缺少 Java 环境等。\n\n启动命令\n{{startCommand}}\n\n请将此信息报告给管理员技术人员或自行排查故障。",
"TXT_CODE_pty_start.ptyCwd": "工作目录: {{cwd}}",
"TXT_CODE_pty_start.ptyParams": "PTY 参数: {{param}}",
"TXT_CODE_pty_start.ptyPath": "PTY 路径: {{path}}",