1
// Copyright 2015 Canonical Ltd.
2
// Copyright 2015 Cloudbase Solutions SRL
3
// Licensed under the AGPLv3, see LICENCE file for details.
10
"github.com/juju/utils/packaging/config"
11
"github.com/juju/utils/proxy"
14
// addPackageCommandsCommon is a helper function which applies the given
15
// packaging-related options to the given CloudConfig.
16
func addPackageCommandsCommon(
18
packageProxySettings proxy.Settings,
20
addUpdateScripts bool,
21
addUpgradeScripts bool,
24
// Set the package mirror.
25
cfg.SetPackageMirror(packageMirror)
27
// For LTS series which need support for the cloud-tools archive,
28
// we need to enable package-list update regardless of the environ
29
// setting, otherwise bootstrap or provisioning will fail.
30
if config.SeriesRequiresCloudArchiveTools(series) && !addUpdateScripts {
31
addUpdateScripts = true
34
// Bring packages up-to-date.
35
cfg.SetSystemUpdate(addUpdateScripts)
36
cfg.SetSystemUpgrade(addUpgradeScripts)
38
// Always run this step - this is where we install packages that juju
40
cfg.addRequiredPackages()
42
// TODO(bogdanteleaga): Deal with proxy settings on CentOS
43
cfg.updateProxySettings(packageProxySettings)
46
// renderScriptCommon is a helper function which generates a bash script that
47
// applies all the settings given by the provided CloudConfig when run.
48
func renderScriptCommon(cfg CloudConfig) (string, error) {
49
// TODO(axw): 2013-08-23 bug 1215777
50
// Carry out configuration for ssh-keys-per-user,
51
// machine-updates-authkeys, using cloud-init config.
53
// We should work with smoser to get a supported
54
// command in (or next to) cloud-init for manually
55
// invoking cloud-config. This would address the
56
// above comment by removing the need to generate a
59
// Bootcmds must be run before anything else,
60
// as they may affect package installation.
61
bootcmds := cfg.BootCmds()
63
// Depending on cfg, potentially add package sources and packages.
64
pkgcmds, err := cfg.getCommandsForAddingPackages()
70
runcmds := cfg.RunCmds()
72
// We prepend "set -xe". This is already in runcmds,
73
// but added here to avoid relying on that to be
75
script := []string{"#!/bin/bash", "set -e"}
76
// We must initialise progress reporting before entering
77
// the subshell and redirecting stderr.
78
script = append(script, InitProgressCmd())
79
stdout, stderr := cfg.Output(OutAll)
80
script = append(script, "(")
82
script = append(script, "(")
84
script = append(script, bootcmds...)
85
script = append(script, pkgcmds...)
86
script = append(script, runcmds...)
88
script = append(script, ") "+stdout)
89
script = append(script, ") "+stderr)
91
script = append(script, ") "+stdout+" 2>&1")
93
return strings.Join(script, "\n"), nil
96
func copyStringSlice(s []string) []string {
100
res := make([]string, len(s))
101
for i, item := range s {