Skip to content

Commit

Permalink
Refactor so system depedencies are installed one time at start of wbi
Browse files Browse the repository at this point in the history
  • Loading branch information
tnederlof committed Feb 21, 2023
1 parent f3eb92a commit c9b5d97
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 146 deletions.
6 changes: 5 additions & 1 deletion cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ func newSetup(setupOpts setupOpts) error {

var WBConfig config.WBConfig

// Determine OS
// 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
131 changes: 131 additions & 0 deletions internal/os/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package os

import (
"errors"
"fmt"

"github.com/dpastoor/wbi/internal/config"
"github.com/dpastoor/wbi/internal/system"
)

func InstallPrereqs(osType config.OperatingSystem) error {
// 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")
}
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

0 comments on commit c9b5d97

Please sign in to comment.