pkg-vsn.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # This script prints the release version for emqx
  4. # ensure dir
  5. cd -P -- "$(dirname -- "$0")"
  6. help() {
  7. echo
  8. echo "$0 PROFILE [options]"
  9. echo
  10. echo "-h|--help: To display this usage information"
  11. echo "--long: Print long vsn number. e.g. 5.0.0-ubuntu20.04-amd64"
  12. echo " Otherwise short e.g. 5.0.0"
  13. echo "--elixir: Include elixir version in the long version string"
  14. echo " e.g. 5.0.0-elixir-ubuntu20.04-amd64"
  15. echo "--vsn_matcher: For --long option, replace the EMQX version with '*'"
  16. echo " so it can be used in find commands"
  17. }
  18. PROFILE="${1:-}"
  19. if [ -z "$PROFILE" ]; then
  20. echo "ERROR: missing profile"
  21. help
  22. exit 1
  23. fi
  24. shift
  25. while [ "$#" -gt 0 ]; do
  26. case $1 in
  27. -h|--help)
  28. help
  29. exit 0
  30. ;;
  31. --long)
  32. LONG_VERSION='yes'
  33. shift 1
  34. ;;
  35. --elixir)
  36. shift 1
  37. case ${1:-novalue} in
  38. -*)
  39. # another option
  40. IS_ELIXIR='yes'
  41. ;;
  42. yes|no)
  43. IS_ELIXIR="${1}"
  44. shift 1
  45. ;;
  46. novalue)
  47. IS_ELIXIR='yes'
  48. ;;
  49. *)
  50. echo "ERROR: unknown option: --elixir $2"
  51. exit 1
  52. ;;
  53. esac
  54. ;;
  55. --vsn_matcher)
  56. IS_MATCHER='yes'
  57. shift 1
  58. ;;
  59. *)
  60. echo "WARN: Unknown arg (ignored): $1"
  61. exit 1
  62. ;;
  63. esac
  64. done
  65. # return immediately if version is already set
  66. if [[ "${PKG_VSN:-novalue}" != novalue && "${LONG_VERSION:-novalue}" != 'yes' ]]; then
  67. echo "$PKG_VSN"
  68. exit 0
  69. fi
  70. case "${PROFILE}" in
  71. *enterprise*)
  72. RELEASE_EDITION="EMQX_RELEASE_EE"
  73. GIT_TAG_PREFIX="e"
  74. ;;
  75. *)
  76. RELEASE_EDITION="EMQX_RELEASE_CE"
  77. GIT_TAG_PREFIX="v"
  78. ;;
  79. esac
  80. ## emqx_release.hrl is the single source of truth for release version
  81. RELEASE="$(grep -E "define.+${RELEASE_EDITION}" apps/emqx/include/emqx_release.hrl | cut -d '"' -f2)"
  82. git_exact_vsn() {
  83. local tag
  84. tag="$(git describe --tags --match "${GIT_TAG_PREFIX}*" --exact 2>/dev/null)"
  85. echo "${tag#[v|e]}"
  86. }
  87. GIT_EXACT_VSN="$(git_exact_vsn)"
  88. if [ "$GIT_EXACT_VSN" != '' ]; then
  89. if [ "$GIT_EXACT_VSN" != "$RELEASE" ]; then
  90. echo "ERROR: Tagged $GIT_EXACT_VSN, but $RELEASE in include/emqx_release.hrl" 1>&2
  91. exit 1
  92. fi
  93. SUFFIX=''
  94. else
  95. SUFFIX="-g$(git rev-parse HEAD | cut -b1-8)"
  96. fi
  97. PKG_VSN="${PKG_VSN:-${RELEASE}${SUFFIX}}"
  98. if [ "${LONG_VERSION:-}" != 'yes' ]; then
  99. echo "$PKG_VSN"
  100. exit 0
  101. fi
  102. ### --long LONG_VERSION handling start
  103. if [ "${IS_MATCHER:-}" = 'yes' ]; then
  104. PKG_VSN='*'
  105. fi
  106. SYSTEM="$(./scripts/get-distro.sh)"
  107. UNAME_M="$(uname -m)"
  108. case "$UNAME_M" in
  109. x86_64)
  110. ARCH='amd64'
  111. ;;
  112. aarch64)
  113. ARCH='arm64'
  114. ;;
  115. arm64)
  116. ARCH='arm64'
  117. ;;
  118. arm*)
  119. ARCH='arm'
  120. ;;
  121. esac
  122. if [ "${IS_ELIXIR:-}" = "yes" ]; then
  123. infix='-elixir'
  124. else
  125. infix=''
  126. fi
  127. echo "${PKG_VSN}${infix}-${SYSTEM}-${ARCH}"