diff --git a/cmd/linux.go b/cmd/linux.go index 766d68f00..1fd857ec0 100644 --- a/cmd/linux.go +++ b/cmd/linux.go @@ -120,6 +120,9 @@ func parseOsRelease(osRelease string) *DistroInfo { return result } +// CheckPkgInstalled is all functions that use local programs to see if a package is installed +type CheckPkgInstalled func(string) (bool, error) + // EqueryInstalled uses equery to see if a package is installed func EqueryInstalled(packageName string) (bool, error) { program := NewProgramHelper() @@ -166,9 +169,9 @@ func RpmInstalled(packageName string) (bool, error) { // RequestSupportForDistribution promts the user to submit a request to support their // currently unsupported distribution -func RequestSupportForDistribution(distroInfo *DistroInfo, libraryName string) error { +func RequestSupportForDistribution(distroInfo *DistroInfo) error { var logger = NewLogger() - defaultError := fmt.Errorf("unable to check libraries on distribution '%s'. Please ensure that the '%s' equivalent is installed", distroInfo.Name, libraryName) + defaultError := fmt.Errorf("unable to check libraries on distribution '%s'", distroInfo.Name) 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) diff --git a/cmd/system.go b/cmd/system.go index 511c6c77e..4749cb74f 100644 --- a/cmd/system.go +++ b/cmd/system.go @@ -269,55 +269,33 @@ func CheckDependencies(logger *Logger) (bool, error) { if err != nil { return false, err } + + var libraryChecker CheckPkgInstalled distroInfo := GetLinuxDistroInfo() + + switch distroInfo.Distribution { + case Ubuntu, Debian, Zorin, Parrot, Linuxmint: + libraryChecker = DpkgInstalled + case Arch: + libraryChecker = PacmanInstalled + case CentOS, Fedora: + libraryChecker = RpmInstalled + case Gentoo: + libraryChecker = EqueryInstalled + default: + return false, RequestSupportForDistribution(distroInfo) + } + for _, library := range *requiredLibraries { - switch distroInfo.Distribution { - case Ubuntu, Debian, Zorin, Parrot, Linuxmint: - installed, err := DpkgInstalled(library.Name) - if err != nil { - return false, err - } - if !installed { - errors = true - logger.Error("Library '%s' not found. %s", library.Name, library.Help) - } else { - logger.Green("Library '%s' installed.", library.Name) - } - case Arch: - installed, err := PacmanInstalled(library.Name) - if err != nil { - return false, err - } - if !installed { - errors = true - logger.Error("Library '%s' not found. %s", library.Name, library.Help) - } else { - logger.Green("Library '%s' installed.", library.Name) - } - case CentOS, Fedora: - installed, err := RpmInstalled(library.Name) - if err != nil { - return false, err - } - if !installed { - errors = true - logger.Error("Library '%s' not found. %s", library.Name, library.Help) - } else { - logger.Green("Library '%s' installed.", library.Name) - } - case Gentoo: - installed, err := EqueryInstalled(library.Name) - if err != nil { - return false, err - } - if !installed { - errors = true - logger.Error("Library '%s' not found. %s", library.Name, library.Help) - } else { - logger.Green("Library '%s' installed.", library.Name) - } - default: - return false, RequestSupportForDistribution(distroInfo, library.Name) + installed, err := libraryChecker(library.Name) + if err != nil { + return false, err + } + if !installed { + errors = true + logger.Error("Library '%s' not found. %s", library.Name, library.Help) + } else { + logger.Green("Library '%s' installed.", library.Name) } } } diff --git a/cmd/wails/0_setup.go b/cmd/wails/0_setup.go index 155a2a156..561b0dae5 100644 --- a/cmd/wails/0_setup.go +++ b/cmd/wails/0_setup.go @@ -108,7 +108,7 @@ func checkLibraries() (errors bool, err error) { logger.Green("Library '%s' installed.", library.Name) } default: - return false, cmd.RequestSupportForDistribution(distroInfo, library.Name) + return false, cmd.RequestSupportForDistribution(distroInfo) } } }