-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add WSL (Windows Subsystem for Linux) support (#21)
* Avoid using wine in WSL * Fix errcheck and stylecheck errors
- Loading branch information
Showing
2 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |