To create a DMG example using the command line

Source: Internet
Author: User
Tags mkdir set background

What is a DMG file and how do I open it?

The DMG format is a mirror file on a Mac system, or a compressed file, if you use a PC and don't have Mac OS X for X86, don't bother. If you are using an Apple or a Mac OS X for X86 on your PC, double-click the file on your Mac system to unlock it, and if you want to burn the file to a DVD, use Toast to burn the file to a disc: Dmg=>disc image

The command line creates the DMG

Automatically get software version number

The code is as follows Copy Code

App_name= "Soulver"
version=$ (/usr/libexec/plistbuddy-c print:cfbundleshortversionstring: "${app_name}.app/contents/info.plist")
Dmg_background_img= "Background.png"

Vol_name= "${app_name} ${version}"
dmg_tmp= "${VOL_NAME}-TEMP.DMG"
Dmg_final= "${VOL_NAME}.DMG"
Staging_dir= "./install"
Create DMG

# Clean folder
Rm-rf "${staging_dir}" "${dmg_tmp}" "${dmg_final}"
# Create folder, copy, Compute
mkdir-p "${staging_dir}"
CP -RPF "${app_name}.app" "${staging_dir}"
size= ' du-sh ' ${staging_dir} ' | sed ' s/([0-9.] *) M (. *)/1/' '
size= ' echo ' ${size} + 1.0 ' | bc | awk ' {print int ($1+0.5)} ' '
# Fault-Tolerant handling
If [$-ne 0]; then
&N bsp;  echo "Error:cannot compute size of staging dir"
   exit
Fi
# Create temporary DMG file
Hdiutil creat E-srcfolder "${staging_dir}"-volname "${vol_name}"-fs hfs+
     -fsargs "-C c=64,a=16,e =16 "-format udrw-size ${size}m" ${dmg_tmp} "
echo" Created dmg: ${dmg_tmp} "
Set DMG

device=$ (Hdiutil attach-readwrite-noverify "${dmg_tmp}" |
Egrep ' ^/dev/' | Sed 1q | awk ' {print '} ')
Sleep 2
# Add soft links to the applications directory
echo "Add link To/applications"
Pushd/volumes/"${vol_name}"
Ln-s/applications
popd
# Copy background picture
Mkdir/volumes/"${vol_name}"/.background
CP "${dmg_background_img}"/volumes/"${vol_name}"/.background/

# Set a series of window properties using AppleScript
Echo '
Tell Application "Finder"
Tell disk "' ${vol_name} '"
Open
Set current view of container windows 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, 938, 432}
Set Viewoptions to the icon view options of container window
Set arrangement of viewoptions to not arranged
Set icon size of Viewoptions to 72
Set background picture of viewoptions to file ". Background: ' ${dmg_background_img} '"
Set position of item "' ${app_name} '. APP" of container window to {160, 195}
Set position of item "Applications" of container window to {360, 195}
Close
Open
Update without registering applications
Delay 2
End Tell
End Tell
' | Osascript

Sync
# Uninstall
Hdiutil detach "${device}"
Compress DMG

echo "Creating compressed Image"
Hdiutil convert "${dmg_tmp}"-format Udzo-imagekey zlib-level=9-o "${dmg_final}"

# Clean Folder
Rm-rf "${dmg_tmp}"
Rm-rf "${staging_dir}"

Echo ' Done. '
Exit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.