diff --git a/cmd/linux.go b/cmd/linux.go index 1728febcb..c2a672eed 100644 --- a/cmd/linux.go +++ b/cmd/linux.go @@ -2,6 +2,9 @@ package cmd import ( "fmt" + "io/ioutil" + "os" + "regexp" "strings" ) @@ -15,6 +18,8 @@ const ( Ubuntu // Arch linux distribution Arch + // RedHat linux distribution + RedHat ) // DistroInfo contains all the information relating to a linux distribution @@ -64,7 +69,19 @@ func GetLinuxDistroInfo() *DistroInfo { } } } - + // check if /etc/os-release exists + } else if _, err := os.Stat("/etc/os-release"); !os.IsNotExist(err) { + // read /etc/os-release + osRelease, _ := ioutil.ReadFile("/etc/os-release") + // compile a regex to find NAME=distro + re := regexp.MustCompile(`^NAME=(.*)\n`) + // extract the distro name + osName := string(re.FindSubmatch(osRelease)[1]) + // Check distro name against list of RedHat distros + if osName == "Fedora" || osName == "CentOS" { + //if it matches set result.Distribution to RedHat + result.Distribution = RedHat + } } return result } @@ -90,3 +107,14 @@ func PacmanInstalled(packageName string) (bool, error) { _, _, exitCode, _ := pacman.Run("-Qs", packageName) return exitCode == 0, nil } + +// YumInstalled uses yum to see if a package is installed +func YumInstalled(packageName string) (bool, error) { + program := NewProgramHelper() + yum := program.FindProgram("yum") + if yum == nil { + return false, fmt.Errorf("cannot check dependencies: yum not found") + } + _, _, exitCode, _ := yum.Run("list", packageName, "--available") + return exitCode == 0, nil +} diff --git a/cmd/prerequisites.go b/cmd/prerequisites.go index 47cabe0b1..cdd41cdf5 100644 --- a/cmd/prerequisites.go +++ b/cmd/prerequisites.go @@ -99,7 +99,10 @@ func getRequiredLibrariesLinux() (*Prerequisites, error) { result.Add(newPrerequisite("libwebkit2gtk-4.0-dev", "Please install with `sudo apt install libwebkit2gtk-4.0-dev` and try again")) case Arch: result.Add(newPrerequisite("gtk3", "Please install with `sudo pacman -S gtk3` and try again")) - result.Add(newPrerequisite("webkit2gtk", "Please install with `sudo pacman -S webkit2gtk")) + result.Add(newPrerequisite("webkit2gtk", "Please install with `sudo pacman -S webkit2gtk` and try again")) + case RedHat: + result.Add(newPrerequisite("gtk3-devel", "Please install with `sudo yum install gtk3-devel` and try again")) + result.Add(newPrerequisite("webkit2gtk3-devel", "Please install with `sudo yum install webkit2gtk3-devel` and try again")) default: result.Add(newPrerequisite("libgtk-3-dev", "Please install with your system package manager and try again")) result.Add(newPrerequisite("libwebkit2gtk-4.0-dev", "Please install with your system package manager and try again")) diff --git a/cmd/system.go b/cmd/system.go index 785c0754b..509958666 100644 --- a/cmd/system.go +++ b/cmd/system.go @@ -283,6 +283,18 @@ func CheckDependencies(logger *Logger) (bool, error) { } else { logger.Green("Library '%s' installed.", library.Name) } + case RedHat: + + installed, err := YumInstalled(library.Name) + if err != nil { + return false, err + } + if !installed { + errors = true + logger.Red("Library '%s' not found. %s", library.Name, library.Help) + } else { + logger.Green("Library '%s' installed.", library.Name) + } default: return false, fmt.Errorf("unable to check libraries on distribution '%s'. Please ensure that the '%s' equivalent is installed", distroInfo.DistributorID, library.Name) } diff --git a/go.mod b/go.mod index 7274e65fb..0e075f554 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/leaanthony/mewn v0.10.5 github.com/leaanthony/slicer v1.3.1 github.com/leaanthony/spinner v0.5.0 + github.com/matishsiao/goInfo v0.0.0-20170803142006-617e6440957e github.com/mattn/go-colorable v0.1.1 // indirect github.com/mattn/go-isatty v0.0.6 // indirect github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index d0179d942..21f88fbe2 100644 --- a/go.sum +++ b/go.sum @@ -31,6 +31,8 @@ github.com/leaanthony/synx v0.1.0 h1:R0lmg2w6VMb8XcotOwAe5DLyzwjLrskNkwU7LLWsyL8 github.com/leaanthony/synx v0.1.0/go.mod h1:Iz7eybeeG8bdq640iR+CwYb8p+9EOsgMWghkSRyZcqs= github.com/leaanthony/wincursor v0.1.0 h1:Dsyp68QcF5cCs65AMBmxoYNEm0n8K7mMchG6a8fYxf8= github.com/leaanthony/wincursor v0.1.0/go.mod h1:7TVwwrzSH/2Y9gLOGH+VhA+bZhoWXBRgbGNTMk+yimE= +github.com/matishsiao/goInfo v0.0.0-20170803142006-617e6440957e h1:Y+GY+bv5vf1gssphFsGiq6R8qdHxnpDZvYljFnXfhD8= +github.com/matishsiao/goInfo v0.0.0-20170803142006-617e6440957e/go.mod h1:yLZrFIhv+Z20hxHvcZpEyKVQp9HMsOJkXAxx7yDqtvg= github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=