#!/bin/sh # ***** BEGIN LICENSE BLOCK ***** # Version: MPL 1.1/GPL 2.0/LGPL 2.1 # # The contents of this file are subject to the Mozilla Public License Version # 1.1 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS IS" basis, # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License # for the specific language governing rights and limitations under the # License. # # The Original Code is the make-diskimage script. # # The Initial Developer of the Original Code is # Netscape Communications Corporation. # Portions created by the Initial Developer are Copyright (C) 2002 # the Initial Developer. All Rights Reserved. # # Contributor(s): # Brian Ryner # Jean-Jacques Enser # # Alternatively, the contents of this file may be used under the terms of # either the GNU General Public License Version 2 or later (the "GPL"), or # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), # in which case the provisions of the GPL or the LGPL are applicable instead # of those above. If you wish to allow use of your version of this file only # under the terms of either the GPL or the LGPL, and not to allow others to # use your version of this file under the terms of the MPL, indicate your # decision by deleting the provisions above and replace them with the notice # and other provisions required by the GPL or the LGPL. If you do not delete # the provisions above, a recipient may use your version of this file under # the terms of any one of the MPL, the GPL or the LGPL. # # ***** END LICENSE BLOCK ***** # Create a read-only disk image of the contents of a folder # # Usage: make-diskimage # # # # <.dsstore_file> # # # tip: use '-null-' for if you only want to # provide <.dsstore_file> and DMG_DIRNAME=`dirname $1` DMG_DIR=`cd $DMG_DIRNAME; pwd` DMG_NAME=`basename $1` DMG_TEMP_NAME=${DMG_DIR}/rw.${DMG_NAME} SRC_FOLDER=`cd $2; pwd` VOLUME_NAME=$3 # optional arguments EULA_RSRC=$4 DMG_DSSTORE=$5 DMG_BKGND_IMG=$6 # Find the size of the folder contents FOLDER_SIZE=`du -s $SRC_FOLDER | sed s/[^0-9].*//` # Allow for partition table and other overhead (3%) IMAGE_SIZE=$(($FOLDER_SIZE * 103/100)) # minimum size for an HFS+ partition is 4Mb [ $IMAGE_SIZE -lt 8300 ] && IMAGE_SIZE=8300 # Make sure NEXT_ROOT is not set (if we're building with an SDK) unset NEXT_ROOT echo FOLDER_SIZE=$FOLDER_SIZE echo IMAGE_SIZE=$IMAGE_SIZE # Create the image echo "creating disk image" hdiutil create -sectors $IMAGE_SIZE -fs HFS+ $DMG_TEMP_NAME -volname $VOLUME_NAME # mount it echo "mounting disk image" # `hdid -nomount rw.$DMG_NAME | grep "^/dev/disk.s2" | sed -e "s?^/dev/??" -e "s/[^0-9a-z].*//"` DEV_NAME=`hdid $DMG_TEMP_NAME | sed 1q | awk '{print $1}'` MOUNT_DIR=`hdid $DMG_TEMP_NAME | grep Apple_HFS | awk '{print $3}'` # copy content via ditto # # ditto fails when target has no space left or is read-only. Let's capture # that condition and cause the build to fail instead of silently moving ahead. # - cmp echo "copying content to disk image" ditto -rsrcFork $SRC_FOLDER $MOUNT_DIR rc=$? if [ $rc != "0" ]; then echo "ERROR: 'ditto -rsrcFork $SRC_FOLDER $MOUNT_DIR' failed ($rc)" exit 1 fi # add optional Finder window layout and background image if [ ! -z ${DMG_DSSTORE} ]; then echo "adding .DS_Store" cp -p ${DMG_DSSTORE} ${MOUNT_DIR}/.DS_Store fi if [ ! -z ${DMG_BKGND_IMG} ]; then echo "adding background image" mkdir ${MOUNT_DIR}/.background cp -p ${DMG_BKGND_IMG} ${MOUNT_DIR}/.background/ fi # make sure it's not world writeable echo "fixing permissions" chmod -R go-w ${MOUNT_DIR} # make the top window open itself on mount: if [ -x /usr/local/bin/openUp ]; then /usr/local/bin/openUp ${MOUNT_DIR} fi # unmnount echo "unmounting disk image" hdiutil detach $DEV_NAME # convert to read-only image echo "converting disk image to read-only" hdiutil convert $DMG_TEMP_NAME -format UDRO -o ${DMG_DIR}/${DMG_NAME} rm -f $DMG_TEMP_NAME # adding EULA resources if [ ! -z "${EULA_RSRC}" -a "${EULA_RSRC}" != "-null-" ]; then echo "adding EULA resources" hdiutil unflatten ${DMG_DIR}/${DMG_NAME} /Developer/Tools/ResMerger -a ${EULA_RSRC} -o ${DMG_DIR}/${DMG_NAME} hdiutil flatten ${DMG_DIR}/${DMG_NAME} fi echo "disk image done" exit 0