scripts/ipkg-make-index.sh: use bash instead of /bin/sh to fix use of [[ ]]
[openwrt/svn-archive/archive.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_svn() {
13 [ -d .svn ] || return 1
14 REV="$(svn info | awk '/^Last Changed Rev:/ { print $4 }')"
15 REV="${REV:+r$REV}"
16 [ -n "$REV" ]
17 }
18
19 try_git() {
20 [ -d .git ] || return 1
21 REV="$(git log | grep -m 1 git-svn-id | awk '{ gsub(/.*@/, "", $0); print $1 }')"
22 REV="${REV:+r$REV}"
23 [ -n "$REV" ]
24 }
25
26 try_hg() {
27 [ -d .hg ] || return 1
28 REV="$(hg log -r-1 --template '{desc}' | awk '{print $2}' | sed 's/\].*//')"
29 REV="${REV:+$REV}"
30 [ -n "$REV" ]
31 }
32
33 try_version || try_svn || try_git || try_hg || REV="unknown"
34 echo "$REV"