Package Updates.
[lfs.git] / git-version.sh
blob09a8fadd7e69f4514ef16468aa7f9f9330de09c2
1 #!/bin/bash
3 if [ "$1" = sysv ]; then
4 SYSV="INCLUDE"
5 SYSTEMD="IGNORE "
6 elif [ "$1" = systemd ]; then
7 SYSV="IGNORE "
8 SYSTEMD="INCLUDE"
9 else
10 echo You must provide either \"sysv\" or \"systemd\" as argument
11 exit 1
14 echo "<!ENTITY % sysv \"$SYSV\">" > conditional.ent
15 echo "<!ENTITY % systemd \"$SYSTEMD\">" >> conditional.ent
17 if [ -e LFS-RELEASE ]; then
18 exit 0
21 if ! 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
35 export LC_ALL=en_US.utf8
36 export TZ=America/Chicago
38 commit_date=$(git show -s --format=format:"%cd" --date=local)
40 year=$(date --date "$commit_date" "+%Y")
41 month=$(date --date "$commit_date" "+%B")
42 month_digit=$(date --date "$commit_date" "+%m")
43 day=$(date --date "$commit_date" "+%d" | sed 's/^0//')
45 case $day in
46 "1" | "21" | "31" ) suffix="st";;
47 "2" | "22" ) suffix="nd";;
48 "3" | "23" ) suffix="rd";;
49 * ) suffix="th";;
50 esac
52 full_date="$month $day$suffix, $year"
54 sha="$(git describe --abbrev=1)"
55 rev=$(echo "$sha" | sed 's/-g[^-]*$//')
56 version="$rev"
57 versiond="$rev-systemd"
59 if [ "$(git diff HEAD | wc -l)" != "0" ]; then
60 version="$version-wip"
61 versiond="$versiond-wip"
64 echo "<![ %sysv; [" > version.ent
65 echo "<!ENTITY version \"$version\">" >> version.ent
66 echo "]]>" >> version.ent
67 echo "<![ %systemd; [" >> version.ent
68 echo "<!ENTITY version \"$versiond\">" >> version.ent
69 echo "]]>" >> version.ent
70 echo "<!ENTITY releasedate \"$full_date\">" >> version.ent
71 echo "<!ENTITY copyrightdate \"1999-$year\">" >> version.ent
73 [ -z "$DIST" ] || echo $version > "$DIST"