[trivial] Fix typo ("improssible" → "impossible")
[bitcoinplatinum.git] / contrib / gitian-build.sh
blob6ee5df47039e6f732b46e421d02f81bf5ccbf24a
1 # Copyright (c) 2016 The Bitcoin Core developers
2 # Distributed under the MIT software license, see the accompanying
3 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 # What to do
6 sign=false
7 verify=false
8 build=false
9 setupenv=false
11 # Systems to build
12 linux=true
13 windows=true
14 osx=true
16 # Other Basic variables
17 SIGNER=
18 VERSION=
19 commit=false
20 url=https://github.com/bitcoin/bitcoin
21 proc=2
22 mem=2000
23 lxc=true
24 osslTarUrl=http://downloads.sourceforge.net/project/osslsigncode/osslsigncode/osslsigncode-1.7.1.tar.gz
25 osslPatchUrl=https://bitcoincore.org/cfields/osslsigncode-Backports-to-1.7.1.patch
26 scriptName=$(basename -- "$0")
27 signProg="gpg --detach-sign"
28 commitFiles=true
30 # Help Message
31 read -d '' usage <<- EOF
32 Usage: $scriptName [-c|u|v|b|s|B|o|h|j|m|] signer version
34 Run this script from the directory containing the bitcoin, gitian-builder, gitian.sigs, and bitcoin-detached-sigs.
36 Arguments:
37 signer GPG signer to sign each build assert file
38 version Version number, commit, or branch to build. If building a commit or branch, the -c option must be specified
40 Options:
41 -c|--commit Indicate that the version argument is for a commit or branch
42 -u|--url Specify the URL of the repository. Default is https://github.com/bitcoin/bitcoin
43 -v|--verify Verify the gitian build
44 -b|--build Do a gitian build
45 -s|--sign Make signed binaries for Windows and Mac OSX
46 -B|--buildsign Build both signed and unsigned binaries
47 -o|--os Specify which Operating Systems the build is for. Default is lwx. l for linux, w for windows, x for osx
48 -j Number of processes to use. Default 2
49 -m Memory to allocate in MiB. Default 2000
50 --kvm Use KVM instead of LXC
51 --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)
52 --detach-sign Create the assert file for detached signing. Will not commit anything.
53 --no-commit Do not commit anything to git
54 -h|--help Print this help message
55 EOF
57 # Get options and arguments
58 while :; do
59 case $1 in
60 # Verify
61 -v|--verify)
62 verify=true
64 # Build
65 -b|--build)
66 build=true
68 # Sign binaries
69 -s|--sign)
70 sign=true
72 # Build then Sign
73 -B|--buildsign)
74 sign=true
75 build=true
77 # PGP Signer
78 -S|--signer)
79 if [ -n "$2" ]
80 then
81 SIGNER=$2
82 shift
83 else
84 echo 'Error: "--signer" requires a non-empty argument.'
85 exit 1
88 # Operating Systems
89 -o|--os)
90 if [ -n "$2" ]
91 then
92 linux=false
93 windows=false
94 osx=false
95 if [[ "$2" = *"l"* ]]
96 then
97 linux=true
99 if [[ "$2" = *"w"* ]]
100 then
101 windows=true
103 if [[ "$2" = *"x"* ]]
104 then
105 osx=true
107 shift
108 else
109 echo 'Error: "--os" requires an argument containing an l (for linux), w (for windows), or x (for Mac OSX)\n'
110 exit 1
113 # Help message
114 -h|--help)
115 echo "$usage"
116 exit 0
118 # Commit or branch
119 -c|--commit)
120 commit=true
122 # Number of Processes
124 if [ -n "$2" ]
125 then
126 proc=$2
127 shift
128 else
129 echo 'Error: "-j" requires an argument'
130 exit 1
133 # Memory to allocate
135 if [ -n "$2" ]
136 then
137 mem=$2
138 shift
139 else
140 echo 'Error: "-m" requires an argument'
141 exit 1
144 # URL
146 if [ -n "$2" ]
147 then
148 url=$2
149 shift
150 else
151 echo 'Error: "-u" requires an argument'
152 exit 1
155 # kvm
156 --kvm)
157 lxc=false
159 # Detach sign
160 --detach-sign)
161 signProg="true"
162 commitFiles=false
164 # Commit files
165 --no-commit)
166 commitFiles=false
168 # Setup
169 --setup)
170 setup=true
172 *) # Default case: If no more options then break out of the loop.
173 break
174 esac
175 shift
176 done
178 # Set up LXC
179 if [[ $lxc = true ]]
180 then
181 export USE_LXC=1
182 export LXC_BRIDGE=lxcbr0
183 sudo ifconfig lxcbr0 up 10.0.2.2
186 # Check for OSX SDK
187 if [[ ! -e "gitian-builder/inputs/MacOSX10.11.sdk.tar.gz" && $osx == true ]]
188 then
189 echo "Cannot build for OSX, SDK does not exist. Will build for other OSes"
190 osx=false
193 # Get signer
194 if [[ -n"$1" ]]
195 then
196 SIGNER=$1
197 shift
200 # Get version
201 if [[ -n "$1" ]]
202 then
203 VERSION=$1
204 COMMIT=$VERSION
205 shift
208 # Check that a signer is specified
209 if [[ $SIGNER == "" ]]
210 then
211 echo "$scriptName: Missing signer."
212 echo "Try $scriptName --help for more information"
213 exit 1
216 # Check that a version is specified
217 if [[ $VERSION == "" ]]
218 then
219 echo "$scriptName: Missing version."
220 echo "Try $scriptName --help for more information"
221 exit 1
224 # Add a "v" if no -c
225 if [[ $commit = false ]]
226 then
227 COMMIT="v${VERSION}"
229 echo ${COMMIT}
231 # Setup build environment
232 if [[ $setup = true ]]
233 then
234 sudo apt-get install ruby apache2 git apt-cacher-ng python-vm-builder qemu-kvm qemu-utils
235 git clone https://github.com/bitcoin-core/gitian.sigs.git
236 git clone https://github.com/bitcoin-core/bitcoin-detached-sigs.git
237 git clone https://github.com/devrandom/gitian-builder.git
238 pushd ./gitian-builder
239 if [[ -n "$USE_LXC" ]]
240 then
241 sudo apt-get install lxc
242 bin/make-base-vm --suite trusty --arch amd64 --lxc
243 else
244 bin/make-base-vm --suite trusty --arch amd64
246 popd
249 # Set up build
250 pushd ./bitcoin
251 git fetch
252 git checkout ${COMMIT}
253 popd
255 # Build
256 if [[ $build = true ]]
257 then
258 # Make output folder
259 mkdir -p ./bitcoin-binaries/${VERSION}
261 # Build Dependencies
262 echo ""
263 echo "Building Dependencies"
264 echo ""
265 pushd ./gitian-builder
266 mkdir -p inputs
267 wget -N -P inputs $osslPatchUrl
268 wget -N -P inputs $osslTarUrl
269 make -C ../bitcoin/depends download SOURCES_PATH=`pwd`/cache/common
271 # Linux
272 if [[ $linux = true ]]
273 then
274 echo ""
275 echo "Compiling ${VERSION} Linux"
276 echo ""
277 ./bin/gbuild -j ${proc} -m ${mem} --commit bitcoin=${COMMIT} --url bitcoin=${url} ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
278 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-linux --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
279 mv build/out/bitcoin-*.tar.gz build/out/src/bitcoin-*.tar.gz ../bitcoin-binaries/${VERSION}
281 # Windows
282 if [[ $windows = true ]]
283 then
284 echo ""
285 echo "Compiling ${VERSION} Windows"
286 echo ""
287 ./bin/gbuild -j ${proc} -m ${mem} --commit bitcoin=${COMMIT} --url bitcoin=${url} ../bitcoin/contrib/gitian-descriptors/gitian-win.yml
288 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-win-unsigned --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-win.yml
289 mv build/out/bitcoin-*-win-unsigned.tar.gz inputs/bitcoin-win-unsigned.tar.gz
290 mv build/out/bitcoin-*.zip build/out/bitcoin-*.exe ../bitcoin-binaries/${VERSION}
292 # Mac OSX
293 if [[ $osx = true ]]
294 then
295 echo ""
296 echo "Compiling ${VERSION} Mac OSX"
297 echo ""
298 ./bin/gbuild -j ${proc} -m ${mem} --commit bitcoin=${COMMIT} --url bitcoin=${url} ../bitcoin/contrib/gitian-descriptors/gitian-osx.yml
299 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-osx-unsigned --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-osx.yml
300 mv build/out/bitcoin-*-osx-unsigned.tar.gz inputs/bitcoin-osx-unsigned.tar.gz
301 mv build/out/bitcoin-*.tar.gz build/out/bitcoin-*.dmg ../bitcoin-binaries/${VERSION}
303 popd
305 if [[ $commitFiles = true ]]
306 then
307 # Commit to gitian.sigs repo
308 echo ""
309 echo "Committing ${VERSION} Unsigned Sigs"
310 echo ""
311 pushd gitian.sigs
312 git add ${VERSION}-linux/${SIGNER}
313 git add ${VERSION}-win-unsigned/${SIGNER}
314 git add ${VERSION}-osx-unsigned/${SIGNER}
315 git commit -a -m "Add ${VERSION} unsigned sigs for ${SIGNER}"
316 popd
320 # Verify the build
321 if [[ $verify = true ]]
322 then
323 # Linux
324 pushd ./gitian-builder
325 echo ""
326 echo "Verifying v${VERSION} Linux"
327 echo ""
328 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-linux ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
329 # Windows
330 echo ""
331 echo "Verifying v${VERSION} Windows"
332 echo ""
333 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-win-unsigned ../bitcoin/contrib/gitian-descriptors/gitian-win.yml
334 # Mac OSX
335 echo ""
336 echo "Verifying v${VERSION} Mac OSX"
337 echo ""
338 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-osx-unsigned ../bitcoin/contrib/gitian-descriptors/gitian-osx.yml
339 # Signed Windows
340 echo ""
341 echo "Verifying v${VERSION} Signed Windows"
342 echo ""
343 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-osx-signed ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
344 # Signed Mac OSX
345 echo ""
346 echo "Verifying v${VERSION} Signed Mac OSX"
347 echo ""
348 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-osx-signed ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
349 popd
352 # Sign binaries
353 if [[ $sign = true ]]
354 then
356 pushd ./gitian-builder
357 # Sign Windows
358 if [[ $windows = true ]]
359 then
360 echo ""
361 echo "Signing ${VERSION} Windows"
362 echo ""
363 ./bin/gbuild -i --commit signature=${COMMIT} ../bitcoin/contrib/gitian-descriptors/gitian-win-signer.yml
364 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-win-signed --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-win-signer.yml
365 mv build/out/bitcoin-*win64-setup.exe ../bitcoin-binaries/${VERSION}
366 mv build/out/bitcoin-*win32-setup.exe ../bitcoin-binaries/${VERSION}
368 # Sign Mac OSX
369 if [[ $osx = true ]]
370 then
371 echo ""
372 echo "Signing ${VERSION} Mac OSX"
373 echo ""
374 ./bin/gbuild -i --commit signature=${COMMIT} ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
375 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-osx-signed --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
376 mv build/out/bitcoin-osx-signed.dmg ../bitcoin-binaries/${VERSION}/bitcoin-${VERSION}-osx.dmg
378 popd
380 if [[ $commitFiles = true ]]
381 then
382 # Commit Sigs
383 pushd gitian.sigs
384 echo ""
385 echo "Committing ${VERSION} Signed Sigs"
386 echo ""
387 git add ${VERSION}-win-signed/${SIGNER}
388 git add ${VERSION}-osx-signed/${SIGNER}
389 git commit -a -m "Add ${VERSION} signed binary sigs for ${SIGNER}"
390 popd