diff --git a/args/args.go b/args/args.go index 3b4939a..8840d64 100644 --- a/args/args.go +++ b/args/args.go @@ -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", ) diff --git a/controller/controller.go b/controller/controller.go index 08236f8..884f61b 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -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) diff --git a/swupd/swupd.go b/swupd/swupd.go index 2b9e499..2d73f81 100644 --- a/swupd/swupd.go +++ b/swupd/swupd.go @@ -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 diff --git a/swupd/swupd_test.go b/swupd/swupd_test.go index 3814ec8..5b0543a 100644 --- a/swupd/swupd_test.go +++ b/swupd/swupd_test.go @@ -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) }