~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/worker/uniter/runner/context/env.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/utils/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
        }
 
24
        return nil
 
25
}
 
26
 
 
27
func appendPath(paths Paths) []string {
 
28
        return []string{
 
29
                "PATH=" + paths.GetToolsDir() + ":" + os.Getenv("PATH"),
 
30
        }
 
31
}
 
32
 
 
33
func ubuntuEnv(paths Paths) []string {
 
34
        path := appendPath(paths)
 
35
        env := []string{
 
36
                "APT_LISTCHANGES_FRONTEND=none",
 
37
                "DEBIAN_FRONTEND=noninteractive",
 
38
        }
 
39
        env = append(env, path...)
 
40
        return env
 
41
}
 
42
 
 
43
func centosEnv(paths Paths) []string {
 
44
        return appendPath(paths)
 
45
}
 
46
 
 
47
// windowsEnv adds windows specific environment variables. PSModulePath
 
48
// helps hooks use normal imports instead of dot sourcing modules
 
49
// its a convenience variable. The PATH variable delimiter is
 
50
// a semicolon instead of a colon
 
51
func windowsEnv(paths Paths) []string {
 
52
        charmDir := paths.GetCharmDir()
 
53
        charmModules := filepath.Join(charmDir, "lib", "Modules")
 
54
        return []string{
 
55
                "Path=" + paths.GetToolsDir() + ";" + os.Getenv("Path"),
 
56
                "PSModulePath=" + os.Getenv("PSModulePath") + ";" + charmModules,
 
57
        }
 
58
}