Repackaging .pkg files without installing/unpacking

You can use the Flat Package Editor from Apple.

  1. Go to Apple's Developer downloads site and download the Auxiliary Tools for Xcode - Late July 2012.
  2. Once downloaded, open the DMG.
  3. Find PackageMaker.app and open the package contents, then navigate to Contents/Resources.
  4. Copy Flat Package Editor.app to /Applications or elsewhere then open it.

From this app you can open a .pkg and edit the contents by dragging files out, editing them and dragging them back in, then saving the package.


Packages can be resigned using the button on the title bar:


I am not aware of any Apple recommended tools to edit existing package, pkg or mpkg, files. Most packages are signed and thus any changes will invalidate their signature; although resigning is simple enough using pkgbuild and an appropriate installer certificate.

Wrapping Up Existing Packages

Consider creating a wrapper multi-package that adjusts any required files after installation. With this approach you can bundle up existing packages and then run post-install/update scripts as required.

pkgbuild

There is little documentation about crafting packages as Apple traditionally relied on the graphical tool PackageMaker. Since Mac OS X 10.8, the PackageMaker tool has been replaced by the command line tools productbuild and pkgbuild.

The tool you will want to investigate is pkgbuild. This tool eases the creation of packages containing multiple packages and scripts. About Distribution Definition Files talks about the internal file format.