uvtd: seat: implement session IDs
[platform/upstream/kmscon.git] / src / genversion.sh
1 #!/bin/sh
2
3 #
4 # Generate $1 with:
5 #   const char shl_git_head[] = "<git-head-revision>";
6 # But do not touch $1 if the git-revision is already up-to-date.
7 #
8
9 if test "x$1" = "x" ; then
10         echo "usage: ./genversion <file>"
11         exit 1
12 fi
13
14 #
15 # Check whether this is a valid git repository.
16 # Set ISGIT to 1=true or 0=false.
17 #
18
19 ISGIT=0
20 REV=`git rev-parse --git-dir 2>/dev/null`
21 if test "x$?" = "x0" ; then
22         ISGIT=1
23 fi
24
25 #
26 # Check the old revision from $1.
27 #
28
29 if test -f "$1" ; then
30         OLDREV=`cat "$1"`
31 else
32         if test $ISGIT = 0 ; then
33                 echo "WARNING: version file $1 is missing"
34                 echo "const char shl_git_head[] = \"UnknownRevision\";" >"$1"
35                 exit 0
36         fi
37
38         OLDREV=""
39 fi
40
41 #
42 # Check new revision from "git describe". However, if this is no valid
43 # git-repository, return success and do nothing.
44 #
45
46 if test $ISGIT = 0 ; then
47         exit 0
48 fi
49
50 NEWREV=`git describe`
51 NEWREV="const char shl_git_head[] = \"$NEWREV\";"
52
53 #
54 # Exit if the file is already up to date.
55 # Otherwise, write the new revision into the file.
56 #
57
58 if test "x$OLDREV" = "x$NEWREV" ; then
59         exit 0
60 fi
61
62 echo "$NEWREV" >"$1"