build-binary 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 etcd/etcdctl/READMEv2.md ${target}/READMEv2-etcdctl.md
  40. cp -R etcd/Documentation ${target}/Documentation
  41. }
  42. function main {
  43. mkdir release
  44. cd release
  45. setup_env ${PROJ} ${VER}
  46. for os in darwin windows linux; do
  47. export GOOS=${os}
  48. export GOARCH="amd64"
  49. pushd etcd >/dev/null
  50. ./build
  51. popd >/dev/null
  52. TARGET="etcd-${VER}-${GOOS}-${GOARCH}"
  53. mkdir ${TARGET}
  54. package ${TARGET} ${PROJ}
  55. if [ ${GOOS} == "linux" ]; then
  56. tar cfz ${TARGET}.tar.gz ${TARGET}
  57. echo "Wrote release/${TARGET}.tar.gz"
  58. else
  59. zip -qr ${TARGET}.zip ${TARGET}
  60. echo "Wrote release/${TARGET}.zip"
  61. fi
  62. done
  63. }
  64. main