if a PKG is added as a target, always install it (#20971)

previously we were only installing on updates

fixes a bug found by @PezHub

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [x] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
This commit is contained in:
Roberto Dip
2024-08-01 18:15:41 -03:00
committed by GitHub
parent 45b61c5085
commit 531b25d2ac
+15 -3
View File
@@ -385,9 +385,8 @@ func (u *Updater) get(target string) (*LocalTarget, error) {
}
}
if strings.HasSuffix(localTarget.Path, ".pkg") && runtime.GOOS == "darwin" {
cmd := exec.Command("installer", "-pkg", localTarget.Path, "-target", "/")
if out, err := cmd.CombinedOutput(); err != nil {
return nil, fmt.Errorf("running pkgutil to install %s: %s: %w", localTarget.Path, string(out), err)
if err := installPKG(localTarget.Path); err != nil {
return nil, fmt.Errorf("updating pkg: %w", err)
}
}
} else {
@@ -398,6 +397,11 @@ func (u *Updater) get(target string) (*LocalTarget, error) {
if err := u.download(target, repoPath, localTarget.Path, localTarget.Info.CustomCheckExec); err != nil {
return nil, fmt.Errorf("download %q: %w", repoPath, err)
}
if strings.HasSuffix(localTarget.Path, ".pkg") && runtime.GOOS == "darwin" {
if err := installPKG(localTarget.Path); err != nil {
return nil, fmt.Errorf("installing pkg for the first time: %w", err)
}
}
default:
return nil, fmt.Errorf("stat %q: %w", localTarget.Path, err)
}
@@ -647,6 +651,14 @@ func extractTarGz(path string) error {
}
}
func installPKG(path string) error {
cmd := exec.Command("installer", "-pkg", path, "-target", "/")
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("running pkgutil to install %s: %s: %w", path, string(out), err)
}
return nil
}
func (u *Updater) initializeDirectories() error {
for _, dir := range []string{
filepath.Join(u.opt.RootDirectory, binDir),