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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
// Copyright 2015 Canonical Ltd.
// Copyright 2015 Cloudbase Solutions SRL
// Licensed under the LGPLv3, see LICENCE file for details.
// Package commands contains an interface which returns common
// package-manager related commands and the reference implementation for apt
// and yum-based systems.
package commands
import (
"github.com/juju/utils/proxy"
)
// PackageCommander is the interface which provides runnable shell
// commands for various packaging-related operations.
type PackageCommander interface {
// InstallPrerequisiteCmd returns the command that installs the
// prerequisite package for repository-handling operations.
InstallPrerequisiteCmd() string
// UpdateCmd returns the command to update the local package list.
UpdateCmd() string
// UpgradeCmd returns the command which issues an upgrade on all packages
// with available newer versions.
UpgradeCmd() string
// InstallCmd returns a *single* command that installs the given package(s).
InstallCmd(...string) string
// RemoveCmd returns a *single* command that removes the given package(s).
RemoveCmd(...string) string
// PurgeCmd returns the command that removes the given package(s) along
// with any associated config files.
PurgeCmd(...string) string
// IsInstalledCmd returns the command which determines whether or not a
// package is currently installed on the system.
IsInstalledCmd(string) string
// SearchCmd returns the command that determines whether the given package is
// available for installation from the currently configured repositories.
SearchCmd(string) string
// ListAvailableCmd returns the command which will list all packages
// available for installation from the currently configured repositories.
// NOTE: includes already installed packages.
ListAvailableCmd() string
// ListInstalledCmd returns the command which will list all
// packages currently installed on the system.
ListInstalledCmd() string
// ListRepositoriesCmd returns the command that lists all repositories
// currently configured on the system.
// NOTE: requires the prerequisite package whose installation command
// is given by InstallPrerequisiteCmd().
ListRepositoriesCmd() string
// AddRepositoryCmd returns the command that adds a repository to the
// list of available repositories.
// NOTE: requires the prerequisite package whose installation command
// is given by InstallPrerequisiteCmd().
AddRepositoryCmd(string) string
// RemoveRepositoryCmd returns the command that removes a given
// repository from the list of available repositories.
// NOTE: requires the prerequisite package whose installation command
// is given by InstallPrerequisiteCmd().
RemoveRepositoryCmd(string) string
// CleanupCmd returns the command that cleans up all orphaned packages,
// left-over files and previously-cached packages.
CleanupCmd() string
// GetProxyCmd returns the command which outputs the proxies set for the
// given package management system.
// NOTE: output may require some additional filtering.
GetProxyCmd() string
// ProxyConfigContents returns the format expected by the package manager
// for proxy settings which can be written directly to the config file.
ProxyConfigContents(proxy.Settings) string
// SetProxyCmds returns the commands which write the proxy configuration
// to the configuration file of the package manager.
SetProxyCmds(proxy.Settings) []string
}
// NewPackageCommander returns a new PackageCommander instance based on the
// given series.
func NewPackageCommander(series string) (PackageCommander, error) {
// TODO (aznashwan): find a more deterministic way of selection here which
// does not imply importing version from core.
switch series {
case "centos7":
return NewYumPackageCommander(), nil
case "opensuseleap":
return NewZypperPackageCommander(), nil
default:
return NewAptPackageCommander(), nil
}
}
// NewAptPackageCommander returns a PackageCommander for apt-based systems.
func NewAptPackageCommander() PackageCommander {
return &aptCmder
}
// NewYumPackageCommander returns a PackageCommander for yum-based systems.
func NewYumPackageCommander() PackageCommander {
return &yumCmder
}
// NewZypperPackageCommander returns a PackageCommander for zypper-based systems.
func NewZypperPackageCommander() PackageCommander {
return &zypperCmder
}
|