net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
[bitcoinplatinum.git] / contrib / gitian-build.sh
blobee47d138f3798b9a0427dc1fd12db77f2c49bf46
1 # What to do
2 sign=false
3 verify=false
4 build=false
5 setupenv=false
7 # Systems to build
8 linux=true
9 windows=true
10 osx=true
12 # Other Basic variables
13 SIGNER=
14 VERSION=
15 commit=false
16 url=https://github.com/bitcoin/bitcoin
17 proc=2
18 mem=2000
19 lxc=true
20 osslTarUrl=http://downloads.sourceforge.net/project/osslsigncode/osslsigncode/osslsigncode-1.7.1.tar.gz
21 osslPatchUrl=https://bitcoincore.org/cfields/osslsigncode-Backports-to-1.7.1.patch
22 scriptName=$(basename -- "$0")
23 signProg="gpg --detach-sign"
24 commitFiles=true
26 # Help Message
27 read -d '' usage <<- EOF
28 Usage: $scriptName [-c|u|v|b|s|B|o|h|j|m|] signer version
30 Run this script from the directory containing the bitcoin, gitian-builder, gitian.sigs, and bitcoin-detached-sigs.
32 Arguments:
33 signer GPG signer to sign each build assert file
34 version Version number, commit, or branch to build. If building a commit or branch, the -c option must be specified
36 Options:
37 -c|--commit Indicate that the version argument is for a commit or branch
38 -u|--url Specify the URL of the repository. Default is https://github.com/bitcoin/bitcoin
39 -v|--verify Verify the gitian build
40 -b|--build Do a gitiain build
41 -s|--sign Make signed binaries for Windows and Mac OSX
42 -B|--buildsign Build both signed and unsigned binaries
43 -o|--os Specify which Operating Systems the build is for. Default is lwx. l for linux, w for windows, x for osx
44 -j Number of processes to use. Default 2
45 -m Memory to allocate in MiB. Default 2000
46 --kvm Use KVM instead of LXC
47 --setup Setup the gitian building environment. Uses KVM. If you want to use lxc, use the --lxc option. Only works on Debian-based systems (Ubuntu, Debian)
48 --detach-sign Create the assert file for detached signing. Will not commit anything.
49 --no-commit Do not commit anything to git
50 -h|--help Print this help message
51 EOF
53 # Get options and arguments
54 while :; do
55 case $1 in
56 # Verify
57 -v|--verify)
58 verify=true
60 # Build
61 -b|--build)
62 build=true
64 # Sign binaries
65 -s|--sign)
66 sign=true
68 # Build then Sign
69 -B|--buildsign)
70 sign=true
71 build=true
73 # PGP Signer
74 -S|--signer)
75 if [ -n "$2" ]
76 then
77 SIGNER=$2
78 shift
79 else
80 echo 'Error: "--signer" requires a non-empty argument.'
81 exit 1
84 # Operating Systems
85 -o|--os)
86 if [ -n "$2" ]
87 then
88 linux=false
89 windows=false
90 osx=false
91 if [[ "$2" = *"l"* ]]
92 then
93 linux=true
95 if [[ "$2" = *"w"* ]]
96 then
97 windows=true
99 if [[ "$2" = *"x"* ]]
100 then
101 osx=true
103 shift
104 else
105 echo 'Error: "--os" requires an argument containing an l (for linux), w (for windows), or x (for Mac OSX)\n'
106 exit 1
109 # Help message
110 -h|--help)
111 echo "$usage"
112 exit 0
114 # Commit or branch
115 -c|--commit)
116 commit=true
118 # Number of Processes
120 if [ -n "$2" ]
121 then
122 proc=$2
123 shift
124 else
125 echo 'Error: "-j" requires an argument'
126 exit 1
129 # Memory to allocate
131 if [ -n "$2" ]
132 then
133 mem=$2
134 shift
135 else
136 echo 'Error: "-m" requires an argument'
137 exit 1
140 # URL
142 if [ -n "$2" ]
143 then
144 url=$2
145 shift
146 else
147 echo 'Error: "-u" requires an argument'
148 exit 1
151 # kvm
152 --kvm)
153 lxc=false
155 # Detach sign
156 --detach-sign)
157 signProg="true"
158 commitFiles=false
160 # Commit files
161 --no-commit)
162 commitFiles=false
164 # Setup
165 --setup)
166 setup=true
168 *) # Default case: If no more options then break out of the loop.
169 break
170 esac
171 shift
172 done
174 # Set up LXC
175 if [[ $lxc = true ]]
176 then
177 export USE_LXC=1
178 export LXC_BRIDGE=lxcbr0
179 sudo ifconfig lxcbr0 up 10.0.2.2
182 # Check for OSX SDK
183 if [[ ! -e "gitian-builder/inputs/MacOSX10.11.sdk.tar.gz" && $osx == true ]]
184 then
185 echo "Cannot build for OSX, SDK does not exist. Will build for other OSes"
186 osx=false
189 # Get signer
190 if [[ -n"$1" ]]
191 then
192 SIGNER=$1
193 shift
196 # Get version
197 if [[ -n "$1" ]]
198 then
199 VERSION=$1
200 COMMIT=$VERSION
201 shift
204 # Check that a signer is specified
205 if [[ $SIGNER == "" ]]
206 then
207 echo "$scriptName: Missing signer."
208 echo "Try $scriptName --help for more information"
209 exit 1
212 # Check that a version is specified
213 if [[ $VERSION == "" ]]
214 then
215 echo "$scriptName: Missing version."
216 echo "Try $scriptName --help for more information"
217 exit 1
220 # Add a "v" if no -c
221 if [[ $commit = false ]]
222 then
223 COMMIT="v${VERSION}"
225 echo ${COMMIT}
227 # Setup build environment
228 if [[ $setup = true ]]
229 then
230 sudo apt-get install ruby apache2 git apt-cacher-ng python-vm-builder qemu-kvm qemu-utils
231 git clone https://github.com/bitcoin-core/gitian.sigs.git
232 git clone https://github.com/bitcoin-core/bitcoin-detached-sigs.git
233 git clone https://github.com/devrandom/gitian-builder.git
234 pushd ./gitian-builder
235 if [[ -n "$USE_LXC" ]]
236 then
237 sudo apt-get install lxc
238 bin/make-base-vm --suite trusty --arch amd64 --lxc
239 else
240 bin/make-base-vm --suite trusty --arch amd64
242 popd
245 # Set up build
246 pushd ./bitcoin
247 git fetch
248 git checkout ${COMMIT}
249 popd
251 # Build
252 if [[ $build = true ]]
253 then
254 # Make output folder
255 mkdir -p ./bitcoin-binaries/${VERSION}
257 # Build Dependencies
258 echo ""
259 echo "Building Dependencies"
260 echo ""
261 pushd ./gitian-builder
262 mkdir -p inputs
263 wget -N -P inputs $osslPatchUrl
264 wget -N -P inputs $osslTarUrl
265 make -C ../bitcoin/depends download SOURCES_PATH=`pwd`/cache/common
267 # Linux
268 if [[ $linux = true ]]
269 then
270 echo ""
271 echo "Compiling ${VERSION} Linux"
272 echo ""
273 ./bin/gbuild -j ${proc} -m ${mem} --commit bitcoin=${COMMIT} --url bitcoin=${url} ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
274 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-linux --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
275 mv build/out/bitcoin-*.tar.gz build/out/src/bitcoin-*.tar.gz ../bitcoin-binaries/${VERSION}
277 # Windows
278 if [[ $windows = true ]]
279 then
280 echo ""
281 echo "Compiling ${VERSION} Windows"
282 echo ""
283 ./bin/gbuild -j ${proc} -m ${mem} --commit bitcoin=${COMMIT} --url bitcoin=${url} ../bitcoin/contrib/gitian-descriptors/gitian-win.yml
284 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-win-unsigned --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-win.yml
285 mv build/out/bitcoin-*-win-unsigned.tar.gz inputs/bitcoin-win-unsigned.tar.gz
286 mv build/out/bitcoin-*.zip build/out/bitcoin-*.exe ../bitcoin-binaries/${VERSION}
288 # Mac OSX
289 if [[ $osx = true ]]
290 then
291 echo ""
292 echo "Compiling ${VERSION} Mac OSX"
293 echo ""
294 ./bin/gbuild -j ${proc} -m ${mem} --commit bitcoin=${COMMIT} --url bitcoin=${url} ../bitcoin/contrib/gitian-descriptors/gitian-osx.yml
295 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-osx-unsigned --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-osx.yml
296 mv build/out/bitcoin-*-osx-unsigned.tar.gz inputs/bitcoin-osx-unsigned.tar.gz
297 mv build/out/bitcoin-*.tar.gz build/out/bitcoin-*.dmg ../bitcoin-binaries/${VERSION}
299 popd
301 if [[ $commitFiles = true ]]
302 then
303 # Commit to gitian.sigs repo
304 echo ""
305 echo "Committing ${VERSION} Unsigned Sigs"
306 echo ""
307 pushd gitian.sigs
308 git add ${VERSION}-linux/${SIGNER}
309 git add ${VERSION}-win-unsigned/${SIGNER}
310 git add ${VERSION}-osx-unsigned/${SIGNER}
311 git commit -a -m "Add ${VERSION} unsigned sigs for ${SIGNER}"
312 popd
316 # Verify the build
317 if [[ $verify = true ]]
318 then
319 # Linux
320 pushd ./gitian-builder
321 echo ""
322 echo "Verifying v${VERSION} Linux"
323 echo ""
324 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-linux ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
325 # Windows
326 echo ""
327 echo "Verifying v${VERSION} Windows"
328 echo ""
329 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-win-unsigned ../bitcoin/contrib/gitian-descriptors/gitian-win.yml
330 # Mac OSX
331 echo ""
332 echo "Verifying v${VERSION} Mac OSX"
333 echo ""
334 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-osx-unsigned ../bitcoin/contrib/gitian-descriptors/gitian-osx.yml
335 # Signed Windows
336 echo ""
337 echo "Verifying v${VERSION} Signed Windows"
338 echo ""
339 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-osx-signed ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
340 # Signed Mac OSX
341 echo ""
342 echo "Verifying v${VERSION} Signed Mac OSX"
343 echo ""
344 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-osx-signed ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
345 popd
348 # Sign binaries
349 if [[ $sign = true ]]
350 then
352 pushd ./gitian-builder
353 # Sign Windows
354 if [[ $windows = true ]]
355 then
356 echo ""
357 echo "Signing ${VERSION} Windows"
358 echo ""
359 ./bin/gbuild -i --commit signature=${COMMIT} ../bitcoin/contrib/gitian-descriptors/gitian-win-signer.yml
360 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-win-signed --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-win-signer.yml
361 mv build/out/bitcoin-*win64-setup.exe ../bitcoin-binaries/${VERSION}
362 mv build/out/bitcoin-*win32-setup.exe ../bitcoin-binaries/${VERSION}
364 # Sign Mac OSX
365 if [[ $osx = true ]]
366 then
367 echo ""
368 echo "Signing ${VERSION} Mac OSX"
369 echo ""
370 ./bin/gbuild -i --commit signature=${COMMIT} ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
371 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-osx-signed --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
372 mv build/out/bitcoin-osx-signed.dmg ../bitcoin-binaries/${VERSION}/bitcoin-${VERSION}-osx.dmg
374 popd
376 if [[ $commitFiles = true ]]
377 then
378 # Commit Sigs
379 pushd gitian.sigs
380 echo ""
381 echo "Committing ${VERSION} Signed Sigs"
382 echo ""
383 git add ${VERSION}-win-signed/${SIGNER}
384 git add ${VERSION}-osx-signed/${SIGNER}
385 git commit -a -m "Add ${VERSION} signed binary sigs for ${SIGNER}"
386 popd