From b308bcfc2b035f024cb7fc9be77788670eaf867a Mon Sep 17 00:00:00 2001 From: mzz2017 Date: Mon, 10 Feb 2020 19:05:43 +0800 Subject: [PATCH] feat: add command param --passcheckroot --- service/global/environmentConfig.go | 4 +++- service/main.go | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/service/global/environmentConfig.go b/service/global/environmentConfig.go index 05ebfff4..51739a6a 100644 --- a/service/global/environmentConfig.go +++ b/service/global/environmentConfig.go @@ -11,6 +11,7 @@ type Params struct { Config string `id:"config" short:"c" default:"/etc/v2ray/v2raya.json" desc:"V2RayA配置文件路径"` Mode string `id:"mode" short:"m" desc:"可选systemctl, service, docker, common. 不设置则自动检测"` SSRListenPort int `short:"s" default:"12346" desc:"使用ss或ssr时的ssr server监听端口,默认12346"` + PassCheckRoot bool `desc:"可跳过启动时的权限检查"` } var params Params @@ -28,8 +29,9 @@ func initFunc() { } } +var once sync.Once + func GetEnvironmentConfig() *Params { - var once sync.Once once.Do(initFunc) return ¶ms } diff --git a/service/main.go b/service/main.go index 70695ff0..a170d97f 100644 --- a/service/main.go +++ b/service/main.go @@ -34,8 +34,12 @@ func checkEnvironment() { _, _ = fmt.Scanf("\n") os.Exit(1) } - if os.Getegid() != 0 { - log.Fatal("请以sudo或root权限执行本程序") + if !global.GetEnvironmentConfig().PassCheckRoot { + if os.Getegid() == -1 { + log.Println("[warning] 无法判断当前是否sudo或拥有root权限,请确保V2RayA以sudo或root权限运行") + } else if os.Getegid() != 0 { + log.Fatal("请以sudo或root权限执行本程序. 或使用--passcheckroot参数跳过检查") + } } _, port, err := net.SplitHostPort(global.GetEnvironmentConfig().Address) if err != nil {