diff --git a/pkg/rcedit/rcedit.go b/pkg/rcedit/rcedit.go index 7da8f24..20cc7e7 100644 --- a/pkg/rcedit/rcedit.go +++ b/pkg/rcedit/rcedit.go @@ -1,6 +1,7 @@ package rcedit import ( + "os" "os/exec" "path/filepath" "runtime" @@ -31,7 +32,7 @@ func editResources(args []string) error { return err } - if util.GetCurrentOs() == util.WINDOWS { + if util.GetCurrentOs() == util.WINDOWS || util.IsWSL() { var rcEditExecutable string if runtime.GOARCH == "amd64" { rcEditExecutable = "rcedit-x64.exe" @@ -39,7 +40,16 @@ func editResources(args []string) error { rcEditExecutable = "rcedit-ia32.exe" } - command := exec.Command(filepath.Join(winCodeSignPath, rcEditExecutable), args...) + rcEditPath := filepath.Join(winCodeSignPath, rcEditExecutable) + + if util.IsWSL() { + err = os.Chmod(rcEditPath, 0755) + if err != nil { + return err + } + } + + command := exec.Command(rcEditPath, args...) _, err = util.Execute(command) if err != nil { return err diff --git a/pkg/util/wsl.go b/pkg/util/wsl.go new file mode 100644 index 0000000..1a6d20c --- /dev/null +++ b/pkg/util/wsl.go @@ -0,0 +1,59 @@ +package util + +import ( + "bytes" + "io/ioutil" + "os/exec" + "strings" +) + +func IsWSL() bool { + if GetCurrentOs() != LINUX { + return false + } + + release, err := getOSRelease() + if err != nil { + return false + } + + if strings.Contains(strings.ToLower(release), "microsoft") { + return true + } + + version, err := getProcVersion() + if err != nil { + return false + } + + if strings.Contains(strings.ToLower(version), "microsoft") { + return true + } + + return false +} + +func getOSRelease() (string, error) { + cmd := exec.Command("uname","-r") + + var out bytes.Buffer + var stderr bytes.Buffer + cmd.Stdout = &out + cmd.Stderr = &stderr + + err := cmd.Run() + if err != nil { + return "", err + } + + return out.String(), nil +} + +func getProcVersion() (string, error) { + content, err := ioutil.ReadFile("/proc/version") + if err != nil { + return "", err + } + + return string(content), nil +}