2
0

common.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #!/bin/sh
  2. ##### -*- mode:shell-script; indent-tabs-mode:nil; sh-basic-offset:2 -*-
  3. src_repo="$(pwd)"
  4. tmp_dir=${TMP_DIR:=".."}
  5. zgrep () { (echo "$2" | grep -e "$1" >/dev/null); }
  6. parse_version () {
  7. local ver="$1" major="" minor="" micro="" rev=""
  8. local next=major
  9. for x in $(echo "$1" | sed -e 's/\([._~-]\)/ \1 /g'); do
  10. if [ $next = rev ]; then
  11. rev="${rev}${x}"
  12. elif [ "$x" = "." ] || [ "$x" = "_" ] || [ "$x" = "~" ] || [ "$x" = "-" ]; then
  13. if [ "$x" = "_" ] || [ "$x" = "~" ] || [ "$x" = "-" ]; then
  14. next=rev
  15. eval $next='$x'
  16. else
  17. case $next in
  18. major) next=minor;;
  19. minor) next=micro;;
  20. micro) next=rev;;
  21. esac
  22. fi
  23. else
  24. local tmp="$(eval echo \$$next)"
  25. eval $next='${tmp}${x}'
  26. fi
  27. done
  28. # The major version should never be null
  29. if [ -z "$major" ]; then
  30. echo "WARNING: parse_version was called with '$1' which is missing a major version number" >&2
  31. fi
  32. # If someone asks for the minor or micro specificially, they
  33. # probably expect that it won't be null. Also, vX.Y should never be
  34. # different from vX.Y.0 (that would be crazy), so we don't lose
  35. # meaningful generality by setting minor or micro to zero on vX or
  36. # vX.Y style versions.
  37. minor="${minor:-0}"
  38. micro="${micro:-0}"
  39. # centos-style versions (don't mess with the argument given for now)
  40. # TODO: what is the CentOS version number policy?
  41. local cmajor cminor cmicro crev cver
  42. cmajor="${major:-0}"
  43. cminor="${minor:-0}"
  44. cmicro="${micro:-0}"
  45. crev="$(echo "$rev" | sed -e 's/[._~-]//')"
  46. cver="${cmajor}.${cminor}.${cmicro}"
  47. [ -n "$crev" ] && cver="${cver}.${crev}"
  48. # fix up if the revision was passed in the minor or micro number
  49. if zgrep '^\(alpha\|beta\|rc\)' "$minor"; then
  50. rev="-${minor}"
  51. minor="0"
  52. micro="0"
  53. ver="${major}${rev}"
  54. fi
  55. if zgrep '^\(alpha\|beta\|rc\)' "$micro"; then
  56. rev="-${micro}"
  57. micro="0"
  58. ver="${major}.${minor}${rev}"
  59. fi
  60. # git-style versions
  61. local gmajor gminor gmicro grev gver
  62. gver="$(echo "$ver" | sed -e 's/[~_]/-/')"
  63. grev="$(echo "$rev" | sed -e 's/[~_]/-/')"
  64. gmajor="$major"
  65. gminor="$minor"
  66. gmicro="$micro"
  67. # debian-style versions
  68. local dmajor dminor dmicro drev dver
  69. dver="$(echo "$ver" | sed -e 's/[-_]/~/')"
  70. drev="$(echo "$rev" | sed -e 's/[-_]/~/')"
  71. dmajor="$major"
  72. dminor="$minor"
  73. dmicro="$micro"
  74. # return variables
  75. echo "ver='$ver'"
  76. echo "major='$major'"
  77. echo "minor='$minor'"
  78. echo "micro='$micro'"
  79. echo "rev='$rev'"
  80. echo "gver='$gver'"
  81. echo "gmajor='$gmajor'"
  82. echo "gminor='$gminor'"
  83. echo "gmicro='$gmicro'"
  84. echo "grev='$grev'"
  85. echo "dver='$dver'"
  86. echo "dmajor='$dmajor'"
  87. echo "dminor='$dminor'"
  88. echo "dmicro='$dmicro'"
  89. echo "drev='$drev'"
  90. echo "cver='$cver'"
  91. echo "cmajor='$cmajor'"
  92. echo "cminor='$cminor'"
  93. echo "cmicro='$cmicro'"
  94. echo "crev='$crev'"
  95. }
  96. set_fs_ver () {
  97. local ver="$1" major="$2" minor="$3" micro="$4" rev="$5" hrev="$6"
  98. sed \
  99. -e "s|\(AC_SUBST(SWITCH_VERSION_MAJOR, \[\).*\(\])\)|\1$major\2|" \
  100. -e "s|\(AC_SUBST(SWITCH_VERSION_MINOR, \[\).*\(\])\)|\1$minor\2|" \
  101. -e "s|\(AC_SUBST(SWITCH_VERSION_MICRO, \[\).*\(\])\)|\1$micro\2|" \
  102. -e "s|\(AC_INIT(\[freeswitch\], \[\).*\(\], bugs@freeswitch.org)\)|\1$ver\2|" \
  103. configure.ac > configure.ac.$$
  104. mv configure.ac.$$ configure.ac
  105. if [ -n "$rev" ]; then
  106. [ -n "$hrev" ] || hrev="$rev"
  107. sed -e "s|\(AC_SUBST(SWITCH_VERSION_REVISION, \[\).*\(\])\)|\1$rev\2|" \
  108. -e "s|\(AC_SUBST(SWITCH_VERSION_REVISION_HUMAN, \[\).*\(\])\)|\1'$hrev'\2|" \
  109. -e "s|#\(AC_SUBST(SWITCH_VERSION_REVISION\)|\1|" \
  110. -e "s|#\(AC_SUBST(SWITCH_VERSION_REVISION_HUMAN\)|\1|" \
  111. configure.ac > configure.ac.$$
  112. mv configure.ac.$$ configure.ac
  113. fi
  114. local rpm_version
  115. if [ -n "$rev" ]; then
  116. rpm_version="$major.$minor.$micro.$rev"
  117. else
  118. rpm_version="$major.$minor.$micro"
  119. fi
  120. sed -e "s|\(%define nonparsedversion \).*|\1$rpm_version|" \
  121. freeswitch.spec > freeswitch.spec.$$
  122. mv freeswitch.spec.$$ freeswitch.spec
  123. sed -e "s|\(%define nonparsedversion \).*|\1$rpm_version|" \
  124. freeswitch-config-rayo.spec > freeswitch-config-rayo.spec.$$
  125. mv freeswitch-config-rayo.spec.$$ freeswitch-config-rayo.spec
  126. #%define version 1.5.16
  127. }
  128. set_fs_release () {
  129. local release="$1"
  130. if [ -n "$release" ]; then
  131. sed -e "s|\(%define release \).*|\1$release|" \
  132. freeswitch.spec > freeswitch.spec.$$
  133. mv freeswitch.spec.$$ freeswitch.spec
  134. sed -e "s|\(%define release \).*|\1$release|" \
  135. freeswitch-config-rayo.spec > freeswitch-config-rayo.spec.$$
  136. mv freeswitch-config-rayo.spec.$$ freeswitch-config-rayo.spec
  137. fi
  138. }
  139. gnuize () {
  140. ./bootstrap.sh
  141. mv bootstrap.sh rebootstrap.sh
  142. rm -f docs/AUTHORS
  143. rm -f docs/COPYING
  144. rm -f docs/ChangeLog
  145. rm -rf .git
  146. }
  147. check_pwd () {
  148. if [ ! -d .git ]; then
  149. echo "error: must be run from within the top level of a FreeSWITCH git tree." 1>&2
  150. exit 1;
  151. fi
  152. }
  153. check_input_ver_build () {
  154. if [ -z "$1" ]; then
  155. echo "usage: $0 <version> <build-number>" 1>&2
  156. exit 1;
  157. fi
  158. }