feat: add command param --passcheckroot

This commit is contained in:
mzz2017 committed 2020-02-10 19:05:43 +08:00
1 parent 23a153b43c
commit b308bcfc2b
2 files changed
+9 -3

No files matched your search

+3 -1
View File
@@ -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 &params
}
+6 -2
View File
@@ -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 {