user-package.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/usr/bin/env bash
  2. # Bash3 Boilerplate. Copyright (c) 2014, kvz.io
  3. set -o errexit
  4. set -o pipefail
  5. set -o nounset
  6. # set -o xtrace
  7. trap 'echo -e "Aborted, error $? in command: $BASH_COMMAND"; trap ERR; exit 1' ERR
  8. # Set magic variables for current file & dir
  9. __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  10. __file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
  11. __base="$(basename ${__file} .sh)"
  12. __root="$(cd "$(dirname "${__dir}")" && pwd)" # <-- change this as it depends on your app
  13. NOW=$(date '+%Y%m%d-%H%M%S')
  14. TMP=$(mktemp -d)
  15. BUILDTAG=$NOW
  16. BUILDNAME="user"
  17. GOPATH=$(go env GOPATH)
  18. cleanup () { rm -rf $TMP; }
  19. trap cleanup INT TERM ERR
  20. get_source() {
  21. go get -v -t v2ray.com/core/...
  22. }
  23. build_v2() {
  24. pushd $GOPATH/src/v2ray.com/core
  25. sed -i "s/\"Po\"/\"${BUILDNAME}\"/;s/\"Custom\"/\"${BUILDTAG}\"/;" core.go
  26. pushd $GOPATH/src/v2ray.com/core/main
  27. env CGO_ENABLED=0 go build -o $TMP/v2ray${EXESUFFIX} -ldflags "-s -w"
  28. popd
  29. git checkout -- core.go
  30. popd
  31. pushd $GOPATH/src/v2ray.com/core/infra/control/main
  32. env CGO_ENABLED=0 go build -o $TMP/v2ctl${EXESUFFIX} -tags confonly -ldflags "-s -w"
  33. popd
  34. }
  35. build_dat() {
  36. wget -qO - https://api.github.com/repos/v2ray/geoip/releases/latest \
  37. | grep browser_download_url | cut -d '"' -f 4 \
  38. | wget -i - -O $TMP/geoip.dat
  39. wget -qO - https://api.github.com/repos/v2ray/domain-list-community/releases/latest \
  40. | grep browser_download_url | cut -d '"' -f 4 \
  41. | wget -i - -O $TMP/geosite.dat
  42. }
  43. copyconf() {
  44. pushd $GOPATH/src/v2ray.com/core/release/config
  45. tar c --exclude "*.dat" . | tar x -C $TMP
  46. }
  47. pack() {
  48. pushd $TMP
  49. local PKG=${__dir}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.zip
  50. zip -r $PKG .
  51. }
  52. nosource=0
  53. nodat=0
  54. noconf=0
  55. GOOS=linux
  56. GOARCH=amd64
  57. EXESUFFIX=
  58. PKGSUFFIX=
  59. for arg in "$@"; do
  60. case $arg in
  61. arm*)
  62. GOARCH=$arg
  63. ;;
  64. mips*)
  65. GOARCH=$arg
  66. ;;
  67. 386)
  68. GOARCH=386
  69. ;;
  70. windows)
  71. GOOS=windows
  72. EXESUFFIX=.exe
  73. ;;
  74. darwin)
  75. GOOS=$arg
  76. ;;
  77. nodat)
  78. nodat=1
  79. PKGSUFFIX=${PKGSUFFIX}nodat-
  80. ;;
  81. noconf)
  82. noconf=1
  83. ;;
  84. nosource)
  85. nosource=1
  86. ;;
  87. esac
  88. done
  89. if [[ $nosource != 1 ]]; then
  90. get_source
  91. fi
  92. export GOOS GOARCH
  93. build_v2
  94. if [[ $nodat != 1 ]]; then
  95. build_dat
  96. fi
  97. if [[ $noconf != 1 ]]; then
  98. copyconf
  99. fi
  100. pack
  101. cleanup