forked from strace/strace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file-date-gen
executable file
·53 lines (41 loc) · 1 KB
/
file-date-gen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
#
# Copyright (c) 2017-2019 The strace developers.
# All rights reserved.
#
# SPDX-License-Identifier: LGPL-2.1-or-later
if [ "$1" = "-f" ]; then
shift
DATE_FORMAT="$1"
shift
fi
: ${FILE:=$1}
: ${DATE_FILE:=$(dirname "$FILE")/.$(basename "${FILE}").date}
: ${DEFAULT_DATE:=$2}
: ${DATE_FORMAT:=%Y-%m-%d}
LC_TIME=C; export LC_TIME
date=
[ -n "${FILE}" ] || {
echo >&2 "$0 $(dirname "$0")/file [$(dirname "$0")/file.date [DEFAULT_DATE]]"
exit 1
}
[ -f "${DATE_FILE}" ] && date="$(cat "${DATE_FILE}")"
[ -n "${date}" ] ||
date="$(git log -s -n 1 --format=format:%cD "${FILE}")"
[ -n "${date}" ] ||
date="${DEFAULT_DATE}"
[ -n "${date}" ] ||
[ -z "${SOURCE_DATE_EPOCH-}" ] ||
date="$(date -u -d "@${SOURCE_DATE_EPOCH}")"
[ -n "${date}" ] ||
date="$(date -u)"
[ -n "${date}" ] || {
printf >&2 "%s: Undefined date.\n" "$0"
exit 1
}
datestr="$(date -u "+${DATE_FORMAT}" -d "${date}")" &&
[ -n "${datestr}" ] || {
printf >&2 "%s: Invalid date: %s\n" "$0" "$date"
exit 1
}
exec printf '%s' "$datestr"