others.go 915 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //go:build !windows
  2. // +build !windows
  3. package platform
  4. import (
  5. "os"
  6. "path/filepath"
  7. )
  8. func ExpandEnv(s string) string {
  9. return os.ExpandEnv(s)
  10. }
  11. func LineSeparator() string {
  12. return "\n"
  13. }
  14. func GetToolLocation(file string) string {
  15. toolPath := NewEnvFlag(ToolLocation).GetValue(getExecutableDir)
  16. return filepath.Join(toolPath, file)
  17. }
  18. // GetAssetLocation searches for `file` in certain locations
  19. func GetAssetLocation(file string) string {
  20. assetPath := NewEnvFlag(AssetLocation).GetValue(getExecutableDir)
  21. defPath := filepath.Join(assetPath, file)
  22. for _, p := range []string{
  23. defPath,
  24. filepath.Join("/usr/local/share/xray/", file),
  25. filepath.Join("/usr/share/xray/", file),
  26. filepath.Join("/opt/share/xray/", file),
  27. } {
  28. if _, err := os.Stat(p); os.IsNotExist(err) {
  29. continue
  30. }
  31. // asset found
  32. return p
  33. }
  34. // asset not found, let the caller throw out the error
  35. return defPath
  36. }