make.bash 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. export GOCACHE=/tmp
  12. prepare_build () {
  13. BUILDINFOFILE="psiphond_buildinfo.txt"
  14. BUILDDATE=$(date -Iseconds)
  15. BUILDREPO=$(git config --get remote.origin.url)
  16. BUILDREV=$(git rev-parse --short HEAD)
  17. GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1')
  18. LDFLAGS="\
  19. -linkmode external -extldflags \"-static\" \
  20. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildDate=$BUILDDATE \
  21. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRepo=$BUILDREPO \
  22. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRev=$BUILDREV \
  23. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.goVersion=$GOVERSION \
  24. "
  25. echo -e "${BUILDDATE}\n${BUILDREPO}\n${BUILDREV}\n" > $BUILDINFOFILE
  26. echo "Variables for ldflags:"
  27. echo " Build date: ${BUILDDATE}"
  28. echo " Build repo: ${BUILDREPO}"
  29. echo " Build revision: ${BUILDREV}"
  30. echo " Go version: ${GOVERSION}"
  31. echo ""
  32. }
  33. build_for_linux () {
  34. prepare_build linux
  35. GOOS=linux GOARCH=amd64 go build -v -x -tags "${BUILD_TAGS}" -ldflags "$LDFLAGS" -o psiphond
  36. if [ $? != 0 ]; then
  37. echo "...'go build' failed, exiting"
  38. exit $?
  39. fi
  40. chmod 555 psiphond
  41. if [ "$1" == "generate" ]; then
  42. ./psiphond --ipaddress 0.0.0.0 --web 3000 --protocol SSH:3001 --protocol OSSH:3002 --logFilename /var/log/psiphond/psiphond.log generate
  43. chmod 666 psiphond.config
  44. chmod 666 psiphond-traffic-rules.config
  45. chmod 666 psiphond-osl.config
  46. chmod 666 psiphond-tactics.config
  47. chmod 666 server-entry.dat
  48. fi
  49. }
  50. build_for_linux generate
  51. echo "Done"