paivana

HTTP paywall reverse proxy
Log | Files | Refs | Submodules | README | LICENSE

get_version.sh (1229B)


      1 #!/bin/sh
      2 # Gets the version number from git, or from the contents of .version
      3 VERSION=
      4 if test -f ".version"; then
      5   VERSION=$(cat .version)
      6 fi
      7 if [ -e ./.git ]; then
      8   # With sparse checkouts, we have a .git dir but possibly no tags
      9   gitver=$(git describe --tags 2>/dev/null || echo no-git-version)
     10   if test "$gitver" != "no-git-version"; then
     11     VERSION=${gitver#v}
     12     # Cache it for builds from a tarball, but only when that actually
     13     # changes something: this runs on every 'meson setup', and a source
     14     # tree that is read-only (distribution builds, nix) or that we would
     15     # otherwise needlessly dirty must not turn into a hard failure.
     16     if test "x$VERSION" != "x$(cat .version 2>/dev/null)"; then
     17       echo "$VERSION" > .version 2>/dev/null || true
     18     fi
     19   fi
     20 fi
     21 if test "x$VERSION" = "x"; then
     22   VERSION="unknown"
     23 fi
     24 case $1 in
     25 "--major")
     26   echo "$VERSION" | sed 's/\(^[0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/g'
     27   ;;
     28 "--minor")
     29   echo "$VERSION" | sed 's/\(^[0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/g'
     30   ;;
     31 "--micro")
     32   echo "$VERSION" | sed 's/\(^[0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/g'
     33   ;;
     34 "--git")
     35   echo "$VERSION" | sed 's/\(^[0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\(.*\)/\4/g'
     36   ;;
     37 *)
     38   echo "$VERSION"
     39 esac