diff options
author | Xi Ruoyao <xry111@mengyan1223.wang> | 2021-04-07 01:01:01 +0800 |
---|---|---|
committer | Xi Ruoyao <xry111@mengyan1223.wang> | 2021-04-07 01:01:01 +0800 |
commit | 594838099780fe0b9e7301143468fbfc6157f4c9 (patch) | |
tree | 9a63628aec29cf15b21aa1413dea828dcc5b5562 /git-version.sh | |
parent | 275f313442348c7932fd2c0656ca871c5eb7374e (diff) |
automatically generate version info from git HEAD
Diffstat (limited to 'git-version.sh')
-rwxr-xr-x | git-version.sh | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/git-version.sh b/git-version.sh new file mode 100755 index 000000000..8b1f13d00 --- /dev/null +++ b/git-version.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +if ! git status; then + # Either it's not a git repository, or git is unavaliable. + # Just workaround. + echo "<!ENTITY version \"unknown\">" > version.ent + echo "<!ENTITY versiond \"unknown-systemd\">" >> version.ent + echo "<!ENTITY releasedate \"unknown\">" >> version.ent + echo "<!ENTITY copyrightdate \"1999-2021\">" >> version.ent + exit 0 +fi + +export LC_ALL=en_US.utf8 +export TZ=US/Pacific + +commit_date=$(git show -s --format=format:"%cd" --date=local) +short_date=$(date --date "$commit_date" "+%Y%m%d") + +year=$(date --date "$commit_date" "+%Y") +month=$(date --date "$commit_date" "+%B") +month_digit=$(date --date "$commit_date" "+%m") +day=$(date --date "$commit_date" "+%d") + +case $day in + "1" | "21" | "31" ) suffix="st";; + "2" | "22" ) suffix="nd";; + "3" | "23" ) suffix="rd";; + * ) suffix="th";; +esac + +full_date="$month $day$suffix, $year" + +sha="g$(git describe --always)" +version="GIT-$short_date-$sha" +versiond="GIT-$short_date-$sha-systemd" + +if [ "$(git diff HEAD | wc -l)" != "0" ]; then + version="$version-MODIFIED" + versiond="$versiond-MODIFIED" +fi + +echo "<!ENTITY version \"$version\">" > version.ent +echo "<!ENTITY versiond \"$versiond\">" >> version.ent +echo "<!ENTITY releasedate \"$full_date\">" >> version.ent +echo "<!ENTITY copyrightdate \"1999-$year\">" >> version.ent |