find_version 843 B

123456789101112131415161718192021
  1. #!/bin/bash
  2. PROJECT_ROOT_PATH="$(cd $(dirname "$0")/../ ; pwd)"
  3. PROJECT_GIT_DIR_PATH="${PROJECT_ROOT_PATH}/.git"
  4. PROJECT_DIR_NAME="$(basename ${PROJECT_ROOT_PATH})"
  5. # if there is a .git directory at the project root then rely on git for the version string
  6. if [ -d "${PROJECT_GIT_DIR_PATH}" ] ; then
  7. git describe --tags --abbrev --dirty --always
  8. exit 0
  9. fi
  10. # if the proejct root directory matches the naming convetion of an extracted archive then
  11. # get the version number out of that
  12. if [[ "${PROJECT_DIR_NAME}" =~ ^RTLSDR-Airband-[0-9]*\.[0-9]*\.[0-9]*$ ]]; then
  13. echo ${PROJECT_DIR_NAME} | cut -d '-' -f 3
  14. exit 0
  15. fi
  16. # print an error string to stderr (any output to stdout is considered success)
  17. >&2 echo "did not find a git root directory at ${PROJECT_GIT_DIR_PATH} and failed to extract a version from ${PROJECT_DIR_NAME}"