swupd: add new flags

Add the swupd's --format, --contenturl and --versionurl arguments.
These arguments are mapped with the --swupd prefix such as:
--swupd-format, --swupd-contenturl and --swupd-versionurl

And are used for constrained environments dealing with local installs,
specially with image generation in a network isolated environment.

Signed-off-by: Leandro Dorileo <leandro.maciel.dorileo@intel.com>
This commit is contained in:
Leandro Dorileo
2018-11-08 15:41:02 -08:00
committed by Leandro Dorileo
parent 48c4123c1f
commit 536f80ea30
4 changed files with 66 additions and 8 deletions
+17
View File
@@ -46,6 +46,9 @@ type Args struct {
CfDownloaded bool
SwupdMirror string
SwupdStateDir string
SwupdFormat string
SwupdContentURL string
SwupdVersionURL string
Telemetry bool
TelemetrySet bool
TelemetryURL string
@@ -142,6 +145,20 @@ func (args *Args) setCommandLineArgs() (err error) {
&args.SwupdStateDir, "swupd-state", args.SwupdMirror, "Swupd state-dir",
)
flag.StringVar(
&args.SwupdFormat, "swupd-format", args.SwupdFormat, "Swupd --format argument",
)
flag.StringVar(
&args.SwupdContentURL, "swupd-contenturl", args.SwupdContentURL,
"Swupd --contenturl argument",
)
flag.StringVar(
&args.SwupdVersionURL, "swupd-versionurl", args.SwupdVersionURL,
"Swupd --versionurl argument",
)
flag.BoolVar(
&args.Telemetry, "telemetry", args.Telemetry, "Enable Telemetry",
)
+1 -1
View File
@@ -391,7 +391,7 @@ func runInstallHook(vars map[string]string, hook *model.InstallHook) error {
// executed using the target swupd
func contentInstall(rootDir string, version string, model *model.SystemInstall, options args.Args) (progress.Progress, error) {
sw := swupd.New(rootDir, options.SwupdStateDir)
sw := swupd.New(rootDir, options)
msg := "Installing the base system"
prg := progress.NewLoop(msg)
+41 -5
View File
@@ -13,6 +13,7 @@ import (
"regexp"
"strings"
"github.com/clearlinux/clr-installer/args"
"github.com/clearlinux/clr-installer/cmd"
"github.com/clearlinux/clr-installer/conf"
"github.com/clearlinux/clr-installer/errors"
@@ -31,8 +32,11 @@ var (
// SoftwareUpdater abstracts the swupd executable, environment and operations
type SoftwareUpdater struct {
rootDir string
stateDir string
rootDir string
stateDir string
format string
contentURL string
versionURL string
}
// Bundle maps a map name and description with the actual checkbox
@@ -52,12 +56,36 @@ func IsCoreBundle(bundle string) bool {
}
// New creates a new instance of SoftwareUpdater with the rootDir properly adjusted
func New(rootDir string, stateDir string) *SoftwareUpdater {
func New(rootDir string, options args.Args) *SoftwareUpdater {
stateDir := options.SwupdStateDir
if stateDir == "" {
stateDir = filepath.Join(rootDir, "/var/lib/swupd")
}
return &SoftwareUpdater{rootDir, stateDir}
return &SoftwareUpdater{
rootDir,
stateDir,
options.SwupdFormat,
options.SwupdContentURL,
options.SwupdVersionURL,
}
}
func (s *SoftwareUpdater) setExtraFlags(args []string) []string {
if s.format != "" {
args = append(args, fmt.Sprintf("--format=%s", s.format))
}
if s.contentURL != "" {
args = append(args, fmt.Sprintf("--contenturl=%s", s.contentURL))
}
if s.versionURL != "" {
args = append(args, fmt.Sprintf("--versionurl=%s", s.versionURL))
}
return args
}
// Verify runs "swupd verify" operation
@@ -66,6 +94,9 @@ func (s *SoftwareUpdater) Verify(version string, mirror string) error {
"swupd",
"verify",
}
args = s.setExtraFlags(args)
if mirror != "" {
args = append(args, fmt.Sprintf("--url=%s", mirror))
}
@@ -104,9 +135,14 @@ func (s *SoftwareUpdater) Verify(version string, mirror string) error {
"swupd",
"bundle-add",
"--skip-diskspace-check",
}
args = s.setExtraFlags(args)
args = append(args,
fmt.Sprintf("--path=%s", s.rootDir),
fmt.Sprintf("--statedir=%s", s.stateDir),
}
)
// Remove the 'os-core' bundle as it is already
// installed and will cause a failure
+7 -2
View File
@@ -7,6 +7,7 @@ package swupd
import (
"testing"
"github.com/clearlinux/clr-installer/args"
"github.com/clearlinux/clr-installer/utils"
)
@@ -84,13 +85,17 @@ func TestParseSwupdMirrorInvalid(t *testing.T) {
}
func TestNewWithState(t *testing.T) {
sw := New("/tmp/test", "/tmp/swupd-state")
options := args.Args{
SwupdStateDir: "/tmp/swupd-state",
}
sw := New("/tmp/test", options)
if sw.stateDir != "/tmp/swupd-state" {
t.Fatalf("stateDir should be set to /tmp/swupd-state")
}
sw = New("/tmp/test", "")
sw = New("/tmp/test", args.Args{})
if sw.stateDir != "/tmp/test/var/lib/swupd" {
t.Fatalf("stateDir should not be set to: %s", sw.stateDir)
}