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