Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move prerequisite installs to the start of wbi to be performed once #44

Merged
merged 2 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
119 changes: 0 additions & 119 deletions internal/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
133 changes: 133 additions & 0 deletions internal/os/install.go
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 0 additions & 13 deletions internal/prodrivers/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 0 additions & 13 deletions internal/workbench/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down