#!/usr/bin/perl
################################################################################
##
##    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
################################################################################

use Getopt::Std;

getopt('d');

$lvm_src = $opt_d;

# help message
if(defined($opt_h) || !defined($opt_d)) {
  $msg = "usage: $0 [OPTIONS]\n";
  $msg = $msg . "\t-d\tLVM src directory\n";
  $msg = $msg . "\t-h\tDisplay this help message\n";
  die $msg;
}

    if ($lvm_src) {
      $file = $lvm_src . '/kernel/lvm.h';
    }

    open(DATAFILE, "< $file") || die "lvmver: can't open $file\n";
    while ($line = <DATAFILE>)
    {
	if ($line =~ /LVM_RELEASE_NAME\s+\"([\w\d. -]+)/)
  	{
	    	$version = $1;
  	}
    }

    close(DATAFILE);

    die "lvmver can't determine the LVM version\n" unless (defined($version));

print "$version\n";

