1 | #!/bin/sh
|
---|
2 |
|
---|
3 | if ! git status > /dev/null; then
|
---|
4 | # Either it's not a git repository, or git is unavaliable.
|
---|
5 | # Just workaround.
|
---|
6 | echo "<!ENTITY day \"??\">" > version.ent
|
---|
7 | echo "<!ENTITY month \"??\">" >> version.ent
|
---|
8 | echo "<!ENTITY year \"????\">" >> version.ent
|
---|
9 | echo "<!ENTITY copyrightdate \"1999-2021\">" >> version.ent
|
---|
10 | echo "<!ENTITY version \"unknown\">" >> version.ent
|
---|
11 | echo "<!ENTITY releasedate \"unknown\">" >> version.ent
|
---|
12 | echo "<!ENTITY pubdate \"unknown\">" >> version.ent
|
---|
13 | exit 0
|
---|
14 | fi
|
---|
15 |
|
---|
16 | export LC_ALL=en_US.utf8
|
---|
17 | export TZ=US/Pacific
|
---|
18 |
|
---|
19 | commit_date=$(git show -s --format=format:"%cd" --date=local)
|
---|
20 | short_date=$(date --date "$commit_date" "+%Y-%m-%d")
|
---|
21 |
|
---|
22 | year=$(date --date "$commit_date" "+%Y")
|
---|
23 | month=$(date --date "$commit_date" "+%B")
|
---|
24 | month_digit=$(date --date "$commit_date" "+%m")
|
---|
25 | day_digit=$(date --date "$commit_date" "+%d")
|
---|
26 | day=$(echo $day_digit | sed 's/^0//')
|
---|
27 |
|
---|
28 | case $day in
|
---|
29 | "1" | "21" | "31" ) suffix="st";;
|
---|
30 | "2" | "22" ) suffix="nd";;
|
---|
31 | "3" | "23" ) suffix="rd";;
|
---|
32 | * ) suffix="th";;
|
---|
33 | esac
|
---|
34 |
|
---|
35 | full_date="$month $day$suffix, $year"
|
---|
36 |
|
---|
37 | sha="$(git describe --abbrev=1)"
|
---|
38 | version=$(echo "$sha" | sed 's/-g[^-]*$//')
|
---|
39 |
|
---|
40 | if [ "$(git diff HEAD | wc -l)" != "0" ]; then
|
---|
41 | version="$version+"
|
---|
42 | fi
|
---|
43 |
|
---|
44 | echo "<!ENTITY day \"$day_digit\">" > version.ent
|
---|
45 | echo "<!ENTITY month \"$month_digit\">" >> version.ent
|
---|
46 | echo "<!ENTITY year \"$year\">" >> version.ent
|
---|
47 | echo "<!ENTITY copyrightdate \"2001-$year\">" >> version.ent
|
---|
48 | echo "<!ENTITY version \"$version\">" >> version.ent
|
---|
49 | echo "<!ENTITY releasedate \"$full_date\">" >> version.ent
|
---|
50 | echo "<!ENTITY pubdate \"$short_date\">" >> version.ent
|
---|