pkg-vsn.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 "--default: Print default vsn number. e.g. e.g. 5.0.0-ubuntu20.04-amd64"
  12. echo "--long: Print long vsn number. e.g. 5.0.0-otp24.2.1-1-ubuntu20.04-amd64"
  13. echo " Otherwise short e.g. 5.0.0"
  14. echo "--elixir: Include elixir version in the long version string"
  15. echo " e.g. 5.0.0-elixir1.13.4-otp24.2.1-1-ubuntu20.04-amd64"
  16. echo "--vsn_matcher: For --long option, replace the EMQX version with '*'"
  17. echo " so it can be used in find commands"
  18. }
  19. PROFILE="${1:-}"
  20. if [ -z "$PROFILE" ]; then
  21. echo "ERROR: missing profile"
  22. help
  23. exit 1
  24. fi
  25. shift
  26. while [ "$#" -gt 0 ]; do
  27. case $1 in
  28. -h|--help)
  29. help
  30. exit 0
  31. ;;
  32. --default)
  33. IS_DEFAULT_RELEASE='yes'
  34. shift 1
  35. ;;
  36. --long)
  37. LONG_VERSION='yes'
  38. shift 1
  39. ;;
  40. --elixir)
  41. shift 1
  42. case ${1:-novalue} in
  43. -*)
  44. # another option
  45. IS_ELIXIR='yes'
  46. ;;
  47. yes|no)
  48. IS_ELIXIR="${1}"
  49. shift 1
  50. ;;
  51. novalue)
  52. IS_ELIXIR='yes'
  53. ;;
  54. *)
  55. echo "ERROR: unknown option: --elixir $2"
  56. exit 1
  57. ;;
  58. esac
  59. ;;
  60. --vsn_matcher)
  61. IS_MATCHER='yes'
  62. shift 1
  63. ;;
  64. *)
  65. echo "WARN: Unknown arg (ignored): $1"
  66. exit 1
  67. ;;
  68. esac
  69. done
  70. # return immediately if version is already set
  71. if [[ "${PKG_VSN:-novalue}" != novalue && "${LONG_VERSION:-novalue}" != 'yes' ]]; then
  72. echo "$PKG_VSN"
  73. exit 0
  74. fi
  75. case "${PROFILE}" in
  76. *enterprise*)
  77. RELEASE_EDITION="EMQX_RELEASE_EE"
  78. GIT_TAG_PREFIX="e"
  79. ;;
  80. *)
  81. RELEASE_EDITION="EMQX_RELEASE_CE"
  82. GIT_TAG_PREFIX="v"
  83. ;;
  84. esac
  85. ## emqx_release.hrl is the single source of truth for release version
  86. RELEASE="$(grep -E "define.+${RELEASE_EDITION}" apps/emqx/include/emqx_release.hrl | cut -d '"' -f2)"
  87. git_exact_vsn() {
  88. local tag
  89. tag="$(git describe --tags --match "${GIT_TAG_PREFIX}*" --exact 2>/dev/null)"
  90. echo "${tag#[v|e]}"
  91. }
  92. GIT_EXACT_VSN="$(git_exact_vsn)"
  93. if [ "$GIT_EXACT_VSN" != '' ]; then
  94. if [ "$GIT_EXACT_VSN" != "$RELEASE" ]; then
  95. echo "ERROR: Tagged $GIT_EXACT_VSN, but $RELEASE in include/emqx_release.hrl" 1>&2
  96. exit 1
  97. fi
  98. SUFFIX=''
  99. else
  100. SUFFIX="-g$(git rev-parse HEAD | cut -b1-8)"
  101. fi
  102. PKG_VSN="${PKG_VSN:-${RELEASE}${SUFFIX}}"
  103. if [ "${LONG_VERSION:-}" != 'yes' ]; then
  104. echo "$PKG_VSN"
  105. exit 0
  106. fi
  107. ### --long LONG_VERSION handling start
  108. if [ "${IS_MATCHER:-}" = 'yes' ]; then
  109. PKG_VSN='*'
  110. fi
  111. OTP_VSN="${OTP_VSN:-$(./scripts/get-otp-vsn.sh)}"
  112. SYSTEM="$(./scripts/get-distro.sh)"
  113. case "$SYSTEM" in
  114. windows*)
  115. # directly build the default package for windows
  116. IS_DEFAULT_RELEASE='yes'
  117. ;;
  118. *)
  119. true
  120. ;;
  121. esac
  122. UNAME_M="$(uname -m)"
  123. case "$UNAME_M" in
  124. x86_64)
  125. ARCH='amd64'
  126. ;;
  127. aarch64)
  128. ARCH='arm64'
  129. ;;
  130. arm*)
  131. ARCH=arm
  132. ;;
  133. esac
  134. if [ "${IS_DEFAULT_RELEASE:-not-default-release}" = 'yes' ]; then
  135. # when it's the default release, we do not add elixir or otp version
  136. infix=''
  137. else
  138. infix="-otp${OTP_VSN}"
  139. if [ "${IS_ELIXIR:-}" = "yes" ]; then
  140. ELIXIR_VSN="${ELIXIR_VSN:-$(./scripts/get-elixir-vsn.sh)}"
  141. infix="-elixir${ELIXIR_VSN}${infix}"
  142. fi
  143. fi
  144. echo "${PKG_VSN}${infix}-${SYSTEM}-${ARCH}"