~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/utils/packaging/commands/apt.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 2015 Canonical Ltd.
 
2
// Copyright 2015 Cloudbase Solutions SRL
 
3
// Licensed under the LGPLv3, see LICENCE file for details.
 
4
 
 
5
package commands
 
6
 
 
7
const (
 
8
        // AptConfFilePath is the full file path for the proxy settings that are
 
9
        // written by cloud-init and the machine environ worker.
 
10
        AptConfFilePath = "/etc/apt/apt.conf.d/42-juju-proxy-settings"
 
11
 
 
12
        // the basic command for all dpkg calls:
 
13
        dpkg = "dpkg"
 
14
 
 
15
        // the basic command for all dpkg-query calls:
 
16
        dpkgquery = "dpkg-query"
 
17
 
 
18
        // the basic command for all apt-get calls:
 
19
        //              --force-confold is passed to dpkg to never overwrite config files
 
20
        //              --force-unsafe-io makes dpkg less sync-happy
 
21
        //              --assume-yes to never prompt for confirmation
 
22
        aptget = "apt-get --option=Dpkg::Options::=--force-confold --option=Dpkg::options::=--force-unsafe-io --assume-yes --quiet"
 
23
 
 
24
        // the basic command for all apt-cache calls:
 
25
        aptcache = "apt-cache"
 
26
 
 
27
        // the basic command for all add-apt-repository calls:
 
28
        //              --yes to never prompt for confirmation
 
29
        addaptrepo = "add-apt-repository --yes"
 
30
 
 
31
        // the basic command for all apt-config calls:
 
32
        aptconfig = "apt-config dump"
 
33
 
 
34
        // the basic format for specifying a proxy option for apt:
 
35
        aptProxySettingFormat = "Acquire::%s::Proxy %q;"
 
36
)
 
37
 
 
38
// aptCmder is the packageCommander instantiation for apt-based systems.
 
39
var aptCmder = packageCommander{
 
40
        prereq:              buildCommand(aptget, "install python-software-properties"),
 
41
        update:              buildCommand(aptget, "update"),
 
42
        upgrade:             buildCommand(aptget, "upgrade"),
 
43
        install:             buildCommand(aptget, "install"),
 
44
        remove:              buildCommand(aptget, "remove"),
 
45
        purge:               buildCommand(aptget, "purge"),
 
46
        search:              buildCommand(aptcache, "search --names-only ^%s$"),
 
47
        isInstalled:         buildCommand(dpkgquery, "-s %s"),
 
48
        listAvailable:       buildCommand(aptcache, "pkgnames"),
 
49
        listInstalled:       buildCommand(dpkg, "--get-selections"),
 
50
        addRepository:       buildCommand(addaptrepo, "%q"),
 
51
        listRepositories:    buildCommand(`sed -r -n "s|^deb(-src)? (.*)|\2|p"`, "/etc/apt/sources.list"),
 
52
        removeRepository:    buildCommand(addaptrepo, "--remove ppa:%s"),
 
53
        cleanup:             buildCommand(aptget, "autoremove"),
 
54
        getProxy:            buildCommand(aptconfig, "Acquire::http::Proxy Acquire::https::Proxy Acquire::ftp::Proxy"),
 
55
        proxySettingsFormat: aptProxySettingFormat,
 
56
        setProxy:            buildCommand("echo %s >> ", AptConfFilePath),
 
57
}