github.com/xraypb/Xray-core@v1.8.1/common/platform/others.go (about)

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