diff --git a/cmd/setup.go b/cmd/setup.go index f409252..e3c21dd 100644 --- a/cmd/setup.go +++ b/cmd/setup.go @@ -32,11 +32,17 @@ func newSetup(setupOpts setupOpts) error { var WBConfig config.WBConfig - // Determine OS + fmt.Println("Welcome to the Workbench Installer!\n") + + // Determine OS and install pre-requisites osType, err := os.DetectOS() if err != nil { return err } + err = os.InstallPrereqs(osType) + if err != nil { + return err + } // Languages selectedLanguages, err := languages.PromptAndRespond() diff --git a/internal/install/install.go b/internal/install/install.go index a0da995..5a98f20 100644 --- a/internal/install/install.go +++ b/internal/install/install.go @@ -9,129 +9,10 @@ import ( "github.com/dpastoor/wbi/internal/system" ) -// Installs Gdebi Core -func InstallGdebiCore() error { - gdebiCoreCommand := "sudo apt-get install -y gdebi-core" - err := system.RunCommand(gdebiCoreCommand) - if err != nil { - return fmt.Errorf("issue installing gdebi-core: %w", err) - } - - fmt.Println("\ngdebi-core has been successfully installed!\n") - return nil -} - -// Upgrades Apt -func UpgradeApt() error { - aptUpgradeCommand := "sudo apt-get update" - err := system.RunCommand(aptUpgradeCommand) - if err != nil { - return fmt.Errorf("issue upgrading apt: %w", err) - } - - fmt.Println("\napt has been successfully upgraded!\n") - return nil -} - -// Enable the CodeReady Linux Builder repository: -func EnableCodeReadyRepo() error { - // TODO add support for On Premise as well as cloud (currently only cloud) - dnfPluginsCoreCommand := "sudo dnf install dnf-plugins-core" - err := system.RunCommand(dnfPluginsCoreCommand) - if err != nil { - return fmt.Errorf("issue installing dnf-plugins-core: %w", err) - } - - enableCodeReadyCommand := `sudo dnf config-manager --set-enabled "codeready-builder-for-rhel-8-*-rpms"` - err = system.RunCommand(enableCodeReadyCommand) - if err != nil { - return fmt.Errorf("issue enabling the CodeReady Linux Builder repo: %w", err) - } - - fmt.Println("\nThe CodeReady Linux Builder repository has been successfully enabled!\n") - return nil -} - -// Enable the Optional repository -func EnableOptionalRepo() error { - // TODO add support for On Premise as well as cloud (currently only cloud) - yumUtilsCommand := "sudo yum install yum-utils" - err := system.RunCommand(yumUtilsCommand) - if err != nil { - return fmt.Errorf("issue installing yum-utils: %w", err) - } - - enableOptionalCommand := `sudo yum-config-manager --enable "rhel-*-optional-rpms"` - err = system.RunCommand(enableOptionalCommand) - if err != nil { - return fmt.Errorf("issue enabling the optional repo: %w", err) - } - - fmt.Println("\nThe Optional repository has been successfully enabled!\n") - return nil -} - -// Enable the Extra Packages for Enterprise Linux (EPEL) repository -func EnableEPELRepo(osType config.OperatingSystem) error { - var EPELCommand string - if osType == config.Redhat8 { - EPELCommand = "sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm" - } else if osType == config.Redhat7 { - EPELCommand = "sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm " - } else { - return errors.New("operating system not supported") - } - - err := system.RunCommand(EPELCommand) - if err != nil { - return fmt.Errorf("issue enabling EPEL repo: %w", err) - } - - fmt.Println("\nThe Extra Packages for Enterprise Linux (EPEL) repository has been successfully enabled!\n") - return nil -} - // Installs R/Python in a certain way based on the operating system func InstallLanguage(language string, filepath string, osType config.OperatingSystem, version string) error { languageTitleCase := strings.Title(language) - // Update apt and install gdebi-core if an Ubuntu system - if osType == config.Ubuntu22 || osType == config.Ubuntu20 || osType == config.Ubuntu18 { - AptErr := UpgradeApt() - if AptErr != nil { - return fmt.Errorf("UpgradeApt: %w", AptErr) - } - - GdebiCoreErr := InstallGdebiCore() - if GdebiCoreErr != nil { - return fmt.Errorf("InstallGdebiCore: %w", GdebiCoreErr) - } - } else if osType == config.Redhat8 { - // Enable the Extra Packages for Enterprise Linux (EPEL) repository - EnableEPELErr := EnableEPELRepo(osType) - if EnableEPELErr != nil { - return fmt.Errorf("EnableEPELRepo: %w", EnableEPELErr) - } - // Enable the CodeReady Linux Builder repository - EnableCodeReadyErr := EnableCodeReadyRepo() - if EnableCodeReadyErr != nil { - return fmt.Errorf("EnableCodeReadyRepo: %w", EnableCodeReadyErr) - } - } else if osType == config.Redhat7 { - // Enable the Extra Packages for Enterprise Linux (EPEL) repository - EnableEPELErr := EnableEPELRepo(osType) - if EnableEPELErr != nil { - return fmt.Errorf("EnableEPELRepo: %w", EnableEPELErr) - } - //Enable the Optional repository - EnableOptionalRepoErr := EnableOptionalRepo() - if EnableOptionalRepoErr != nil { - return fmt.Errorf("EnableOptionalRepo: %w", EnableOptionalRepoErr) - } - } else { - return errors.New("unsupported operating system") - } - installCommand, err := RetrieveInstallCommand(filepath, osType) if err != nil { return fmt.Errorf("RetrieveInstallCommand: %w", err) diff --git a/internal/os/install.go b/internal/os/install.go new file mode 100644 index 0000000..fc468f9 --- /dev/null +++ b/internal/os/install.go @@ -0,0 +1,133 @@ +package os + +import ( + "errors" + "fmt" + + "github.com/dpastoor/wbi/internal/config" + "github.com/dpastoor/wbi/internal/system" +) + +func InstallPrereqs(osType config.OperatingSystem) error { + fmt.Println("Installing prerequisites...\n") + // Update apt and install gdebi-core if an Ubuntu system + if osType == config.Ubuntu22 || osType == config.Ubuntu20 || osType == config.Ubuntu18 { + AptErr := UpgradeApt() + if AptErr != nil { + return fmt.Errorf("UpgradeApt: %w", AptErr) + } + + GdebiCoreErr := InstallGdebiCore() + if GdebiCoreErr != nil { + return fmt.Errorf("InstallGdebiCore: %w", GdebiCoreErr) + } + } else if osType == config.Redhat8 { + // Enable the Extra Packages for Enterprise Linux (EPEL) repository + EnableEPELErr := EnableEPELRepo(osType) + if EnableEPELErr != nil { + return fmt.Errorf("EnableEPELRepo: %w", EnableEPELErr) + } + // Enable the CodeReady Linux Builder repository + EnableCodeReadyErr := EnableCodeReadyRepo() + if EnableCodeReadyErr != nil { + return fmt.Errorf("EnableCodeReadyRepo: %w", EnableCodeReadyErr) + } + } else if osType == config.Redhat7 { + // Enable the Extra Packages for Enterprise Linux (EPEL) repository + EnableEPELErr := EnableEPELRepo(osType) + if EnableEPELErr != nil { + return fmt.Errorf("EnableEPELRepo: %w", EnableEPELErr) + } + //Enable the Optional repository + EnableOptionalRepoErr := EnableOptionalRepo() + if EnableOptionalRepoErr != nil { + return fmt.Errorf("EnableOptionalRepo: %w", EnableOptionalRepoErr) + } + } else { + return errors.New("unsupported operating system") + } + fmt.Println("\nPrerequisites successfully installed!\n") + return nil +} + +// Installs Gdebi Core +func InstallGdebiCore() error { + gdebiCoreCommand := "sudo apt-get install -y gdebi-core" + err := system.RunCommand(gdebiCoreCommand) + if err != nil { + return fmt.Errorf("issue installing gdebi-core: %w", err) + } + + fmt.Println("\ngdebi-core has been successfully installed!\n") + return nil +} + +// Upgrades Apt +func UpgradeApt() error { + aptUpgradeCommand := "sudo apt-get update" + err := system.RunCommand(aptUpgradeCommand) + if err != nil { + return fmt.Errorf("issue upgrading apt: %w", err) + } + + fmt.Println("\napt has been successfully upgraded!\n") + return nil +} + +// Enable the CodeReady Linux Builder repository: +func EnableCodeReadyRepo() error { + // TODO add support for On Premise as well as cloud (currently only cloud) + dnfPluginsCoreCommand := "sudo dnf install dnf-plugins-core" + err := system.RunCommand(dnfPluginsCoreCommand) + if err != nil { + return fmt.Errorf("issue installing dnf-plugins-core: %w", err) + } + + enableCodeReadyCommand := `sudo dnf config-manager --set-enabled "codeready-builder-for-rhel-8-*-rpms"` + err = system.RunCommand(enableCodeReadyCommand) + if err != nil { + return fmt.Errorf("issue enabling the CodeReady Linux Builder repo: %w", err) + } + + fmt.Println("\nThe CodeReady Linux Builder repository has been successfully enabled!\n") + return nil +} + +// Enable the Optional repository +func EnableOptionalRepo() error { + // TODO add support for On Premise as well as cloud (currently only cloud) + yumUtilsCommand := "sudo yum install yum-utils" + err := system.RunCommand(yumUtilsCommand) + if err != nil { + return fmt.Errorf("issue installing yum-utils: %w", err) + } + + enableOptionalCommand := `sudo yum-config-manager --enable "rhel-*-optional-rpms"` + err = system.RunCommand(enableOptionalCommand) + if err != nil { + return fmt.Errorf("issue enabling the optional repo: %w", err) + } + + fmt.Println("\nThe Optional repository has been successfully enabled!\n") + return nil +} + +// Enable the Extra Packages for Enterprise Linux (EPEL) repository +func EnableEPELRepo(osType config.OperatingSystem) error { + var EPELCommand string + if osType == config.Redhat8 { + EPELCommand = "sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm" + } else if osType == config.Redhat7 { + EPELCommand = "sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm " + } else { + return errors.New("operating system not supported") + } + + err := system.RunCommand(EPELCommand) + if err != nil { + return fmt.Errorf("issue enabling EPEL repo: %w", err) + } + + fmt.Println("\nThe Extra Packages for Enterprise Linux (EPEL) repository has been successfully enabled!\n") + return nil +} diff --git a/internal/prodrivers/install.go b/internal/prodrivers/install.go index 9254875..77559ce 100644 --- a/internal/prodrivers/install.go +++ b/internal/prodrivers/install.go @@ -78,19 +78,6 @@ func DownloadAndInstallProDrivers(osType config.OperatingSystem) error { // Installs Posit Pro Drivers in a certain way based on the operating system func InstallProDrivers(filepath string, osType config.OperatingSystem) error { - // Install gdebi-core if an Ubuntu system - if osType == config.Ubuntu22 || osType == config.Ubuntu20 || osType == config.Ubuntu18 { - AptErr := install.UpgradeApt() - if AptErr != nil { - return fmt.Errorf("UpgradeApt: %w", AptErr) - } - - GdebiCoreErr := install.InstallGdebiCore() - if GdebiCoreErr != nil { - return fmt.Errorf("InstallGdebiCore: %w", GdebiCoreErr) - } - } - installCommand, err := install.RetrieveInstallCommand(filepath, osType) if err != nil { return fmt.Errorf("RetrieveInstallCommand: %w", err) diff --git a/internal/workbench/install.go b/internal/workbench/install.go index 474c29e..d388cb2 100644 --- a/internal/workbench/install.go +++ b/internal/workbench/install.go @@ -81,19 +81,6 @@ func DownloadAndInstallWorkbench(osType config.OperatingSystem) error { // Installs Workbench in a certain way based on the operating system func InstallWorkbench(filepath string, osType config.OperatingSystem) error { - // Install gdebi-core if an Ubuntu system - if osType == config.Ubuntu22 || osType == config.Ubuntu20 || osType == config.Ubuntu18 { - AptErr := install.UpgradeApt() - if AptErr != nil { - return fmt.Errorf("UpgradeApt: %w", AptErr) - } - - GdebiCoreErr := install.InstallGdebiCore() - if GdebiCoreErr != nil { - return fmt.Errorf("InstallGdebiCore: %w", GdebiCoreErr) - } - } - installCommand, err := RetrieveInstallCommandForWorkbench(filepath, osType) if err != nil { return fmt.Errorf("RetrieveInstallCommandForWorkbench: %w", err)