source: git-version.sh@ 064f3b8

11.2
Last change on this file since 064f3b8 was 50836740, checked in by Xi Ruoyao <xry111@…>, 3 years ago

merge conditional XML from LFS

There was some consistency issues in URLs to LFS. For example, in
systemd revision the URL to LFS "General Network Configuration" points
to the sysv book, this can be really troubling to new readers.

Instead of fixing them one by one, merge conditional XML developed by
Pierre from LFS.

  • Property mode set to 100755
File size: 1.7 KB
Line 
1#!/bin/sh
2
3if [ "$1" = sysv ]; then
4 SYSV="INCLUDE"
5 SYSTEMD="IGNORE "
6elif [ "$1" = systemd ]; then
7 SYSV="IGNORE "
8 SYSTEMD="INCLUDE"
9else
10 echo You must provide either \"sysv\" or \"systemd\" as argument
11 exit 1
12fi
13
14echo "<!ENTITY % sysv \"$SYSV\">" > conditional.ent
15echo "<!ENTITY % systemd \"$SYSTEMD\">" >> conditional.ent
16
17if ! git status > /dev/null; then
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
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
39 "1" | "21" | "31" ) suffix="st";;
40 "2" | "22" ) suffix="nd";;
41 "3" | "23" ) suffix="rd";;
42 * ) suffix="th";;
43esac
44
45full_date="$month $day$suffix, $year"
46
47sha="$(git describe --abbrev=1)"
48version=$(echo "$sha" | sed 's/-g[^-]*$//')
49
50if [ "$(git diff HEAD | wc -l)" != "0" ]; then
51 version="$version+"
52fi
53
54echo "<!ENTITY year \"$year\">" > version.ent
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.