Use compressed form of ipv6 in $sender_host_address under -bh. Bug 3027
[exim.git] / src / scripts / reversion
1 #!/bin/sh
2 # Copyright (c) The Exim Maintainers 1995 - 2021
3 # SPDX-License-Identifier: GPL-2.0-or-later
4
5 set -e
6 LC_ALL=C
7 export LC_ALL
8
9 # Update Exim's version header file.
10
11 # Compatibility gross-ness for non-POSIX systems
12 if [ -z "$EXIM_REVERSION_ADJUSTED" ]
13 then
14   SHELL=/bin/sh
15   EXIM_REVERSION_ADJUSTED=yes
16   export SHELL EXIM_REVERSION_ADJUSTED
17   # Solaris:
18   if [ -x /usr/xpg4/bin/sh ]
19   then
20     PATH="/usr/xpg4/bin:$PATH"
21     SHELL=/usr/xpg4/bin/sh
22     export PATH SHELL
23   fi
24   # Irix:
25   _XPG=1 ; export _XPG
26   #
27   exec "$SHELL" "$0" "$@"
28 fi
29
30 # Read version information that was generated by a previous run of
31 # this script, or during the release process.
32
33 # Override, used for automated testing w/o access to the
34 # .git directory (w.g. inside a git worktree)
35 if   [ -n "$EXIM_RELEASE_VERSION" ]; then
36     :
37 elif   [ -f ./version.sh ]; then
38     .    ./version.sh
39 elif [ -f ../src/version.sh ]; then
40     .    ../src/version.sh
41 elif [ -d ../../.git ] || [ -f ../../.git ] || [ "$1" = release ]; then
42     # Modify the output of git describe into separate parts for
43     # the name "exim" and the release and variant versions.
44     # Put a dot in the version number and remove a spurious g.
45     if [ "$2" ]
46     then
47         description=$(git describe "$2")
48     else
49         description=$(git describe --dirty=-XX --match 'exim-4*')
50     fi
51     set $(echo "$description" | sed 's/-/ /; s/-g/-/')
52     # Only update if we need to
53     if [ "$2 $3" != "$EXIM_RELEASE_VERSION $EXIM_VARIANT_VERSION" ]
54     then
55             EXIM_RELEASE_VERSION="$2"
56             EXIM_VARIANT_VERSION="$3"
57             rm -f version.h
58     fi
59 fi
60
61 if [ -z "$EXIM_RELEASE_VERSION" ]; then
62     echo "Cannot determine the release number" >&2
63     echo "You may want to override it with EXIM_RELEASE_VERSION" >&2
64     exit 1
65 fi
66
67 # If you are maintaining a patched version of Exim, you can either
68 # create your own version.sh as part of your release process, or you
69 # can modify EXIM_VARIANT_VERSION at this point in this script.
70
71 if test -z "$EXIM_RELEASE_VERSION"; then
72     echo "$0: Your copy of Exim lacks any version information." >&2
73     exit 1
74 fi
75
76 EXIM_COMPILE_NUMBER=$(expr "${EXIM_COMPILE_NUMBER:-0}" + 1)
77
78 echo "$EXIM_COMPILE_NUMBER" >cnumber.h
79
80 # Reproducible builds, accept a build timestamp override from environ per
81 # <https://reproducible-builds.org/specs/source-date-epoch/>.
82 # We require a fairly modern date(1) command here, which is not portable
83 # to some of the systems Exim is built on.  That's okay, because the scenarios
84 # are:
85 #  1) Local postmaster building, not using $SOURCE_DATE_EPOCH, doesn't matter
86 #  2) Packaging folks who don't care about reproducible builds
87 #  3) Packaging folks who care but are using systems where date Just Works
88 #  3) Packaging folks who care and can put a modern date(1) in $PATH
89 #  4) Packaging folks who care and can supply us with a clean patch to support
90 #     their requirements
91 #  5) Packaging folks who care but won't do any work to support their strange
92 #     old systems and want us to do the work for them.  We don't care either,
93 #     they're SOL and have to live without reproducible builds.
94 #
95 exim_build_date_override=''
96 if [ ".${SOURCE_DATE_EPOCH:-}" != "." ]; then
97   fmt='+%d-%b-%Y %H:%M:%S'
98   # Non-reproducible, we use __DATE__ and __TIME__ in C, which respect timezone
99   # (think localtime, not gmtime); for reproduction between systems, UTC makes
100   # more sense and the examples available use UTC without explicitly mandating
101   # it.  I think that we can switch behavior and use UTC for reproducible
102   # builds without it causing any problems: nothing really cares about timezone.
103   # GNU date: "date -d @TS"
104   # BSD date: "date -r TS"
105   exim_build_date_override="$(date -u -d "@${SOURCE_DATE_EPOCH}" "$fmt" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "$fmt" 2>/dev/null)"
106 fi
107
108 ( echo '# automatically generated file - see ../scripts/reversion'
109   echo EXIM_RELEASE_VERSION='"'"$EXIM_RELEASE_VERSION"'"'
110   test -n "$EXIM_VARIANT_VERSION" && \
111   echo EXIM_VARIANT_VERSION='"'"$EXIM_VARIANT_VERSION"'"'
112   echo EXIM_COMPILE_NUMBER='"'"$EXIM_COMPILE_NUMBER"'"'
113   if [ ".${exim_build_date_override:-}" != "." ]; then
114     echo EXIM_BUILD_DATE_OVERRIDE='"'"${exim_build_date_override}"'"'
115   fi
116 ) >version.sh
117
118 if [ ! -f version.h ]
119 then
120 ( echo '/* automatically generated file - see ../scripts/reversion */'
121   echo '#define EXIM_RELEASE_VERSION "'"$EXIM_RELEASE_VERSION"'"'
122   test -n "$EXIM_VARIANT_VERSION" && \
123   echo '#define EXIM_VARIANT_VERSION "'"$EXIM_VARIANT_VERSION"'"'
124   echo '#ifdef EXIM_VARIANT_VERSION'
125   echo '#define EXIM_VERSION_STR EXIM_RELEASE_VERSION "-" EXIM_VARIANT_VERSION'
126   echo '#else'
127   echo '#define EXIM_VERSION_STR EXIM_RELEASE_VERSION'
128   echo '#endif'
129   if [ ".${exim_build_date_override:-}" != "." ]; then
130     echo '#define EXIM_BUILD_DATE_OVERRIDE "'"${exim_build_date_override}"'"'
131   fi
132 ) >version.h
133 fi
134
135 #test -t 1 && echo ">>> version $EXIM_RELEASE_VERSION $EXIM_VARIANT_VERSION #$EXIM_COMPILE_NUMBER"