如何强制Mac软件包安装程序检查版本?
问题描述:
基于productbuild的Distribution XML结构,pkg-ref
的version
属性由productbuild
本身自动填充。您也可以使用--version
参数指定软件包版本productbuild
。如何强制Mac软件包安装程序检查版本?
我做了两个软件包:软件包A与版本1.0和软件包B与2.0版本相同的二进制文件。这些版本在三个方面分别给予:
- 作为
--version
参数 - 作为二进制被包装
- 版本值
Distribution.xml
文件中
不过的版本,它似乎安装程序不麻烦检查版本,只安装正在运行的任何软件包。如果您先安装2.0版,然后再运行1.0版软件包,则应用程序将被覆盖。
如何强制安装程序检查版本?是否有一个键/属性/参数,我需要指定的地方,使软件包版本敏感?
答
在你Distribution.xml代码,添加这个功能:
function dontDowngrade(prefix) {
if (typeof(my.result) != 'undefined') my.result.message = system.localizedString('ERROR_2');
var bundle = system.files.bundleAtPath(prefix + '/Applications/YOURAPPNAMEHERE');
if (!bundle) {
return true;
}
var bundleKeyValue = bundle['CFBundleShortVersionString'];
if (!bundleKeyValue) {
return true;
}
if (system.compareVersions(bundleKeyValue, '$packageVersion') > 0) {
return false;
}
return true;
}
错误字符串ERROR_2是Localizable.strings:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ERROR_0</key>
<string>This update requires Mac OS X version %@ or later.</string>
<key>ERROR_1</key>
<string>This software is not supported on your system.</string>
<key>ERROR_2</key>
<string>A newer version of this software is already installed. </string>
<key>SU_TITLE</key>
<string>YOURAPPNAMEHERE</string>
</dict>
</plist>
我把这一切都在一个bash脚本,并使用这里是用shell变量替换文本的文档。例如,$ packageVersion是我的应用程序的版本,例如“2.0.0.0”。字符串YOURAPPNAMEHERE也可以用一个shell变量替换。
cat <<EOF >"Distribution.xml"
<?xml version="1.0" encoding="utf-8"?>
...other text...
EOF
通过检查iTunes安装程序,您可以学到很多东西。下载安装程序,安装它,拖动pkg文件并展开:
$ /usr/sbin/pkgutil --expand Install\ iTunes.pkg iTunesExpanded
然后你就可以看到代码和闲逛
感谢这个!这是一个很好的领先。特别指出以iTunes.pkg为例。从来没有想过检查这个软件包。 – radj