~widelands-dev/widelands/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
#
# Creates a DMG disk image for Mac OS X. The Widelands native application
# should be compiled before from the XCode project.
#
# Mac OS X 10.4 or higher is required.

# The path to Widelands application
APPLICATION=`dirname $0`/build/Release/Widelands.app

# Temporary directories
TMP_DIR="/tmp/wl_dmg"
FILES_DIR="$TMP_DIR/files"
MOUNT_DIR="$TMP_DIR/mount"

####
# Print the script usage
####
function print_usage() {
	echo "Usage: `basename $0` svn | release <name>"
	echo "  svn            Use SVN revision as name"
	echo "  release <name> Use the specified name"
}

####
# Collect all needed files into the DMG-source directory
#
# $1: Target directory
# $2: Widelands application
####
function collect_files() {
	
	cp -r $2 $1
#	ln -s /Applications $1/

	cp `dirname $0`/widelands-disk.icns $1/.VolumeIcon.icns

}

####
# Main
####

# Parse arguments
if [ -z $1 ]; then
	print_usage
	exit 1
elif [ $1 = svn ]; then
	revision=`\`dirname $0\`/../../utils/detect_revision.py`
elif [ $1 = release ]; then
	if [ -z $2 ]; then
		print_usage
		exit 1
	else
		 revision=$2
	 fi
else
	print_usage
	exit 1
fi

outfile=Widelands-$revision.dmg

# Tests if the DMG already exists
if [ -f $outfile ]; then
	echo "File $outfile already exists"
	echo "Overwrite not allowed (can be mounted)"
	exit 1
fi

# Tests if the application is built
if [ ! -d $APPLICATION ]; then
	echo "Widelands application not found, is it built ?"
	echo "Expected: $APPLICATION"
	exit 1
fi

# Creates the source directory
echo "Creating directory..."
if [ -e $FILES_DIR ]; then
	rm -r -f $FILES_DIR
fi
mkdir -p $FILES_DIR
mkdir -p $MOUNT_DIR
collect_files $FILES_DIR $APPLICATION

# Creates the DMG file
echo "Building a DMG image to $outfile..."
rm -f $TMP_DIR/readwrite.dmg
hdiutil create  \
  -srcfolder $FILES_DIR \
  -format UDRW \
  -fs HFS+ \
  -volname "Widelands $revision" \
  $TMP_DIR/readwrite.dmg

# Attach the image to set properties
echo "Setting filesystem properties..."
hdiutil attach $TMP_DIR/readwrite.dmg -readwrite -mountpoint $MOUNT_DIR -nobrowse
/Developer/Tools/SetFile -a C $MOUNT_DIR
hdiutil detach $MOUNT_DIR

# Convert with zlib compression
hdiutil convert $TMP_DIR/readwrite.dmg -format UDZO -o $outfile
rm -f $TMP_DIR/readwrite.dmg