5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 17:52:29 +08:00

Initial Linux distro detection

This commit is contained in:
Lea Anthony 2018-12-16 20:16:40 +11:00
parent 04c64c1bea
commit 6edd941c1a
2 changed files with 57 additions and 0 deletions

34
cmd/linux.go Normal file
View File

@ -0,0 +1,34 @@
package cmd
import "fmt"
// LinuxDistribution is of type int
type LinuxDistribution int
const (
// Ubuntu distro
Ubuntu LinuxDistribution = 0
)
// DistroInfo contains all the information relating to a linux distribution
type DistroInfo struct {
distribution LinuxDistribution
name string
release string
}
func getLinuxDistroInfo() *DistroInfo {
result := &DistroInfo{}
program := NewProgramHelper()
// Does lsb_release exist?
lsbRelease := program.FindProgram("lsb_release")
if lsbRelease != nil {
stdout, _, err := lsbRelease.Run("-a")
if err != nil {
return nil
}
fmt.Println(stdout)
}
return result
}

View File

@ -1,6 +1,7 @@
package cmd package cmd
import ( import (
"bytes"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
) )
@ -41,3 +42,25 @@ func (p *ProgramHelper) FindProgram(programName string) *Program {
Path: path, Path: path,
} }
} }
func (p *Program) GetFullPathToBinary() (string, error) {
result := filepath.Join(p.Path, p.Name)
return filepath.Abs(result)
}
// Run will execute the program with the given parameters
// Returns stdout + stderr as strings and an error if one occured
func (p *Program) Run(vars ...string) (stdout, stderr string, err error) {
command, err := p.GetFullPathToBinary()
if err != nil {
return "", "", err
}
cmd := exec.Command(command, vars...)
var stdo, stde bytes.Buffer
cmd.Stdout = &stdo
cmd.Stderr = &stde
err = cmd.Run()
stdout = string(stdo.Bytes())
stderr = string(stde.Bytes())
return
}