scripts/get_source_date_epoch.sh: for SVN use a variant that is compatible with older...
[openwrt/openwrt.git] / scripts / get_source_date_epoch.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.date ] || return 1
8 SOURCE_DATE_EPOCH="$(cat version.date)"
9 [ -n "$SOURCE_DATE_EPOCH" ]
10 }
11
12 try_svn() {
13 [ -d .svn ] || return 1
14 SOURCE_DATE_EPOCH="$(./scripts/portable_date.sh "$(LC_ALL=C svn info | sed -ne 's/^Last Changed Date: //p')" +%s)"
15 [ -n "$SOURCE_DATE_EPOCH" ]
16 }
17
18 try_git() {
19 [ -e .git ] || return 1
20 SOURCE_DATE_EPOCH="$(git log -1 --format=format:%ct)"
21 [ -n "$SOURCE_DATE_EPOCH" ]
22 }
23
24 try_hg() {
25 [ -d .hg ] || return 1
26 SOURCE_DATE_EPOCH=""
27 [ -n "$SOURCE_DATE_EPOCH" ]
28 }
29
30 try_version || try_svn || try_git || try_hg || SOURCE_DATE_EPOCH=""
31 echo "$SOURCE_DATE_EPOCH"