hdiutil打包dmg

  • 先创建一个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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值