本文整理汇总了Golang中github.com/wallyworld/core/cloudinit.Config.AptUpdate方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.AptUpdate方法的具体用法?Golang Config.AptUpdate怎么用?Golang Config.AptUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/wallyworld/core/cloudinit.Config
的用法示例。
在下文中一共展示了Config.AptUpdate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addPackageCommands
// addPackageCommands returns a slice of commands that, when run,
// will add the required apt repositories and packages.
func addPackageCommands(cfg *cloudinit.Config) ([]string, error) {
var cmds []string
if len(cfg.AptSources()) > 0 {
// Ensure add-apt-repository is available.
cmds = append(cmds, cloudinit.LogProgressCmd("Installing add-apt-repository"))
cmds = append(cmds, aptget+"install python-software-properties")
}
for _, src := range cfg.AptSources() {
// PPA keys are obtained by add-apt-repository, from launchpad.
if !strings.HasPrefix(src.Source, "ppa:") {
if src.Key != "" {
key := utils.ShQuote(src.Key)
cmd := fmt.Sprintf("printf '%%s\\n' %s | apt-key add -", key)
cmds = append(cmds, cmd)
}
}
cmds = append(cmds, cloudinit.LogProgressCmd("Adding apt repository: %s", src.Source))
cmds = append(cmds, "add-apt-repository -y "+utils.ShQuote(src.Source))
if src.Prefs != nil {
path := utils.ShQuote(src.Prefs.Path)
contents := utils.ShQuote(src.Prefs.FileContents())
cmds = append(cmds, "install -D -m 644 /dev/null "+path)
cmds = append(cmds, `printf '%s\n' `+contents+` > `+path)
}
}
if len(cfg.AptSources()) > 0 || cfg.AptUpdate() {
cmds = append(cmds, cloudinit.LogProgressCmd("Running apt-get update"))
cmds = append(cmds, aptget+"update")
}
if cfg.AptUpgrade() {
cmds = append(cmds, cloudinit.LogProgressCmd("Running apt-get upgrade"))
cmds = append(cmds, aptget+"upgrade")
}
for _, pkg := range cfg.Packages() {
cmds = append(cmds, cloudinit.LogProgressCmd("Installing package: %s", pkg))
if !strings.Contains(pkg, "--target-release") {
// We only need to shquote the package name if it does not
// contain additional arguments.
pkg = utils.ShQuote(pkg)
}
cmd := fmt.Sprintf(aptget+"install %s", pkg)
cmds = append(cmds, cmd)
}
if len(cmds) > 0 {
// setting DEBIAN_FRONTEND=noninteractive prevents debconf
// from prompting, always taking default values instead.
cmds = append([]string{"export DEBIAN_FRONTEND=noninteractive"}, cmds...)
}
return cmds, nil
}