app_tar.sh
#!/bin/bash
#################################
# 制作dmg鏡像
#################################
### 變量聲明
gitDir="/Volumes/vs2015/demo"
# 工程目錄
projectDir="$gitDir/src/chai"
# 編譯目錄
buildDir="$HOME/qt/build/chai-Release"
# 應(yīng)用程序名
appName="chai"
# 鏡像目錄
dmgDir="$HOME/Desktop/$appName"
# 證書
identity="Developer ID Application: XXXXX (MVGBX5DTX9)"
qtVersion="5.9.6"
### 工程編譯
echo "**************************************** start make ****************************************"
rm -rf $buildDir
mkdir -p $buildDir
cd $buildDir
# 獲取環(huán)境變量VERSION猎莲,以及獲取的版本md5值
buildVer="${VERSION} 2e923332a004adcad600236a2f27ccab45e8b93c"
# 修改pro的DEFINES VER_CHAI變量,修改版本宏的變量
sed -i "" "s/VER_CHAI=.*/VER_CHAI=\\\\\"\\\\\\\\\\\\\"${buildVer}\\\\\"\\\\\\\\\\\\\"/g" $projectDir/chai.pro
$HOME/Qt${qtVersion}/${qtVersion}/clang_64/bin/qmake $projectDir/chai.pro -o $buildDir
make -j 4
if [ $? -ne 0 ]; then exit -1; fi
### 拷貝其他資源文件
echo "**************************************** copy resources ****************************************"
resArr=(
cfg.db
Resources/appIcon.icns
)
# 由于資源都在windows存放技即,會(huì)存在權(quán)限不正確的現(xiàn)象
for res in ${resArr[@]}
do
# 對(duì)資源里的目錄進(jìn)行權(quán)限調(diào)整:對(duì)文件修改為666,對(duì)目錄修改為755
if [ -d "$projectDir/$res" ];then
cp -r $projectDir/$res $appName.app/Contents/Resources/$(basename $res)
find $appName.app/Contents/Resources/$(basename $res) -type d -exec chmod 755 {} \;
find $appName.app/Contents/Resources/$(basename $res) -type f -exec chmod 666 {} \;
# 對(duì)資源里的dylib進(jìn)行權(quán)限調(diào)整
elif [ "dylib" == "${res##*.}" ];then
cp $projectDir/$res $appName.app/Contents/Resources/
chmod 755 $appName.app/Contents/Resources/$(basename $res)
# 對(duì)其他普通文件權(quán)限進(jìn)行調(diào)整
else
cp $projectDir/$res $appName.app/Contents/Resources/
chmod 666 $appName.app/Contents/Resources/$(basename $res)
fi
done
### 拷貝dmg資源著洼,供appdmg使用
resArr=(
Resources/install_bg.png
Resources/dmg.json
)
for res in "${resArr[@]}"
do
cp $projectDir/$res .
done
### 拷貝qt相關(guān)的資源、文件、so
echo "**************************************** copy qt resources ****************************************"
$HOME/Qt${qtVersion}/${qtVersion}/clang_64/bin/macdeployqt $appName.app -qmldir=$projectDir
# 設(shè)置Info.plist文件
infoArr=(
# 應(yīng)用程序圖標(biāo)
"Set :CFBundleIconFile appIcon.icns"
"Set :CFBundleIdentifier 'com.chai.demo'"
# 設(shè)置網(wǎng)頁(yè)啟動(dòng)
"Add :CFBundleURLTypes array"
"Add :CFBundleURLTypes:0 dict"
"Add :CFBundleURLTypes:0:CFBundleTypeRole string 'Editor'"
"Add :CFBundleURLTypes:0:CFBundleURLName string 'com.chai.demo'"
"Add :CFBundleURLTypes:0:CFBundleURLSchemes array"
# 設(shè)置啟動(dòng)的 scheme
"Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string 'chai_demo'"
)
for info in "${infoArr[@]}"
do
/usr/libexec/PlistBuddy -c "$info" $appName.app/Contents/Info.plist
done
### 開始簽名
echo "**************************************** signature ****************************************"
function signature()
{
# 證書解鎖身笤,輸入密碼交互
(/usr/bin/expect <<-EOF
spawn security unlock-keychain login.keychain
expect {
"password*" { send "123456\r" }
}
expect eof
EOF
)
# 這句話在腳本里一定要有豹悬,不然公證的時(shí)候可能會(huì)出現(xiàn)奇葩的問題
plutil -convert xml1 "$projectDir/../script/chai.entitlements"
codesign -f --deep --timestamp -o runtime -v --entitlements "$projectDir/../script/chai.entitlements" -s "$identity" "$1"
}
signature "$appName.app"
# 制作dmg鏡像文件
echo "**************************************** tar dmg ****************************************"
rm ${appName}-${VERSION}.dmg
# https://github.com/LinusU/node-appdmg 查看具體安裝方法及配置說(shuō)明
appdmg dmg.json ${appName}-${VERSION}.dmg
# 插入公證的shell腳本位置
mv ${appName}-${VERSION}.dmg $HOME/Desktop
查看appdmg具體安裝方法及配置說(shuō)明
公證需要codesign的時(shí)候加上-o runtime參數(shù),加上了此參數(shù)液荸,就需要給app賦予權(quán)限瞻佛,否則會(huì)導(dǎo)致運(yùn)行時(shí)的崩潰。chai.entitlements就是權(quán)限的描述文件
-
errSecInternalComponent:錯(cuò)誤的其中一種情況
啟動(dòng)臺(tái)->其他->鑰匙串訪問
鑰匙串選擇登陸
種類選擇證書
找到簽名的證書娇钱,展開涤久,找到種類為專用秘鑰的鑰匙串,雙擊忍弛,點(diǎn)擊訪問控制响迂,將訪問權(quán)限改為允許所有應(yīng)用程序訪問此項(xiàng)目
chai.entitlements
<?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>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.cs.disable-executable-page-protection</key>
<true/>
</dict>
</plist>
查看chai.entitlements權(quán)限說(shuō)明
如果不清楚里面具體的含義,建議把上述的配置文件的權(quán)限如數(shù)加上细疚,減少不必要的問題蔗彤。其他權(quán)限可以根據(jù)需求來(lái)定
dmg.json
{
"title": "chai",
"icon-size": 128,
"background": "install_bg.png",
"contents": [
{ "x": 230, "y": 190, "type": "file", "path": "chai.app" },
{ "x": 550, "y": 190, "type": "link", "path": "/Applications" }
],
"window": {
"size": {
"width": 770,
"height": 500
}
},
"format": "UDZO"
}
notarization.sh
#!/bin/bash
#################################
# 公證dmg鏡像安裝包
#################################
# appleID
notarizationUser="chai@email.com"
# 公證密碼,不是appleID密碼疯兼,需要到 https://appleid.apple.com 生成app專用密碼然遏,生成的格式如下
notarizationPasswd="xxxx-xxxx-xxxx-xxxx"
# 與打包腳本的CFBundleIdentifier一致
bundleId="com.chai.demo"
# 證書里面()的內(nèi)容
identityId="MVGBX5DTX9"
cd $HOME/Desktop
### 開始公證
function notarizationApp()
{
appName="$1"
echo "**************************************** notarization $appName ****************************************"
uploadInfo=$(xcrun altool --notarize-app --primary-bundle-id "$bundleId" --username "$notarizationUser" --password "$notarizationPasswd" --asc-provider "$identityId" --file ${appName}-${VERSION}.dmg)
uploadUUID=$(echo $uploadInfo | awk '{print $7}')
echo "uploadUUID:$uploadUUID"
# 循環(huán)查詢公證結(jié)果
echo "**************************************** start waiting notarization ****************************************"
sleep 120
while :
do
status=$(xcrun altool --notarization-info "$uploadUUID" --username "$notarizationUser" --password "$notarizationPasswd" | grep "Status: " | awk -F":" '{print $2}')
if [ " in progress" == "$status" ];then
echo "**************************************** waiting notarization ****************************************"
sleep 30
elif [ " success" == "$status" ]; then
echo "**************************************** notarization success ****************************************"
break
else
echo "**************************************** notarization error ****************************************"
exit
fi
done
# 對(duì)dmg添加票據(jù)
xcrun stapler staple -v ${appName}-${VERSION}.dmg
}
notarizationApp "chai"
identityId獲取方法,執(zhí)行xcrun altool --list-providers -u "$notarizationUser" -p "$notarizationPasswd"
即可獲取
- 問題 Embedded entitlements are invalid: syntax error near line 1
使用spctl --verbose=4 --assess --type chai.app
查看簽名沒有問題吧彪,但是公證的時(shí)候會(huì)遇到以下問題
{
"severity": "error",
"code": null,
"path": "chai-V1.0.0.dmg/chai.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore",
"message": "Embedded entitlements are invalid: syntax error near line 1",
"docUrl": null,
"architecture": null
}
是因?yàn)?strong>chai.entitlements格式不正確待侵,一般在windows、mac混用會(huì)出現(xiàn)的問題姨裸,使用以下命令進(jìn)行轉(zhuǎn)換平臺(tái)格式即可
plutil -convert xml1 "chai.entitlements"