productbuild: add third-party product archive to installer? - xcode

I need to make Mac OS app installer, which also installs other third-party package.
When trying to add it via productbuild --synthesize, it tells "ThirdPartyPackage.pkg is a product archive, not a component package".
So, how should I correctly insert third-party product installer into my installer?

You can actually split up a "product archive" into its component packages by using:
pkgutil --expand your_product_archive.pkg some_folder
This will create the some_folder directory with the contents of the product archive.

If the third-party archive is reliably available for download, then you could have a post (or pre) install script use curl to fetch it (probably into /tmp) and installer to install it.
Error handling with curl is a little janky, since it tends to report no error for lots of errors: 404 not found, domain not resolved, etc. You could just assume it worked, and count on installer to error out if there's not an actual package where you tried to download it.

Related

Can macOS flat file pkg installer throw error dialog?

I want to throw error dialog (and fail the installation) if certain file exists on the system. Is it possible?
pkg = flat file pkg
It's possible to customize the installer in various ways to get whatever functionality is needed generally. Typically in your scenario either a Pre-Installation script could be used or a Package Installer Plugin. The options would normally be defined in the installer package's distribution.dist which essentially functions as the schema it will follow.
See productbuild in the man pages:
--scripts scripts-path
- The contents of scripts-path is added to the product archive for use by system.run() commands commands in the distribution. This is valid only for product archives targeted to the OS X Installer application.
--plugins plugins-path
- The contents of plugins-path is added to the product archive for use by the OS X Installer application's plugin mechanism. It will normally contain a InstallerSections.plist file, and one or more plugin bundles.
↳ About Distribution Definition Files & productbuild

Cannot find .pkg file upon building it in terminal / How to convert a .app into a .pkg

Currently I am working on submitting an app to the mac app store. I have gone through several steps but am stuck on the last one. This is as I am trying to build my .app file (made in unity) into a .pkg so I am able to Deliver it to iTunes connect via application loader.
I am entering this command into terminal:
productbuild --component GAMENAME.app /Applications --sign "3rd Party Mac Developer Installer: DEVELOPER NAME" GAMENAME.pkg
For some reason though, after entering even though I don not get an error:
Usage: productbuild [--product <requirements-plist>] {--component <component-path> <install-path>} <product-output-path>
Build product with a self-contained bundle, e.g. for the Mac App Store
Usage: productbuild {--content <content-path>} <product-output-path>
Build product with in-app content
Usage: productbuild [--product <requirements-plist>] {--root <root-path> <install-path>} <product-output-path>
Build product with an xcodebuild destination root
Usage: productbuild [options] --distribution <dist-path> [--package-path <search-path>] <product-output-path>
Build product with a distribution and the packages it references
Usage: productbuild --synthesize [--product <requirements-plist>] {--package <pkg-path>} <distribution-output-path>
Synthesize and write a distribution from component packages
See productbuild(1) for details.
I cannot find the .pkg file that has just been built...
I am not sure if this is because it is hidden somewhere or if I have made a mistake I'm unaware of, but any help would be appreciated
So, in short This question basically is how to make a .app to a .pkg which can be using application loader uploaded to iTunes connect...
EDIT:
Ok as someone suggested I might have gotten the initial terminal command wrong after all so any suggestions on where I went wrong would be appreciated.
Your developer name must be followed by the team ID.
Like - "DEVELOPER NAME (ABC123456)"

How to Force install location from OSX .pkg

I'm attempting to create a package installer for our product. Previously we installed with a .dmg, and the process was to just drag it to the /Applications folder. Now we want it to install to /Application/Company/Suite/product.
Problem is: If we use the .pkg installer on a system that previously had our product installed it creates the folders, but installs the product over the old location.
How can I make the pkg installer do the following:
Remove the old version
Install new version to proper location
I've had very little experience with OSX - so maybe I'm just missing something? Also looking in the applications folder - it doesn't appear that anything else is installed to a subdirectory, is it unusual to do things this way?
Thank you!
EDIT:
I'm looking into the answers located here OSX .pkg installer sometimes does not install .app file, differently worded problem - but the answer might be just what I need.
EDIT2: OSX .pkg installer sometimes does not install .app file Does not apply. We didn't install with any package manager - so there isn't a previous entry.
EDIT3: We were using dmg, but are now moving to pkg.
So I found the answer.
In order to have it install to a new location:
The plist inside the app package (product.app/Contents/Info.plist) has an identifier "CFBundleIdentifier", these needs to be different from the old application. For instance ours was "Company.Product-Name", I've changed it to "Company.Product.Name". This will allow the new installation to go to the new location.
In order to remove the old installation:
I simply added this line to the preinstall script:
"sudo rm -Rf '/Application/Product Name.app'"
Thank you for your assistance.

