You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.9 KiB

8 years ago
  1. #!/usr/bin/env bash
  2. set -e
  3. g_version=$(git tag -l v* | sort --version-sort | tail -1)
  4. g_version=${g_version#"v"}
  5. show_help()
  6. {
  7. echo -e "`basename $0` [option] [argument]"
  8. echo
  9. echo -e "Options:"
  10. echo -e " -h show this help."
  11. echo -e " -v with argument version (${g_version} by default)."
  12. echo -e " -f with argument format (tar.gz by default) used by git archive."
  13. echo
  14. echo -e "Examples:"
  15. echo -e " to build base on version \`2.4.1' with format \`tar.xz', run:"
  16. echo -e " `basename $0` -f tar.xz -v 2.4.1"
  17. }
  18. version_greater_equal()
  19. {
  20. [ "$1" = $(printf "$1\n$2\n" | sort --version-sort | tail -1) ]
  21. }
  22. while getopts "hv:f:" opt
  23. do
  24. case ${opt} in
  25. h)
  26. show_help
  27. exit 0
  28. ;;
  29. v)
  30. if [ "${OPTARG}" = v* ]; then
  31. version=${OPTARG#"v"}
  32. else
  33. version=${OPTARG}
  34. fi
  35. ;;
  36. f)
  37. format=${OPTARG}
  38. ;;
  39. *)
  40. exit 1
  41. ;;
  42. esac
  43. done
  44. : ${version:=${g_version}}
  45. : ${format:=tar.gz}
  46. supported_max_version="2.6.2"
  47. if ! version_greater_equal ${supported_max_version} ${version}; then
  48. echo "version(${version}) greater than ${supported_max_version} are not currently supported."
  49. exit 1
  50. fi
  51. name="shadowsocks-libev"
  52. spec_name="shadowsocks-libev.spec"
  53. pushd `git rev-parse --show-toplevel`
  54. git archive "v${version}" --format="${format}" --prefix="${name}-${version}/" -o rpm/SOURCES/"${name}-${version}.${format}"
  55. pushd rpm
  56. sed -e "s/^\(Version: \).*$/\1${version}/" \
  57. -e "s/^\(Source0: \).*$/\1${name}-${version}.${format}/" \
  58. SPECS/"${spec_name}".in > SPECS/"${spec_name}"
  59. completion_min_verion="2.6.0"
  60. version_greater_equal ${version} ${completion_min_verion} \
  61. && with_completion="--with completion" || :
  62. rpmbuild -bb SPECS/"${spec_name}" --define "%_topdir `pwd`" \
  63. ${with_completion}