部分逻辑优化
This commit is contained in:
@@ -666,10 +666,10 @@ print_environment_summary() {
|
|||||||
print_title
|
print_title
|
||||||
print_subtitle "环境检测结果"
|
print_subtitle "环境检测结果"
|
||||||
echo ""
|
echo ""
|
||||||
echo -e " ${CYAN}操作系统:${NC} $OS $OS_VERSION"
|
echo -e " 操作系统:${NC} $OS $OS_VERSION"
|
||||||
echo -e " ${CYAN}CPU 架构:${NC} $ARCH"
|
echo -e " CPU 架构:${NC} $ARCH"
|
||||||
echo ""
|
echo ""
|
||||||
echo " ${CYAN}必要工具:${NC}"
|
echo " 必要工具:${NC}"
|
||||||
if [ "$HAS_GIT" = true ]; then
|
if [ "$HAS_GIT" = true ]; then
|
||||||
echo -e " git ✅ 已安装 ($(git --version | awk '{print $3}'))"
|
echo -e " git ✅ 已安装 ($(git --version | awk '{print $3}'))"
|
||||||
else
|
else
|
||||||
@@ -686,7 +686,7 @@ print_environment_summary() {
|
|||||||
echo " wget ❌ 未安装 (将自动安装)"
|
echo " wget ❌ 未安装 (将自动安装)"
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
echo " ${CYAN}Docker 环境:${NC}"
|
echo " Docker 环境:${NC}"
|
||||||
if [ "$HAS_DOCKER" = true ]; then
|
if [ "$HAS_DOCKER" = true ]; then
|
||||||
echo -e " docker ✅ 已安装 ($(docker --version | awk '{print $3}' | tr -d ','))"
|
echo -e " docker ✅ 已安装 ($(docker --version | awk '{print $3}' | tr -d ','))"
|
||||||
else
|
else
|
||||||
@@ -696,7 +696,7 @@ print_environment_summary() {
|
|||||||
fi
|
fi
|
||||||
if [ "$CONTAINER_EXISTS" = true ]; then
|
if [ "$CONTAINER_EXISTS" = true ]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo " ${CYAN}容器状态:${NC}"
|
echo " 容器状态:${NC}"
|
||||||
if [ "$CONTAINER_RUNNING" = true ]; then
|
if [ "$CONTAINER_RUNNING" = true ]; then
|
||||||
echo -e " frpc-console ✅ 运行中"
|
echo -e " frpc-console ✅ 运行中"
|
||||||
else
|
else
|
||||||
|
|||||||
+28
-22
@@ -19,7 +19,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GetFrpcPath 获取 frpc 二进制路径
|
// GetFrpcPath 获取 frpc 二进制路径
|
||||||
// 优先级: 本地缓存 > 内嵌二进制 > 系统 PATH
|
// 优先级: 本地缓存 > 程序同目录 > 当前工作目录 > embed 提取到当前目录 > 系统 PATH
|
||||||
func GetFrpcPath() (string, error) {
|
func GetFrpcPath() (string, error) {
|
||||||
frpcPathMutex.Lock()
|
frpcPathMutex.Lock()
|
||||||
defer frpcPathMutex.Unlock()
|
defer frpcPathMutex.Unlock()
|
||||||
@@ -50,38 +50,44 @@ func GetFrpcPath() (string, error) {
|
|||||||
return "", fmt.Errorf("不支持的平台: %s/%s", runtime.GOOS, runtime.GOARCH)
|
return "", fmt.Errorf("不支持的平台: %s/%s", runtime.GOOS, runtime.GOARCH)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 尝试从本地 bin 目录加载
|
// 方法1: 尝试从程序同目录加载
|
||||||
localPath := filepath.Join(".", "bin", fileName)
|
execPath, err := os.Executable()
|
||||||
if _, err := os.Stat(localPath); err == nil {
|
if err == nil {
|
||||||
cachedFrpcPath = localPath
|
execDir := filepath.Dir(execPath)
|
||||||
return localPath, nil
|
localPath := filepath.Join(execDir, "frpc")
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
localPath += ".exe"
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(localPath); err == nil {
|
||||||
|
cachedFrpcPath = localPath
|
||||||
|
return localPath, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从 embed 提取到 data 目录(Windows 和 Linux 统一)
|
// 方法2: 尝试从当前工作目录加载
|
||||||
dataDir := "./data"
|
cwdPath := "./frpc"
|
||||||
if err := os.MkdirAll(dataDir, 0755); err != nil {
|
|
||||||
return "", fmt.Errorf("创建 data 目录失败: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpPath := filepath.Join(dataDir, "frpc")
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
tmpPath += ".exe"
|
cwdPath += ".exe"
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(cwdPath); err == nil {
|
||||||
|
cachedFrpcPath = cwdPath
|
||||||
|
return cwdPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 方法3: 从 embed 提取到当前工作目录
|
||||||
data, err := embeddedFrpc.ReadFile("bin/" + fileName)
|
data, err := embeddedFrpc.ReadFile("bin/" + fileName)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if err := os.WriteFile(tmpPath, data, 0755); err == nil {
|
extractPath := "./frpc"
|
||||||
cachedFrpcPath = tmpPath
|
if runtime.GOOS == "windows" {
|
||||||
return tmpPath, nil
|
extractPath += ".exe"
|
||||||
}
|
}
|
||||||
// 如果写入失败,检查文件是否已存在
|
if err := os.WriteFile(extractPath, data, 0755); err == nil {
|
||||||
if _, statErr := os.Stat(tmpPath); statErr == nil {
|
cachedFrpcPath = extractPath
|
||||||
cachedFrpcPath = tmpPath
|
return extractPath, nil
|
||||||
return tmpPath, nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 最后尝试从系统 PATH 查找
|
// 方法4: 从系统 PATH 查找
|
||||||
path, err := exec.LookPath("frpc")
|
path, err := exec.LookPath("frpc")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cachedFrpcPath = path
|
cachedFrpcPath = path
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -35,7 +36,21 @@ func main() {
|
|||||||
log.Println("⚠️ 生成配置文件失败:", err)
|
log.Println("⚠️ 生成配置文件失败:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pm := process.NewManager("./data", "./data/frpc.toml", "./data/frpc")
|
// ============================================================
|
||||||
|
// 获取 frpc 二进制路径(自动处理平台差异)
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
frpcPath, err := frp.GetFrpcPath()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("⚠️ 获取 frpc 路径失败: %v", err)
|
||||||
|
frpcPath = "./frpc"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
frpcPath += ".exe"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Printf("📌 frpc 路径: %s", frpcPath)
|
||||||
|
|
||||||
|
pm := process.NewManager("./data", "./data/frpc.toml", frpcPath)
|
||||||
process.SetGlobalManager(pm)
|
process.SetGlobalManager(pm)
|
||||||
|
|
||||||
if err := pm.LoadConfig(); err != nil {
|
if err := pm.LoadConfig(); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user