Skip to content

Comments

Extract "Distribution" XML to get versions from downloaded packages using "xar" instead of "pkgutil --expand"#917

Open
PicoMitchell wants to merge 3 commits intoInstallomator:devfrom
PicoMitchell:efficient-pkg-distribution-extraction
Open

Extract "Distribution" XML to get versions from downloaded packages using "xar" instead of "pkgutil --expand"#917
PicoMitchell wants to merge 3 commits intoInstallomator:devfrom
PicoMitchell:efficient-pkg-distribution-extraction

Conversation

@PicoMitchell
Copy link

All information about the why's and how's of extracting only the "Distribution" XML file from a package using "xar" have been written into the code comments. Basically, extracting ONLY the "Distribution" XML from the package can be a lot more efficient when dealing with large packages rather than extracting the entire package contents which could include large "Payload" files, etc.

But, since "man xar" has a deprecation warning, this code checks if "xar" returned nothing in case of future removal or breakage and will fallback on extracting the entire package contents using "pkgutil --expand" like is currently being done. So, I think this is a win win since either the process is more efficient or the same as it currently is no matter what happens to "xar" in the future.

If no version is detected either because the package is not a "distribution package" and therefore doesn't have a "Distribution" XML file or the XPath expression failed to retrieve a version for some reason, those errors will be logged by using new "appNewVersion" error values which would always just fail the "if [[ $appversion == $appNewVersion ]]; then" condition to always install the downloaded package when a version couldn't be detected for any reason.

…sing "xar" instead of "pkgutil --expand"

All information about the why's and how's of extracting only the "Distribution" XML file from a package using "xar" have been written into the code comments. Basically, extracting ONLY the "Distribution" XML from the package can be a lot more efficient when dealing with large packages rather than extracting the entire package contents which could include large "Payload" files, etc.

But, since "man xar" has a deprecation warning, this code checks if "xar" returned nothing in case of future removal or breakage and will fallback on extracting the entire package contents using "pkgutil --expand" like is currently being done. So, I think this is a win win since either the process is more efficient or the same as it currently is no matter what happens to "xar" in the future.

If no version is detected either because the package is not a "distribution package" and therefore doesn't have a "Distribution" XML file or the XPath expression failed to retrieve a version for some reason, those errors will be logged by using new "appNewVersion" error values which would always just fail the "if [[ $appversion == $appNewVersion ]]; then" condition to always install the downloaded package when a version couldn't be detected for any reason.
@PicoMitchell
Copy link
Author

I see that

appNewVersion=$(cat "$expandedPkg"/Distribution | xpath "string(//installer-gui-script/pkg-ref[@id='$packageID'][@version]/@version)" 2>/dev/null )
in the dev branch has an improved XPath expression to retrieve the version for the specific packageID.

I did not include this change since I was working off the main branch, but wanted to point it out depending on if this change get merged into a minor or major release.

Also exclude all digits and a few other common symbols in filenames to exclude that would never exist in the one and only "Distribution" filename that we want to extract.
@PicoMitchell
Copy link
Author

I think the PackageInfo XML file could also be checked for a version for non-distribution/component style packages.

But I think it's not uncommon for folks to not include --version when just using pkgbuild. With no version specified in pkgutil or productbuild it will default to "0". It seems like "1.0" is also a common value so maybe other package building tools set that default value and folks don't update it.

@scriptingosx
Copy link
Collaborator

The reason we are expanding the entire archive is that the xar command did not have these options in older versions of macOS. How far back does this work?

@scriptingosx scriptingosx added the improvement minor improvement of an existing feature label Mar 1, 2023
@PicoMitchell
Copy link
Author

Just confirmed xar and all the options I'm using are available at least back to High Sierra, and also double-check Mojave. But, with how I wrote the fallback, if xar or at least the -t option did end up being unavailable on older versions of macOS, pkgutil --extract would get fallen back on anyways.

@hcbraun hcbraun mentioned this pull request Mar 2, 2023
@hcbraun
Copy link

hcbraun commented Mar 2, 2023

fyi, I had to update the xpath again to make it work for the Adobe Acrobat package: xpath patch

@scriptingosx scriptingosx added this to the v11.0 milestone May 27, 2023
@scriptingosx scriptingosx changed the base branch from main to dev May 27, 2023 08:02
@Theile Theile deleted the branch Installomator:dev June 5, 2023 13:28
@Theile Theile closed this Jun 5, 2023
@scriptingosx scriptingosx reopened this Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement minor improvement of an existing feature not-label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants