15.4. Creating Fink Packages

 < Day Day Up > 

15.3. Disk Images

Many applications in Mac OS X do not require a special installer. Often, they can be installed by simply dragging the application's folder or icon to a convenient location in the directory structure, usually the /Applications folder. Applications that are distributed this way are typically packaged as a disk image. A disk image is a file that, when double-clicked, creates a virtual volume that is mounted as shown in Figure 15-7.

Inside Applications

Actually, an application is a folder with the extension .app, which is typically hidden from the user. This folder contains all of the application's resources.

To view the contents of an application bundle, Control-click on the application icon and select Show Package Contents from the pop-up menu; this opens the application's Contents folder in the Finder.

You can turn a Java application into a .app with the Jar Builder (/Developer/Applications/Java Tools). Since Mac OS X comes with Java, you can place your Java application on a disk image, secure in the knowledge that any Mac OS X user can double-click on the application to launch it.

Figure 15-7. A disk image and its mounted volume

Disk images can be created by using Disk Utility (/Applications/Utilities) or via the command line (described later). There are two types of disk images. One is a dual fork disk image with a .img extension, and the other is a single fork disk image with a .dmg extension. A dual fork disk image requires additional (MacBinary) encoding in order for it to be transferred across networks. The single fork version is preferred for distributing software in Mac OS X, as it requires no additional encoding and, as we shall see later, can be "Internet-enabled."

The Unix command df reveals a disk image as a mounted volume that will appear in the /Volumes directory. When you are done with the mounted volume, unmount it by clicking on the volume (in Figure 15-7, the mounted volume is named Fink 0.7.1 Installer) to select it and choose File Eject (-E). You could also Control-click and select Eject Disk from the contextual menu, or drag the mounted volume to the Trash.

15.3.1. Creating a Disk Image with Disk Utility

To create a disk image using Disk Utility, perform the following steps:

  1. Launch Disk Utility (/Applications/Utilities).

  2. Either select File New Blank Disk Image or click the New Image icon from the toolbar. Either way, Disk Utility prompts you for a name, location, size (the maximum size is limited by available disk space), encryption options, and format, as shown in Figure 15-8. If you choose to enable encryption, Disk Utility will prompt you for a passphrase.

    Figure 15-8. Creating a new blank image with Disk Utility

  3. Name the new image "MyDiskImage" and choose the Desktop as the location. The new image will be created as MyDiskImage.dmg and mounted as MyDiskImage. You can change this Volume name to, say "SampleVol," in the Finder.

  4. Double-click on the disk icon to open the empty volume in a Finder window, as shown in Figure 15-9.

  5. Select File New Finder Window (or -N) to open a new Finder window, where you can select the files you want to place in the disk image, as shown in Figure 15-10.

  6. To copy the files to the mounted volume, select and then drag the items into the empty SampleVol window.

    Figure 15-9. A blank disk image, ready to be loaded up with files

    Figure 15-10. Copying the file to the disk image

  7. Once you've placed the files into the disk image, eject this disk (-E, click the eject icon next to the SampleVol in the left column of the Finder, or drag SampleVol to the Trash).

  8. Return to the Disk Utility application, highlight MyDiskImage.dmg in the left column of Disk Utility, and select Images Convert, or click the Convert icon from the toolbar, as shown in Figure 15-11.

    Figure 15-11. Choosing the image to convert in Disk Utility

  9. In the Convert Image window, enter either a new name or the same name in the Save As field, and then select read-only from the Image Format pull-down menu, as shown in Figure 15-12. (You can also compress the disk image from this menu.)

  10. Click the Save button. If you've given the disk image the same filename as the original image you created, an alert window appears, asking you to confirm whether you want to replace the older file with the new one. Click Replace to finish the process, then quit Disk Utility with -Q.

Figure 15-12. Converting an image in Disk Utility

15.3.2. Creating a Disk Image from the Command Line

