#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Std;
use File::Temp;
use Archive::Extract;
use Carp;

require "gnu_chkproj.pm";

my %opts = ();
my $verbose = 0;
my $debug = 0;
my $tempdir = "";
my $status = 0;

sub usage();
sub extract_tarball($);
sub cleanup();

getopt('',\%opts);

$verbose = 1 if exists($opts{"v"});
$debug = 1 if exists($opts{"d"});

if ($#ARGV != 0){
   usage();
}

my $tarball = $ARGV[0];

$status = extract_tarball($tarball);
croak("extracting tarball failed\n") if (-z $status);



sub extract_tarball($){
   my $tarball = shift;
   my $ae;

   $tempdir = File::Temp->tempdir("XXXXXX", CLEANUP => 1);
   return "" if (! -d $tempdir);
   $ae = Archive::Extract->new(archive => $tarball) || return "";
   ($ae->extract( to => $tempdir )) || return "";
   return $tempdir;
}

sub usage(){
   print("usage: $0 [-v|-d] <tarball>\n");
   print("\t-d: debug\n");
   print("\t-v: verbose\n");
   exit(1);
}

