File: gen-ver.sh

package info (click to toggle)
cclive 0.9.3-0.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 2,404 kB
  • sloc: sh: 11,339; cpp: 3,198; makefile: 138
file content (70 lines) | stat: -rwxr-xr-x 1,537 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
#
# cclive
# Copyright (C) 2012  Toni Gundogdu <legatvs@gmail.com>
#
# This file is part of cclive <http://cclive.sourceforge.net/>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with this program.  If not, see
# <http://www.gnu.org/licenses/>.
#
dir=`dirname $0`
o=
# flags:
c= # strip off the 'v' prefix

# VERSION file is part of the dist tarball.
from_VERSION_file()
{
  o=`cat "$dir/VERSION" 2>/dev/null`
}

from_git_describe()
{
  [ -d "$dir/.git" -o -f "$dir/.git" ] && {
    o=`git describe --match "v[0-9]*" --abbrev=4 HEAD 2>/dev/null`
  }
}

dump_vn()
{
  [ -n "$c" ] && o=${o#v} # strip off the 'v' prefix.
  echo $o
  exit 0
}

help()
{
  echo "$0 [OPTIONS]
-h  Show this help and exit
-c  Strip off the 'v' prefix from the output"
  exit 0
}

while [ $# -gt 0 ]
do
  case "$1" in
    -c) c=1;;
    -h) help;;
     *) break;;
  esac
  shift
done

from_VERSION_file
[ -z "$o" ] && from_git_describe
[ -n "$o" ] && dump_vn
exit 1

# vim: set ts=2 sw=2 tw=72 expandtab: