#!/bin/sh

revfile=`ls -1 /etc/*-revision 2>/dev/null | head -n 1`
if [ ! -z "$revfile" ] ; then
  revname=`basename $revfile '-revision'`
else
  revfile=`ls -1 /etc/*-version 2>/dev/null | head -n 1`
  if [ ! -z "$revfile" ] ; then
    revname=`basename $revfile '-version'`
  fi
fi
if [ ! -z "$revfile" ] ; then
  revision=`cat "$revfile" | head -n 1`
  if [ ! -z "$revision" ] ; then
    echo "frontend_distribution=\"$revname $revision\""
  fi
fi
sysinfo=`uname -a 2>/dev/null | head -n 1`
if [ ! -z "$sysinfo" ] ; then
  echo "frontend_system=\"$sysinfo\""
fi
hostcert=$X509_USER_CERT
if [ -z "$hostcert" ] ; then hostcert=$X509_HOST_CERT ; fi
if [ -z "$hostcert" ] ; then hostcert='/etc/grid-security/hostcert.pem' ; fi
if [ -r "$hostcert" ] ; then
  hostsubject=`openssl x509 -in /etc/grid-security/hostcert.pem  -subject -noout 2>/dev/null | head -n 1 | sed 's/^subject= *//'`  
  hostissuer=`openssl x509 -in /etc/grid-security/hostcert.pem  -issuer -noout 2>/dev/null | head -n 1 | sed 's/^issuer= *//'`  
  if [ ! -z "$hostsubject" ] ; then
    echo "frontend_subject=\"$hostsubject\""
  fi
  if [ ! -z "$hostissuer" ] ; then
    echo "frontend_ca=\"$hostissuer\""
  fi
fi
