summaryrefslogtreecommitdiff
path: root/tools/svnversion.sh
blob: 8fe98046228706f609d75a63e95e45578ba2f8bf (plain)
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
#!/bin/sh
#             __________               __   ___.
#   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
#   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
#   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
#   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
#                     \/            \/     \/    \/            \/
# $Id$
#

# Usage: svnversion.sh [source-root]

# Prints the revision "rXYZ" of the first argument, as reported by svnversion.
# Prints "unknown" if svnversion fails or says "exported".
svnversion_safe() {
    # LANG=C forces svnversion to not localize "exported".
    if OUTPUT=`LANG=C svnversion "$@"`; then
        if [ "$OUTPUT" = "exported" ]; then

            # Not a SVN repository, maybe a git-svn one ?
            if [ -z "$1" ]; then
                GITDIR="./.git"
            else
                GITDIR="$1/.git"
            fi

            # First make sure it is a git repository
            if [ -d "$GITDIR" ]; then
                OUTPUT=`LANG=C git --git-dir="$GITDIR" svn info 2>/dev/null|grep '^Revision: '|cut -d\  -f2`
                if [ -z "$OUTPUT" ]; then
                    echo "unknown"
                else
                    echo "r$OUTPUT"
                fi
            else # not a git repository
                echo "unknown"
            fi
        else
            echo "r$OUTPUT"
        fi
    else
        echo "unknown"
    fi
}

VERSIONFILE=docs/VERSION
if [ -n "$1" ]; then TOP=$1; else TOP=..; fi
if [ -r $TOP/$VERSIONFILE ]; then SVNVER=`cat $TOP/$VERSIONFILE`; 
else
    SVNVER=`svnversion_safe $TOP`;
    if [ "$SVNVER" = "unknown" ]; then
        # try getting it from a subdir to test if perhaps they are symlinked
        # from the root
        SVNVER=`svnversion_safe $TOP/tools`;
    fi
fi
VERSION=$SVNVER-`date -u +%y%m%d`
echo $VERSION