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