2016-12-06 103 views
0

基於productbuildDistribution XML結構,pkg-refversion屬性由productbuild本身自動填充。您也可以使用--version參數指定軟件包版本productbuild如何強制Mac軟件包安裝程序檢查版本?

我做了兩個軟件包:軟件包A與版本1.0和軟件包B與2.0版本相同的二進制文件。這些版本在三個方面分別給予:

  1. 作爲--version參數
  2. 作爲二進制被包裝
  3. 版本值Distribution.xml文件中

不過的版本,它似乎安裝程序不麻煩檢查版本,只安裝正在運行的任何軟件包。如果您先安裝2.0版,然後再運行1.0版軟件包,則應用程序將被覆蓋。

如何強制安裝程序檢查版本?是否有一個鍵/屬性/參數,我需要指定的地方,使軟件包版本敏感?

回答

1

在你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 

然後你就可以看到代碼和閒逛

+0

感謝這個!這是一個很好的領先。特別指出以iTunes.pkg爲例。從來沒有想過檢查這個軟件包。 – radj

相關問題