1
// Copyright 2012, 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
13
var aptLogger = loggo.GetLogger("juju.utils.apt")
15
// Some helpful functions for running apt in a sane way
17
// osRunCommand calls cmd.Run, this is used as an overloading point so we can
18
// test what *would* be run without actually executing another program
19
func osRunCommand(cmd *exec.Cmd) error {
23
var runCommand = osRunCommand
25
// This is the default apt-get command used in cloud-init, the various settings
26
// mean that apt won't actually block waiting for a prompt from the user.
27
var aptGetCommand = []string{
28
"apt-get", "--option=Dpkg::Options::=--force-confold",
29
"--option=Dpkg::options::=--force-unsafe-io", "--assume-yes", "--quiet",
32
// aptEnvOptions are options we need to pass to apt-get to not have it prompt
34
var aptGetEnvOptions = []string{"DEBIAN_FRONTEND=noninteractive"}
36
// AptGetInstall runs 'apt-get install packages' for the packages listed here
37
func AptGetInstall(packages ...string) error {
38
cmdArgs := append([]string(nil), aptGetCommand...)
39
cmdArgs = append(cmdArgs, "install")
40
cmdArgs = append(cmdArgs, packages...)
41
aptLogger.Infof("Running: %s", cmdArgs)
42
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
43
cmd.Env = append(os.Environ(), aptGetEnvOptions...)
44
return runCommand(cmd)