2020-01-30 11:38:30 +01:00
|
|
|
#!/bin/sh
|
2019-05-15 14:48:06 +02:00
|
|
|
set -e
|
|
|
|
|
2020-02-18 09:53:38 +01:00
|
|
|
buildtags="-tags ooni"
|
2019-11-14 12:20:04 +01:00
|
|
|
ldflags="-s -w"
|
|
|
|
|
2020-01-29 18:48:12 +01:00
|
|
|
if [ "$1" = "bindata" ]; then
|
2020-01-28 11:48:25 +01:00
|
|
|
GO_BINDATA_V=$(go-bindata -version | grep go-bin | cut -d ' ' -f2)
|
2020-01-30 11:38:30 +01:00
|
|
|
if [ "$GO_BINDATA_V" = "3.2.0" ]; then
|
|
|
|
echo "Updating bindata"
|
|
|
|
go-bindata -nometadata -o internal/bindata/bindata.go -pkg bindata data/...
|
|
|
|
echo "DONE"
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "Wrong go-bindata-version"
|
|
|
|
echo "Please install go-bindata with:"
|
|
|
|
echo " go get -u github.com/shuLhan/go-bindata/..."
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-01-28 11:48:25 +01:00
|
|
|
fi
|
|
|
|
|
2019-05-15 14:48:06 +02:00
|
|
|
if [ "$1" = "windows" ]; then
|
|
|
|
set -x
|
|
|
|
CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ \
|
2020-02-26 22:34:23 +01:00
|
|
|
CGO_LDFLAGS_ALLOW='-fstack-.*' CGO_ENABLED=1 GOOS=windows GOARCH=amd64 \
|
2019-11-14 12:20:04 +01:00
|
|
|
go build $buildtags -ldflags="$ldflags" \
|
|
|
|
-o dist/windows/amd64/ooniprobe.exe -v ./cmd/ooniprobe
|
2019-05-15 14:48:06 +02:00
|
|
|
|
|
|
|
elif [ "$1" = "linux" ]; then
|
|
|
|
set -x
|
2019-12-26 18:36:41 +01:00
|
|
|
$0 __docker go build $buildtags -ldflags="$ldflags" \
|
2019-11-14 12:20:04 +01:00
|
|
|
-o dist/linux/amd64/ooniprobe -v ./cmd/ooniprobe
|
2019-05-15 14:48:06 +02:00
|
|
|
|
|
|
|
elif [ "$1" = "macos" ]; then
|
|
|
|
set -x
|
2019-11-14 12:20:04 +01:00
|
|
|
go build $buildtags -ldflags="$ldflags" \
|
|
|
|
-o dist/macos/amd64/ooniprobe -v ./cmd/ooniprobe
|
2019-05-15 14:48:06 +02:00
|
|
|
|
2019-10-03 11:45:49 +02:00
|
|
|
elif [ "$1" = "release" ]; then
|
|
|
|
set -x
|
|
|
|
v=`git describe --tags`
|
|
|
|
$0 linux
|
2019-10-03 20:22:19 +02:00
|
|
|
tar -czf ooniprobe_${v}_linux_amd64.tar.gz LICENSE.md Readme.md \
|
|
|
|
-C ./dist/linux/amd64 ooniprobe
|
|
|
|
shasum -a 256 ooniprobe_${v}_linux_amd64.tar.gz > ooniprobe_checksums.txt
|
2019-10-03 11:45:49 +02:00
|
|
|
$0 macos
|
2019-10-03 20:22:19 +02:00
|
|
|
tar -czf ooniprobe_${v}_darwin_amd64.tar.gz LICENSE.md Readme.md \
|
|
|
|
-C ./dist/macos/amd64 ooniprobe
|
|
|
|
shasum -a 256 ooniprobe_${v}_darwin_amd64.tar.gz >> ooniprobe_checksums.txt
|
2019-10-03 11:45:49 +02:00
|
|
|
$0 windows
|
2020-02-26 22:34:23 +01:00
|
|
|
tar -czf ooniprobe_${v}_windows_amd64.tar.gz LICENSE.md Readme.md \
|
2019-10-03 20:22:19 +02:00
|
|
|
-C dist/windows/amd64 ooniprobe.exe
|
|
|
|
shasum -a 256 ooniprobe_${v}_windows_amd64.tar.gz >> ooniprobe_checksums.txt
|
2019-10-03 11:45:49 +02:00
|
|
|
echo ""
|
2019-10-03 23:34:41 +02:00
|
|
|
echo "Now sign ooniprobe_checksums.txt and upload it along with tarballs to GitHub"
|
2019-10-03 11:45:49 +02:00
|
|
|
|
2019-12-26 18:36:41 +01:00
|
|
|
elif [ "$1" = "__docker" ]; then
|
|
|
|
set -x
|
|
|
|
shift
|
|
|
|
docker build -t oonibuild .
|
|
|
|
docker run -v `pwd`:/oonibuild \
|
|
|
|
-w /oonibuild \
|
|
|
|
-t \
|
|
|
|
--cap-drop=all \
|
|
|
|
--user `id -u`:`id -g` \
|
|
|
|
-e 'GOCACHE=/oonibuild/testdata/gotmp/cache' \
|
|
|
|
-e 'GOPATH=/oonibuild/testdata/gotmp/path' \
|
|
|
|
-e "TRAVIS_JOB_ID=$TRAVIS_JOB_ID" \
|
|
|
|
-e "TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST" \
|
|
|
|
oonibuild "$@"
|
|
|
|
|
2019-05-15 14:48:06 +02:00
|
|
|
elif [ "$1" = "_travis-linux" ]; then
|
|
|
|
set -x
|
|
|
|
$0 linux
|
2019-12-26 18:36:41 +01:00
|
|
|
# TODO -race does not work on alpine.
|
|
|
|
# See: https://travis-ci.org/ooni/probe-cli/builds/619631256#L962
|
|
|
|
$0 __docker go get -v golang.org/x/tools/cmd/cover
|
|
|
|
$0 __docker go get -v github.com/mattn/goveralls
|
2020-02-18 09:53:38 +01:00
|
|
|
$0 __docker go test $buildtags -v -coverprofile=coverage.cov -coverpkg=./... ./...
|
2019-12-26 18:36:41 +01:00
|
|
|
$0 __docker /oonibuild/testdata/gotmp/path/bin/goveralls \
|
|
|
|
-coverprofile=coverage.cov -service=travis-ci
|
2019-05-15 14:48:06 +02:00
|
|
|
|
|
|
|
elif [ "$1" = "_travis-osx" ]; then
|
|
|
|
set -x
|
|
|
|
brew tap measurement-kit/measurement-kit
|
|
|
|
brew update
|
|
|
|
brew upgrade
|
|
|
|
brew install measurement-kit
|
|
|
|
$0 macos
|
2019-12-02 15:01:37 +01:00
|
|
|
go test -v -race -coverprofile=coverage.cov -coverpkg=./... ./...
|
2019-05-15 14:48:06 +02:00
|
|
|
|
|
|
|
elif [ "$1" = "help" ]; then
|
2019-10-03 11:45:49 +02:00
|
|
|
echo "Usage: $0 linux | macos | release | windows"
|
2019-05-15 14:48:06 +02:00
|
|
|
echo ""
|
|
|
|
echo "Builds OONI on supported systems. The output binary will"
|
2019-10-02 19:27:15 +02:00
|
|
|
echo "be saved at './dist/<system>/<arch>/ooniprobe[.exe]'."
|
2019-05-15 14:48:06 +02:00
|
|
|
echo ""
|
|
|
|
echo "# Linux"
|
|
|
|
echo ""
|
|
|
|
echo "To compile for Linux we use a docker container with the binary"
|
|
|
|
echo "Measurement Kit dependency installed. So you need docker installed."
|
|
|
|
echo ""
|
|
|
|
echo "# macOS"
|
|
|
|
echo ""
|
|
|
|
echo "You must be on macOS. You must install Measurement Kit once using:"
|
|
|
|
echo ""
|
|
|
|
echo "- brew tap measurement-kit/measurement-kit"
|
|
|
|
echo "- brew install measurement-kit"
|
|
|
|
echo ""
|
|
|
|
echo "You should keep Measurement Kit up-to-date using:"
|
|
|
|
echo ""
|
|
|
|
echo "- brew upgrade"
|
|
|
|
echo ""
|
2019-10-03 11:45:49 +02:00
|
|
|
echo "# Release"
|
|
|
|
echo ""
|
|
|
|
echo "Will build ooniprobe for all supported systems."
|
|
|
|
echo ""
|
2019-05-15 14:48:06 +02:00
|
|
|
echo "# Windows"
|
|
|
|
echo ""
|
|
|
|
echo "You must be on macOS. You must install Measurement Kit once using:"
|
|
|
|
echo ""
|
|
|
|
echo "- brew tap measurement-kit/measurement-kit"
|
|
|
|
echo "- brew install mingw-w64-measurement-kit"
|
|
|
|
echo ""
|
|
|
|
echo "You should keep Measurement Kit up-to-date using:"
|
|
|
|
echo ""
|
|
|
|
echo "- brew upgrade"
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
else
|
|
|
|
echo "Invalid usage; try '$0 help' for more help." 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|