github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/uniter/runner/context/env.go (about) 1 // Copyright 2012-2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package context 5 6 import ( 7 "os" 8 "path/filepath" 9 10 jujuos "github.com/juju/os" 11 ) 12 13 // OSDependentEnvVars returns the OS-dependent environment variables that 14 // should be set for a hook context. 15 func OSDependentEnvVars(paths Paths) []string { 16 switch jujuos.HostOS() { 17 case jujuos.Windows: 18 return windowsEnv(paths) 19 case jujuos.Ubuntu: 20 return ubuntuEnv(paths) 21 case jujuos.CentOS: 22 return centosEnv(paths) 23 case jujuos.OpenSUSE: 24 return opensuseEnv(paths) 25 } 26 return nil 27 } 28 29 func appendPath(paths Paths) []string { 30 return []string{ 31 "PATH=" + paths.GetToolsDir() + ":" + os.Getenv("PATH"), 32 } 33 } 34 35 func ubuntuEnv(paths Paths) []string { 36 path := appendPath(paths) 37 env := []string{ 38 "APT_LISTCHANGES_FRONTEND=none", 39 "DEBIAN_FRONTEND=noninteractive", 40 } 41 env = append(env, path...) 42 return env 43 } 44 45 func centosEnv(paths Paths) []string { 46 return appendPath(paths) 47 } 48 49 func opensuseEnv(paths Paths) []string { 50 return appendPath(paths) 51 } 52 53 // windowsEnv adds windows specific environment variables. PSModulePath 54 // helps hooks use normal imports instead of dot sourcing modules 55 // its a convenience variable. The PATH variable delimiter is 56 // a semicolon instead of a colon 57 func windowsEnv(paths Paths) []string { 58 charmDir := paths.GetCharmDir() 59 charmModules := filepath.Join(charmDir, "lib", "Modules") 60 return []string{ 61 "Path=" + paths.GetToolsDir() + ";" + os.Getenv("Path"), 62 "PSModulePath=" + os.Getenv("PSModulePath") + ";" + charmModules, 63 } 64 }