-
Notifications
You must be signed in to change notification settings - Fork 22
/
pack.sh
executable file
·351 lines (310 loc) · 14.4 KB
/
pack.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/usr/bin/env bash
# Exit on error
set -e
BUILD_DIR=`pwd`
WORKING_DIR="${BUILD_DIR}/TMP"
RELEASE_DIR="${BUILD_DIR}/releases"
CONFIG_FILE="${BUILD_DIR}/config.json"
if [[ "${2}" =~ "--config" ]]; then
CONFIG_FILE="${2#*=}";
fi
get_value_by_key() {
JSON_FILE=${CONFIG_FILE}
KEY=${1}
REGEX="(?<=\"${KEY}\":.\")[^\"]*"
JSON_VALUE=$(cat ${JSON_FILE} | grep -Po ${REGEX})
echo ${JSON_VALUE}
}
# Name of your package
PKG_NAME=$(get_value_by_key name)
if [[ ! -f "${WORKING_DIR}" ]]; then
mkdir -p TMP
fi
architechture="ia32 x64"
architechtureMacos="x64"
usage() {
clear && cat <<EOF
NAME
NWJS app pack script
DESCRIPTION
Build installers for Windows, Linux and OSX
DEPENDENCIES
Zip (all)
tar (all)
NSIS (Windows installer)
ImageMagick (OSX installer)
cpio (OSX installer)
libxml2 (OSX installer)
USAGE
$ ./pack.sh init - generate 'config.json' with interactive CMD
$ ./pack.sh --windows - to build Windows installers
$ ./pack.sh --linux - to build Linux installers
$ ./pack.sh --osx - to build OSX installers
$ ./pack.sh --all - to build installers for all systems
$ ./pack.sh --all --config=/path/to/config.json - to build installers for all systems but using 'config.json' located in any other path than in root directory
$ ./pack.sh --clean - removes the 'TMP' working directory
$ ./pack.sh --clean all - removes the 'TMP' working directory and 'releases' directory (with all the content)
Hooks:
Place hooks in "./hooks/" directory
- file name 'before.sh' will be executed befor each build
- file name 'after.sh' will be executed after pack script is finished
- file name 'after_build.sh' will be executed after each platform build is finished
EOF
}
init_config_file() {
set -i
read -e -p "Application name (no spaces): " CONF_NAME;
read -e -p "Application version: " -i "1.0.0" CONF_VERSION;
read -e -p "Application description: " -i "${CONF_NAME} v${CONF_VERSION} Application" CONF_DESCRIPTION;
read -e -p "nwjs version to use: " -i "0.12.3" CONF_NW_VERSION;
read -e -p "Application src directory path: " CONF_SRC;
read -e -p "PNG icon path: " CONF_ICON_PNG;
read -e -p "Windows icon (.ico) path: " CONF_ICON_WIN;
read -e -p "OSX icon (.icns) path: " CONF_ICON_OSX;
read -e -p "OSX .pkg background file path: " CONF_osxBgPath
read -e -p "OSX CFBundleIdentifier: " CONF_CFBundleIdentifier;
read -e -p "License file path: " CONF_LICENSE;
cat << create_conf > config.json
{
"name": "${CONF_NAME}",
"description": "${CONF_DESCRIPTION}",
"version": "${CONF_VERSION}",
"nwjsVersion": "${CONF_NW_VERSION}",
"src": "${CONF_SRC}",
"iconPath": "${CONF_ICON_PNG}",
"windowsIconPath": "${CONF_ICON_WIN}",
"osxIconPath": "${CONF_ICON_OSX}",
"osxBgPath": "${CONF_osxBgPath}",
"CFBundleIdentifier": "${CONF_CFBundleIdentifier}",
"license": "${CONF_LICENSE}"
}
create_conf
}
check_dependencies() {
# Check if NSIS is present
if [[ "`makensis`" =~ "MakeNSIS" && "`convert`" =~ "Version: ImageMagick" ]]; then
echo 'OK';
else
echo 'NO';
fi
}
pack_linux () {
for arch in ${architechture[@]}; do
cd ${WORKING_DIR}
cp -R ${BUILD_DIR}/resources/linux/PKGNAME-VERSION-Linux ${BUILD_DIR}/TMP/$(get_value_by_key name)-$(get_value_by_key version)-Linux-${arch}
PKG_MK_DIR=${BUILD_DIR}/TMP/$(get_value_by_key name)-$(get_value_by_key version)-Linux-${arch}
mv ${PKG_MK_DIR}/PKGNAME ${PKG_MK_DIR}/$(get_value_by_key name)
mv ${PKG_MK_DIR}/$(get_value_by_key name)/PKGNAME ${PKG_MK_DIR}/$(get_value_by_key name)/$(get_value_by_key name)
# replaces
sed -i "s/PKGNAME/$(get_value_by_key name)/gi" {PKG_MK_DIR}/README
sed -i "s/PKGDESCRIPTION/$(get_value_by_key description)/gi" {PKG_MK_DIR}/README
sed -i "s/PKGNAME/$(get_value_by_key name)/gi" ${PKG_MK_DIR}/$(get_value_by_key name)/$(get_value_by_key name)
sed -i "s/PKGNAME/$(get_value_by_key name)/gi" ${PKG_MK_DIR}/setup
# app file
mkdir ${PKG_MK_DIR}/share/pixmaps
cp $(get_value_by_key iconPath) ${PKG_MK_DIR}/share/pixmaps/$(get_value_by_key name).png
convert ${PKG_MK_DIR}/share/pixmaps/$(get_value_by_key name).png ${PKG_MK_DIR}/share/pixmaps/$(get_value_by_key name).xpm
cp -R ${BUILD_DIR}/TMP/linux-${arch}/latest-git/* ${PKG_MK_DIR}/$(get_value_by_key name)/
mv ${PKG_MK_DIR}/$(get_value_by_key name)/$(get_value_by_key name) ${PKG_MK_DIR}/$(get_value_by_key name)/$(get_value_by_key name)-bin
# application
mv ${PKG_MK_DIR}/share/applications/PKGNAME.desktop ${PKG_MK_DIR}/share/applications/$(get_value_by_key name).desktop
sed -i "s/PKGNAME/$(get_value_by_key name)/gi" ${PKG_MK_DIR}/share/applications/$(get_value_by_key name).desktop
sed -i "s/PKGVERSION/$(get_value_by_key version)/gi" ${PKG_MK_DIR}/share/applications/$(get_value_by_key name).desktop
# menu
mv ${PKG_MK_DIR}/share/menu/PKGNAME ${PKG_MK_DIR}/share/menu/$(get_value_by_key name)
sed -i "s/PKGNAME/$(get_value_by_key name)/gi" ${PKG_MK_DIR}/share/menu/$(get_value_by_key name)
# make the tar
tar -C ${WORKING_DIR} -czf $(get_value_by_key name)-$(get_value_by_key version)-Linux-${arch}.tar.gz $(get_value_by_key name)-$(get_value_by_key version)-Linux-${arch}
mv ${WORKING_DIR}/$(get_value_by_key name)-$(get_value_by_key version)-Linux-${arch}.tar.gz ${RELEASE_DIR}
printf "\nDone Linux ${arch}\n"
done;
}
pack_osx () {
for arch in ${architechtureMacos[@]}; do
cd ${WORKING_DIR}
if [[ ! -d "${WORKING_DIR}/bomutils" ]]; then
git clone https://github.com/hogliux/bomutils && cd bomutils && make && cd ${WORKING_DIR}
fi
if [[ ! -d "${WORKING_DIR}/xar-xar-1.5.2" ]]; then
wget https://github.com/mackyle/xar/archive/xar-1.5.2.tar.gz && tar -zxvf ./xar-1.5.2.tar.gz && cd xar-xar-1.5.2 && ./autogen.sh && make && cd ${WORKING_DIR}
fi
mkdir -p ${WORKING_DIR}/build_osx/flat/base.pkg
mkdir -p ${WORKING_DIR}/build_osx/flat/Resources/en.lproj
mkdir -p ${WORKING_DIR}/build_osx/root/Applications
cp -R "${WORKING_DIR}/osx-${arch}/latest-git/$(get_value_by_key name).app" ${WORKING_DIR}/build_osx/root/Applications/
( cd ${WORKING_DIR}/build_osx/root/Applications && chmod -R a+xr $(get_value_by_key name).app )
local COUNT_FILES=$(find ${WORKING_DIR}/build_osx/root | wc -l)
local INSTALL_KB_SIZE=$(du -k -s ${WORKING_DIR}/build_osx/root | awk '{print $1}')
( cd ${WORKING_DIR}/build_osx/root && find . | cpio -o --format odc --owner 0:80 | gzip -c ) > ${WORKING_DIR}/build_osx/flat/base.pkg/Payload
cat << osx_packageinfo_helper > ${WORKING_DIR}/build_osx/flat/base.pkg/PackageInfo
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<pkg-info overwrite-permissions="true" relocatable="false" identifier="$(get_value_by_key CFBundleIdentifier).base.pkg" postinstall-action="none" version="$(get_value_by_key version)" format-version="2" generator-version="InstallCmds-502 (14B25)" auth="root">
<payload installKBytes="${INSTALL_KB_SIZE}" numberOfFiles="${COUNT_FILES}"/>
<bundle-version>
<bundle id="$(get_value_by_key CFBundleIdentifier)" CFBundleIdentifier="$(get_value_by_key CFBundleIdentifier)" path="./Applications/$(get_value_by_key name).app" CFBundleVersion="1.3.0"/>
</bundle-version>
<update-bundle/>
<atomic-update-bundle/>
<strict-identifier/>
<scripts/>
</pkg-info>
osx_packageinfo_helper
local BG=$(get_value_by_key osxBgPath)
if [[ -f ${BG} ]];then
cp "${BG}" "${WORKING_DIR}/build_osx/flat/Resources/en.lproj/background"
local BG_NODE='<background file="background" alignment="bottomleft" scaling="none"/>'
fi
cat << osx_distribution_helper > ${WORKING_DIR}/build_osx/flat/Distribution
<?xml version="1.0" encoding="utf-8"?>
<installer-script minSpecVersion="1.000000" authoringTool="com.apple.PackageMaker" authoringToolVersion="3.0.3" authoringToolBuild="174">
<title>${PKG_NAME} $(get_value_by_key version)</title>
<options customize="never" allow-external-scripts="no"/>
${BG_NODE}
<domains enable_anywhere="false"/>
<installation-check script="pm_install_check();"/>
<script>function pm_install_check() {
if(!(system.compareVersions(system.version.ProductVersion,'10.5') >= 0)) {
my.result.title = 'Failure';
my.result.message = 'You need at least Mac OS X 10.5 to install ${PKG_NAME}.';
my.result.type = 'Fatal';
return false;
}
return true;
}
</script>
<choices-outline>
<line choice="choice1"/>
</choices-outline>
<choice id="choice1" title="base">
<pkg-ref id="$(get_value_by_key CFBundleIdentifier).base.pkg"/>
</choice>
<pkg-ref id="$(get_value_by_key CFBundleIdentifier).base.pkg" installKBytes="${INSTALL_KB_SIZE}" version="$(get_value_by_key version)" auth="Root">#base.pkg</pkg-ref>
</installer-script>
osx_distribution_helper
${WORKING_DIR}/bomutils/build/bin/mkbom -u 0 -g 80 ${WORKING_DIR}/build_osx/root ${WORKING_DIR}/build_osx/flat/base.pkg/Bom
( cd ${WORKING_DIR}/build_osx/flat/ && ${WORKING_DIR}/xar-xar-1.5.2/src/xar --compression none -cf "${RELEASE_DIR}/${PKG_NAME}-$(get_value_by_key version)-OSX-${arch}.pkg" * )
printf "\nDone OSX ${arch}\n"
done;
}
pack_windows() {
for arch in ${architechture[@]}; do
cd ${WORKING_DIR}
cp -R ${BUILD_DIR}/resources/windows/app.nsi ${WORKING_DIR}
cp -R $(get_value_by_key windowsIconPath) ${BUILD_DIR}/TMP/win-${arch}/latest-git/
# Replce paths and vars in nsi script
replace \
NWJS_APP_REPLACE_APPNAME "$(get_value_by_key name)" \
NWJS_APP_REPLACE_DESCRIPTION "$(get_value_by_key description)" \
NWJS_APP_REPLACE_LICENSE $(get_value_by_key license) \
NWJS_APP_REPLACE_VERSION $(get_value_by_key version) \
NWJS_APP_REPLACE_EXE_NAME $(get_value_by_key name)-$(get_value_by_key version)-Windows-${arch}.exe \
NWJS_APP_REPLACE_INC_FILES_locales ${BUILD_DIR}/TMP/win-${arch}/latest-git/locales \
NWJS_APP_REPLACE_INC_FILES_swiftshader ${BUILD_DIR}/TMP/win-${arch}/latest-git/swiftshader \
NWJS_APP_REPLACE_INC_FILES_APP ${BUILD_DIR}/TMP/win-${arch}/latest-git/$(get_value_by_key name).exe \
NWJS_APP_REPLACE_INC_FILES_credits.html ${BUILD_DIR}/TMP/win-${arch}/latest-git/credits.html \
NWJS_APP_REPLACE_INC_FILES_d3dcompiler_47.dll ${BUILD_DIR}/TMP/win-${arch}/latest-git/d3dcompiler_47.dll \
NWJS_APP_REPLACE_INC_FILES_ffmpeg.dll ${BUILD_DIR}/TMP/win-${arch}/latest-git/ffmpeg.dll \
NWJS_APP_REPLACE_INC_FILES_icon.ico ${BUILD_DIR}/TMP/win-${arch}/latest-git/icon.ico \
NWJS_APP_REPLACE_INC_FILES_icudtl.dat ${BUILD_DIR}/TMP/win-${arch}/latest-git/icudtl.dat \
NWJS_APP_REPLACE_INC_FILES_libEGL.dll ${BUILD_DIR}/TMP/win-${arch}/latest-git/libEGL.dll \
NWJS_APP_REPLACE_INC_FILES_libGLESv2.dll ${BUILD_DIR}/TMP/win-${arch}/latest-git/libGLESv2.dll \
NWJS_APP_REPLACE_INC_FILES_natives_blob.bin ${BUILD_DIR}/TMP/win-${arch}/latest-git/natives_blob.bin \
NWJS_APP_REPLACE_INC_FILES_natives_blob.bin ${BUILD_DIR}/TMP/win-${arch}/latest-git/natives_blob.bin \
NWJS_APP_REPLACE_INC_FILES_nw.dll ${BUILD_DIR}/TMP/win-${arch}/latest-git/nw.dll \
NWJS_APP_REPLACE_INC_FILES_nw.exe ${BUILD_DIR}/TMP/win-${arch}/latest-git/nw.exe \
NWJS_APP_REPLACE_INC_FILES_nw_100_percent.pak ${BUILD_DIR}/TMP/win-${arch}/latest-git/nw_100_percent.pak \
NWJS_APP_REPLACE_INC_FILES_nw_200_percent.pak ${BUILD_DIR}/TMP/win-${arch}/latest-git/nw_200_percent.pak \
NWJS_APP_REPLACE_INC_FILES_nw_elf.dll ${BUILD_DIR}/TMP/win-${arch}/latest-git/nw_elf.dll \
NWJS_APP_REPLACE_INC_FILES_resources.pak ${BUILD_DIR}/TMP/win-${arch}/latest-git/resources.pak \
NWJS_APP_REPLACE_INC_FILES_snapshot_blob.bin ${BUILD_DIR}/TMP/win-${arch}/latest-git/snapshot_blob.bin \
NWJS_APP_REPLACE_ICO_FILE_NAME $(basename $(get_value_by_key windowsIconPath)) \
NWJS_APP_REPLACE_INC_FILE_ICO $(get_value_by_key windowsIconPath) -- app.nsi;
makensis app.nsi
# Clean a bit
rm -rf ${WORKING_DIR}/$(get_value_by_key name).nsi;
mv ${WORKING_DIR}/$(get_value_by_key name)-$(get_value_by_key version)-Windows-${arch}.exe ${RELEASE_DIR}
printf "\nDone Windows ${arch}\n"
done
}
build() {
if [[ `check_dependencies` = "NO" ]]; then
printf "\nNOTE! NSIS or ImageMagick is missing in the system\n\n";
exit 1;
fi
if [[ ! -d "${RELEASE_DIR}" ]]; then
mkdir ${RELEASE_DIR}
fi
${BUILD_DIR}/nwjs-build.sh \
--src=$(get_value_by_key src) \
--name=$(get_value_by_key name) \
--nw=$(get_value_by_key nwjsVersion) \
--win-icon=$(get_value_by_key windowsIconPath) \
--osx-icon=$(get_value_by_key osxIconPath) \
--CFBundleIdentifier=$(get_value_by_key CFBundleIdentifier) \
--target="${1}" \
--version=$(get_value_by_key version) \
--libudev \
--build
cd ${BUILD_DIR}
}
# Execute hooks
hook() {
printf "\nNOTE! \"${1}\" hook executed\n\n";
case "$1" in
before)
${BUILD_DIR}/hooks/before.sh
;;
after)
${BUILD_DIR}/hooks/after.sh
;;
after_build)
${BUILD_DIR}/hooks/after_build.sh
;;
esac
}
clean() {
if [[ ${1} = "all" ]];then
rm -rf ${RELEASE_DIR}; printf "\nCleaned ${RELEASE_DIR}\n\n";
fi
rm -rf ${WORKING_DIR}; printf "\nCleaned ${WORKING_DIR}\n\n";
}
# TODO maybe deal with cmd switches or leave it all in the config.json file
if [[ ${1} = "--help" || ${1} = "-h" ]]; then
usage;
elif [[ ${1} = "init" ]]; then
init_config_file;
elif [[ ${1} = "--clean" ]]; then
clean ${2};
elif [[ ${1} = "--linux" ]]; then
clean;
hook "before";
build "0 1";
hook "after_build";
pack_linux;
hook "after";
elif [[ ${1} = "--osx" ]]; then
clean;
hook "before";
build "4";
hook "after_build";
pack_osx;
hook "after";
elif [[ ${1} = "--windows" ]]; then
clean;
hook "before";
build "2 3";
hook "after_build";
pack_windows;
hook "after";
elif [[ ${1} = "--all" ]]; then
clean;
hook "before";
build "0 1 2 3 4";
hook "after_build";
pack_osx;
pack_linux;
pack_windows;
hook "after";
else
usage;
fi