From: Ralph Corderoy Date: Tue, 9 May 2017 22:10:06 +0000 (+0100) Subject: config/version.sh: Rewrite. Use uname(1), git-describe(1), and UTC. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/571d5e7543fd73aeb77af653a8d1b20d78c84b48?hp=d8f618fee89be7c25e9cc232a358d2d2b1ed53ac config/version.sh: Rewrite. Use uname(1), git-describe(1), and UTC. Not sure why it searched through PATH manually for uname(1) and hostname(1). uname and its -n option are POSIX so just use those. It was the preference over hostname anyway. Use git-describe(1), not just git-branch(1), as it gives more detail, including --dirty to show the built source differs from the commit. Specify the format for the build date, and its timezone; +0000. --- diff --git a/config/version.sh b/config/version.sh index a0105e36..b94c62cc 100755 --- a/config/version.sh +++ b/config/version.sh @@ -1,50 +1,21 @@ -#!/bin/sh +#! /bin/sh # # version.sh -- script to create version string(s) for nmh. -# # You need to pass the script the version number to use. -# - -if [ -z "$1" ]; then - echo "usage: version.sh VERSION" 1>&2 - exit 1 -fi -VERSION=$1 -OFS="$IFS" -IFS=: -HOSTNAME=unknown +set -e -# Find out the name of the host we are compiling on -for prog in uname hostname -do - for dir in $PATH - do - if [ ! -f $dir/$prog ]; then - continue - fi - case $prog in - uname) HOSTNAME=`$prog -n` - ;; - hostname) HOSTNAME=`$prog` - ;; - esac - break - done - if [ X"$HOSTNAME" != X -a X"$HOSTNAME" != Xunknown ]; then - break - fi -done - -IFS=" " - -if [ -d "${srcdir}/.git" ] ; then - branch=`(git branch | grep '^\*' | tr -d '* ') || true` -fi -if [ "${branch}" -a "${branch}" != "master" ] ; then - echo "char *version_str = \"nmh-$VERSION [branch ${branch}] [compiled on $HOSTNAME at `date`]\";" +version=${1?} +host=`uname -n` +if test -d "$srcdir/.git"; then + git=" `git describe --long --dirty`" else - echo "char *version_str = \"nmh-$VERSION [compiled on $HOSTNAME at `date`]\";" + git= fi -echo "char *version_num = \"nmh-$VERSION\";" -echo "char *user_agent = \"nmh/$VERSION\";" +date="`TZ=GMT0 date +'%Y-%m-%d %T'` +0000" + +cat <