Packagemaker 3 - An Introduction
Packagemaker is Apple's official packaging tool which is used for packaging the applications before distributing them. It is part of XCode developer software suite. Earlier, it was installed as part of XCode installation, however, with the release of XCode 4.3, it is a part of separate package (Auxiliary Tools for XCode) which has to be downloaded separately. You need an Apple Id to download these tools.
At the time of writing, the latest Packagemaker version is 3.0.5. This version offers great improvements over the previous versions in terms of GUI mode of creating the installers. Talking about the GUI mode, most of the things are self-explanatory, so it is pretty easy to end up with a decent, working installer. However, if you are planning to use the command line mode for creating the installers, it is highly likely that you are going to have some trouble as the documentation is just not good enough.
Before moving on, lets have a look at the supported package formats-
There are two types of packages- Bundles and Flat Packages.
Bundle vs Flat Package
- Bundle contains data in a hierarchical manner. You can do RightClick --> Show Package Contents and browse through all the items present inside as if they were part of some folder structure and modify it. For some, it was good to be able to see what is inside the package, tweak it according to their will and requirements and then use it. However, for others, it was a security issue because users had the ability to modify the contents of the packages.
So Apple came up with concept of Flat packages. These packages behave as files instead of folders. With these, you cannot browse through the contents easily though it is possible if you are curious enough to peek inside the package. - If your application distribution target is MacOS 10.5 and above, PM3 will create flat packages. For MacOS 10.4 and below, PM3 also supports Backwards-Compatibility mode that creates older packages(Bundles).
Here, we will be talking more about the flat packages, though we will be pointing out the significant differences from the Bundles if any.
Want to peek inside a flat package?
There are some tools available for opening/modifying flat packages as well. If you want to see inside the package, open it using Flat Package Editor.
This tool allows you to see the basic structure of the package which in most cases will be one of the following-
After getting the above information, some of you won't be satisfied as it just shows the high level structure and doesn't allow to see what is inside the Payload or Scripts.
So, what next!.
Is it not possible to see the contents of the flat package?
Well! Everything is possible in this world if you are curious enough to know and do it.
Let's take a look at a command-line tool - pkgutil.
We can use this utility to perform a number of operations in our packages. I will be mentioning only some of the operations here. You can get more detailed information at the man pages of pkgutil.
For those of you who were dying to see the contents of the flat package, we can expand the flat package using pkgutil.
pkgutil --expand FlatPackage.pkg NewPackage.pkg
Now, newly created package is older-style package which we can browse through by doing RightClick --> Show Package Contents. After going inside, double click the Payload file to extract the contents! So finally you got what you were looking for. Here you can modify files at your will.
But will the package work after we modify the files?
Yes! As far as we don't change the basic structure of the package.
Suppose we modified some script inside the Scripts directory to bypass some settings that were not allowing installation in my machine. Now we have to flatten the package again. Use
pkgutil --flatten OlderStylePkg.pkg NewFlatPackage.pkg
And you get your modified package back in flat format ready for installation.
Component Package
Distribution Package(Left) and Component Package(Right)
After getting the above information, some of you won't be satisfied as it just shows the high level structure and doesn't allow to see what is inside the Payload or Scripts.
So, what next!.
Is it not possible to see the contents of the flat package?
Well! Everything is possible in this world if you are curious enough to know and do it.
Let's take a look at a command-line tool - pkgutil.
We can use this utility to perform a number of operations in our packages. I will be mentioning only some of the operations here. You can get more detailed information at the man pages of pkgutil.
For those of you who were dying to see the contents of the flat package, we can expand the flat package using pkgutil.
pkgutil --expand FlatPackage.pkg NewPackage.pkg
Now, newly created package is older-style package which we can browse through by doing RightClick --> Show Package Contents. After going inside, double click the Payload file to extract the contents! So finally you got what you were looking for. Here you can modify files at your will.
But will the package work after we modify the files?
Yes! As far as we don't change the basic structure of the package.
Suppose we modified some script inside the Scripts directory to bypass some settings that were not allowing installation in my machine. Now we have to flatten the package again. Use
pkgutil --flatten OlderStylePkg.pkg NewFlatPackage.pkg
And you get your modified package back in flat format ready for installation.
Types of Flat Packages:
So in the images above, you see two different types of packages. One contains only compressed files inside while the other one contains packages inside as well.
So what's the difference between the two?
The one with only compressed files inside is Component Package. Their primary purpose is to dump the payload in the system where they are installed and of course perform the preinstall and postinstall actions.
Well, you must be wondering that this is exactly what a package is supposed to do when installed. So what is it that they can not do during the installation?
They can't show any License, ReadMe, etc to the user. They cannot perform InstallationCheck as well.
If we want to show all these things to the user before installation, we use Distribution Package for this purpose. Distribution Packages contain the component packages to be installed, a Distribution file that has the information about the location and name of license files, background images and javascript functions for InstallationCheck actions. It also contains the ususal Resources directory that contains required localization directories which then contain the localized resources (License, background image, etc).
When you will build the package using GUI mode, you will notice that whenever you try to add license, background, etc or InstallationCheck actions to your package, the type of your package changes to Distribution.
Conclusion:
This was a little introduction about the Packagemaker 3, package format and types and about some useful tools to interact with those packages.
With PM3, building a package using its GUI is fairly simple, however, for people who need to create packages everyday and use some sort of automation for creating packages, its command line mode can be of great help. I will be talking about command line mode for building packages in my next post.
Adios!
Links to External Resources:
So in the images above, you see two different types of packages. One contains only compressed files inside while the other one contains packages inside as well.
So what's the difference between the two?
The one with only compressed files inside is Component Package. Their primary purpose is to dump the payload in the system where they are installed and of course perform the preinstall and postinstall actions.
Well, you must be wondering that this is exactly what a package is supposed to do when installed. So what is it that they can not do during the installation?
They can't show any License, ReadMe, etc to the user. They cannot perform InstallationCheck as well.
If we want to show all these things to the user before installation, we use Distribution Package for this purpose. Distribution Packages contain the component packages to be installed, a Distribution file that has the information about the location and name of license files, background images and javascript functions for InstallationCheck actions. It also contains the ususal Resources directory that contains required localization directories which then contain the localized resources (License, background image, etc).
When you will build the package using GUI mode, you will notice that whenever you try to add license, background, etc or InstallationCheck actions to your package, the type of your package changes to Distribution.
Conclusion:
This was a little introduction about the Packagemaker 3, package format and types and about some useful tools to interact with those packages.
With PM3, building a package using its GUI is fairly simple, however, for people who need to create packages everyday and use some sort of automation for creating packages, its command line mode can be of great help. I will be talking about command line mode for building packages in my next post.
Adios!
Links to External Resources:
- Apple's User Guide:
- More about Flat Package format:
- Many good articles at: