1 | #!/bin/sh
|
---|
2 |
|
---|
3 | if [ "$1" = sysv ]; then
|
---|
4 | SYSV="INCLUDE"
|
---|
5 | SYSTEMD="IGNORE "
|
---|
6 | S6="IGNORE "
|
---|
7 | elif [ "$1" = systemd ]; then
|
---|
8 | SYSV="IGNORE "
|
---|
9 | SYSTEMD="INCLUDE"
|
---|
10 | S6="IGNORE "
|
---|
11 | elif [ "$1" = s6 ]; then
|
---|
12 | SYSV="IGNORE "
|
---|
13 | SYSTEMD="IGNORE "
|
---|
14 | S6="INCLUDE "
|
---|
15 | else
|
---|
16 | echo You must provide either \"sysv\" or \"systemd\" as argument
|
---|
17 | exit 1
|
---|
18 | fi
|
---|
19 |
|
---|
20 | echo "<!ENTITY % sysv \"$SYSV\">" > conditional.ent
|
---|
21 | echo "<!ENTITY % systemd \"$SYSTEMD\">" >> conditional.ent
|
---|
22 | echo "<!ENTITY % s6 \"$S6\">" >> conditional.ent
|
---|
23 |
|
---|
24 | if ! git status > /dev/null; then
|
---|
25 | # Either it's not a git repository, or git is unavaliable.
|
---|
26 | # Just workaround.
|
---|
27 | echo "<![ %sysv; [" > version.ent
|
---|
28 | echo "<!ENTITY version \"unknown\">" >> version.ent
|
---|
29 | echo "]]>" >> version.ent
|
---|
30 | echo "<![ %systemd; [" >> version.ent
|
---|
31 | echo "<!ENTITY version \"unknown-systemd\">" >> version.ent
|
---|
32 | echo "]]>" >> version.ent
|
---|
33 | echo "<![ %s6; [" >> version.ent
|
---|
34 | echo "<!ENTITY version \"unknown-s6\">" >> version.ent
|
---|
35 | echo "]]>" >> version.ent
|
---|
36 | echo "<!ENTITY releasedate \"unknown\">" >> version.ent
|
---|
37 | echo "<!ENTITY copyrightdate \"1999-2022\">" >> version.ent
|
---|
38 | exit 0
|
---|
39 | fi
|
---|
40 |
|
---|
41 | export LC_ALL=en_US.utf8
|
---|
42 | export TZ=US/Pacific
|
---|
43 |
|
---|
44 | commit_date=$(git show -s --format=format:"%cd" --date=local)
|
---|
45 |
|
---|
46 | year=$(date --date "$commit_date" "+%Y")
|
---|
47 | month=$(date --date "$commit_date" "+%B")
|
---|
48 | month_digit=$(date --date "$commit_date" "+%m")
|
---|
49 | day=$(date --date "$commit_date" "+%d" | sed 's/^0//')
|
---|
50 |
|
---|
51 | case $day in
|
---|
52 | "1" | "21" | "31" ) suffix="st";;
|
---|
53 | "2" | "22" ) suffix="nd";;
|
---|
54 | "3" | "23" ) suffix="rd";;
|
---|
55 | * ) suffix="th";;
|
---|
56 | esac
|
---|
57 |
|
---|
58 | full_date="$month $day$suffix, $year"
|
---|
59 |
|
---|
60 | sha="$(git describe --abbrev=1)"
|
---|
61 | rev=$(echo "$sha" | sed 's/-g[^-]*$//')
|
---|
62 | version="$rev"
|
---|
63 | versiond="$rev-systemd"
|
---|
64 | version6="$rev-s6"
|
---|
65 |
|
---|
66 | if [ "$(git diff HEAD | wc -l)" != "0" ]; then
|
---|
67 | version="$version+"
|
---|
68 | versiond="$versiond+"
|
---|
69 | version6="$version6+"
|
---|
70 | fi
|
---|
71 |
|
---|
72 | echo "<![ %sysv; [" > version.ent
|
---|
73 | echo "<!ENTITY version \"$version\">" >> version.ent
|
---|
74 | echo "]]>" >> version.ent
|
---|
75 | echo "<![ %systemd; [" >> version.ent
|
---|
76 | echo "<!ENTITY version \"$versiond\">" >> version.ent
|
---|
77 | echo "]]>" >> version.ent
|
---|
78 | echo "<![ %s6; [" >> version.ent
|
---|
79 | echo "<!ENTITY version \"$version6\">" >> version.ent
|
---|
80 | echo "]]>" >> version.ent
|
---|
81 | echo "<!ENTITY releasedate \"$full_date\">" >> version.ent
|
---|
82 | echo "<!ENTITY copyrightdate \"1999-$year\">" >> version.ent
|
---|