update-version.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #!/usr/bin/env bash
  2. # update-version.sh v2.00 (c)2016-2023 Henri Beauchamp.
  3. # Released under the GPL (v2 or later, at your convenience) License:
  4. # http://www.gnu.org/copyleft/gpl.html
  5. # Stop on error
  6. set -e
  7. script=`readlink -f "$0" || echo "$0"`
  8. cd `dirname "$script" || echo .`
  9. cd ..
  10. if echo "$*" | grep "\-h" &>/dev/null ; then
  11. echo "This script syncs or increments the version numbers for the Cool VL Viewer"
  12. echo "sources. The numbers are held inside the scripts/VIEWER_VERSION file."
  13. echo "Usage: $0 [[-r|--release]|[-b|--branch]|[-m|--minor]|[-M|--major]|[-h|--help]]"
  14. echo "With: -r | --release : increment the release number."
  15. echo " -b | --branch : increment the branch number"
  16. echo " (also zeroes the release number)."
  17. echo " -m | --minor : increment the minor version number"
  18. echo " (also zeroes the release and branch numbers)."
  19. echo " -M | --Major : increment the major version number"
  20. echo " (also zeroes all other numbers)."
  21. echo " -h, --help : this help..."
  22. echo "If no option is passed, then the script will just sync the viewer version"
  23. echo "with the numbers held inside the scripts/VIEWER_VERSION file."
  24. exit 0
  25. fi
  26. if ! [ -f scripts/VIEWER_VERSION ] ; then
  27. echo "This script shall be ran from the sources tree of the Cool VL Viewer !"
  28. exit 1
  29. fi
  30. . scripts/VIEWER_VERSION
  31. version_old_major=$LL_VERSION_MAJOR
  32. version_old_minor=$LL_VERSION_MINOR
  33. version_old_branch=$LL_VERSION_BRANCH
  34. was_experimental="no"
  35. if [ $(( $version_old_minor % 2 )) -eq 1 ] || [ $(( $version_old_branch % 2 )) -eq 1 ] ; then
  36. was_experimental="yes"
  37. fi
  38. if [ -f scripts/FORMER_VERSIONS ] ; then
  39. . scripts/FORMER_VERSIONS
  40. elif [ "$was_experimental" == "yes" ] ; then
  41. FORMER_EXPERIMENTAL_MAJOR=$version_old_major
  42. FORMER_EXPERIMENTAL_MINOR=$version_old_minor
  43. FORMER_EXPERIMENTAL_BRANCH=$version_old_branch
  44. FORMER_STABLE_MAJOR=x
  45. FORMER_STABLE_MINOR=y
  46. FORMER_STABLE_BRANCH=z
  47. else
  48. FORMER_STABLE_MAJOR=$version_old_major
  49. FORMER_STABLE_MINOR=$version_old_minor
  50. FORMER_STABLE_BRANCH=$version_old_branch
  51. FORMER_EXPERIMENTAL_MAJOR=x
  52. FORMER_EXPERIMENTAL_MINOR=y
  53. FORMER_EXPERIMENTAL_BRANCH=z
  54. fi
  55. if echo "$*" | grep "\-M" &>/dev/null ; then
  56. let LL_VERSION_MAJOR=$LL_VERSION_MAJOR+1
  57. LL_VERSION_MINOR=0
  58. LL_VERSION_BRANCH=0
  59. LL_VERSION_RELEASE=0
  60. if [ "$was_experimental" == "yes" ] ; then
  61. FORMER_EXPERIMENTAL_MAJOR=$version_old_major
  62. FORMER_EXPERIMENTAL_MINOR=$version_old_minor
  63. FORMER_EXPERIMENTAL_BRANCH=$version_old_branch
  64. else
  65. FORMER_STABLE_MAJOR=$version_old_major
  66. FORMER_STABLE_MINOR=$version_old_minor
  67. FORMER_STABLE_BRANCH=$version_old_branch
  68. FORMER_EXPERIMENTAL_MAJOR=x
  69. FORMER_EXPERIMENTAL_MINOR=y
  70. FORMER_EXPERIMENTAL_BRANCH=z
  71. fi
  72. elif echo "$*" | grep "\-m" &>/dev/null ; then
  73. let LL_VERSION_MINOR=$LL_VERSION_MINOR+1
  74. LL_VERSION_BRANCH=0
  75. LL_VERSION_RELEASE=0
  76. if [ "$was_experimental" == "yes" ] ; then
  77. FORMER_EXPERIMENTAL_MAJOR=$version_old_major
  78. FORMER_EXPERIMENTAL_MINOR=$version_old_minor
  79. FORMER_EXPERIMENTAL_BRANCH=$version_old_branch
  80. else
  81. FORMER_STABLE_MAJOR=$version_old_major
  82. FORMER_STABLE_MINOR=$version_old_minor
  83. FORMER_STABLE_BRANCH=$version_old_branch
  84. FORMER_EXPERIMENTAL_MAJOR=x
  85. FORMER_EXPERIMENTAL_MINOR=y
  86. FORMER_EXPERIMENTAL_BRANCH=z
  87. fi
  88. elif echo "$*" | grep "\-b" &>/dev/null ; then
  89. let LL_VERSION_BRANCH=$LL_VERSION_BRANCH+1
  90. LL_VERSION_RELEASE=0
  91. if [ "$was_experimental" == "yes" ] ; then
  92. FORMER_EXPERIMENTAL_MAJOR=$version_old_major
  93. FORMER_EXPERIMENTAL_MINOR=$version_old_minor
  94. FORMER_EXPERIMENTAL_BRANCH=$version_old_branch
  95. else
  96. FORMER_STABLE_MAJOR=$version_old_major
  97. FORMER_STABLE_MINOR=$version_old_minor
  98. FORMER_STABLE_BRANCH=$version_old_branch
  99. FORMER_EXPERIMENTAL_MAJOR=x
  100. FORMER_EXPERIMENTAL_MINOR=y
  101. FORMER_EXPERIMENTAL_BRANCH=z
  102. fi
  103. elif echo "$*" | grep "\-r" &>/dev/null ; then
  104. let LL_VERSION_RELEASE=$LL_VERSION_RELEASE+1
  105. fi
  106. cat <<EOF1 >scripts/VIEWER_VERSION
  107. LL_VERSION_MAJOR=$LL_VERSION_MAJOR
  108. LL_VERSION_MINOR=$LL_VERSION_MINOR
  109. LL_VERSION_BRANCH=$LL_VERSION_BRANCH
  110. LL_VERSION_RELEASE=$LL_VERSION_RELEASE
  111. EOF1
  112. cat <<EOF2 >scripts/FORMER_VERSIONS
  113. FORMER_EXPERIMENTAL_MAJOR=$FORMER_EXPERIMENTAL_MAJOR
  114. FORMER_EXPERIMENTAL_MINOR=$FORMER_EXPERIMENTAL_MINOR
  115. FORMER_EXPERIMENTAL_BRANCH=$FORMER_EXPERIMENTAL_BRANCH
  116. FORMER_STABLE_MAJOR=$FORMER_STABLE_MAJOR
  117. FORMER_STABLE_MINOR=$FORMER_STABLE_MINOR
  118. FORMER_STABLE_BRANCH=$FORMER_STABLE_BRANCH
  119. EOF2
  120. echo "New viewer version is: $LL_VERSION_MAJOR.$LL_VERSION_MINOR.$LL_VERSION_BRANCH.$LL_VERSION_RELEASE"
  121. if [ "$FORMER_EXPERIMENTAL_MAJOR" != "x" ] ; then
  122. echo "Former experimental branch was: $FORMER_EXPERIMENTAL_MAJOR.$FORMER_EXPERIMENTAL_MINOR.$FORMER_EXPERIMENTAL_BRANCH"
  123. fi
  124. if [ "$FORMER_STABLE_MAJOR" != "x" ] ; then
  125. echo "Former stable branch was: $FORMER_STABLE_MAJOR.$FORMER_STABLE_MINOR.$FORMER_STABLE_BRANCH"
  126. fi
  127. year=`date +%Y`
  128. find . -type f -name "*.in" | while read i ; do
  129. if grep "viewer_version_" "$i" &>/dev/null ; then
  130. echo "Processing file $i into ${i%.in}..."
  131. sed -e "s/viewer_version_major/$LL_VERSION_MAJOR/" \
  132. -e "s/viewer_version_minor/$LL_VERSION_MINOR/" \
  133. -e "s/viewer_version_branch/$LL_VERSION_BRANCH/" \
  134. -e "s/viewer_version_release/$LL_VERSION_RELEASE/" \
  135. -e "s/previous_experimental_major/$FORMER_EXPERIMENTAL_MAJOR/" \
  136. -e "s/previous_experimental_minor/$FORMER_EXPERIMENTAL_MINOR/" \
  137. -e "s/previous_experimental_branch/$FORMER_EXPERIMENTAL_BRANCH/" \
  138. -e "s/previous_stable_major/$FORMER_STABLE_MAJOR/" \
  139. -e "s/previous_stable_minor/$FORMER_STABLE_MINOR/" \
  140. -e "s/previous_stable_branch/$FORMER_STABLE_BRANCH/" \
  141. -e "s/viewer_copyright_year/$year/" \
  142. "$i" >"${i%.in}"
  143. fi
  144. done
  145. if echo "$*" | grep "\-r" &>/dev/null ; then
  146. echo "Removing unchanged *.mpi (InstallJammer) files:"
  147. find . -type f -name "Cool VL Viewer.mpi" -print -exec rm -f "{}" \;
  148. find . -type f -name "Cool VL Viewer-x86_64.mpi" -print -exec rm -f "{}" \;
  149. else
  150. echo "Removing deprecated *.mpi (InstallJammer) files:"
  151. find . -type f -name "Cool VL Viewer-$version_old_major.*.mpi" -print -exec rm -f "{}" \;
  152. find . -type f -name "Cool VL Viewer-x86_64-$version_old_major.*.mpi" -print -exec rm -f "{}" \;
  153. new_suffix="-$LL_VERSION_MAJOR.$LL_VERSION_MINOR.$LL_VERSION_BRANCH.mpi"
  154. find . -type f -name "Cool VL Viewer*.mpi" | while read i ; do
  155. echo "Renaming $i into ${i%.mpi}${new_suffix}"
  156. mv -f "$i" "${i%.mpi}${new_suffix}"
  157. done
  158. fi
  159. echo "Done."