diff --git a/cmd/linux.go b/cmd/linux.go index 61090238..e5ba768d 100644 --- a/cmd/linux.go +++ b/cmd/linux.go @@ -33,63 +33,23 @@ const ( // DistroInfo contains all the information relating to a linux distribution type DistroInfo struct { - Distribution LinuxDistribution - Description string - Release string - Codename string - DistributorID string - DiscoveredBy string + Distribution LinuxDistribution + Name string + ID string + Description string + Release string + DiscoveredBy string } // GetLinuxDistroInfo returns information about the running linux distribution func GetLinuxDistroInfo() *DistroInfo { result := &DistroInfo{Distribution: Unknown} - program := NewProgramHelper() - // Does lsb_release exist? - lsbRelease := program.FindProgram("lsb_release") - if lsbRelease != nil { - stdout, _, _, err := lsbRelease.Run("-a") - if err != nil { - return result - } - result.DiscoveredBy = "lsb" - for _, line := range strings.Split(stdout, "\n") { - if strings.Contains(line, ":") { - // Iterate lines a - details := strings.Split(line, ":") - key := strings.TrimSpace(details[0]) - value := strings.TrimSpace(details[1]) - switch key { - case "Distributor ID": - result.DistributorID = value - switch value { - case "Ubuntu": - result.Distribution = Ubuntu - case "Arch", "ManjaroLinux": - result.Distribution = Arch - case "Debian": - result.Distribution = Debian - case "Gentoo": - result.Distribution = Gentoo - case "Zorin": - result.Distribution = Zorin - case "Fedora": - result.Distribution = RedHat - } - case "Description": - result.Description = value - case "Release": - result.Release = value - case "Codename": - result.Codename = value - } - } - } - // check if /etc/os-release exists - } else if _, err := os.Stat("/etc/os-release"); !os.IsNotExist(err) { + _, err := os.Stat("/etc/os-release") + if !os.IsNotExist(err) { // Default value - osName := "Unknown" + osID := "unknown" + osNAME := "Unknown" version := "" // read /etc/os-release osRelease, _ := ioutil.ReadFile("/etc/os-release") @@ -104,8 +64,10 @@ func GetLinuxDistroInfo() *DistroInfo { continue } switch splitLine[0] { + case "ID": + osID = strings.Trim(splitLine[1], "\"") case "NAME": - osName = strings.Trim(splitLine[1], "\"") + osNAME = strings.Trim(splitLine[1], "\"") case "VERSION_ID": version = strings.Trim(splitLine[1], "\"") } @@ -114,21 +76,23 @@ func GetLinuxDistroInfo() *DistroInfo { // Check distro name against list of distros result.Release = version result.DiscoveredBy = "os-release" - switch osName { - case "Fedora": + switch osID { + case "fedora", "centos": result.Distribution = RedHat - case "CentOS": - result.Distribution = RedHat - case "Arch Linux": + case "arch": result.Distribution = Arch - case "Debian GNU/Linux": + case "debian", "ubuntu": result.Distribution = Debian - case "Gentoo/Linux": + case "gentoo": result.Distribution = Gentoo + case "zorin": + result.Distribution = Zorin default: result.Distribution = Unknown - result.DistributorID = osName } + + result.ID = osID + result.Name = osNAME } return result } @@ -181,16 +145,16 @@ func RpmInstalled(packageName string) (bool, error) { // currently unsupported distribution func RequestSupportForDistribution(distroInfo *DistroInfo, libraryName string) error { var logger = NewLogger() - defaultError := fmt.Errorf("unable to check libraries on distribution '%s'. Please ensure that the '%s' equivalent is installed", distroInfo.DistributorID, libraryName) + defaultError := fmt.Errorf("unable to check libraries on distribution '%s'. Please ensure that the '%s' equivalent is installed", distroInfo.Name, libraryName) - logger.Yellow("Distribution '%s' is not currently supported, but we would love to!", distroInfo.DistributorID) - q := fmt.Sprintf("Would you like to submit a request to support distribution '%s'?", distroInfo.DistributorID) + logger.Yellow("Distribution '%s' is not currently supported, but we would love to!", distroInfo.Name) + q := fmt.Sprintf("Would you like to submit a request to support distribution '%s'?", distroInfo.Name) result := Prompt(q, "yes") if strings.ToLower(result) != "yes" { return defaultError } - title := fmt.Sprintf("Support Distribution '%s'", distroInfo.DistributorID) + title := fmt.Sprintf("Support Distribution '%s'", distroInfo.Name) var str strings.Builder @@ -205,16 +169,16 @@ func RequestSupportForDistribution(distroInfo *DistroInfo, libraryName string) e str.WriteString(fmt.Sprintf("| Platform | %s |\n", runtime.GOOS)) str.WriteString(fmt.Sprintf("| Arch | %s |\n", runtime.GOARCH)) str.WriteString(fmt.Sprintf("| GO111MODULE | %s |\n", gomodule)) - str.WriteString(fmt.Sprintf("| Distribution ID | %s |\n", distroInfo.DistributorID)) + str.WriteString(fmt.Sprintf("| Distribution ID | %s |\n", distroInfo.ID)) + str.WriteString(fmt.Sprintf("| Distribution Name | %s |\n", distroInfo.Name)) str.WriteString(fmt.Sprintf("| Distribution Version | %s |\n", distroInfo.Release)) str.WriteString(fmt.Sprintf("| Discovered by | %s |\n", distroInfo.DiscoveredBy)) - body := fmt.Sprintf("**Description**\nDistribution '%s' is currently unsupported.\n\n**Further Information**\n\n%s\n\n*Please add any extra information here, EG: libraries that are needed to make the distribution work, or commands to install them*", distroInfo.DistributorID, str.String()) + body := fmt.Sprintf("**Description**\nDistribution '%s' is currently unsupported.\n\n**Further Information**\n\n%s\n\n*Please add any extra information here, EG: libraries that are needed to make the distribution work, or commands to install them*", distroInfo.ID, str.String()) fullURL := "https://github.com/wailsapp/wails/issues/new?" params := "title=" + title + "&body=" + body fmt.Println("Opening browser to file request.") browser.OpenURL(fullURL + url.PathEscape(params)) return nil - }