Scriptable way to create flat .pkg files with custom resources and scripts

I have created a flat .pkg file with following options on 10.7 using PackageMaker 3.0.6:
/Applications/PackageMaker.app/Contents/MacOS/Package --root ./myroot \
--id com.myroot.pkg --title "My Root" --scripts ./scripts --target 10.5 \
--verbose --resources ./resources --root-volume-only --domain system \
--no-relocate --versio 1.0 --certificate "My Cert Name"
In the resources folder I have background.png, Welcome.rtf and License.rtf and in the scripts folder I have preflight, postflight and various support files for those scripts. The resulting .pkg appears to be fully functional except that the installer does not display my background, welcome or license.
How can I add a custom background, welcome and license to a flat package?
As far as I can tell, the Distribution file in the .pkg is missing references to the background, welcome and license files.
As a workaround I tried using xar. If I unpack the package with xar like so:
xar -xf ./myroot.pkg -C work
and add the 3 tags for those files, then pack it again with xar:
cd work && xar -cf ../myroot2.pkg *
I get a package that starts installation ok with my background etc., but when it comes time to install my .app I get these errors (from /var/log/install.log):
run preupgrade script for myroot
Could not create task for action: run preupgrade script for myroot2
Install failed: The Installer could not extract files from the package for myroot2. Contact the software manufacturer for assistance.
IFDInstallController 863170 state = 7
I have also tried Flat Package Editor: open myroot.pkg, drag out Distribution, edit it, drag it back, delete old Distribution, save. Same problem as with xar.
I would prefer to have a fully scriptable solution as opposed to using GUIs.
Edit: I have also tried to use pkgutil to expand, edit Distribution, and reflatten a flat package. This gets the icons and readme in the installer, but the installer is then unable to unpack the payload. Same if I reflatten with Flat Package Editor. I have also tried to create an expanded package without PackageMaker (which works, except on 10.8), but when I try to flatten that with pkgutil the result is a corrupted package again.
PackageMaker always was buggy has hell, and got deprecated with Mac OS X 10.6 Snow Leopard.
You should use pkgbuild together with productbuild.
This Mac Installers Blog has some useful posts about Packagemaker including details about the usage and solutions to common problems. Hope it will help.
Check out the Luggage - it's a Makefile helper file that lets you create OS X packages with sane Makefiles. Disclaimer: I am the original author for it, though there are a lot of other people's contributions in it now.

CodeSigning pkg file with Installer Certificate in Mac

I have one Mac Desktop Cocoa based application which i have signed succesfully by mac Certificates.
To generate .pkg installer file i am using the following command:
productbuild --component 'App.app' /Applications --sign '3rd Party Mac
Developer Installer: Some Name' App.pkg
which generates .pkg file succesfully with proper signing. No complaints about it.
But now i want to include some precheck installation scripts in that .pkg which can perform some validations on user's system prioir to installation. How to do it once i have my pkg generated already?
I can easily include such scripts in the package through Package Maker but then how to sign .pkg  file with Installer Certificate. As this process does not signs my pkg file and hence unacceptable to upload to AppStore
First, I'm not sure you're allowed to include such scripts in an App Store package in the first place.
But if you are, the manpage for productbuild explains how to generate a package from a custom Distribution file by using the --distribution option instead of --component. And, if you don't know how to write a Distribution file, you can look at the ones inside any package (just "xar xf App.pkg" to extract the contents, and Distribution will be at the top level) and/or use productbuild with the --synthesize option.

Resources