Creating a .DMG

后端 未结 4 994
渐次进展
渐次进展 2020-12-23 10:44

I want to create a dmg file for my Mac project. Can someone please tell me how to do this? This being my first Mac project, I do not have any idea how to proceed. I also wan

4条回答
  •  佛祖请我去吃肉
    2020-12-23 11:03

    I made a little bash script to automate a disc image creation.

    It creates a temporary directory to store all needed files then export it in a new DMG file. Temporary directory is then deleted. You can automatically launch this script at the end of your build process.

    #!/bin/bash
    # Create .dmg file for macOS
    
    # Adapt these variables to your needs
    APP_VERS="1.0"
    DMG_NAME="MyApp_v${APP_VERS}_macos"
    OUTPUT_DMG_DIR="path_to_output_dmg_file"
    APP_FILE="path_to_my_app/MyApp.app"
    OTHER_FILES_TO_INCLUDE="path_to_other_files"
    
    
    # The directory of the script
    DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    
    # The temp directory used, within $DIR
    WORK_DIR=`mktemp -d "${DIR}/tmp"`
    
    # Check if tmp dir was created
    if [[ ! "${WORK_DIR}" || ! -d "${WORK_DIR}" ]]; then
        echo "Could not create temp dir"
        exit 1
    fi
    
    # Function to deletes the temp directory
    function cleanup {
        rm -rf "${WORK_DIR}"
        #echo "Deleted temp working directory ${WORK_DIR}"
    }
    
    # Register the cleanup function to be called on the EXIT signal
    trap cleanup EXIT
    
    # Copy application on temp dir
    cp -R "${APP_FILE}" "${WORK_DIR}"
    # Copy other files without hidden files
    rsync -a --exclude=".*" "${OTHER_FILES_TO_INCLUDE}" "${WORK_DIR}"
    
    # Create .dmg
    hdiutil create -volname "${DMG_NAME}" -srcfolder "${WORK_DIR}" -ov -format UDZO "${OUTPUT_DMG_DIR}/${DMG_NAME}.dmg"
    

提交回复
热议问题