2021-09-20 21:00:55 +08:00
|
|
|
//go:build !windows
|
2020-11-25 19:01:53 +08:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package platform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ExpandEnv(s string) string {
|
|
|
|
return os.ExpandEnv(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func LineSeparator() string {
|
|
|
|
return "\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetToolLocation(file string) string {
|
2023-10-28 18:21:57 -04:00
|
|
|
toolPath := NewEnvFlag(ToolLocation).GetValue(getExecutableDir)
|
2020-11-25 19:01:53 +08:00
|
|
|
return filepath.Join(toolPath, file)
|
|
|
|
}
|
|
|
|
|
2025-03-24 16:26:48 +03:30
|
|
|
// GetAssetLocation searches for `file` in the env dir, the executable dir, and certain locations
|
2020-11-25 19:01:53 +08:00
|
|
|
func GetAssetLocation(file string) string {
|
2023-10-28 18:21:57 -04:00
|
|
|
assetPath := NewEnvFlag(AssetLocation).GetValue(getExecutableDir)
|
2020-11-25 19:01:53 +08:00
|
|
|
defPath := filepath.Join(assetPath, file)
|
|
|
|
for _, p := range []string{
|
|
|
|
defPath,
|
|
|
|
filepath.Join("/usr/local/share/xray/", file),
|
|
|
|
filepath.Join("/usr/share/xray/", file),
|
2021-02-27 23:09:44 +08:00
|
|
|
filepath.Join("/opt/share/xray/", file),
|
2020-11-25 19:01:53 +08:00
|
|
|
} {
|
|
|
|
if _, err := os.Stat(p); os.IsNotExist(err) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// asset found
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// asset not found, let the caller throw out the error
|
|
|
|
return defPath
|
|
|
|
}
|
2025-03-24 16:26:48 +03:30
|
|
|
|
|
|
|
// GetCertLocation searches for `file` in the env dir and the executable dir
|
|
|
|
func GetCertLocation(file string) string {
|
|
|
|
certPath := NewEnvFlag(CertLocation).GetValue(getExecutableDir)
|
|
|
|
return filepath.Join(certPath, file)
|
|
|
|
}
|