build-binary 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env bash
  2. set -e
  3. VER=$1
  4. PROJ="etcd"
  5. if [ -z "$1" ]; then
  6. echo "Usage: ${0} VERSION" >> /dev/stderr
  7. exit 255
  8. fi
  9. set -u
  10. function setup_env {
  11. local proj=${1}
  12. local ver=${2}
  13. if [ ! -d ${proj} ]; then
  14. git clone https://github.com/coreos/${proj}
  15. fi
  16. pushd ${proj} >/dev/null
  17. git checkout master
  18. git fetch --all
  19. git reset --hard origin/master
  20. git checkout $ver
  21. popd >/dev/null
  22. }
  23. function package {
  24. local target=${1}
  25. local srcdir="${2}/bin"
  26. local ccdir="${srcdir}/${GOOS}_${GOARCH}"
  27. if [ -d ${ccdir} ]; then
  28. srcdir=${ccdir}
  29. fi
  30. local ext=""
  31. if [ ${GOOS} == "windows" ]; then
  32. ext=".exe"
  33. fi
  34. for bin in etcd etcdctl; do
  35. cp ${srcdir}/${bin} ${target}/${bin}${ext}
  36. done
  37. cp etcd/README.md ${target}/README.md
  38. cp etcd/etcdctl/README.md ${target}/README-etcdctl.md
  39. cp -R etcd/Documentation ${target}/Documentation
  40. }
  41. function main {
  42. mkdir release
  43. cd release
  44. setup_env ${PROJ} ${VER}
  45. for os in darwin windows linux; do
  46. export GOOS=${os}
  47. export GOARCH="amd64"
  48. pushd etcd >/dev/null
  49. ./build
  50. popd >/dev/null
  51. TARGET="etcd-${VER}-${GOOS}-${GOARCH}"
  52. mkdir ${TARGET}
  53. package ${TARGET} ${PROJ}
  54. if [ ${GOOS} == "linux" ]; then
  55. tar cfz ${TARGET}.tar.gz ${TARGET}
  56. echo "Wrote release/${TARGET}.tar.gz"
  57. else
  58. zip -qr ${TARGET}.zip ${TARGET}
  59. echo "Wrote release/${TARGET}.zip"
  60. fi
  61. done
  62. }
  63. main