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.

87 lines
2.4 KiB

  1. #!/usr/bin/env bash
  2. set -e
  3. SELF=$(readlink -f -- "$0")
  4. HERE=$(dirname -- "$SELF")
  5. show_help()
  6. {
  7. echo -e "`basename $0` [OPTION...]"
  8. echo
  9. echo -e "Options:"
  10. echo -e " -h show this help."
  11. echo -e " -s use system shared libraries"
  12. }
  13. OPT_USE_SYSTEM_LIB=0
  14. while getopts "hs" opt
  15. do
  16. case ${opt} in
  17. h)
  18. show_help
  19. exit 0
  20. ;;
  21. s)
  22. OPT_USE_SYSTEM_LIB=1
  23. ;;
  24. *)
  25. show_help
  26. exit 1
  27. ;;
  28. esac
  29. done
  30. # determine version and release number
  31. GIT_DESCRIBE=$(git describe --tags --match 'v*' --long)
  32. # GIT_DESCRIBE is like v3.0.3-11-g1e3f35c-dirty
  33. if [[ ! "$GIT_DESCRIBE" =~ ^v([^-]+)-([0-9]+)-g([0-9a-f]+)$ ]]; then
  34. >&2 echo 'ERROR - unrecognized `git describe` output: '"$GIT_DESCRIBE"
  35. exit 1
  36. fi
  37. TARGET_VERSION=${BASH_REMATCH[1]}
  38. TARGET_COMMITS=${BASH_REMATCH[2]}
  39. TARGET_SHA1=${BASH_REMATCH[3]}
  40. TARGET_RELEASE=1
  41. if [ "$TARGET_COMMITS" -gt 0 ]; then
  42. TARGET_RELEASE+=".$TARGET_COMMITS.git$TARGET_SHA1"
  43. fi
  44. TARGET_VERREL=$TARGET_VERSION-$TARGET_RELEASE
  45. >&2 echo "INFO - RPM version-release is $TARGET_VERREL."
  46. # archive tarball from Git workspace
  47. export TARGET_TARBALL_NAME=shadowsocks-libev-$TARGET_VERSION
  48. export TARGET_TARBALL_DIR=$HERE/SOURCES
  49. mkdir -p -- "$TARGET_TARBALL_DIR"
  50. pushd "$HERE"/..
  51. # archive this repo
  52. git archive HEAD --format=tar --prefix="$TARGET_TARBALL_NAME/" \
  53. -o "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar"
  54. # archive submodules
  55. git submodule update --init
  56. git submodule foreach 'git archive HEAD --format=tar \
  57. --prefix="$TARGET_TARBALL_NAME/$path/" \
  58. -o "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME-submodule-$path-$sha1.tar"
  59. tar -n --concatenate --file="$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar" \
  60. "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME-submodule-$path-$sha1.tar"'
  61. gzip -c "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar" > "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar.gz"
  62. popd
  63. # generate spec file
  64. TARGET_SPEC_DIR=$HERE/SPECS
  65. mkdir -p -- "$TARGET_SPEC_DIR"
  66. TARGET_SPEC_PATH=$TARGET_SPEC_DIR/shadowsocks-libev.spec
  67. sed -e "s/^\(Version:\).*$/\1 ${TARGET_VERSION}/" \
  68. -e "s/^\(Release:\).*$/\1 ${TARGET_RELEASE}%{?dist}/" \
  69. -e "s/^\(Source0:\).*$/\1 ${TARGET_TARBALL_NAME}.tar.gz/" \
  70. "${TARGET_SPEC_PATH}".in > "${TARGET_SPEC_PATH}"
  71. # build rpms
  72. rpmbuild -ba "$TARGET_SPEC_PATH" \
  73. --define "%_topdir $HERE" \
  74. --define "%use_system_lib $OPT_USE_SYSTEM_LIB"