#!/usr/bin/perl

my $basedir = '/misc/suse/custom/10.2';

# generate packages files
chdir "$basedir/RPMS";
system "$basedir/scripts/create_package_descr -x $basedir/RPMS/setup/descr/EXTRA_PROV";

# set up content file
open (BASE, "$basedir/content.base") 
	or die "Can't read $basedir/content.base: $!\n";
open (CONTENT, ">$basedir/content")
	or die "Can't write $basedir/content: $!\n";
while (<BASE>) {
	print CONTENT
}
close (BASE);

# Generate checksums
my $dir = "$basedir/RPMS/setup/descr";
opendir (DIR, $dir) or die "Unable to opendir $dir: $!\n";
my @files = readdir (DIR);
close (DIR);
chdir ("$dir");
foreach my $file (@files) {
	next unless -f $file;
	my $sha = `sha1sum $file`;
	print CONTENT "META SHA1 $sha";
}
# and now the checksum for the key
chdir "$basedir";
my $sha = `sha1sum content.key`;
print CONTENT "KEY SHA1 $sha";
close (CONTENT);

# Generate detached signature
system "/usr/bin/gpg --yes -sab $basedir/content";
system "/usr/bin/gpg -a --export Cambridge > $basedir/content.key";
