source: git-version.sh@ 17c9da8

trunk
Last change on this file since 17c9da8 was 17c9da8, checked in by Xi Ruoyao <xry111@…>, 3 months ago

generate version info from git

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