]> diplodocus.org Git - nmh/blobdiff - config/version.sh
Invert ternary condition to remove one negative.
[nmh] / config / version.sh
index bf95447d6971eb771057bc7ba2f940b936c00fc7..5b76808f2ca469adf54500bd426945be784672b3 100755 (executable)
@@ -1,49 +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 -C $srcdir describe --long --dirty`"
 else
-    echo "char *version_str = \"nmh-$VERSION [compiled on $HOSTNAME at `date`]\";"
+    git=
 fi
-echo "char *version_num = \"nmh-$VERSION\";"
+date="`TZ=GMT0 date +'%Y-%m-%d %T'` +0000"
+
+cat <<E
+char *version_str = "nmh-$version$git built $date on $host";
+char *version_num = "nmh-$version";
+char *user_agent = "nmh/$version";
+E