#!/usr/bin/perl -w
# creates the release, assuming build application

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
++$mon;
$year = $year + 1900;
my $datestring = sprintf("$year-%02d-%02d", $mon, $mday);



sub createSourceTarball();

print "Did you remember to run dch -v and commit the changes? (y/n)?\n";
my $decide = <STDIN>;
if ( $decide =~ /n/ )
{
	die "aborting";
}

my $headmodule = "packagesearch";	# toplevel module

my $releaseDir = "../packagesearch-release";


mkdir("$releaseDir");

createSourceTarball();



sub createSourceTarball() {
	my $targetSourceDir = "$releaseDir/$headmodule-$datestring";
	my $doCheckout = 1;
	if (-e $targetSourceDir ) {
		print "There is already a directory $targetSourceDir available, would you like to overwrite this?\n";
		my $decide = <STDIN>;
		if ( $decide =~ /n/ ) {
			$doCheckout = 0;
		}
		else {
			system("rm -rf $targetSourceDir");
		}
	}
	if ($doCheckout) {
		print "Cloning git version\n";
		(system("git clone ./ $targetSourceDir")==0)
			|| die("Could not clone git version.\n");
	}
}
