macos 如何解压和打包pkg文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11298855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to unpack and pack pkg file?
提问by dream2work
I have a pkg file created by Install Maker for Mac. I want to replace one file in pkg. But I must do this under Linux system, because this is a part of download process. When user starts to download file server must replace one file in pkg. I have a solution how unpack pkg and replace a file but I dont know how pack again to pkg. http://emresaglam.com/blog/1035http://ilostmynotes.blogspot.com/2012/06/mac-os-x-pkg-bom-files-package.html
我有一个由 Install Maker for Mac 创建的 pkg 文件。我想替换 pkg 中的一个文件。但是我必须在Linux系统下这样做,因为这是下载过程的一部分。当用户开始下载文件时,服务器必须替换 pkg 中的一个文件。我有一个解决方案如何解包 pkg 并替换文件,但我不知道如何再次打包到 pkg。 http://emresaglam.com/blog/1035 http://ilostmynotes.blogspot.com/2012/06/mac-os-x-pkg-bom-files-package.html
回答by abarnert
Packages are just .xar archives with a different extension and a specified file hierarchy. Unfortunately, part of that file hierarchy is a cpio.gz archive of the actual installables, and usually that's what you want to edit. And there's also a Bom file that includes information on the files inside that cpio archive, and a PackageInfo file that includes summary information.
包只是具有不同扩展名和指定文件层次结构的 .xar 档案。不幸的是,该文件层次结构的一部分是实际可安装文件的 cpio.gz 存档,通常这就是您想要编辑的内容。还有一个 Bom 文件,其中包含有关该 cpio 存档中文件的信息,以及一个 PackageInfo 文件,其中包含摘要信息。
If you really do just need to edit one of the info files, that's simple:
如果您真的只需要编辑信息文件之一,那很简单:
mkdir Foo
cd Foo
xar -xf ../Foo.pkg
# edit stuff
xar -cf ../Foo-new.pkg *
But if you need to edit the installable 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 distros. (If you can get ditto, that makes things even easier, but I'm not sure if that's nearly as ubiquitously available.)
我相信您可以获得大多数 linux 发行版的 mkbom(和 lsbom)。(如果你能得到同上,那会让事情变得更容易,但我不确定这是否几乎无处不在。)
回答by ccpizza
Here is a bash script inspired by abarnert's answerwhich will unpack a package named MyPackage.pkg
into a subfolder named MyPackage_pkg
and then open the folder in Finder.
这是一个受abarnert 答案启发的 bash 脚本,它将把一个名为的包解压MyPackage.pkg
到一个名为的子文件夹中MyPackage_pkg
,然后在 Finder 中打开该文件夹。
#!/usr/bin/env bash
filename="$*"
dirname="${filename/\./_}"
pkgutil --expand "$filename" "$dirname"
cd "$dirname"
tar xvf Payload
open .
Usage:
用法:
pkg-upack.sh MyPackage.pkg
Warning: This will not work in all cases, and will fail with certain files, e.g. the PKGs inside the OSX system installer. If you want to peek inside the pkg file and see what's inside, you can try SuspiciousPackage(free app), and if you need more options such as selectively unpacking specific files, then have a look at Pacifist(nagware).
警告:这不会在所有情况下都有效,并且会因某些文件而失败,例如 OSX 系统安装程序中的 PKG。如果您想窥视 pkg 文件并查看其中的内容,您可以尝试SuspiciousPackage(免费应用程序),如果您需要更多选项,例如选择性地解压特定文件,请查看Pacifist(nagware)。
回答by h6ah4i
@shrx I've succeeded to unpack the BSD.pkg (part of the Yosemite installer) by using "pbzx" command.
@shrx 我已经使用“pbzx”命令成功解压了 BSD.pkg(Yosemite 安装程序的一部分)。
pbzx <pkg> | cpio -idmu
pbzx <pkg> | cpio -idmu
The "pbzx" command can be downloaded from the following link:
“pbzx”命令可以从以下链接下载:
回答by Malte Rohde
In addition to what @abarnert said, I today had to find out that the default cpio
utility on Mountain Lion uses a different archive format per default (not sure which), even with the man page stating it would use the old cpio/odc format. So, if anyone stumbles upon the cpio read error: bad file format
message while trying to install his/her manipulated packages, be sure to include the format in the re-pack step:
除了@abarnert 所说的之外,我今天还必须发现cpio
Mountain Lion 上的默认实用程序默认使用不同的存档格式(不确定是哪个),即使手册页声明它将使用旧的 cpio/odc 格式。因此,如果有人cpio read error: bad file format
在尝试安装他/她操纵的软件包时偶然发现该消息,请确保在重新打包步骤中包含格式:
find ./Foo.app | cpio -o --format odc | gzip -c > Payload
回答by Niklas R
You might want to look into my fork of pbzx
here: https://github.com/NiklasRosenstein/pbzx
你可能想看看我在pbzx
这里的分支:https: //github.com/NiklasRosenstein/pbzx
It allows you to stream pbzx files that are not wrapped in a XAR archive. I've experienced this with recent XCode Command-Line Tools Disk Images (eg. 10.12 XCode 8).
它允许您流式传输未包装在 XAR 存档中的 pbzx 文件。我在最近的 XCode 命令行工具磁盘映像(例如 10.12 XCode 8)中遇到过这种情况。
pbzx -n Payload | cpio -i