others.go 983 B

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