summaryrefslogtreecommitdiff
path: root/copyright-year-gen
blob: e044601e47a5e58fe7b51e05ae80fdcef1e8fa2d (plain)
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
#!/bin/sh
#
# Copyright (c) 2017-2019 The strace developers.
# All rights reserved.
#
# SPDX-License-Identifier: LGPL-2.1-or-later

: ${YEAR_FILE:=$1}
: ${DEFAULT_YEAR:=$2}
LC_TIME=C; export LC_TIME

year=

[ -n "${YEAR_FILE}" ] || {
	echo >&2 "$0 $(dirname "$0")/.year [DEFAULT_YEAR]"
	exit 1
}

[ -f "${YEAR_FILE}" ] && year="$(cat "${YEAR_FILE}")"

[ -n "${year}" ] ||
	year="$(date -u +%Y -d "$(git show -s --format=format:%cD)")"

[ -n "${year}" ] ||
	year="${DEFAULT_YEAR}"

[ -n "${year}" ] ||
	[ -z "${SOURCE_DATE_EPOCH-}" ] ||
	year="$(date -u +%Y -d "@${SOURCE_DATE_EPOCH}")"

[ -n "${year}" ] ||
	year="$(date -u +%Y)"

[ -n "${year}" ] || {
	printf >&2 "%s: Undefined year.\n" "$0"
	exit 1
}

printf "%s" "${year}"