pkg-vsn.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 log vsn number. e.g. 5.0.0-otp24.2.1-1-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-elixir1.13.4-otp24.2.1-1-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. case "${PROFILE}" in
  66. *enterprise*)
  67. RELEASE_EDITION="EMQX_RELEASE_EE"
  68. GIT_TAG_PREFIX="e"
  69. ;;
  70. *)
  71. RELEASE_EDITION="EMQX_RELEASE_CE"
  72. GIT_TAG_PREFIX="v"
  73. ;;
  74. esac
  75. ## emqx_release.hrl is the single source of truth for release version
  76. RELEASE="$(grep -E "define.+${RELEASE_EDITION}" apps/emqx/include/emqx_release.hrl | cut -d '"' -f2)"
  77. git_exact_vsn() {
  78. local tag
  79. tag="$(git describe --tags --match "${GIT_TAG_PREFIX}*" --exact 2>/dev/null)"
  80. echo "${tag#[v|e]}"
  81. }
  82. GIT_EXACT_VSN="$(git_exact_vsn)"
  83. if [ "$GIT_EXACT_VSN" != '' ]; then
  84. if [ "$GIT_EXACT_VSN" != "$RELEASE" ]; then
  85. echo "ERROR: Tagged $GIT_EXACT_VSN, but $RELEASE in include/emqx_release.hrl" 1>&2
  86. exit 1
  87. fi
  88. SUFFIX=''
  89. else
  90. SUFFIX="-$(git rev-parse HEAD | cut -b1-8)"
  91. fi
  92. PKG_VSN="${RELEASE}${SUFFIX}"
  93. if [ "${LONG_VERSION:-}" != 'yes' ]; then
  94. echo "$PKG_VSN"
  95. exit 0
  96. fi
  97. ### --long LONG_VERSION handling start
  98. if [ "${IS_MATCHER:-}" = 'yes' ]; then
  99. PKG_VSN='*'
  100. fi
  101. OTP_VSN="${OTP_VSN:-$(./scripts/get-otp-vsn.sh)}"
  102. SYSTEM="$(./scripts/get-distro.sh)"
  103. UNAME="$(uname -m)"
  104. case "$UNAME" in
  105. x86_64)
  106. ARCH='amd64'
  107. ;;
  108. aarch64)
  109. ARCH='arm64'
  110. ;;
  111. arm*)
  112. ARCH=arm
  113. ;;
  114. esac
  115. if [ "${IS_ELIXIR:-}" = "yes" ]; then
  116. ELIXIR_VSN="${ELIXIR_VSN:-$(./scripts/get-elixir-vsn.sh)}"
  117. FULL_VSN="${PKG_VSN}-elixir${ELIXIR_VSN}-otp${OTP_VSN}-${SYSTEM}-${ARCH}"
  118. else
  119. FULL_VSN="${PKG_VSN}-otp${OTP_VSN}-${SYSTEM}-${ARCH}"
  120. fi
  121. echo "${FULL_VSN}"