forked from OpenBazaar/OpenBazaar-Installer
/
make_openbazaar.sh
executable file
·313 lines (252 loc) · 9.06 KB
/
make_openbazaar.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
#!/bin/sh
## Version 0.1.0
##
## Usage
## ./make_openbazaar.sh OS
##
## OS supported:
## win32 win64 linux osx
##
ELECTRONVER=0.36.2
NODEJSVER=5.1.1
PYTHONVER=2.7.11
UPXVER=391
OS="${1}"
# Get Version
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
echo "OpenBazaar Version: $PACKAGE_VERSION"
# Check if user specified repository to pull code from
clone_url_server="https://github.com/OpenBazaar/OpenBazaar-Server.git"
clone_url_client="https://github.com/OpenBazaar/OpenBazaar-Client.git"
command_exists () {
if ! [ -x "$(command -v $1)" ]; then
echo "$1 is not installed." >&2
fi
}
clone_command() {
if git clone ${clone_url_server} -b ${branch}; then
echo "Cloned OpenBazaar Server successfully"
else
echo "OpenBazaar encountered an error and could not be cloned"
exit 2
fi
}
clone_command_client() {
if git clone ${clone_url_client}; then
echo "Cloned OpenBazaar Client successfully"
else
echo "OpenBazaar encountered an error and could not be cloned"
exit 2
fi
}
if ! [ -d OpenBazaar-Client ]; then
echo "Cloning OpenBazaar-Client"
clone_command_client
else
cd OpenBazaar-Client
git pull
cd ..
fi
branch=master
if ! [ -d OpenBazaar-Server ]; then
echo "Cloning OpenBazaar-Server"
clone_command
else
cd OpenBazaar-Server
git pull
cd ..
fi
if [ -z "${dir}" ]; then
dir="."
fi
cd ${dir}
echo "Switched to ${PWD}"
if [ -d build-$OS ]; then
rm -rf build-$OS
fi
mkdir -p temp-$OS
mkdir -p build-$OS/OpenBazaar-Server
# Clean past builds in OpenBazaar-Server
rm -rf OpenBazaar-Server/dist/*
#command_exists grunt
command_exists npm
#command_exists wine
# Notes about windows: In windows we want to compile the application for both
# 32 bit and 64 bit versions even if the host operating system is 64 bit.
# To make it possible to run either 32 bit and 64 bit versions of python
# we need to install Python 2.7 32 bit, Python 2.7 64 bit and afterwards
# we need to install latest Python 3 in either 32 or 64 bits. This is needed
# becuase starting with Python 3.3 a launcher is installed that allows us
# to run any python version that is already installed
# by calling either `py.exe -2.7-x64 ` or `py.exe -2.7-32`
# Download OS specific installer files to package
case $OS in win32*)
export OB_OS=win32
command_exists py
;;
win64*)
export OB_OS=win64
command_exists python
echo 'Building Server Binary...'
cd OpenBazaar-Server
pip install virtualenv
virtualenv env
env/scripts/activate.bat
pip install pyinstaller==3.1
pip install https://openbazaar.org/downloads/miniupnpc-1.9-cp27-none-win_amd64.whl
pip install https://openbazaar.org/downloads/PyNaCl-0.3.0-cp27-none-win_amd64.whl
pip install -r requirements.txt
pyinstaller -i ../windows/icon.ico ../openbazaard.win.spec --noconfirm
cp -rf dist/openbazaard/* ../build-$OS/OpenBazaar-Server
cp ob.cfg ../build-$OS/OpenBazaar-Server
cd ..
echo 'Installing Node modules'
npm install electron-packager
cd OpenBazaar-Client
npm install
echo 'Building Client Binary...'
cd ../temp-$OS
../node_modules/.bin/electron-packager ../OpenBazaar-Client OpenBazaar --asar=true --protocol-name=OpenBazaar --version-string.ProductName=OpenBazaar --protocol=ob --platform=win32 --arch=x64 --icon=../windows/icon.ico --version=${ELECTRONVER} --overwrite
cd ..
echo 'Copying server files into application folder(s)...'
cp -rf build-$OS/OpenBazaar-Server temp-$OS/OpenBazaar-win32-x64/resources/
echo 'Building Installer...'
npm install -g grunt
npm install --save-dev grunt-electron-installer
grunt create-windows-installer --version=$PACKAGE_VERSION
echo "Do not forget to sign the release before distributing..."
echo "signtool sign /t http://timestamp.digicert.com /a [filename]"
;;
osx*)
echo 'Building OS X binary...'
echo 'Cleaning build directories...'
if [ -d build-$OS ]; then
rm -rf build-$OS/*
fi
if [ -d temp-$OS ]; then
rm -rf temp-$OS/*
fi
echo 'Installing node.js packages for installer...'
npm install electron-packager
npm install electron-installer-dmg
echo 'Installing node.js packages for OpenBazaar-Client...'
cd OpenBazaar-Client
npm install
cd ..
echo 'Creating virtualenv and building OpenBazaar-Server binary...'
cd OpenBazaar-Server
virtualenv env
source env/bin/activate
pip install --ignore-installed -r requirements.txt
pip install --ignore-installed pyinstaller==3.1
pip install setuptools==19.1
env/bin/pyinstaller -F -n openbazaard -i ../osx/tent.icns --osx-bundle-identifier=com.openbazaar.openbazaard ../openbazaard.mac.spec
echo 'Completed building OpenBazaar-Server binary...'
echo 'Code-signing Daemon binaries...'
codesign --force --sign "$SIGNING_IDENTITY" dist/openbazaard
codesign --force --sign "$SIGNING_IDENTITY" ob.cfg
cd ..
echo 'Packaging Electron application...'
cd temp-$OS
../node_modules/.bin/electron-packager ../OpenBazaar-Client OpenBazaar --sign=$SIGNING_IDENTITY --protocol-name=OpenBazaar --protocol=ob --platform=darwin --arch=x64 --icon=../osx/tent.icns --version=${ELECTRONVER} --overwrite
cd ..
echo 'Moving .app to build directory...'
mv temp-$OS/OpenBazaar-darwin-x64/* build-$OS/
rm -rf build-$OS/OpenBazaar-darwin-x64
echo 'Create OpenBazaar-Server folder inside the .app...'
mkdir build-$OS/OpenBazaar.app/Contents/Resources/OpenBazaar-Server
cd OpenBazaar-Server
echo 'Copy binary files to .app folder...'
cp dist/openbazaard ../build-$OS/OpenBazaar.app/Contents/Resources/OpenBazaar-Server
cp ob.cfg ../build-$OS/OpenBazaar.app/Contents/Resources/OpenBazaar-Server
cd ..
echo 'Creating DMG installer from build...'
npm i electron-installer-dmg -g
electron-installer-dmg ./build-$OS/OpenBazaar.app OpenBazaar-$PACKAGE_VERSION --icon ./osx/tent.icns --out=./build-$OS --overwrite --background=./osx/finder_background.png --debug
echo 'Codesign the DMG and zip'
codesign --force --sign "$SIGNING_IDENTITY" ./build-$OS/OpenBazaar-$PACKAGE_VERSION.dmg
zip -r ./build-osx/OpenBazaar-mac-$PACKAGE_VERSION.zip ./build-osx/OpenBazaar-$PACKAGE_VERSION.dmg
;;
linux32*)
echo 'Building Linux binary'
if [ -d build-$OS ]; then
rm -rf build-$OS
fi
if ! [ -d temp-$OS ]; then
mkdir -p temp-$OS
fi
branch=master
if ! [ -d OpenBazaar-Server ]; then
echo "Cloning OpenBazaar-Server"
clone_command
else
cd OpenBazaar-Server
git pull
cd ..
fi
npm install electron-packager
echo 'Compiling node packages'
cd OpenBazaar-Client
npm install
echo 'Packaging Electron application'
cd ../temp-$OS
../node_modules/.bin/electron-packager ../OpenBazaar-Client openbazaar --platform=linux --arch=all --version=${ELECTRONVER} --overwrite
cd ..
# Set up build directories
cp -rf OpenBazaar-Client build-$OS
mkdir build-$OS/OpenBazaar-Server
# Build OpenBazaar-Server Binary
cd OpenBazaar-Server
virtualenv2 env
source env/bin/activate
pip2 install -r requirements.txt
pip2 install git+https://github.com/pyinstaller/pyinstaller.git
env/bin/pyinstaller -F -n openbazaard openbazaard.py
cp dist/openbazaard ../build-$OS/OpenBazaar-Server
cp ob.cfg ../build-$OS/OpenBazaar-Server
echo "Build done in build-$OS"
;;
linux64*)
echo 'Building Linux binary'
if [ -d build-$OS ]; then
rm -rf build-$OS
fi
if ! [ -d temp-$OS ]; then
mkdir -p temp-$OS
fi
branch=master
if ! [ -d OpenBazaar-Server ]; then
echo "Cloning OpenBazaar-Server"
clone_command
else
cd OpenBazaar-Server
git pull
cd ..
fi
npm install electron-packager
echo 'Compiling node packages'
cd OpenBazaar-Client
npm install
echo 'Packaging Electron application'
cd ../temp-$OS
../node_modules/.bin/electron-packager ../OpenBazaar-Client openbazaar --platform=linux --arch=all --version=${ELECTRONVER} --overwrite
cd ..
# Set up build directories
cp -rf OpenBazaar-Client build-$OS
mkdir build-$OS/OpenBazaar-Server
# Build OpenBazaar-Server Binary
cd OpenBazaar-Server
virtualenv2 env
source env/bin/activate
pip2 install -r requirements.txt
pip2 install git+https://github.com/pyinstaller/pyinstaller.git
env/bin/pyinstaller -F -n openbazaard openbazaard.py
cp dist/openbazaard ../build-$OS/OpenBazaar-Server
cp ob.cfg ../build-$OS/OpenBazaar-Server
echo "Build done in build-$OS"
esac