Skip to content

Commit eda4cfb

Browse files
committed
Create an easy to use gitian building script
I've written a script that automates the setup and building of binaries with gitian. All of the commands are pulled from various documentation on gitian building.
1 parent c072b8f commit eda4cfb

File tree

2 files changed

+365
-0
lines changed

2 files changed

+365
-0
lines changed

contrib/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ Scripts and notes for Mac builds.
4545
### [RPM](/contrib/rpm) ###
4646
RPM spec file for building bitcoin-core on RPM based distributions
4747

48+
### [Gitian-build](/contrib/gitian-build.sh) ###
49+
Script for running full gitian builds.
50+
4851
Test and Verify Tools
4952
---------------------
5053

contrib/gitian-build.sh

Lines changed: 362 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,362 @@
1+
# What to do
2+
sign=false
3+
verify=false
4+
build=false
5+
setupenv=false
6+
7+
# Systems to build
8+
linux=true
9+
windows=true
10+
osx=true
11+
12+
# Other Basic variables
13+
SIGNER=
14+
VERSION=
15+
commit=false
16+
url=https://github.com/bitcoin/bitcoin
17+
proc=4
18+
mem=4000
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+
24+
# Help Message
25+
read -d '' usage <<- EOF
26+
Usage: $scriptName [-c|u|v|b|s|B|o|h|j|m|] signer version
27+
28+
Run this script from the directory containing the bitcoin, gitian-builder, gitian.sigs, and bitcoin-detached-sigs.
29+
30+
Arguments:
31+
signer GPG signer to sign each build assert file
32+
version Version number, commit, or branch to build. If building a commit or branch, the -c option must be specified
33+
34+
Options:
35+
-c|--commit Indicate that the version argument is for a commit or branch
36+
-u|--url Specify the URL of the repository. Default is https://github.com/bitcoin/bitcoin
37+
-v|--verify Verify the gitian build
38+
-b|--build Do a gitiain build
39+
-s|--sign Make signed binaries for Windows and Mac OSX
40+
-B|--buildsign Build both signed and unsigned binaries
41+
-o|--os Specify which Operating Systems the build is for. Default is lwx. l for linux, w for windows, x for osx
42+
-j Number of processes to use. Default 4
43+
-m Memory to allocate in MiB. Default 2000
44+
--kvm Use KVM instead of LXC
45+
--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)
46+
-h|--help Print this help message
47+
EOF
48+
49+
# Get options and arguments
50+
while :; do
51+
case $1 in
52+
# Verify
53+
-v|--verify)
54+
verify=true
55+
;;
56+
# Build
57+
-b|--build)
58+
build=true
59+
;;
60+
# Sign binaries
61+
-s|--sign)
62+
sign=true
63+
;;
64+
# Build then Sign
65+
-B|--buildsign)
66+
sign=true
67+
build=true
68+
;;
69+
# PGP Signer
70+
-S|--signer)
71+
if [ -n "$2" ]
72+
then
73+
SIGNER=$2
74+
shift
75+
else
76+
echo 'Error: "--signer" requires a non-empty argument.'
77+
exit 1
78+
fi
79+
;;
80+
# Operating Systems
81+
-o|--os)
82+
if [ -n "$2" ]
83+
then
84+
linux=false
85+
windows=false
86+
osx=false
87+
if [[ "$2" = *"l"* ]]
88+
then
89+
linux=true
90+
fi
91+
if [[ "$2" = *"w"* ]]
92+
then
93+
windows=true
94+
fi
95+
if [[ "$2" = *"x"* ]]
96+
then
97+
osx=true
98+
fi
99+
shift
100+
else
101+
echo 'Error: "--os" requires an argument containing an l (for linux), w (for windows), or x (for Mac OSX)\n'
102+
exit 1
103+
fi
104+
;;
105+
# Help message
106+
-h|--help)
107+
echo "$usage"
108+
exit 0
109+
;;
110+
# Commit or branch
111+
-c|--commit)
112+
commit=true
113+
;;
114+
# Number of Processes
115+
-j)
116+
if [ -n "$2" ]
117+
then
118+
proc=$2
119+
shift
120+
else
121+
echo 'Error: "-j" requires an argument'
122+
exit 1
123+
fi
124+
;;
125+
# Memory to allocate
126+
-m)
127+
if [ -n "$2" ]
128+
then
129+
mem=$2
130+
shift
131+
else
132+
echo 'Error: "-m" requires an argument'
133+
exit 1
134+
fi
135+
;;
136+
# URL
137+
-u)
138+
if [ -n "$2" ]
139+
then
140+
url=$2
141+
shift
142+
else
143+
echo 'Error: "-u" requires an argument'
144+
exit 1
145+
fi
146+
;;
147+
# kvm
148+
--kvm)
149+
lxc=false
150+
;;
151+
# Setup
152+
--setup)
153+
setup=true
154+
;;
155+
*) # Default case: If no more options then break out of the loop.
156+
break
157+
esac
158+
shift
159+
done
160+
161+
# Set up LXC
162+
if [[ $lxc = true ]]
163+
then
164+
export USE_LXC=1
165+
export LXC_BRIDGE=lxcbr0
166+
sudo ifconfig lxcbr0 up 10.0.2.2
167+
fi
168+
169+
# Get signer
170+
if [[ -n"$1" ]]
171+
then
172+
SIGNER=$1
173+
shift
174+
fi
175+
176+
# Get version
177+
if [[ -n "$1" ]]
178+
then
179+
VERSION=$1
180+
COMMIT=$VERSION
181+
shift
182+
fi
183+
184+
# Check that a signer is specified
185+
if [[ $SIGNER == "" ]]
186+
then
187+
echo "$scriptName: Missing signer."
188+
echo "Try $scriptName --help for more information"
189+
exit 1
190+
fi
191+
192+
# Check that a version is specified
193+
if [[ $VERSION == "" ]]
194+
then
195+
echo "$scriptName: Missing version."
196+
echo "Try $scriptName --help for more information"
197+
exit 1
198+
fi
199+
200+
# Add a "v" if no -c
201+
if [[ $commit = false ]]
202+
then
203+
COMMIT="v${VERSION}"
204+
fi
205+
echo ${COMMIT}
206+
207+
# Setup build environment
208+
if [[ $setup = true ]]
209+
then
210+
pushd ./gitian-builder
211+
sudo apt-get install ruby apache2 git apt-cacher-ng python-vm-builder qemu-kvm qemu-utils
212+
git clone https://github.com/bitcoin-core/gitian.sigs.git
213+
git clone https://github.com/bitcoin-core/bitcoin-detached-sigs.git
214+
git clone https://github.com/devrandom/gitian-builder.git
215+
if [[ -n "$USE_LXC" ]]
216+
then
217+
sudo apt-get install lxc
218+
bin/make-base-vm --suite trusty --arch amd64 --lxc
219+
else
220+
bin/make-base-vm --suite trusty --arch amd64
221+
fi
222+
popd
223+
fi
224+
225+
# Set up build
226+
pushd ./bitcoin
227+
git fetch
228+
git checkout ${COMMIT}
229+
popd
230+
231+
# Build
232+
if [[ $build = true ]]
233+
then
234+
# Make output folder
235+
mkdir -p ./bitcoin-binaries/${VERSION}
236+
237+
# Build Dependencies
238+
echo ""
239+
echo "Building Dependencies"
240+
echo ""
241+
pushd ./gitian-builder
242+
mkdir -p inputs
243+
wget -N -P inputs $osslPatchUrl
244+
wget -N -P inputs $osslTarUrl
245+
make -C ../bitcoin/depends download SOURCES_PATH=`pwd`/cache/common
246+
247+
# Linux
248+
if [[ $linux = true ]]
249+
then
250+
echo ""
251+
echo "Compiling ${VERSION} Linux"
252+
echo ""
253+
./bin/gbuild -j ${proc} -m ${mem} --commit bitcoin=${COMMIT} --url bitcoin=${url} ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
254+
./bin/gsign --signer $SIGNER --release ${VERSION}-linux --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
255+
mv build/out/bitcoin-*.tar.gz build/out/src/bitcoin-*.tar.gz ../bitcoin-binaries/${VERSION}
256+
fi
257+
# Windows
258+
if [[ $windows = true ]]
259+
then
260+
echo ""
261+
echo "Compiling ${VERSION} Windows"
262+
echo ""
263+
./bin/gbuild -j ${proc} -m ${mem} --commit bitcoin=${COMMIT} --url bitcoin=${url} ../bitcoin/contrib/gitian-descriptors/gitian-win.yml
264+
./bin/gsign --signer $SIGNER --release ${VERSION}-win-unsigned --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-win.yml
265+
mv build/out/bitcoin-*-win-unsigned.tar.gz inputs/bitcoin-win-unsigned.tar.gz
266+
mv build/out/bitcoin-*.zip build/out/bitcoin-*.exe ../bitcoin-binaries/${VERSION}
267+
fi
268+
# Mac OSX
269+
if [[ $osx = true ]]
270+
then
271+
echo ""
272+
echo "Compiling ${VERSION} Mac OSX"
273+
echo ""
274+
./bin/gbuild -j ${proc} -m ${mem} --commit bitcoin=${COMMIT} --url bitcoin=${url} ../bitcoin/contrib/gitian-descriptors/gitian-osx.yml
275+
./bin/gsign --signer $SIGNER --release ${VERSION}-osx-unsigned --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-osx.yml
276+
mv build/out/bitcoin-*-osx-unsigned.tar.gz inputs/bitcoin-osx-unsigned.tar.gz
277+
mv build/out/bitcoin-*.tar.gz build/out/bitcoin-*.dmg ../bitcoin-binaries/${VERSION}
278+
fi
279+
popd
280+
281+
# Commit to gitian.sigs repo
282+
echo ""
283+
echo "Committing ${VERSION} Unsigned Sigs"
284+
echo ""
285+
pushd gitian.sigs
286+
git add ${VERSION}-linux/${SIGNER}
287+
git add ${VERSION}-win-unsigned/${SIGNER}
288+
git add ${VERSION}-osx-unsigned/${SIGNER}
289+
git commit -a -m "Add ${VERSION} unsigned sigs for ${SIGNER}"
290+
popd
291+
fi
292+
293+
# Verify the build
294+
if [[ $verify = true ]]
295+
then
296+
# Linux
297+
pushd ./gitian-builder
298+
echo ""
299+
echo "Verifying v${VERSION} Linux"
300+
echo ""
301+
./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-linux ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
302+
# Windows
303+
echo ""
304+
echo "Verifying v${VERSION} Windows"
305+
echo ""
306+
./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-win-unsigned ../bitcoin/contrib/gitian-descriptors/gitian-win.yml
307+
# Mac OSX
308+
echo ""
309+
echo "Verifying v${VERSION} Mac OSX"
310+
echo ""
311+
./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-osx-unsigned ../bitcoin/contrib/gitian-descriptors/gitian-osx.yml
312+
# Signed Windows
313+
echo ""
314+
echo "Verifying v${VERSION} Signed Windows"
315+
echo ""
316+
./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-osx-signed ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
317+
# Signed Mac OSX
318+
echo ""
319+
echo "Verifying v${VERSION} Signed Mac OSX"
320+
echo ""
321+
./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-osx-signed ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
322+
popd
323+
fi
324+
325+
# Sign binaries
326+
if [[ $sign = true ]]
327+
then
328+
329+
pushd ./gitian-builder
330+
# Sign Windows
331+
if [[ $windows = true ]]
332+
then
333+
echo ""
334+
echo "Signing ${VERSION} Windows"
335+
echo ""
336+
./bin/gbuild -i --commit signature=${COMMIT} ../bitcoin/contrib/gitian-descriptors/gitian-win-signer.yml
337+
./bin/gsign --signer $SIGNER --release ${VERSION}-win-signed --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-win-signer.yml
338+
mv build/out/bitcoin-*win64-setup.exe ../bitcoin-binaries/${VERSION}
339+
mv build/out/bitcoin-*win32-setup.exe ../bitcoin-binaries/${VERSION}
340+
fi
341+
# Sign Mac OSX
342+
if [[ $osx = true ]]
343+
then
344+
echo ""
345+
echo "Signing ${VERSION} Mac OSX"
346+
echo ""
347+
./bin/gbuild -i --commit signature=${COMMIT} ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
348+
./bin/gsign --signer $SIGNER --release ${VERSION}-osx-signed --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
349+
mv build/out/bitcoin-osx-signed.dmg ../bitcoin-binaries/${VERSION}/bitcoin-${VERSION}-osx.dmg
350+
fi
351+
popd
352+
353+
# Commit Sigs
354+
pushd gitian.sigs
355+
echo ""
356+
echo "Committing ${VERSION} Signed Sigs"
357+
echo ""
358+
git add ${VERSION}-win-signed/${SIGNER}
359+
git add ${VERSION}-osx-signed/${SIGNER}
360+
git commit -a -m "Add ${VERSION} signed binary sigs for ${SIGNER}"
361+
popd
362+
fi

0 commit comments

Comments
 (0)