Skip to content

Commit

Permalink
feat: add WSL (Windows Subsystem for Linux) support (#21)
Browse files Browse the repository at this point in the history
* Avoid using wine in WSL

* Fix errcheck and stylecheck errors
  • Loading branch information
SomaticIT authored and develar committed Nov 27, 2019
1 parent 5fdf622 commit 1897b39
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/rcedit/rcedit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rcedit

import (
"os"
"os/exec"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -31,15 +32,24 @@ 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"
} else {
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
Expand Down
59 changes: 59 additions & 0 deletions pkg/util/wsl.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 1897b39

Please sign in to comment.