-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmakeDMG.sh
executable file
·310 lines (277 loc) · 8.26 KB
/
makeDMG.sh
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/bin/sh
#
# This script will produce a dmg for DMDirc.
#
# DMDirc - Open Source IRC Client
# Copyright (c) 2006-2017 DMDirc Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
showHelp() {
echo "This will generate a DMDirc osx package."
echo "The following command line arguments are known:"
echo "---------------------"
echo "-h, --help Help information"
echo "-j, --jar <jar> What jar to use for the package (requires --version)"
echo "-v, --version <version> What version is this package."
echo "-p, --packagename <name> Name for output (rather than DMDirc-<version>"
echo "-e, --extra <extra> Extra tagging on output file."
echo "---------------------"
exit 0;
}
JAR=""
VERSION=""
finalTag=""
PACKAGENAME=""
while test -n "$1"; do
case "$1" in
--jar|-j)
shift
JAR=${1}
;;
--version|-v)
shift
VERSION=${1}
;;
--help|-h)
showHelp;
;;
--packagename|-p)
shift
PACKAGENAME="${1}"
;;
--extra|-e)
shift
finalTag="${1}"
;;
esac
shift
done
if [ "${JAR}" = "" -o "${VERSION}" = "" -o ! -e "${JAR}" ]; then
echo "You must provide a jar file and a version number to continue."
exit 1;
fi;
# Find out where we are
BASEDIR=$(cd "${0%/*}" 2>/dev/null; echo $PWD)
cd "${BASEDIR}"
# Check that we can create dmg files.
MKISOFS=`which mkisofs`
HDIUTIL=`which hdiutil`
if [ "" = "${HDIUTIL}" ]; then
if [ "" != "${MKISOFS}" ]; then
MKISOFS_TEST=`${MKISOFS} --help 2>&1 | grep apple`
if [ "" = "${MKISOFS_TEST}" ]; then
echo "This machine is unable to produce dmg images (no support from mkisofs). Aborting."
exit 1;
fi;
else
echo "This machine is unable to produce dmg images (missing mkisofs or hdiutil). Aborting."
exit 1;
fi;
fi;
# Go into the OS X dir and check that the jni lib exists, if not try to compile
# it (this will only work on a mac)
#
# We do this here so that we have it for future if needed rather than needing to
# do it every time.
cd osx
JNIName="libDMDirc-Apple.jnilib"
if [ ! -e "${JNIName}" ]; then
if [ -e "/System/Library/Frameworks/JavaVM.framework/Headers" ]; then
GCC=`which gcc`
${GCC} -dynamiclib -framework JavaVM -framework Carbon -o ${JNIName} DMDirc-Apple.c -arch x86_64
if [ ! -e "${JNIName}" ]; then
echo "JNI Lib not found and failed to compile. Aborting."
exit 1;
fi;
else
echo "JNI Lib not found, unable to compile on this system. Aborting."
exit 1;
fi;
fi;
cd "${BASEDIR}"
WGET=`which wget`
FETCH=`which fetch`
CURL=`which curl`
getFile() {
URL=${1}
OUTPUT=${2}
if [ "${WGET}" != "" ]; then
${WGET} -O ${OUTPUT} ${URL}
elif [ "${FETCH}" != "" ]; then
${FETCH} -o ${OUTPUT} ${URL}
elif [ "${CURL}" != "" ]; then
${CURL} -o ${OUTPUT} ${URL}
fi;
}
cd "${BASEDIR}"
# Where will we be building DMDirc today?
BUILDDIR=`mktemp -d "--tmpdir=${BASEDIR}"`
echo "Building in: '${BUILDDIR}'"
# Create required OS X directories.
APPDIR="${BUILDDIR}/DMDirc.app"
CONTENTSDIR="${APPDIR}/Contents"
RESDIR="${CONTENTSDIR}/Resources"
MACOSDIR="${CONTENTSDIR}/MacOS"
mkdir -pv "${APPDIR}"
mkdir -pv "${CONTENTSDIR}"
mkdir -pv "${RESDIR}"
mkdir -pv "${RESDIR}/Java"
mkdir -pv "${MACOSDIR}"
mkdir -pv "${BUILDDIR}/.background/"
# Copy in required files.
cp "${JAR}" "${RESDIR}/Java/DMDirc.jar"
cp "osx/${JNIName}" "${RESDIR}/Java/${JNIName}"
cp "launcher/unix/DMDirc.sh" "${MACOSDIR}/DMDirc.sh"
cp "launcher/unix/functions.sh" "${MACOSDIR}/functions.sh"
cp "osx/res/dmdirc.icns" "${RESDIR}/dmdirc.icns"
cp -v "osx/res/VolumeIcon.icns" "${BUILDDIR}/.VolumeIcon.icns"
cp -v "osx/res/Background.png" "${BUILDDIR}/.background/background.png"
cp -v "osx/.DS_Store" "${BUILDDIR}/.DS_Store"
ln -sf /Applications ${BUILDDIR}/
echo "Creating meta files"
echo "APPLDMDI" > "${CONTENTSDIR}/PkgInfo"
# Create the plist file
cat <<EOF> "${CONTENTSDIR}/Info.plist"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>CFBundleName</key>
<string>DMDirc</string>
<key>CFBundleIdentifier</key>
<string>com.dmdirc.osx</string>
<key>CFBundleAllowMixedLocalizations</key>
<string>true</string>
<key>CFBundleExecutable</key>
<string>DMDirc.sh</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>DMDI</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleIconFile</key>
<string>dmdirc.icns</string>
<key>CFBundleVersion</key>
<string>${VERSION}</string>
<key>CFBundleShortVersionString</key>
<string>${VERSION}</string>
<key>Java</key>
<dict>
<key>WorkingDirectory</key>
<string>\$APP_PACKAGE/Contents/Resources/Java</string>
<key>MainClass</key>
<string>com.dmdirc.Main</string>
<key>JVMVersion</key>
<string>1.6+</string>
<key>ClassPath</key>
<string>\$JAVAROOT/DMDirc.jar</string>
</dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>IRC URL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>irc</string>
</array>
</dict>
</array>
</dict>
</plist>
EOF
# Now, make a dmg
OUTPUTFILE="DMDirc.dmg"
rm -Rf "${OUTPUTFILE}" "${OUTPUTFILE}.pre"
if [ "" = "${HDIUTIL}" ]; then
# File Mapping.
MAPFILE=`mktemp`
echo ".icns Raw 'icnC' 'ICON' \"Icon File\"" > ${MAPFILE}
# Create Read-Only blessed image
${MKISOFS} -V 'DMDirc' -no-pad -r -apple -map ${MAPFILE} -o "${OUTPUTFILE}" -hfs-bless "${BUILDDIR}" "${BUILDDIR}"
rm ${MAPFILE};
# Compres it \o
if [ ! -e "osx/compress-dmg" ]; then
getFile "http://binary.dmdirc.com/dmg" "osx/compress-dmg"
chmod a+x osx/compress-dmg
fi;
if [ ! -e "osx/compress-dmg" ]; then
echo "DMG will not be compressed."
else
echo "Compressing DMG"
mv "${OUTPUTFILE}" "${OUTPUTFILE}.pre"
osx/compress-dmg dmg "${OUTPUTFILE}.pre" "${OUTPUTFILE}"
if [ -e "${OUTPUTFILE}" ]; then
rm -Rf "${OUTPUTFILE}.pre"
else
echo "Compression failed."
mv "${OUTPUTFILE}.pre" "${OUTPUTFILE}"
fi;
fi;
else
# Set information for the volume icon
SETFILE=`ls /Developer/Tools/SetFile`
if [ "" != "${SETFILE}" ]; then
${SETFILE} -c icnC "${BUILDDIR}/.VolumeIcon.icns"
fi;
# OSX
# Create Read/Write image
${HDIUTIL} create -volname "DMDirc" -fs HFS+ -srcfolder "${BUILDDIR}" -format UDRW "${OUTPUTFILE}.pre"
# Make it auto-open
BLESS=`which bless`
if [ "" != "${BLESS}" ]; then
if [ -e /Volumes/DMDirc ]; then
${HDIUTIL} detach /Volumes/DMDirc
fi;
if [ ! -e /Volumes/DMDirc ]; then
${HDIUTIL} attach "${OUTPUTFILE}.pre"
${BLESS} -openfolder /Volumes/DMDirc
${HDIUTIL} detach /Volumes/DMDirc
fi;
fi;
# Fix VolumeIcon
if [ "" != "${SETFILE}" ]; then
if [ -e /Volumes/DMDirc ]; then
${HDIUTIL} detach /Volumes/DMDirc
fi;
if [ ! -e /Volumes/DMDirc ]; then
${HDIUTIL} attach "${OUTPUTFILE}.pre"
${SETFILE} -a C /Volumes/DMDirc
${HDIUTIL} detach /Volumes/DMDirc
fi;
fi;
# Convert to compressed read-only image
${HDIUTIL} convert "${OUTPUTFILE}.pre" -format UDZO -imagekey zlib-level=9 -o "${OUTPUTFILE}"
rm "${OUTPUTFILE}.pre"
fi;
if [ "${PACKAGENAME}" = "" ]; then
DEST="DMDirc-${VERSION}"
else
DEST="${PACKAGENAME}"
fi
if [ "${finalTag}" != "" ]; then
DEST="${DEST}-${finalTag}"
fi;
DEST="${DEST}.dmg"
mv "${OUTPUTFILE}" "output/${DEST}"
rm -Rf "${OUTPUTFILE}" "${OUTPUTFILE}.pre" "${BUILDDIR}"
echo "DMG Creation complete!"