d0916713ad92a7a6f915fa5a281f3155bbfd5456
[openwrt/openwrt.git] / scripts / getver.sh
1 #!/usr/bin/env bash
2 export LANG=C
3 export LC_ALL=C
4 [ -n "$TOPDIR" ] && cd $TOPDIR
5
6 try_version() {
7 [ -f version ] || return 1
8 REV="$(cat version)"
9 [ -n "$REV" ]
10 }
11
12 try_git() {
13 git rev-parse --git-dir >/dev/null 2>&1 || return 1
14 REV="$(git describe --match reboot | sed "s/reboot-\([0-9]*\)-.*/\1/g")"
15 REV="${REV:+r$REV}"
16 [ -n "$REV" ]
17 }
18
19 try_hg() {
20 [ -d .hg ] || return 1
21 REV="$(hg log -r-1 --template '{desc}' | awk '{print $2}' | sed 's/\].*//')"
22 REV="${REV:+r$REV}"
23 [ -n "$REV" ]
24 }
25
26 try_version || try_git || try_hg || REV="unknown"
27 echo "$REV"