How to unpack and pack a pkg file?

I have a pkg file created by Install Maker for Mac. I want to replace one file in pkg. But I have to do this on a Linux system because it is part of the boot process. When the user starts loading the file server, he must replace one file in pkg. I have a solution how to unzip pkg and replace the file, but I don't know how the pkg package is again. http://emresaglam.com/blog/1035 http://ilostmynotes.blogspot.com/2012/06/mac-os-x-pkg-bom-files-package.html

+67
pkg-file macos
Jul 02 2018-12-12T00:
source share
5 answers

Packages are simply .xar archives with a different extension and a specified file hierarchy. Unfortunately, part of this file hierarchy is the cpio.gz archive of real installation files, and usually this is what you want to edit. There is also a Bom file that contains information about the files inside this cpio archive and a PackageInfo file that includes the summary information.

If you really just need to edit one of the information files, this is simple:

mkdir Foo cd Foo xar -xf ../Foo.pkg # edit stuff xar -cf ../Foo-new.pkg * 

But if you need to edit the installation files:

 mkdir Foo cd Foo xar -xf ../Foo.pkg cd foo.pkg cat Payload | gunzip -dc |cpio -i # edit Foo.app/* rm Payload find ./Foo.app | cpio -o | gzip -c > Payload mkbom Foo.app Bom # or edit Bom # edit PackageInfo rm -rf Foo.app cd .. xar -cf ../Foo-new.pkg 

I believe you can get mkbom (and lsbom) for most Linux distributions. (If you can get the same thing that makes things even easier, but I'm not sure if this is almost universally available.)

+131
Jul 02 '12 at 19:23
source share

Inspired by abarnert 's answer, I created a bash script that will unpack a package named MyPackage.pkg into a subfolder named MyPackage_pkg and then open the folder in Finder. Delete the last line if you do not need the Finder step.

  #!/usr/bin/env bash filename="$*" dirname="${filename/\./_}" pkgutil --expand "$filename" "$dirname" cd "$dirname" tar xvf Payload open . 

Using:

  pkg-upack.sh MyPackage.pkg 

Warning. This will not work in all cases and will not work with certain files, for example. PKG inside the OSX installer. If you just want to look inside the pkg file and see what's inside, you can try SuspiciousPackage (a free application), and if you want to do some serious unpacking, including extracting certain files, then look at Pacifist (nagware).

+16
May 30 '14 at 9:00
source share

In addition to what @abarnert said, I needed to find out today that the default cpio utility for Mountain Lion uses a different default archive format (not sure which one), even with a man page in which it will use the old cpio format / odc. So, if someone came across the message cpio read error: bad file format , trying to install his / her managed packages, be sure to enable the format at the re-pack stage:

 find ./Foo.app | cpio -o --format odc | gzip -c > Payload 
+2
Feb 27 '13 at 10:02
source share

@shrx I was able to unzip BSD.pkg (part of the Yosemite installer) using the "pbzx" command.

pbzx <pkg> | cpio -idmu

The pbzx command can be downloaded from the following link:

+2
Jan 09 '15 at 15:39
source share

You might want to look into your pbzx plug here: https://github.com/NiklasRosenstein/pbzx

It allows you to transfer pbzx files that were not wrapped in the XAR archive. I experienced this with the latest Xcode images with command line tools (e.g. 10.12 Xcode 8).

 pbzx -n Payload | cpio -i 
+2
Jan 11 '17 at 18:01
source share



All Articles