bash MAC PackageMaker 预安装/后安装脚本以获取原始 *.pkg 文件目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10498618/
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
MAC PackageMaker preinstall/postinstall script to get original *.pkg file directory
提问by trent.xu
How do I get the original *.pkg file directory when install it?
安装时如何获取原始*.pkg文件目录?
I have created a pkg file, and put it with another file(like test.txt) into a same folder, like ~/Desktop/test
我创建了一个 pkg 文件,并将它与另一个文件(如test.txt)放在同一个文件夹中,如 ~/Desktop/test
And when install pkg file, I want it to copy the "test.txt" file to ~/Library folder. So I add preinstall/postinstall script into pkg file to copy the "test.txt" file. I try to get the directory use
并且在安装 pkg 文件时,我希望它将“test.txt”文件复制到 ~/Library 文件夹。所以我将安装前/安装后脚本添加到 pkg 文件中以复制“test.txt”文件。我尝试获取目录使用
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
But it will return the tmp directory
但它会返回tmp目录
/private/tmp/PKInstallSandbox.G5GFI6/Scripts/com.myApp.testApp.pkg.o5k2nE
not the original pkg directory (~/Desktop/test)
不是原来的 pkg 目录 (~/Desktop/test)
Has anybody know how to get the original directory when install?
有人知道安装时如何获取原始目录吗?
回答by
You've created a flat package? Have you tried looking at the parameters passed to the postinstall script?
你已经创建了一个平面包?您是否尝试查看传递给安装后脚本的参数?
pkgpath=\`dirname "$PACKAGE_PATH"\`
- Script path
- Package path
- Target location
- Target volume`
Parameter $1 should give you what you're looking for.
参数 $1 应该给你你正在寻找的东西。
Copied from old bundle style format information, but still seems to apply to newer flat packages.
从旧的包样式格式信息复制,但似乎仍然适用于较新的扁平包。
回答by Vikram Singh
This Mac Installers Bloghas some useful posts about Packagemaker including details about the usage and solutions to common problems.
这个Mac 安装者博客有一些关于 Packagemaker 的有用帖子,包括有关使用和常见问题解决方案的详细信息。
回答by pliniop
This:
这个:
##代码##will give you the path to the package in the variable $pkgpath.
将为您提供变量中包的路径$pkgpath。

