source: git-version.sh@ 0c06e1e

12.1-rc1
Last change on this file since 0c06e1e was fd02389a, checked in by Xi Ruoyao <xry111@…>, 4 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
RevLine 
[a9dc972]1#!/bin/bash
[59483809]2
[4467b18d]3if [ "$1" = sysv ]; then
[c37e846]4 SYSV="INCLUDE"
5 SYSTEMD="IGNORE "
[4467b18d]6elif [ "$1" = systemd ]; then
[c37e846]7 SYSV="IGNORE "
8 SYSTEMD="INCLUDE"
[4467b18d]9else
[c37e846]10 echo You must provide either \"sysv\" or \"systemd\" as argument
11 exit 1
[4467b18d]12fi
13
14echo "<!ENTITY % sysv \"$SYSV\">" > conditional.ent
15echo "<!ENTITY % systemd \"$SYSTEMD\">" >> conditional.ent
16
[b91b12a]17if [ -e LFS-RELEASE ]; then
18 exit 0
19fi
20
[8186f16]21if ! git status > /dev/null; then
[c37e846]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
[c5fe6ee]31 echo "<!ENTITY copyrightdate \"1999-2023\">" >> version.ent
[c37e846]32 exit 0
[59483809]33fi
34
35export LC_ALL=en_US.utf8
[45a010a]36export TZ=America/Chicago
[59483809]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")
[8186f16]43day=$(date --date "$commit_date" "+%d" | sed 's/^0//')
[59483809]44
45case $day in
[c37e846]46 "1" | "21" | "31" ) suffix="st";;
47 "2" | "22" ) suffix="nd";;
48 "3" | "23" ) suffix="rd";;
49 * ) suffix="th";;
[59483809]50esac
51
52full_date="$month $day$suffix, $year"
53
[6ca780c]54sha="$(git describe --abbrev=1)"
[7af57d2e]55rev=$(echo "$sha" | sed 's/-g[^-]*$//')
56version="$rev"
57versiond="$rev-systemd"
[59483809]58
59if [ "$(git diff HEAD | wc -l)" != "0" ]; then
[fd02389a]60 version="$version-wip"
61 versiond="$versiond-wip"
[59483809]62fi
63
[4467b18d]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
[59483809]70echo "<!ENTITY releasedate \"$full_date\">" >> version.ent
71echo "<!ENTITY copyrightdate \"1999-$year\">" >> version.ent
[c858ba4e]72
73[ -z "$DIST" ] || echo $version > "$DIST"
Note: See TracBrowser for help on using the repository browser.