make.bash 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env bash
  2. set -e
  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. prepare_build () {
  10. BUILDINFOFILE="${EXE_BASENAME}_buildinfo.txt"
  11. BUILDDATE=$(date --iso-8601=seconds)
  12. BUILDREPO=$(git config --get remote.origin.url)
  13. BUILDREV=$(git rev-parse --short HEAD)
  14. GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1')
  15. DEPENDENCIES=$(echo -n "{" && go list -f '{{range $dep := .Deps}}{{printf "%s\n" $dep}}{{end}}' | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' | xargs -I pkg bash -c 'cd $GOPATH/src/pkg && echo -n "\"pkg\":\"$(git rev-parse --short HEAD)\","' | sed 's/,$/}/')
  16. LDFLAGS="\
  17. -linkmode external -extldflags \"-static\" \
  18. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.buildDate=$BUILDDATE \
  19. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.buildRepo=$BUILDREPO \
  20. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.buildRev=$BUILDREV \
  21. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.goVersion=$GOVERSION \
  22. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.dependencies=$DEPENDENCIES \
  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 " Dependencies: ${DEPENDENCIES}"
  31. echo ""
  32. }
  33. build_for_linux () {
  34. echo "Getting project dependencies (via go get) for Linux. Parameter is: '$1'"
  35. GOOS=linux GOARCH=amd64 go get -d -v ./...
  36. prepare_build
  37. if [ $? != 0 ]; then
  38. echo "...'go get' failed, exiting"
  39. exit $?
  40. fi
  41. GOOS=linux GOARCH=amd64 go build -ldflags "$LDFLAGS" -o psiphond main.go
  42. if [ $? != 0 ]; then
  43. echo "...'go build' failed, exiting"
  44. exit $?
  45. fi
  46. chmod 555 psiphond
  47. if [ "$1" == "generate" ]; then
  48. ./psiphond --ipaddress 0.0.0.0 --web 3000 --protocol SSH:3001 --protocol OSSH:3002 --logFilename /var/log/psiphond/psiphond.log generate
  49. chmod 666 psiphond.config
  50. chmod 666 psiphond-traffic-rules.config
  51. chmod 666 server-entry.dat
  52. fi
  53. }
  54. build_for_linux generate
  55. echo "Done"