2
0

get_source_date_epoch.sh 649 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env bash
  2. export LANG=C
  3. export LC_ALL=C
  4. [ -n "$TOPDIR" ] && cd $TOPDIR
  5. try_version() {
  6. [ -f version.date ] || return 1
  7. SOURCE_DATE_EPOCH="$(cat version.date)"
  8. [ -n "$SOURCE_DATE_EPOCH" ]
  9. }
  10. try_git() {
  11. [ -e .git ] || return 1
  12. SOURCE_DATE_EPOCH="$(git log -1 --format=format:%ct)"
  13. [ -n "$SOURCE_DATE_EPOCH" ]
  14. }
  15. try_hg() {
  16. [ -d .hg ] || return 1
  17. SOURCE_DATE_EPOCH="$(hg log --template '{date}' -l 1 | cut -d. -f1)"
  18. [ -n "$SOURCE_DATE_EPOCH" ]
  19. }
  20. try_mtime() {
  21. perl -e 'print((stat $ARGV[0])[9])' "$0"
  22. [ -n "$SOURCE_DATE_EPOCH" ]
  23. }
  24. try_version || try_git || try_hg || try_mtime || SOURCE_DATE_EPOCH=""
  25. echo "$SOURCE_DATE_EPOCH"