package_version.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. # Copyright (c) 2013 Luca Barbato
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"),
  6. # to deal in the Software without restriction, including without limitation
  7. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. # and/or sell copies of the Software, and to permit persons to whom
  9. # the Software is furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included
  12. # in all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. # IN THE SOFTWARE.
  21. if [ -d .git ]; then
  22. # Retrieve the version from the last git tag.
  23. VER=`git describe --always | sed -e "s:v::"`
  24. if [ x"`git diff-index --name-only HEAD`" != x ]; then
  25. # If the sources have been changed locally, add -dirty to the version.
  26. VER="${VER}-dirty"
  27. fi
  28. elif [ -f .version ]; then
  29. # If git is not available (e.g. when building from source package)
  30. # we can extract the package version from .version file.
  31. VER=`< .version`
  32. else
  33. # The package version cannot be retrieved.
  34. VER="Unknown"
  35. fi
  36. printf '%s' "$VER"