source: git-version.sh

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

git-version: Use "-wip" as the version suffix instead of "+" for changes not committed yet

It's not allowed to use "+" in id attributes etc.

  • Property mode set to 100755
File size: 2.4 KB
Line 
1#!/bin/bash
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 [ -e LFS-RELEASE ]; then
18 exit 0
19fi
20
21if ! git status > /dev/null; then
22 # Either it's not a git repository, or git is unavaliable.
23 # Just workaround.
24 echo "<![ %sysv; [" > version.ent
25 echo "<!ENTITY version \"unknown\">" >> version.ent
26 echo "]]>" >> version.ent
27 echo "<![ %systemd; [" >> version.ent
28 echo "<!ENTITY version \"unknown-systemd\">" >> version.ent
29 echo "]]>" >> version.ent
30 echo "<!ENTITY releasedate \"unknown\">" >> version.ent
31 echo "<!ENTITY copyrightdate \"1999-2023\">" >> version.ent
32 exit 0
33fi
34
35export LC_ALL=en_US.utf8
36export TZ=America/Chicago
37
38commit_date=$(git show -s --format=format:"%cd" --date=local)
39
40year=$(date --date "$commit_date" "+%Y")
41month=$(date --date "$commit_date" "+%B")
42month_digit=$(date --date "$commit_date" "+%m")
43day=$(date --date "$commit_date" "+%d" | sed 's/^0//')
44
45case $day in
46 "1" | "21" | "31" ) suffix="st";;
47 "2" | "22" ) suffix="nd";;
48 "3" | "23" ) suffix="rd";;
49 * ) suffix="th";;
50esac
51
52full_date="$month $day$suffix, $year"
53
54sha="$(git describe --abbrev=1)"
55rev=$(echo "$sha" | sed 's/-g[^-]*$//')
56version="$rev"
57versiond="$rev-systemd"
58
59if [ "$(git diff HEAD | wc -l)" != "0" ]; then
60 version="$version-wip"
61 versiond="$versiond-wip"
62fi
63
64echo "<![ %sysv; [" > version.ent
65echo "<!ENTITY version \"$version\">" >> version.ent
66echo "]]>" >> version.ent
67echo "<![ %systemd; [" >> version.ent
68echo "<!ENTITY version \"$versiond\">" >> version.ent
69echo "]]>" >> version.ent
70echo "<!ENTITY releasedate \"$full_date\">" >> version.ent
71echo "<!ENTITY copyrightdate \"1999-$year\">" >> version.ent
72
73[ -z "$DIST" ] || echo $version > "$DIST"
Note: See TracBrowser for help on using the repository browser.