From 8422aa21dbe47c92b66a2a40af3d8bef3bfc6534 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Mon, 27 Feb 2023 18:14:32 -0800 Subject: [PATCH] Skip configuring the bash_profile on linux if bash_profile does not exist to fix #79 --- client/cmd/install.go | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/client/cmd/install.go b/client/cmd/install.go index 24a7c59..6524923 100644 --- a/client/cmd/install.go +++ b/client/cmd/install.go @@ -10,6 +10,7 @@ import ( "os" "os/exec" "path" + "runtime" "strings" "syscall" "time" @@ -352,14 +353,16 @@ func configureBashrc(homedir, binaryPath string) error { } } // Check if we need to configure the bash_profile and configure it if so - bashProfileIsConfigured, err := isBashProfileConfigured(homedir) - if err != nil { - return fmt.Errorf("failed to check ~/.bash_profile: %v", err) - } - if !bashProfileIsConfigured { - err = addToShellConfig(path.Join(homedir, ".bash_profile"), getBashConfigFragment(homedir)) + if doesBashProfileNeedConfig(homedir) { + bashProfileIsConfigured, err := isBashProfileConfigured(homedir) if err != nil { - return err + return fmt.Errorf("failed to check ~/.bash_profile: %v", err) + } + if !bashProfileIsConfigured { + err = addToShellConfig(path.Join(homedir, ".bash_profile"), getBashConfigFragment(homedir)) + if err != nil { + return err + } } } return nil @@ -394,6 +397,20 @@ func isBashRcConfigured(homedir string) (bool, error) { return strings.Contains(string(bashrc), getBashConfigFragment(homedir)), nil } +func doesBashProfileNeedConfig(homedir string) bool { + if runtime.GOOS == "darwin" { + // Darwin always needs it configured for #14 + return true + } + if runtime.GOOS == "linux" { + // Only configure it on linux if .bash_profile already exists + _, err := os.Stat(path.Join(homedir, ".bash_profile")) + return !errors.Is(err, os.ErrNotExist) + } + // Default to not configuring it + return false +} + func isBashProfileConfigured(homedir string) (bool, error) { _, err := os.Stat(path.Join(homedir, ".bash_profile")) if errors.Is(err, os.ErrNotExist) {