source: git-version.sh

trunk
Last change on this file was 4e207bb, checked in by Pierre Labastie <pierre.labastie@…>, 2 weeks ago

Replace tabs with spaces (except in Makefile :)

  • Property mode set to 100755
File size: 1.7 KB
RevLine 
[17c9da8]1#!/bin/sh
2
[50836740]3if [ "$1" = sysv ]; then
[4e207bb]4 SYSV="INCLUDE"
5 SYSTEMD="IGNORE "
[50836740]6elif [ "$1" = systemd ]; then
[4e207bb]7 SYSV="IGNORE "
8 SYSTEMD="INCLUDE"
[50836740]9else
[4e207bb]10 echo You must provide either \"sysv\" or \"systemd\" as argument
11 exit 1
[50836740]12fi
13
14echo "<!ENTITY % sysv \"$SYSV\">" > conditional.ent
15echo "<!ENTITY % systemd \"$SYSTEMD\">" >> conditional.ent
16
[17c9da8]17if ! git status > /dev/null; then
[4e207bb]18 # Either it's not a git repository, or git is unavaliable.
19 # Just workaround.
20 echo "<!ENTITY year \"????\">" > version.ent
21 echo "<!ENTITY version \"unknown\">" >> version.ent
22 echo "<!ENTITY releasedate \"unknown\">" >> version.ent
23 echo "<!ENTITY pubdate \"unknown\">" >> version.ent
24 exit 0
[17c9da8]25fi
26
27export LC_ALL=en_US.utf8
28export TZ=US/Pacific
29
30commit_date=$(git show -s --format=format:"%cd" --date=local)
31short_date=$(date --date "$commit_date" "+%Y-%m-%d")
32
33year=$(date --date "$commit_date" "+%Y")
34month=$(date --date "$commit_date" "+%B")
35day_digit=$(date --date "$commit_date" "+%d")
36day=$(echo $day_digit | sed 's/^0//')
37
38case $day in
[4e207bb]39 "1" | "21" | "31" ) suffix="st";;
40 "2" | "22" ) suffix="nd";;
41 "3" | "23" ) suffix="rd";;
42 * ) suffix="th";;
[17c9da8]43esac
44
45full_date="$month $day$suffix, $year"
46
[ca5e52a]47sha="$(git describe --abbrev=1)"
[8025137]48version=$(echo "$sha" | sed 's/-g[^-]*$//')
[17c9da8]49
50if [ "$(git diff HEAD | wc -l)" != "0" ]; then
[4e207bb]51 version="$version+"
[17c9da8]52fi
53
[50836740]54echo "<!ENTITY year \"$year\">" > version.ent
[17c9da8]55echo "<!ENTITY version \"$version\">" >> version.ent
56echo "<!ENTITY releasedate \"$full_date\">" >> version.ent
57echo "<!ENTITY pubdate \"$short_date\">" >> version.ent
Note: See TracBrowser for help on using the repository browser.