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:
parent
04c64c1bea
commit
6edd941c1a
34
cmd/linux.go
Normal file
34
cmd/linux.go
Normal 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
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
)
|
||||
@ -41,3 +42,25 @@ func (p *ProgramHelper) FindProgram(programName string) *Program {
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user