make.bash 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env bash
  2. set -e -u -x
  3. BASE_DIR=$( cd "$(dirname "$0")" ; pwd -P )
  4. cd $BASE_DIR
  5. if [ ! -f make.bash ]; then
  6. echo "make.bash must be run from $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/Server"
  7. exit 1
  8. fi
  9. # $1, if specified, is go build tags
  10. if [ -z ${1+x} ]; then BUILD_TAGS=""; else BUILD_TAGS="$1"; fi
  11. prepare_build () {
  12. BUILDINFOFILE="psiphond_buildinfo.txt"
  13. BUILDDATE=$(date -Iseconds)
  14. BUILDREPO=$(git config --get remote.origin.url)
  15. BUILDREV=$(git rev-parse --short HEAD)
  16. GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1')
  17. LDFLAGS="\
  18. -linkmode external -extldflags \"-static\" \
  19. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildDate=$BUILDDATE \
  20. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRepo=$BUILDREPO \
  21. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRev=$BUILDREV \
  22. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.goVersion=$GOVERSION \
  23. "
  24. echo -e "${BUILDDATE}\n${BUILDREPO}\n${BUILDREV}\n" > $BUILDINFOFILE
  25. echo "Variables for ldflags:"
  26. echo " Build date: ${BUILDDATE}"
  27. echo " Build repo: ${BUILDREPO}"
  28. echo " Build revision: ${BUILDREV}"
  29. echo " Go version: ${GOVERSION}"
  30. echo ""
  31. }
  32. build_for_linux () {
  33. prepare_build linux
  34. GOOS=linux GOARCH=amd64 go build -v -x -tags "${BUILD_TAGS}" -ldflags "$LDFLAGS" -o psiphond
  35. if [ $? != 0 ]; then
  36. echo "...'go build' failed, exiting"
  37. exit $?
  38. fi
  39. chmod 555 psiphond
  40. if [ "$1" == "generate" ]; then
  41. ./psiphond --ipaddress 0.0.0.0 --web 3000 --protocol SSH:3001 --protocol OSSH:3002 --logFilename /var/log/psiphond/psiphond.log generate
  42. chmod 666 psiphond.config
  43. chmod 666 psiphond-traffic-rules.config
  44. chmod 666 psiphond-osl.config
  45. chmod 666 psiphond-tactics.config
  46. chmod 666 server-entry.dat
  47. fi
  48. }
  49. build_for_linux generate
  50. echo "Done"