Skip to content

Commit

Permalink
Add installation step to copy offline content
Browse files Browse the repository at this point in the history
This commit adds an installation step to copy offline update contents to
the install target media. When installing from an ISO image, unsquashfs
is used to decompress offline content directly to the target which is
faster than a file copy.

Signed-off-by: John Akre <[email protected]>
  • Loading branch information
John Akre committed Sep 23, 2019
1 parent 3aeef56 commit a765200
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 4 deletions.
60 changes: 56 additions & 4 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,19 +479,31 @@ func contentInstall(rootDir string, version string, md *model.SystemInstall, opt
bundles = append(bundles, md.Kernel.Bundle)
}

msg := utils.Locale.Get("Installing base OS and configured bundles")
log.Info(msg)

if swupd.IsOfflineContent() {
msg := utils.Locale.Get("Copying cached content to target media")
prg = progress.NewLoop(msg)
log.Info(msg)

if err := utils.ParseOSClearVersion(); err != nil {
prg = progress.NewLoop(msg)
return prg, err
}
version = utils.ClearVersion

// Copying offline content here is a performance optimization and is not a hard
// failure because Swupd may be able to successfully copy offline content or
// install over the network.
if err := copyOfflineToStatedir(rootDir, sw.GetStateDir()); err != nil {
log.Warning("Failed to copy offline content: %s", err)
}

prg.Success()
} else if md.AutoUpdate {
version = "latest"
}

msg := utils.Locale.Get("Installing base OS and configured bundles")
log.Info(msg)

log.Debug("Installing bundles: %s", strings.Join(bundles, ", "))
if err := sw.VerifyWithBundles(version, md.SwupdMirror, bundles); err != nil {
// If the swupd command failed to run there wont be a progress
Expand Down Expand Up @@ -601,6 +613,46 @@ func contentInstall(rootDir string, version string, md *model.SystemInstall, opt
return nil, nil
}

func copyOfflineToStatedir(rootDir, stateDir string) error {
if err := utils.MkdirAll(filepath.Dir(stateDir), 0755); err != nil {
return err
}

log.Debug("Overwriting stateDir with offline content")
if err := os.RemoveAll(stateDir); err != nil {
return err
}

if isoLoopDev := isoutils.GetIsoLoopDevice(); strings.Compare(isoLoopDev, "") != 0 {
// Extract offline contents for ISO installer
log.Debug("Extracting offline content in squashfs to target media")

if err := isoutils.ExtractSquashfs(conf.OfflineContentDir, rootDir, isoLoopDev); err != nil {
return err
}
if err := os.Rename(path.Join(rootDir, conf.OfflineContentDir), stateDir); err != nil {
return err
}
} else {
// Copy offline contents for img installer
log.Debug("Copying offline content to target media")

// The performance of utils.CopyAllFiles is much slower than cp when
// copying a large number of files.
args := []string{
"cp",
"-ar",
conf.OfflineContentDir,
stateDir,
}
err := cmd.RunAndLog(args...)
if err != nil {
return err
}
}
return nil
}

// ConfigureNetwork applies the model/configured network interfaces
func ConfigureNetwork(model *model.SystemInstall) error {
prg, err := configureNetwork(model)
Expand Down
41 changes: 41 additions & 0 deletions isoutils/isoutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package isoutils

import (
"bytes"
"io/ioutil"
"os"
"os/exec"
Expand Down Expand Up @@ -112,6 +113,46 @@ func mkRootfs() error {
return err
}

// GetIsoLoopDevice returns the name of the ISO loop device
func GetIsoLoopDevice() string {
w := bytes.NewBuffer(nil)
args := []string{
"losetup",
"-j",
"/mnt/media/images/rootfs.img",
"-O",
"NAME",
"-n",
}
err := cmd.Run(w, args...)
if err != nil {
return ""
}
if strings.Compare(w.String(), "") == 0 {
return ""
}

return strings.TrimSuffix(w.String(), "\n")
}

// ExtractSquashfs extracts the src directory from a squashfs to the dest directory
func ExtractSquashfs(src, dest, loopDev string) error {
args := []string{
"unsquashfs",
"-d",
dest,
"-f",
loopDev,
"-e",
src,
}
err := cmd.RunAndLog(args...)
if err != nil {
return err
}
return err
}

func mkInitrd(version string, model *model.SystemInstall, options args.Args) error {
msg := "Installing the base system for initrd"
var prg progress.Progress
Expand Down
3 changes: 3 additions & 0 deletions locale/en_US/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ msgstr "Select Additional Bundles"
msgid "Offline Install: Removing additional bundles"
msgstr "Offline Install: Removing additional bundles"

msgid "Copying cached content to target media"
msgstr "Copying cached content to target media"

msgid "Manage User"
msgstr "Manage User"

Expand Down
3 changes: 3 additions & 0 deletions locale/es_MX/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ msgstr "Seleccionar paquetes adicionales"
msgid "Offline Install: Removing additional bundles"
msgstr "Instalación sin conexión: Eliminación de paquetes adicionales"

msgid "Copying cached content to target media"
msgstr "Copia de contenido almacenado en caché en medios de destino"

msgid "Manage User"
msgstr "Administrar usuarios"

Expand Down
3 changes: 3 additions & 0 deletions locale/zh_CN/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ msgstr "选择附加捆绑包"
msgid "Offline Install: Removing additional bundles"
msgstr "脱机安装:删除其他包"

msgid "Copying cached content to target media"
msgstr "将缓存的内容复制到目标媒体"

msgid "Manage User"
msgstr "管理用户"

Expand Down
5 changes: 5 additions & 0 deletions swupd/swupd.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ func (s *SoftwareUpdater) setExtraFlags(args []string) []string {
return args
}

// GetStateDir returns the state directory
func (s *SoftwareUpdater) GetStateDir() string {
return s.stateDir
}

// Verify runs "swupd verify" operation
func (s *SoftwareUpdater) Verify(version string, mirror string, verifyOnly bool) error {
args := []string{
Expand Down

0 comments on commit a765200

Please sign in to comment.