pkg-vsn.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. 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. OTP_VSN="${OTP_VSN:-$(./scripts/get-otp-vsn.sh)}"
  107. SYSTEM="$(./scripts/get-distro.sh)"
  108. case "$SYSTEM" in
  109. windows*)
  110. # directly build the default package for windows
  111. IS_DEFAULT_RELEASE='yes'
  112. ;;
  113. *)
  114. true
  115. ;;
  116. esac
  117. UNAME_M="$(uname -m)"
  118. case "$UNAME_M" in
  119. x86_64)
  120. ARCH='amd64'
  121. ;;
  122. aarch64)
  123. ARCH='arm64'
  124. ;;
  125. arm*)
  126. ARCH=arm
  127. ;;
  128. esac
  129. if [ "${IS_DEFAULT_RELEASE:-not-default-release}" = 'yes' ]; then
  130. # when it's the default release, we do not add elixir or otp version
  131. infix=''
  132. else
  133. infix="-otp${OTP_VSN}"
  134. if [ "${IS_ELIXIR:-}" = "yes" ]; then
  135. ELIXIR_VSN="${ELIXIR_VSN:-$(./scripts/get-elixir-vsn.sh)}"
  136. infix="-elixir${ELIXIR_VSN}${infix}"
  137. fi
  138. fi
  139. echo "${PKG_VSN}${infix}-${SYSTEM}-${ARCH}"