Skip to content

Commit

Permalink
model: add Version field
Browse files Browse the repository at this point in the history
The mass-installer use case for image generation requires to specify
the target system version. This patch allows the configuration of
an arbitrary version.

Signed-off-by: Leandro Dorileo <[email protected]>
  • Loading branch information
Leandro Dorileo authored and Leandro Dorileo committed Sep 27, 2018
1 parent a58c12d commit a26b541
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 12 deletions.
29 changes: 17 additions & 12 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,27 @@ func Install(rootDir string, model *model.SystemInstall) error {
}
}

log.Info("Querying Clear Linux version")
if model.Version == 0 {
log.Info("Querying Clear Linux version")

// in order to avoid issues raised by format bumps between installers image
// version and the latest released we assume the installers host version
// in other words we use the same version swupd is based on
if versionBuf, err = ioutil.ReadFile("/usr/lib/os-release"); err != nil {
return errors.Errorf("Read version file /usr/lib/os-release: %v", err)
}
versionExp := regexp.MustCompile(`VERSION_ID=([0-9][0-9]*)`)
match := versionExp.FindSubmatch(versionBuf)

// in order to avoid issues raised by format bumps between installers image
// version and the latest released we assume the installers host version
// in other words we use the same version swupd is based on
if versionBuf, err = ioutil.ReadFile("/usr/lib/os-release"); err != nil {
return errors.Errorf("Read version file /usr/lib/os-release: %v", err)
}
versionExp := regexp.MustCompile(`VERSION_ID=([0-9][0-9]*)`)
match := versionExp.FindSubmatch(versionBuf)
if len(match) < 2 {
return errors.Errorf("Version not found in /usr/lib/os-release")
}

if len(match) < 2 {
return errors.Errorf("Version not found in /usr/lib/os-release")
version = string(match[1])
} else {
version = fmt.Sprintf("%d", model.Version)
}

version = string(match[1])
log.Debug("Clear Linux version: %s", version)

// do we have the minimum required to install a system?
Expand Down
4 changes: 4 additions & 0 deletions massinstall/massinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (mi *MassInstall) Run(md *model.SystemInstall, rootDir string) (bool, error

log.Debug("Starting install")

if md.Version > 0 {
fmt.Printf("Config file specifies a target \"version\", forcing auto-update off.")
}

instError = controller.Install(rootDir, md)
if instError != nil {
if !errors.IsValidationError(instError) {
Expand Down
5 changes: 5 additions & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type SystemInstall struct {
TelemetryPolicy string `yaml:"telemetryPolicy,omitempty,flow"`
PreInstall []*InstallHook `yaml:"pre-install,omitempty,flow"`
PostInstall []*InstallHook `yaml:"post-install,omitempty,flow"`
Version uint `yaml:"version,omitempty,flow"`
}

// InstallHook is a commands to be executed in a given point of the install process
Expand Down Expand Up @@ -230,6 +231,10 @@ func LoadFile(path string) (*SystemInstall, error) {
}
}

if result.Version > 0 {
result.AutoUpdate = false
}

return &result, nil
}

Expand Down
1 change: 1 addition & 0 deletions model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestLoadFile(t *testing.T) {
{"real-example.yaml", true},
{"valid-network.yaml", true},
{"valid-minimal.yaml", true},
{"valid-with-version.yaml", true},
}

for _, curr := range tests {
Expand Down
26 changes: 26 additions & 0 deletions tests/valid-with-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#clear-linux-config
targetMedia:
- name: sda
size: "30752636928"
type: disk
children:
- name: sda1
fstype: vfat
mountpoint: /boot
size: "157286400"
type: part
- name: sda2
fstype: swap
size: "2147483648"
type: part
- name: sda3
fstype: ext4
mountpoint: /
size: "28447866880"
type: part
bundles: [os-core, os-core-update]
telemetry: false
keyboard: us
language: en_US.UTF-8
kernel: kernel-native
version: 1010

0 comments on commit a26b541

Please sign in to comment.