diff --git a/cmd/linux.go b/cmd/linux.go new file mode 100644 index 000000000..067e3068c --- /dev/null +++ b/cmd/linux.go @@ -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 +} diff --git a/cmd/program.go b/cmd/program.go index c19ed989d..836b5ad63 100644 --- a/cmd/program.go +++ b/cmd/program.go @@ -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 +}