2
# ***** BEGIN LICENSE BLOCK *****
3
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
# The contents of this file are subject to the Mozilla Public License Version
6
# 1.1 (the "License"); you may not use this file except in compliance with
7
# the License. You may obtain a copy of the License at
8
# http://www.mozilla.org/MPL/
10
# Software distributed under the License is distributed on an "AS IS" basis,
11
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
# for the specific language governing rights and limitations under the
15
# The Original Code is the make-diskimage script.
17
# The Initial Developer of the Original Code is
18
# Netscape Communications Corporation.
19
# Portions created by the Initial Developer are Copyright (C) 2002
20
# the Initial Developer. All Rights Reserved.
23
# Brian Ryner <bryner@brianryner.com>
24
# Jean-Jacques Enser <jj@netscape.com>
26
# Alternatively, the contents of this file may be used under the terms of
27
# either the GNU General Public License Version 2 or later (the "GPL"), or
28
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
# in which case the provisions of the GPL or the LGPL are applicable instead
30
# of those above. If you wish to allow use of your version of this file only
31
# under the terms of either the GPL or the LGPL, and not to allow others to
32
# use your version of this file under the terms of the MPL, indicate your
33
# decision by deleting the provisions above and replace them with the notice
34
# and other provisions required by the GPL or the LGPL. If you do not delete
35
# the provisions above, a recipient may use your version of this file under
36
# the terms of any one of the MPL, the GPL or the LGPL.
38
# ***** END LICENSE BLOCK *****
40
# Create a read-only disk image of the contents of a folder
42
# Usage: make-diskimage <image_file>
45
# <eula_resource_file>
47
# <background_image_file>
49
# tip: use '-null-' for <eula-resource-file> if you only want to
50
# provide <.dsstore_file> and <background_image_file>
52
DMG_DIRNAME=`dirname $1`
53
DMG_DIR=`cd $DMG_DIRNAME; pwd`
54
DMG_NAME=`basename $1`
55
DMG_TEMP_NAME=${DMG_DIR}/rw.${DMG_NAME}
56
SRC_FOLDER=`cd $2; pwd`
64
# Find the size of the folder contents
65
FOLDER_SIZE=`du -s $SRC_FOLDER | sed s/[^0-9].*//`
67
# Allow for partition table and other overhead (3%)
68
IMAGE_SIZE=$(($FOLDER_SIZE * 103/100))
69
# minimum size for an HFS+ partition is 4Mb
70
[ $IMAGE_SIZE -lt 8300 ] && IMAGE_SIZE=8300
72
# Make sure NEXT_ROOT is not set (if we're building with an SDK)
75
echo FOLDER_SIZE=$FOLDER_SIZE
76
echo IMAGE_SIZE=$IMAGE_SIZE
79
echo "creating disk image"
80
hdiutil create -sectors $IMAGE_SIZE -fs HFS+ $DMG_TEMP_NAME -volname $VOLUME_NAME
83
echo "mounting disk image"
84
# `hdid -nomount rw.$DMG_NAME | grep "^/dev/disk.s2" | sed -e "s?^/dev/??" -e "s/[^0-9a-z].*//"`
85
DEV_NAME=`hdid $DMG_TEMP_NAME | sed 1q | awk '{print $1}'`
86
MOUNT_DIR=`hdid $DMG_TEMP_NAME | grep Apple_HFS | awk '{print $3}'`
89
echo "copying content to disk image"
90
ditto -rsrcFork $SRC_FOLDER $MOUNT_DIR
91
# add optional Finder window layout and background image
92
if [ ! -z ${DMG_DSSTORE} ]; then
93
echo "adding .DS_Store"
94
cp -p ${DMG_DSSTORE} ${MOUNT_DIR}/.DS_Store
96
if [ ! -z ${DMG_BKGND_IMG} ]; then
97
echo "adding background image"
98
mkdir ${MOUNT_DIR}/.background
99
cp -p ${DMG_BKGND_IMG} ${MOUNT_DIR}/.background/
102
# make sure it's not world writeable
103
echo "fixing permissions"
104
chmod -R go-w ${MOUNT_DIR}
106
# make the top window open itself on mount:
107
if [ -x /usr/local/bin/openUp ]; then
108
/usr/local/bin/openUp ${MOUNT_DIR}
112
echo "unmounting disk image"
113
hdiutil detach $DEV_NAME
115
# convert to read-only image
116
echo "converting disk image to read-only"
117
hdiutil convert $DMG_TEMP_NAME -format UDRO -o ${DMG_DIR}/${DMG_NAME}
120
# adding EULA resources
121
if [ ! -z "${EULA_RSRC}" -a "${EULA_RSRC}" != "-null-" ]; then
122
echo "adding EULA resources"
123
hdiutil unflatten ${DMG_DIR}/${DMG_NAME}
124
/Developer/Tools/ResMerger -a ${EULA_RSRC} -o ${DMG_DIR}/${DMG_NAME}
125
hdiutil flatten ${DMG_DIR}/${DMG_NAME}
128
echo "disk image done"