get-version.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. version=1.3.2-head
  3. # This script outputs a version number for this project to stdout.
  4. # - if $SCRYPT_VERSION is given, it is used.
  5. # - otherwise, it uses ${version}.
  6. # - if there is a ".git/" directory, it will attempt to get a version number
  7. # from `git describe` in the form 1.2.0-238-g0a25a7c, where the middle value
  8. # is the number of commits since the 1.2.0 tag.
  9. # Use $SCRYPT_VERSION if it exists.
  10. if [ -n "${SCRYPT_VERSION}" ]; then
  11. # Do not use \n; that confuses autoconf.
  12. printf "%s" "${SCRYPT_VERSION}"
  13. exit 0
  14. fi
  15. # Get a version number from git, if it exists.
  16. if git rev-parse 2>/dev/null; then
  17. # Get a version string from the latest git tag.
  18. if version_git=$( git describe --tags --match '[[:digit:]].*' ) \
  19. 2>/dev/null ; then
  20. version_decapitated=$( echo "${version}" | sed "s/-head//" )
  21. # Check that the beginning of this tag matches the version.
  22. case ${version_git} in
  23. "${version_decapitated}"*)
  24. # If so, use that version string.
  25. version=${version_git};;
  26. *)
  27. printf "git tag does not match version\n" 1>&2
  28. exit 1;;
  29. esac
  30. fi
  31. fi
  32. # Output the version to stdout. Do not use \n; that confuses autoconf.
  33. printf "%s" "${version}"