#!/bin/bash
################################################################################
##
##    Copyright 2001 Sistina Software, Inc.
##
##    This is free software released under the GNU General Public License.
##    There is no warranty for this software.  See the file COPYING for
##    details.
##
##    See the file CONTRIBUTORS for a list of contributors.
##
##    This file is maintained by:
##      AJ Lewis <lewis@sistina.com>
## 
##    File name: lvmver
##
##    Description: outputs the version of lvm in the src directory specified 
##                 to stdout
################################################################################

#  help message
usage()
{
  echo "usage: $0 [OPTIONS]";
  echo -e "\t-d\tLVM src directory";
  echo -e "\t-h\tDisplay this help message";
  exit 0;
}


while getopts "d:h" option ;
do
	case $option in
		d) lvm_src=${OPTARG};;
		*) usage; exit;;
	esac
done

if [ -z ${lvm_src} ]; then
	lvm_src=".";
fi

file="${lvm_src}/kernel/lvm.h";

ver=`cat $file | grep "#define[[:blank:]]LVM_RELEASE_NAME" | \
	sed -e 's/\(#define[[:blank:]]LVM_RELEASE_NAME[[:blank:]]*"\)\([-.[:alnum:]+^\n]*\)\(".*\)/\2/'`;

if [ -z "$ver" ]; then
	echo "Error: iopver can't determine the IOP version from $file" >&2;
	exit -1;
fi

echo "$ver"

