-
Notifications
You must be signed in to change notification settings - Fork 55
/
build.sh
executable file
·261 lines (229 loc) · 10.4 KB
/
build.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
#!/bin/bash
#
# Script to handle creating builds for win/mac/linux
#####################################################
# Mac Developer Identity
# You can find your identity by doing : security find-identity
identity="8C21C6C320C3FFA6ECFA042E29B4C9461C0497CD"
# Path to nwjs executable
nwjs=/Applications/nwjs.app/Contents/MacOS/nwjs
###
### DO NOT EDIT ANYTHING BELOW THIS LINE
###
# Verify we are building on a mac
if [ "$OSTYPE" != "darwin" ] ; then
echo "Build script is meant to be run on MacOS!"
exit
fi
# Extract path to freewallet-desktop source code
base_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Extract app name and version from package.json
app_name=`cat package.json | grep -m1 "name" | awk '{print $2}' | tr -d '",'`
version=`cat package.json | grep -m1 "version" | awk '{print $2}' | tr -d '",'`
# Copy files to build directory
while true; do
read -p "Copy files to build directory?" yn
case $yn in
[Yy]* ) yn="Y"
echo "### Copying files to build directory..."
mkdir $base_dir/build 2> /dev/null
rm -rf $base_dir/build/*
cp -a css html images js index.html package.json build/
break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
# Install node modules
while true; do
read -p "Install Node Modules?" yn
case $yn in
[Yy]* ) yn="Y"
echo "### Installing node modules..."
cd $base_dir/build
npm install
break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
# Run test build
while true; do
read -p "Run test build for debugging?" yn
case $yn in
[Yy]* ) yn="Y"
echo "### Running nwjs..."
$nwjs $base_dir/build
break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
# Run nwjs builder
while true; do
read -p "Run nwjs builder?" yn
case $yn in
[Yy]* ) yn="Y"
cd $base_dir
rm -rf $base_dir/builds/*
echo "### Running nwjs builder..."
node $base_dir/build.js
break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
# Update app to handle custom URIs
while true; do
read -p "Update app to handle custom urls?" yn
case $yn in
[Yy]* ) yn="Y"
plist=$base_dir/builds/$app_name/osx64/$app_name.app/Contents/Info.plist
echo "### Editing Plist file at $plist..."
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:3:CFBundleURLName string Bitcoin" $plist
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:3:CFBundleURLSchemes array" $plist
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:3:CFBundleURLSchemes:0 string bitcoin" $plist
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:4:CFBundleURLName string Counterparty" $plist
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:4:CFBundleURLSchemes array" $plist
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:4:CFBundleURLSchemes:0 string counterparty" $plist
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:5:CFBundleURLName string FreeWallet" $plist
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:5:CFBundleURLSchemes array" $plist
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:5:CFBundleURLSchemes:0 string freewallet" $plist
break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
# Sign the mac app
while true; do
read -p "Sign the mac build with your developer key?" yn
case $yn in
[Yy]* ) yn="Y"
cd $base_dir
app="$base_dir/builds/$app_name/osx64/$app_name.app"
echo "### Signing Mac builds..."
codesign --force --verify --verbose --sign "$identity" "$app"
echo "### Verifying signature..."
codesign -vvv -d "$app"
# Do security assesment to verify the app is signed by known developer
sudo spctl -a -vvvv "$app"
break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
# Create DMG Installer for mac
while true; do
read -p "Create a DMG installer?" yn
case $yn in
[Yy]* ) yn="Y"
# Define some vars used in the build process
vol_name="$app_name $version" # volume name will be "SuperCoolApp 1.0.0"
dmg_bg="mac-installer-bg.png" # Background for the DMG installer
dmg_tmp="$app_name-temp.dmg" # Temporary DMG file
dmg_out="$app_name.dmg" # Finalized DMG file
staging="./mac-installer" # We copy all our stuff into this directory
# Check the background image DPI and convert it if it isn't 72x72
# This avoids distortion problems on Mac OS X 10.7+
_bg_h=`sips -g dpiHeight $base_dir/misc/$dmg_bg | grep -Eo '[0-9]+\.[0-9]+'`
_bg_w=`sips -g dpiWidth $base_dir/misc/$dmg_bg | grep -Eo '[0-9]+\.[0-9]+'`
if [ $(echo " $_bg_h != 72.0 " | bc) -eq 1 -o $(echo " $_bg_w != 72.0 " | bc) -eq 1 ]; then
echo "### Converting dmg background is 72 DPI..."
_bg_tmp="$dmg_bg%.*"_dpifix."$dmg_bg##*."
sips -s dpiWidth 72 -s dpiHeight 72 $dmg_bg --out $_bg_tmp
dmg_bg="$_bg_tmp"
fi
# clear out any old data (just to be safe)
rm -rf $staging $dmg_tmp $dmg_out
# copy over the stuff we want in the final disk image to our staging dir
echo "### Copying data to staging directory..."
mkdir -p $staging
cp -a $base_dir/builds/$app_name/osx64/$app_name.app $staging
# figure out how big our DMG needs to be (assumes our contents are at least 1M!)
size=`du -sh "$staging" | sed 's/\([0-9]*\)M\(.*\)/\1/'`
size=`echo "$size + 10.0" | bc | awk '{print int($1+0.5)}'`
if [ $? -ne 0 ]; then
echo "Error: Cannot compute size of staging dir"
exit
fi
# create the temp DMG file
echo "### Creating temporary DMG file..."
hdiutil create -srcfolder "$staging" -volname "$vol_name" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW -size ${size}M "$dmg_tmp"
# mount it and save the device
echo "### Mounting temporary DMG file : $dmg_tmp ..."
device=$(hdiutil attach -readwrite -noverify "$dmg_tmp" | egrep '^/dev/' | sed 1q | awk '{print $1}')
# sleep to let the device actually mount
sleep 2
# add a link to the Applications dir
echo "### Creating link to /Applications ..."
pushd /Volumes/"$vol_name"
ln -s /Applications
popd
# add a background image
mkdir /Volumes/"$vol_name"/.background
cp $base_dir/misc/$dmg_bg /Volumes/"$vol_name"/.background/
# tell the Finder to resize window, set background, change icon size, place the icons in the right position, etc.
echo '
tell application "Finder"
tell disk "'${vol_name}'"
open
set current view of container window to icon view
set toolbar visible of container window to false
set statusbar visible of container window to false
set the bounds of container window to {400, 100, 920, 440}
set viewOptions to the icon view options of container window
set arrangement of viewOptions to not arranged
set icon size of viewOptions to 72
set background picture of viewOptions to file ".background:'${dmg_bg}'"
set position of item "'${app_name}'.app" of container window to {160, 205}
set position of item "Applications" of container window to {360, 205}
close
open
update without registering applications
delay 2
end tell
end tell
' | osascript
sync
# unmount it
hdiutil detach $device
# now make the final image a compressed disk image
echo "### Creating compressed image..."
hdiutil convert $dmg_tmp -format UDZO -imagekey zlib-level=9 -o $dmg_out
# Move file to its final destination
echo "### Moving dmg to final destination..."
mv $dmg_out $base_dir/builds/$app_name/osx64/
echo "### Cleaning up..."
rm -rf $staging $dmg_tmp
break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
# Create Linux installer?
while true; do
read -p "Create linux installer?" yn
case $yn in
[Yy]* ) yn="Y"
platform=( 32 64 )
for bits in "${platform[@]}"; do
echo "### Creating $bits-bit installer"
cd $base_dir/builds/$app_name/linux$bits/
mkdir /tmp/$app_name 2> /dev/null
rm -rf /tmp/$app_name/*
rm -rf /tmp/$app_name.x$bits.tgz
rm -rf $app_name.x$bits.tgz
echo "### Copying files to build directory"
cp -a * /tmp/$app_name/
echo "### Copying additional files to install directory..."
cd $base_dir/misc/
cp FreeWallet.png install.sh FreeWallet.desktop /tmp/$app_name/
cd /tmp
tar -cvzf $app_name.x$bits.tgz $app_name
cp $app_name.x$bits.tgz $base_dir/builds/$app_name/linux$bits/
done
break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done