From 2af0bc667b09ce5e433d0f665f75f4c61f6f4acd Mon Sep 17 00:00:00 2001 From: naiba Date: Tue, 18 Jan 2022 21:07:16 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A9=20=E5=BC=BA=E5=88=B6=20windows=20?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E5=AF=B9=E5=BA=94=E6=AD=A3=E7=A1=AE=E4=BA=8C?= =?UTF-8?q?=E8=BF=9B=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/agent/main.go | 22 +++++++++++++++++++--- cmd/agent/monitor/monitor.go | 4 ++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/cmd/agent/main.go b/cmd/agent/main.go index c75f9ab..6abacc5 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -18,6 +18,7 @@ import ( "github.com/go-ping/ping" "github.com/gorilla/websocket" "github.com/p14yground/go-github-selfupdate/selfupdate" + "github.com/shirou/gopsutil/v3/host" flag "github.com/spf13/pflag" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -46,7 +47,7 @@ type AgentConfig struct { var ( version string - arch string = runtime.GOARCH + arch string client pb.NezhaServiceClient inited bool ) @@ -73,8 +74,23 @@ func init() { } func main() { - if arch != runtime.GOARCH { - panic(fmt.Sprintf("与当前系统不匹配,当前运行 %s_%s, 需要下载 %s_%s", runtime.GOOS, arch, runtime.GOOS, runtime.GOARCH)) + if runtime.GOOS == "windows" { + hostArch, err := host.KernelArch() + if err != nil { + panic(err) + } + if hostArch == "i386" { + hostArch = "386" + } + if hostArch == "i686" || hostArch == "ia64" || hostArch == "x86_64" { + hostArch = "amd64" + } + if hostArch == "aarch64" { + hostArch = "arm64" + } + if arch != hostArch { + panic(fmt.Sprintf("与当前系统不匹配,当前运行 %s_%s, 需要下载 %s_%s", runtime.GOOS, arch, runtime.GOOS, hostArch)) + } } // 来自于 GoReleaser 的版本号 diff --git a/cmd/agent/monitor/monitor.go b/cmd/agent/monitor/monitor.go index 3e9e582..62507cd 100644 --- a/cmd/agent/monitor/monitor.go +++ b/cmd/agent/monitor/monitor.go @@ -23,8 +23,8 @@ import ( ) var ( - Version string = "debug" - expectDiskFsTypes = []string{ + Version string + expectDiskFsTypes = []string{ "apfs", "ext4", "ext3", "ext2", "f2fs", "reiserfs", "jfs", "btrfs", "fuseblk", "zfs", "simfs", "ntfs", "fat32", "exfat", "xfs", "fuse.rclone", }