discover/network: Null terminate ifname buffer explicitly
[petitboot] / version.sh
1 #! /bin/bash
2 #
3 # version.sh: create a version string for use by configure.ac
4
5 version=
6 datefmt='%Y%m%d'
7
8 export GIT_DIR=$(dirname $0)/.git/
9
10 if head=$(git rev-parse --short=8 --verify HEAD 2>/dev/null); then
11
12         suffix=''
13         # Add a '-dirty' suffix for uncommitted changes.
14         if git diff-index HEAD | read dummy; then
15                 suffix=-dirty
16         fi
17
18         if tag=$(git describe --tags --exact-match 2>/dev/null); then
19                 # use a tag; remove any 'v' prefix from v<VERSION> tags
20                 tag=${tag#v}
21                 version=$(printf "%s%s" ${tag} ${suffix})
22         else
23                 # Use the git commit revision for the package version, and add
24                 # a date prefix for easy comparisons.
25                 date=$(git log --pretty=format:"%ct" -1 HEAD)
26                 version=$(printf "%($datefmt)T.g%s%s" ${date} ${head} ${suffix})
27         fi
28 else
29         # Check if a specific version is set, eg: by buildroot
30         if [ ! -z "$PETITBOOT_VERSION" ];
31         then
32                 # Full git hash
33                 len=$(echo -n "${PETITBOOT_VERSION}" | wc -c)
34                 if [[ ${len} == 40 ]]; then
35                         version=`echo -n ${PETITBOOT_VERSION} | \
36                                 sed "s/^\([0-9a-f]\{7\}\).*/\1/;"`
37                 else
38                         version="$PETITBOOT_VERSION"
39                 fi
40         else
41                 # Default to current date and time.
42                 version="$(date +dev.$datefmt)"
43         fi
44 fi
45
46 echo $version