release.sh 1.63 KB
Newer Older
1 2 3
#!/bin/bash
set -e

4
# version and keys are supplied as arguments
5
version="$1"
Luke Champine's avatar
Luke Champine committed
6
rc=`echo $version | awk -F - '{print $2}'`
7
keyfile="$2"
8
pubkeyfile="$3" # optional
9 10 11 12
if [[ -z $version || -z $keyfile ]]; then
	echo "Usage: $0 VERSION KEYFILE"
	exit 1
fi
13 14 15
if [[ -z $pubkeyfile ]]; then
	echo "Warning: no public keyfile supplied. Binaries will not be verified."
fi
16 17 18 19 20 21

# check for keyfile before proceeding
if [ ! -f $keyfile ]; then
    echo "Key file not found: $keyfile"
    exit 1
fi
22
keysum=$(shasum -a 256 $keyfile | cut -c -64)
23 24 25 26
if [ $keysum != "735320b4698010500d230c487e970e12776e88f33ad777ab380a493691dadb1b" ]; then
    echo "Wrong key file: checksum does not match developer key file."
    exit 1
fi
27

28
# setup build-time vars
29
ldflags="-s -w -X 'gitlab.com/NebulousLabs/Sia/build.GitRevision=`git rev-parse --short HEAD`' -X 'gitlab.com/NebulousLabs/Sia/build.BuildTime=`date`' -X 'gitlab.com/NebulousLabs/Sia/build.ReleaseTag=${rc}'"
30

31 32 33
for os in darwin linux windows; do
	echo Packaging ${os}...
	# create workspace
34
	folder=release/Sia-$version-$os-amd64
35 36 37 38 39 40 41 42
	rm -rf $folder
	mkdir -p $folder
	# compile and sign binaries
	for pkg in siac siad; do
		bin=$pkg
		if [ "$os" == "windows" ]; then
			bin=${pkg}.exe
		fi
43
		GOOS=${os} go build -a -tags 'netgo' -ldflags="$ldflags" -o $folder/$bin ./cmd/$pkg
44
		openssl dgst -sha256 -sign $keyfile -out $folder/${bin}.sig $folder/$bin
45 46 47 48 49
		# verify signature
		if [[ -n $pubkeyfile ]]; then
			openssl dgst -sha256 -verify $pubkeyfile -signature $folder/${bin}.sig $folder/$bin
		fi

50 51
	done
	# add other artifacts
52
	cp -r doc LICENSE README.md $folder
53
	# zip
Luke Champine's avatar
Luke Champine committed
54 55 56 57
	(
		cd release
		zip -rq Sia-$version-$os-amd64.zip Sia-$version-$os-amd64
	)
58
done