- 先创建一个UDRW格式的DMG,然后attach。
- AppScrip设置窗口大小、app位置,背景图片。
- detach DMG;
- 转换格式为UDBZ
-
#项目路径 setEnv设置 #WORKSPACE="xx" dmgSource_path="${WORKSPACE}/DMG" #挂载后显示的名称 volname="XX" #.app和Application替身复制到的地方 sourceFolder_path="${dmgSource_path}/dmgFolder" #背景图片名 backgroundPictureName="bg_install.png" #背景图路径 setEnv设置 #backgroundPicture_path="${WORKSPACE}/xx/${backgroundPictureName}" #.app名称 setEnv设置 #applicationName="xx.app" #临时dmg tmpDMG_path="tmp.dmg" #最终dmg路径 setEnv设置 #finalDMG_path="${dmgSource_path}/xx.dmg" #图片保存的位置,在sourceFolder_path内,加.代表隐藏 backgroundFolder_path="${sourceFolder_path}/.background" #复制过来的app原位置 setEnv设置 #app_source_path="${WORKSPACE}/build/Release/xx.app" #app复制后的位置 app_final_path="${sourceFolder_path}/${applicationName}" #Applications替身位置 application_path="${sourceFolder_path}/Applications" cd ${WORKSPACE} function prepare { rm -r ${finalDMG_path} #创建目录 rm -r $dmgSource_path mkdir -p $dmgSource_path rm -r $sourceFolder_path mkdir -p $sourceFolder_path rm -r $tmpDMG_path #创建background_path rm -r $backgroundFolder_path mkdir -p $backgroundFolder_path #复制背景图到background_path cp -r $backgroundPicture_path "${backgroundFolder_path}/${backgroundPictureName}" #复制App到目录 echo "---------${app_source_path}--------------${app_final_path}-----------" #有替身的不能直接-r,不然会报替身替换成源文件,导致体积过大 cp -a $app_source_path $app_final_path #制作Applications替身,放到sourceFolder_path ln -s /Applications/ $application_path } function appleScript { echo ' tell application "Finder" tell disk "'${volname}'" open set current view of container window to icon view set toolbar visible of container window to false set statusbar visible of container window to false set the bounds of container window to {400, 100, 950, 470} set theViewOptions to the icon view options of container window set arrangement of theViewOptions to not arranged set icon size of theViewOptions to 128 set background picture of theViewOptions to file ".background:'${backgroundPictureName}'" # make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"} set position of item "'${applicationName}'" of container window to {125, 160} set position of item "Applications" of container window to {447, 160} set position of item ".background" of container window to {447, 1000} set position of item ".fseventsd" of container window to {447, 1000} update without registering applications close end tell end tell ' | osascript } function removeFiles { rm -r $tmpDMG_path rm -r $sourceFolder_path rm -r $dmgSource_path } function detachDMG { hdiutil detach -force "/Volumes/${volname}" } function main { prepare detachDMG hdiutil create -srcdir $sourceFolder_path -volname ${volname} -format UDRW "${tmpDMG_path}" hdiutil attach $tmpDMG_path appleScript detachDMG hdiutil convert "${tmpDMG_path}" -format UDBZ -o "${finalDMG_path}" removeFiles } main
hdiutil打包dmg
最新推荐文章于 2024-12-30 14:32:16 发布