-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprep-dmg
executable file
·272 lines (245 loc) · 6.88 KB
/
prep-dmg
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
#!/bin/bash
QT_DIR="/Developer/Applications/Qt"
APP_NAME="NONE"
APP_VERSION="0.1"
APP_BINS="NONE"
APP_ICON="NONE"
APP_LICENSE="NONE"
APP_PLIST="NONE"
APP_DSSTORE="NONE"
APP_EXTRA="NONE"
APP_LIBPATH="NONE"
APP_QML="NONE"
usage()
{
echo "Usage: $0 [options]"
echo " -a <Application name>"
echo " -d <Qt root dir>"
echo " -e <Extra files / dirs to add, space separated>"
echo " -b <Application binary to copy>"
echo " -i <Icon to generate icon set from>"
echo " -l <License file to copy>"
echo " -L <Additional search path for libraries>"
echo " -p <Target Info.plist for the application>"
echo " -q <QML-containing dir to add to deployment>"
echo " -v <Application version>"
exit 1
}
# Parse options
while getopts "a:b:d:e:i:l:L:v:p:q:" opt
do
case $opt in
a)
APP_NAME=${OPTARG}
echo "Application name set to '${APP_NAME}'."
;;
b)
APP_BINS=${OPTARG}
echo "Binaries to copy (space separated) are '${APP_BINS}'."
;;
d)
QT_DIR=${OPTARG}
echo "Qt root directory is '${QT_DIR}'."
;;
e)
APP_EXTRA=${OPTARG}
echo "Extra files / dirs to add are '${APP_EXTRA}'."
;;
i)
APP_ICON=${OPTARG}
echo "Icon to generate icon set from is '${APP_ICON}'."
;;
l)
APP_LICENSE=${OPTARG}
echo "License file to copy is '${APP_LICENSE}'."
;;
L)
APP_LIBPATH=${OPTARG}
echo "Extra library path is '${APP_LIBPATH}'."
;;
p)
APP_PLIST=${OPTARG}
echo "PList file to use is '${APP_PLIST}'."
;;
q)
APP_QML=${OPTARG}
echo "QML dir to include is '${APP_QML}'."
;;
v)
APP_VERSION=${OPTARG}
echo "Application version set to '${APP_VERSION}'."
;;
*)
usage
;;
esac
done
# Enable erroring
set -e
# /-----------------\
# | Check variables |
# \-----------------/
# -- Check for NONE being specified for a critical variable
if [ "${APP_NAME}" = "NONE" ] || [ "${APP_BINS}" = "NONE" ] || [ "${APP_PLIST}" = "NONE" ]
then
echo "One or more critical variables have not been defined."
echo "name=[${APP_NAME}] bin=[${APP_BINS}] plist=[${APP_PLIST}]"
exit 1
fi
# Check existence of plist file
if [ ! -e "${APP_PLIST}" ]
then
echo "Error: Specified plist file does not exist: ${APP_PLIST}"
exit 1
fi
# Check existence of (optional) license file
if [ "${APP_LICENSE}" != "NONE" ] && [ ! -e "${APP_LICENSE}" ]
then
echo "Error: Specified license file does not exist: ${APP_LICENSE}"
exit 1
fi
# Check existence of (optional) extra data
if [ "${APP_EXTRA}" != "NONE" ]
then
for a in ${APP_EXTRA};
do
if [ ! -e "${a}" ]; then
echo "Error: Specified extra data does not exist: ${a}"
exit 1
fi
done
fi
# /-------------------\
# | Create bundle dir |
# \-------------------/
echo -e "\nCreating bundle directory structure....\n"
# -- Construct full name of the package directory and create dir
APP_ROOT=${APP_NAME}-${APP_VERSION}
# -- Create new directory structure for our bundle
if [ -e "${APP_ROOT}" ]; then rm -rf ${APP_ROOT}; fi
APP_CONTENTS=${APP_ROOT}/${APP_NAME}.app/Contents
mkdir -vp ${APP_CONTENTS}
APP_FRAMEWORKS=${APP_CONTENTS}/Frameworks
APP_BINARIES=${APP_CONTENTS}/MacOS
APP_LIBRARIES=${APP_CONTENTS}/lib
APP_PLUGINS=${APP_CONTENTS}/PlugIns
APP_RESOURCES=${APP_CONTENTS}/Resources
APP_SHAREDSUPPORT=${APP_CONTENTS}/SharedSupport
mkdir -v ${APP_FRAMEWORKS} ${APP_BINARIES} ${APP_LIBRARIES} ${APP_PLUGINS} ${APP_RESOURCES}
# /-----------------\
# | Copy plist file |
# \-----------------/
echo -e "\nCopy plist file....\n"
if ! cp -v ${APP_PLIST} ${APP_CONTENTS}; then
echo "Error: Failed to copy plist file: ${APP_PLIST}"
exit 1
fi
# /---------------\
# | Copy binaries |
# \---------------/
echo -e "\nCopying binary files....\n"
# -- Loop over files
for binary in ${APP_BINS};
do
if [ ! -e $binary ]; then
echo "Error: Specified binary does not exist: $binary"
exit 1
fi
if ! cp -v $binary ${APP_BINARIES}; then
echo "Error: Failed to copy binary: $binary"
exit 1
fi
done
# /-----------------\
# | Run macdeployqt |
# \-----------------/
echo -e "\nRunning macdeployqt....\n"
if [ "x${APP_QML}" != "xNONE" ];
then
$QT_DIR/bin/macdeployqt ${APP_ROOT}/${APP_NAME}.app -verbose=2 -libpath=$APP_LIBPATH -qmldir=${APP_QML}
else
$QT_DIR/bin/macdeployqt ${APP_ROOT}/${APP_NAME}.app -verbose=2 -libpath=$APP_LIBPATH
fi
# Run otool on the binaries to show link paths for libs
for target in ${APP_BINARIES}/*
do
otool -L $target
done
# /------------------\
# | Generate iconset |
# \------------------/
if [ "x${APP_ICON}" != "xNONE" ];
then
echo -e "\nGenerating iconset....\n"
if [ ! -e ${APP_ICON} ]; then
echo "Error: Specified icon file does not exist: ${APP_ICON}"
exit 1
fi
mkdir ${APP_NAME}.iconset
sips -z 16 16 ${APP_ICON} --out ${APP_NAME}.iconset/icon_16x16.png
sips -z 32 32 ${APP_ICON} --out ${APP_NAME}.iconset/[email protected]
sips -z 32 32 ${APP_ICON} --out ${APP_NAME}.iconset/icon_32x32.png
sips -z 64 64 ${APP_ICON} --out ${APP_NAME}.iconset/[email protected]
sips -z 128 128 ${APP_ICON} --out ${APP_NAME}.iconset/icon_128x128.png
sips -z 256 256 ${APP_ICON} --out ${APP_NAME}.iconset/[email protected]
sips -z 256 256 ${APP_ICON} --out ${APP_NAME}.iconset/icon_256x256.png
sips -z 512 512 ${APP_ICON} --out ${APP_NAME}.iconset/[email protected]
sips -z 512 512 ${APP_ICON} --out ${APP_NAME}.iconset/icon_512x512.png
cp -v ${APP_ICON} ${APP_NAME}.iconset/[email protected]
iconutil -c icns ${APP_NAME}.iconset
if ! cp -v ${APP_NAME}.icns ${APP_RESOURCES}; then
echo "Error: Failed to copy icon file: ${APP_ICON}"
exit 1
fi
if ! cp -v ${APP_NAME}.icns ${APP_ROOT}/.VolumeIcon.icns; then
echo "Error: Failed to copy icon file: ${APP_ICON}"
exit 1
fi
rm -rf ${APP_NAME}.iconset ${APP_NAME}.icns
fi
# /--------------\
# | Copy license |
# \--------------/
echo -e "\nCopying license....\n"
if [ "${APP_LICENSE}" != "NONE" ];
then
if ! cp -v ${APP_LICENSE} ${APP_ROOT}/.COPYING; then
echo "Error: Failed to copy license file: ${APP_LICENSE}"
exit 1
fi
fi
# /-----------------\
# | Copy extra data |
# \-----------------/
if [ "x${APP_EXTRA}" != "xNONE" ];
then
echo -e "\nCopying extra data....(${APP_EXTRA})\n"
mkdir -v "${APP_SHAREDSUPPORT}"
for a in ${APP_EXTRA};
do
if [ ! -e "${a}" ]; then
echo "Error: Specified extra data does not exist: ${a}"
exit 1
fi
if ! cp -rv "${APP_EXTRA}" "${APP_SHAREDSUPPORT}"; then
echo "Error: Failed to copy extra data from: ${APP_EXTRA}"
exit 1
fi
done
fi
# /--------------------------\
# | Copy background/DS_Store |
# \--------------------------/
if [ "x${APP_DSSTORE}" != "xNONE" ];
then
echo -e "\nCopying DS_Store information....\n"
if [ ! -e ${APP_DSSTORE} ]; then
echo "Error: Specified DS_Store file does not exist: ${APP_DSSTORE}"
exit 1
fi
if ! cp -rv ${APP_DSSTORE}/ ${APP_ROOT}; then
echo "Error: Failed to copy DS_Store files."
exit 1
fi
fi
exit 0