Skip to content

Commit

Permalink
offline-update: Add --ostree-repo-source option
Browse files Browse the repository at this point in the history
This option allows a local ostree repo to be specified as replacement
for the factory ostree repo when building the offline bundle.
This if required when a custom ostree repo was pushed with `fiopush` and
a target was was manually added referencing a hash from this custom
repo.

Signed-off-by: Andre Detsch <[email protected]>
  • Loading branch information
detsch committed Oct 31, 2024
1 parent 5c58cda commit 9e1f8ea
Showing 1 changed file with 68 additions and 2 deletions.
70 changes: 68 additions & 2 deletions subcommands/targets/offline-update.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var (
ouNoApps bool
ouAllowMultipleTargets bool
ouWave string
ouOstreeRepoSrc string
)

func init() {
Expand Down Expand Up @@ -87,6 +88,8 @@ func init() {
"Skip fetching Target Apps")
offlineUpdateCmd.Flags().BoolVarP(&ouAllowMultipleTargets, "allow-multiple-targets", "", false,
"Allow multiple targets to be stored in the same <dst> directory")
offlineUpdateCmd.Flags().StringVarP(&ouOstreeRepoSrc, "ostree-repo-source", "", "",
"Path to the local ostree repo to be used in the offline bundle")
offlineUpdateCmd.MarkFlagsMutuallyExclusive("tag", "wave")
offlineUpdateCmd.MarkFlagsMutuallyExclusive("prod", "wave")
initSignCmd(offlineUpdateCmd)
Expand Down Expand Up @@ -169,8 +172,13 @@ Notice that multiple targets in the same directory is only supported in LmP >= v
ti, err := getTargetInfo(targetCustomData)
subcommands.DieNotNil(err)

fmt.Printf("Downloading an ostree repo from the Target's OE build %d...\n", ti.ostreeVersion)
subcommands.DieNotNil(downloadOstree(factory, ti.ostreeVersion, ti.hardwareID, dstDir), "Failed to download Target's ostree repo:")
if ouOstreeRepoSrc != "" {
fmt.Printf("Copying local ostree repo from %s...\n", ouOstreeRepoSrc)
subcommands.DieNotNil(copyOstree(ouOstreeRepoSrc, dstDir+"/ostree_repo/"), "Failed to copy local ostree repo:")
} else {
fmt.Printf("Downloading an ostree repo from the Target's OE build %d...\n", ti.ostreeVersion)
subcommands.DieNotNil(downloadOstree(factory, ti.ostreeVersion, ti.hardwareID, dstDir), "Failed to download Target's ostree repo:")
}
if !ouNoApps {
if (len(ouWave) > 0 || ouProd) && ti.fetchedApps == nil {
// Get the specified target from the list of factory targets to obtain the "original" tag/branch that produced
Expand Down Expand Up @@ -366,6 +374,64 @@ func downloadTufRepo(factory string, target string, tag string, prod bool, wave
return nil
}

func copyFile(src string, dst string) error {
srcFile, err := os.Open(src)
if err != nil {
return err
}
defer srcFile.Close()

dstFile, err := os.Create(dst)
if err != nil {
return err
}
defer dstFile.Close()

_, err = dstFile.ReadFrom(srcFile)
if err != nil {
return err
}
srcInfo, err := os.Stat(src)
if err != nil {
return err
}
return os.Chmod(dst, srcInfo.Mode())
}

func copyDirRecursive(srcDir string, dstDir string) error {
srcInfo, err := os.Stat(srcDir)
if err != nil {
return err
}

err = os.MkdirAll(dstDir, srcInfo.Mode())
if err != nil {
return err
}

dirEntries, err := os.ReadDir(srcDir)
if err != nil {
return err
}
for _, dirEntry := range dirEntries {
src := path.Join(srcDir, dirEntry.Name())
dst := path.Join(dstDir, dirEntry.Name())
if dirEntry.IsDir() {
err = copyDirRecursive(src, dst)
} else {
err = copyFile(src, dst)
}
if err != nil {
return err
}
}
return nil
}

func copyOstree(srcDir string, dstDir string) error {
return copyDirRecursive(srcDir, dstDir)
}

func downloadOstree(factory string, targetVer int, hardwareID string, dstDir string) error {
runName := hardwareID
artifactName := hardwareID + "-ostree_repo.tar.bz2"
Expand Down

0 comments on commit 9e1f8ea

Please sign in to comment.