The following example illustrates how to create a disk image at the command line.

  1. Change (cd) to the directory where you want to create the disk image:

         $ cd ~/Documents

  2. Create the disk image of a given size (10 MB in this example) using hdiutil:

         $ hdiutil create -megabytes 10 -fs HFS+ \         -volname SampleVol Sample.dmg

  3. Mount the image as a volume. Since you named it SampleVol when you issued the hdiutil create command, it will be mounted as SampleVol and will be available in /Volumes/SampleVol:

         $ hdiutil mount Sample.dmg

  4. Use the Finder or command-line tools to write to the volume SampleVol.

  5. When you are done writing to the volume, you can eject it with hdiutil unmount:

         $ hdiutil unmount /Volumes/SampleVol/

  6. Copy the disk image to a compressed, read-only image named Ready4Dist.dmg:

         $ hdiutil convert -format UDZO Sample.dmg -o Ready4Dist.dmg

The UDZO format option is used to create a UDIF zlib-compressed image. Other formats can be chosen, for example, UDIF bzip2, which is available for Mac OS X 10.4+ and can be selected with the UDBZ format option. For a complete list of format options, see the manpage for hdiutil.

Whenever you want to mount this volume again, double-click the file Ready4Dist.dmg in the finder. Note that the writable disk image Sample.dmg is not destroyed in this process.

15.3.3. Distributing Your Image

Once you've created a disk image, you can share it with the world. Put the image up on a web server or FTP server for others to enjoy, share it on your iDisk, or burn it to a CD using Disk Utility (select either select Images Burn or press -B). Internet-enabled disk images

An Internet-enabled disk image is a read-only disk image that cleans up after itself, leaving only the software and no by-products of the download. If you distribute your software as an Internet-enabled disk image, the user just needs to perform these steps:

  1. Download the .dmg file to the Desktop (i.e., ~/Desktop) using a web browser.

  2. When the download completes, the following sequence of events happens automatically:

    1. The .dmg file is mounted.

    2. Its contents are copied to the user's default download folder (e.g., ~/Desktop).

    3. The disk image is unmounted.

    4. The Internet-enabled flag of the .dmg file is set to No.

    5. The .dmg file is moved to the Trash.

  3. Locate the software and move it to its appropriate location.

The disk image is mounted in a hidden location until its contents are copied to the user's default download folder, which is typically the Desktop folder. If the disk image contains a single file, only this file is copied. On the other hand, if the disk image contains more than one file, a new folder is created in the download folder bearing the root name of the .dmg file. Files contained in the disk image are then copied to this folder. For example, if the Internet-enabled disk image containing multiple files is named Sample.dmg, a folder named Sample will be created in the download folder and the files contained in the disk image will be copied to the Sample folder.

In this scheme, the user does not deal directly with the .dmg file (other than initiating the download). This is in contrast to the situation before Internet-enabled disk images were supported, in which the user had to manually unmount the disk image and drag it to the Trash.

To create an Internet-enabled disk image, first create a read-only .dmg formatted disk image as described earlier (neither read-write disk images nor older .img/.smi formats can be Internet-enabled), then set the Internet-enabled flag with the hdiutil command:

     $ hdiutil internet-enable -yes Ready4Dist.dmg 

If you want to disable the Internet-enabled flag, enter this command:

     $ hdiutil internet-enable -no Ready4Dist.dmg 

If you are not sure whether a disk image has its Internet-enabled flag set, the following command reveals this information:

     $ hdiutil internet-enable -query Ready4Dist.dmg 

As noted earlier, Internet-enabled disk images are moved to the Trash after they are downloaded and acted upon by Mac OS X. Although their Internet-enabled flags are set to No during the process, you can still rescue .dmg files from the Trash in case you want to reinstall the software later.

     < Day Day Up > 

    Mac OS X Tiger for Unix Geeks
    Mac OS X Tiger for Unix Geeks
    ISBN: 0596009127
    EAN: 2147483647
    Year: 2006
    Pages: 176

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net