forked from bq/web2board
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.sh
executable file
·413 lines (328 loc) · 15.7 KB
/
package.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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#!/bin/bash
# This script is to package the web2board package for Windows/Linux
# This script should run under Linux and Mac OS X, as well as Windows with Cygwin.
#############################
# CONFIGURATION
#############################
##Select the build target
BUILD_TARGET=${1:-none}
#BUILD_TARGET=win32
#BUILD_TARGET=debian
#BUILD_TARGET=darwin
EXTRA_ARGS=${2}
##Which version name are we appending to the final archive
# VERSION=`head -1 pkg/linux/debian/changelog | grep -o '\(([^\)]*\)' | tr -d '()' | head -1`
VERSION=$(cat res/common/config.json | python -c 'import sys, json;print(json.load(sys.stdin)["version"])')
echo "Version -->" ${VERSION} ${#VERSION}
VEXT=${VEXT:=""}
TARGET_DIR=web2board-${VERSION}-${BUILD_TARGET}
##Which versions of external programs to use
WIN_PORTABLE_PY_VERSION=2.7.2.1 #TODO: 2.7.6.1
#############################
# Support functions
#############################
function checkTool
{
if [ -z `which $1` ]; then
echo "The $1 command must be somewhere in your \$PATH."
echo "Fix your \$PATH or install it"
exit 1
fi
}
function downloadURL
{
filename=`basename "$1"`
echo "Checking for $filename"
if [ ! -f "$filename" ]; then
echo "Downloading $1"
curl -L -O "$1"
if [ $? != 0 ]; then
echo "Failed to download $1"
exit 1
fi
fi
}
function extract
{
if [ $1 != ${1%%.exe} ] || [ $1 != ${1%%.zip} ] || [ $1 != ${1%%.msi} ]; then
echo "1.-Extracting $*"
echo "7z x -y $*" >> log.txt
7z x -y $* >> log.txt
echo $?
if [ $? != 0 ]; then
echo "Failed to extract $*"
exit 1
fi
elif [ $1 != ${1%%.tar.gz} ]; then
echo "2.-Extracting $*"
echo "tar -zxvf $*" >> log.txt
tar -zxvf $* >> log.txt
if [ $? != 0 ]; then
echo "Failed to extract $*"
exit 1
fi
fi
}
#############################
# Actual build script
#############################
if [ "$BUILD_TARGET" = "none" ]; then
echo "You need to specify a build target with:"
echo "$0 win32"
echo "$0 debian"
echo "$0 darwin"
exit 0
fi
# Change working directory to the directory the script is in
# http://stackoverflow.com/a/246128
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $SCRIPT_DIR
checkTool git "git: http://git-scm.com/"
checkTool curl "curl: http://curl.haxx.se/"
if [ $BUILD_TARGET = "win32" ]; then
#Check if we have 7zip, needed to extract and packup a bunch of packages for windows.
checkTool 7z "7zip: http://www.7-zip.org/"
fi
# Clean sources
rm -rf deb_dist
rm -rf win_dist
rm -rf dar_dist
#############################
# Debian 32 bits packaging
#############################
if [ $BUILD_TARGET = "debian32" ]; then
#Remove everything inside src/res
rm -rf src/res
rm -rf debian
#Copy everything inside res/
cp -a res/linux src/res
cp -a res/common/* src/res
# Generate Debian source package
CLFAGS=-m32 LDFLAGS=-m32 python setup.py --command-packages=stdeb.command sdist_dsc debianize \
#--debian-version 1 \
#--suite 'trusty' \
#--section 'main' \
#--package 'web2board' \
#--depends 'python,
# python-serial,
# avrdude \
#bdist_deb # Used to generate deb files
# Copy postinst and postrm files
cp -a pkg/linux/debian/postinst deb_dist/web2board-${VERSION}/debian/postinst
# cp -a pkg/linux/debian/preinst deb_dist/web2board-${VERSION}/debian/preinst
cp -a pkg/linux/debian/postrm deb_dist/web2board-${VERSION}/debian/postrm
# Modify changelog and control files
cp -a pkg/linux/debian/changelog deb_dist/web2board-${VERSION}/debian/changelog
cp -a pkg/linux/debian/control deb_dist/web2board-${VERSION}/debian/control
cd deb_dist/web2board-${VERSION}
if [ $EXTRA_ARGS ]; then
if [ $EXTRA_ARGS = "-s" ]; then
# Build and sign Debian sources
debuild -S -sa
elif [ $EXTRA_ARGS = "-i" ]; then
# Install Debian package
dpkg-buildpackage -ai386 -b -us -uc
sudo dpkg -i ../web2board*.deb
sudo apt-get -f install
fi
else
# Build and sign Debian package
dpkg-buildpackage -ai386 -b -us -uc
fi
# Clean directory
cd ../..
rm -rf "web2board.egg-info"
mv deb_dist/*.deb deb_dist/web2board.deb
fi
#############################
# Debian 64 bits packaging
#############################
if [ $BUILD_TARGET = "debian" ]; then
#Remove everything inside src/res
rm -rf src/res
#Copy everything inside res/
cp -a res/linux src/res
cp -a res/common/* src/res
# Generate Debian source package
python setup.py --command-packages=stdeb.command sdist_dsc debianize \
#--debian-version 1 \
#--suite 'trusty' \
#--section 'main' \
#--package 'web2board' \
#--depends 'python,
# python-serial,
# avrdude \
#bdist_deb # Used to generate deb files
# Copy postinst and postrm files
cp -a pkg/linux/debian/postinst deb_dist/web2board-${VERSION}/debian/postinst
# cp -a pkg/linux/debian/preinst deb_dist/web2board-${VERSION}/debian/preinst
cp -a pkg/linux/debian/postrm deb_dist/web2board-${VERSION}/debian/postrm
# Modify changelog and control files
cp -a pkg/linux/debian/changelog deb_dist/web2board-${VERSION}/debian/changelog
cp -a pkg/linux/debian/control deb_dist/web2board-${VERSION}/debian/control
cd deb_dist/web2board-${VERSION}
if [ $EXTRA_ARGS ]; then
if [ $EXTRA_ARGS = "-s" ]; then
# Build and sign Debian sources
debuild -S -sa
elif [ $EXTRA_ARGS = "-i" ]; then
# Install Debian package
dpkg-buildpackage -b -us -uc
sudo dpkg -i ../web2board*.deb
sudo apt-get -f install
fi
else
# Build and sign Debian package
dpkg-buildpackage -b -us -uc
fi
# Clean directory
cd ../..
rm -rf "web2board.egg-info"
echo [Desktop Entry] | tee -a deb_dist/Web2Board-PROD.desktop deb_dist/Web2Board-BETA.desktop deb_dist/Web2Board-QA.desktop deb_dist/Web2Board-STAGING.desktop
echo Encoding=UTF-8 | tee -a deb_dist/Web2Board-PROD.desktop deb_dist/Web2Board-BETA.desktop deb_dist/Web2Board-QA.desktop deb_dist/Web2Board-STAGING.desktop
echo Name=Web2Board-PROD deb_dist/Web2Board-PROD.desktop
echo Name=Web2Board-BETA deb_dist/Web2Board-BETA.desktop
echo Name=Web2Board-QA deb_dist/Web2Board-QA.desktop
echo Name=Web2Board-STAGING deb_dist/Web2Board-STAGING.desktop
echo Comment=Install | tee -a deb_dist/Web2Board-PROD.desktop deb_dist/Web2Board-BETA.desktop deb_dist/Web2Board-QA.desktop deb_dist/Web2Board-STAGING.desktop
#PROD:
echo "Exec=bash -c 'echo \$ \"-------------------------------------------------- \" && echo \" INSTALANDO WEB2BOARD PARA BITBLOQ. NO CERRAR \" && echo \" INSTALLING BITBLOQS WEB2BOARD. DO NOT CLOSE\" && echo \$ \"--------------------------------------------------\n\n\n \" && echo \"Instalando... \" && echo \"Installing... \" && userName=\$( who | head -1| cut -d \" \" -f 1) && sudo adduser \$userName dialout && sudo apt-get -y install gdebi && sudo apt-get install xterm && sudo apt-get install wget && wget http://bitbloq.com.s3.amazonaws.com/web2board/linux/64bit/web2board.deb && sudo gdebi --non-interactive web2board.deb && rm web2board.deb && echo \$ \"\n\n\n-------------------------------------------------- \" && echo \"INSTALACIÓN TERMINADA. PUEDE CERRAR LA VENTANA \" && echo \"INSTALLATION FINISHED. YOU MAY CLOSE THE WINDOW \" && echo \"REINICIE EL ORDENADOR \" && echo \"REBOOT THE COMPUTER \" && echo \$ \"--------------------------------------------------\n\n\n \" && sudo chown -R \$userName ~/Arduino'">> deb_dist/Web2Board-PROD.desktop
#BETA:
echo "Exec=bash -c 'echo \$ \"-------------------------------------------------- \" && echo \" INSTALANDO WEB2BOARD PARA BITBLOQ. NO CERRAR \" && echo \" INSTALLING BITBLOQS WEB2BOARD. DO NOT CLOSE\" && echo \$ \"--------------------------------------------------\n\n\n \" && echo \"Instalando... \" && echo \"Installing... \" && userName=\$( who | head -1| cut -d \" \" -f 1) && sudo adduser \$userName dialout && sudo apt-get -y install gdebi && sudo apt-get install xterm && sudo apt-get install wget && wget http://bitbloq.com.s3.amazonaws.com/dev/beta/linux/64bit/web2board.deb && sudo gdebi --non-interactive web2board.deb && rm web2board.deb && echo \$ \"\n\n\n-------------------------------------------------- \" && echo \"INSTALACIÓN TERMINADA. PUEDE CERRAR LA VENTANA \" && echo \"INSTALLATION FINISHED. YOU MAY CLOSE THE WINDOW \" && echo \"REINICIE EL ORDENADOR \" && echo \"REBOOT THE COMPUTER \" && echo \$ \"--------------------------------------------------\n\n\n \" && sudo chown -R \$userName ~/Arduino'">> deb_dist/Web2Board-BETA.desktop
#QA:
echo "Exec=bash -c 'echo \$ \"-------------------------------------------------- \" && echo \" INSTALANDO WEB2BOARD PARA BITBLOQ. NO CERRAR \" && echo \" INSTALLING BITBLOQS WEB2BOARD. DO NOT CLOSE\" && echo \$ \"--------------------------------------------------\n\n\n \" && echo \"Instalando... \" && echo \"Installing... \" && userName=\$( who | head -1| cut -d \" \" -f 1) && sudo adduser \$userName dialout && sudo apt-get -y install gdebi && sudo apt-get install xterm && sudo apt-get install wget && wget http://bitbloq.com.s3.amazonaws.com/dev/qa/linux/64bit/web2board.deb && sudo gdebi --non-interactive web2board.deb && rm web2board.deb && echo \$ \"\n\n\n-------------------------------------------------- \" && echo \"INSTALACIÓN TERMINADA. PUEDE CERRAR LA VENTANA \" && echo \"INSTALLATION FINISHED. YOU MAY CLOSE THE WINDOW \" && echo \"REINICIE EL ORDENADOR \" && echo \"REBOOT THE COMPUTER \" && echo \$ \"--------------------------------------------------\n\n\n \" && sudo chown -R \$userName ~/Arduino'">> deb_dist/Web2Board-QA.desktop
#STAGING:
echo "Exec=bash -c 'echo \$ \"-------------------------------------------------- \" && echo \" INSTALANDO WEB2BOARD PARA BITBLOQ. NO CERRAR \" && echo \" INSTALLING BITBLOQS WEB2BOARD. DO NOT CLOSE\" && echo \$ \"--------------------------------------------------\n\n\n \" && echo \"Instalando... \" && echo \"Installing... \" && userName=\$( who | head -1| cut -d \" \" -f 1) && sudo adduser \$userName dialout && sudo apt-get -y install gdebi && sudo apt-get install xterm && sudo apt-get install wget && wget http://bitbloq.com.s3.amazonaws.com/dev/staging/linux/64bit/web2board.deb && sudo gdebi --non-interactive web2board.deb && rm web2board.deb && echo \$ \"\n\n\n-------------------------------------------------- \" && echo \"INSTALACIÓN TERMINADA. PUEDE CERRAR LA VENTANA \" && echo \"INSTALLATION FINISHED. YOU MAY CLOSE THE WINDOW \" && echo \"REINICIE EL ORDENADOR \" && echo \"REBOOT THE COMPUTER \" && echo \$ \"--------------------------------------------------\n\n\n \" && sudo chown -R \$userName ~/Arduino'">> deb_dist/Web2Board-STAGING.desktop
echo "Terminal=true" | tee -a deb_dist/Web2Board-PROD.desktop deb_dist/Web2Board-BETA.desktop deb_dist/Web2Board-QA.desktop deb_dist/Web2Board-STAGING.desktop
# echo "Icon=/usr/share/icons/gnome/48x48/mimetypes/application-x-executable.png" >> deb_dist/INSTALL.desktop
echo "Type=Application" | tee -a deb_dist/Web2Board-PROD.desktop deb_dist/Web2Board-BETA.desktop deb_dist/Web2Board-QA.desktop deb_dist/Web2Board-STAGING.desktop
mv deb_dist/*.deb deb_dist/web2board.deb
# mv deb_dist/INSTALL.desktop deb_dist/Web2Board.desktop
chmod +x deb_dist/Web2Board*.desktop
cd deb_dist
mv Web2Board-PROD.desktop Web2Board.desktop
tar -czpf Web2Board-PROD.tar.gz Web2Board.desktop
rm Web2board.desktop
mv Web2Board-BETA.desktop Web2Board.desktop
tar -czpf Web2Board-BETA.tar.gz Web2Board.desktop
rm Web2board.desktop
mv Web2Board-QA.desktop Web2Board.desktop
tar -czpf Web2Board-QA.tar.gz Web2Board.desktop
rm Web2board.desktop
mv Web2Board-STAGING.desktop Web2Board.desktop
tar -czpf Web2Board-STAGING.tar.gz Web2Board.desktop
rm Web2board.desktop
rm -rf Web2Board*.desktop
rm -rf web2board-*
rm -rf web2board_*
fi
#############################
# Darwin packaging
#############################
if [ $BUILD_TARGET = "darwin" ]; then
#Remove everything inside src/res
rm -rf src/res
rm -rf distResources/mac
#Copy everything inside res/
cp -a res/darwin src/res
cp -a res/common/* src/res
python setup_mac.py py2app -b build_mac -d distResources/mac
python setup_mac_serialmonitor.py py2app -b build_mac -d distResources/mac
chmod -R 755 distResources/mac/Web2Board.app/Contents/Resources/res/arduinoDarwin/hardware
# Create pkg :
echo "Building mpkg..."
/usr/local/bin/packagesbuild pkg/darwin/create-mpkg/web2board/web2board.pkgproj
# Create basic dmg :
# pkg/darwin/create-dmg/create-dmg \
# --volname "Web2board Installer" \
# --volicon "src/res/web2board.icns" \
# --background "src/res/installer_background.jpg" \
# --window-pos 200 120 \
# --window-size 700 400 \
# --icon-size 100 \
# --icon web2board.app 180 280 \
# --hide-extension Web2Board.app \
# --app-drop-link 530 275 \
# distResources/mac/Web2Board.dmg \
# distResources/mac/Web2Board.app
rm -rf build_mac
fi
#############################
# Rest
#############################
#############################
# Download all needed files.
#############################
if [ $BUILD_TARGET = "win32" ]; then
#Remove everything inside src/res
rm -rf src/res
#Copy everything inside res/
cp -a res/windows src/res
cp -a res/common/* src/res
# #Remove all possible arduino files:
# rm -rf src/res/arduino*
# #Copy the ones we need
# cp -a res/arduinoWin src/res/
# #Remove last .reg file and copy it
# rm src/res/web2board.reg
# cp -a res/web2board.reg src/res/
# #Remove last avrdude and copy new one
# rm src/res/avrdude*
# rm libusb0.dll
# cp -a res/avrdude* src/res
# cp -a res/libusb0.dll src/res
mkdir -p win_dist
cd win_dist
# Get portable python for windows and extract it. (Linux and Mac need to install python themselfs)
downloadURL http://ftp.nluug.nl/languages/python/portablepython/v2.7/PortablePython_${WIN_PORTABLE_PY_VERSION}.exe
downloadURL http://sourceforge.net/projects/pyserial/files/pyserial/2.7/pyserial-2.7.win32.exe
downloadURL http://sourceforge.net/projects/winavr/files/WinAVR/20100110/WinAVR-20100110-install.exe
fi
#############################
# Build the packages
#############################
if [ $BUILD_TARGET = "win32" ]; then
rm -rf ${TARGET_DIR}
mkdir -p ${TARGET_DIR}
rm -f log.txt
# For windows extract portable python to include it.
extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/App
extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/Lib/site-packages
extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/dateutil
extract pyserial-2.7.win32.exe PURELIB
mkdir -p ${TARGET_DIR}/python
mv \$_OUTDIR/App/* ${TARGET_DIR}/python
mv \$_OUTDIR/Lib/site-packages/wx* ${TARGET_DIR}/python/Lib/site-packages
mv \$_OUTDIR/dateutil ${TARGET_DIR}/python/Lib
mv PURELIB/serial ${TARGET_DIR}/python/Lib
rm -rf \$_OUTDIR
rm -rf PURELIB
rm -rf PLATLIB
rm -rf Win32
# Clean up portable python a bit, to keep the package size down.
rm -rf ${TARGET_DIR}/python/PyScripter.*
rm -rf ${TARGET_DIR}/python/Doc
rm -rf ${TARGET_DIR}/python/locale
rm -rf ${TARGET_DIR}/python/tcl
rm -rf ${TARGET_DIR}/python/Lib/test
rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/tools
rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/locale
#Remove the gle files because they require MSVCR71.dll, which is not included. We also don't need gle, so it's safe to remove it.
rm -rf ${TARGET_DIR}/python/Lib/OpenGL/DLLS/gle*
# Add Web2board
mkdir -p ${TARGET_DIR}/doc ${TARGET_DIR}/res ${TARGET_DIR}/src
#cp -a ../doc/* ${TARGET_DIR}/doc
# cp -a ../res/* ${TARGET_DIR}/res
cp -a ../src/* ${TARGET_DIR}/src
# Add script files
cp -a ../pkg/${BUILD_TARGET}/*.bat $TARGET_DIR/
# Add binaries
cp -a ../pkg/${BUILD_TARGET}/binaries/* $TARGET_DIR/
# Package the result
rm -rf ../pkg/win32/dist
ln -sf `pwd`/${TARGET_DIR} ../pkg/win32/dist
makensis ../pkg/win32/installer.nsi
if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
mv ../pkg/win32/Web2board.exe web2board.exe
rm -rf ../pkg/win32/dist
fi