#!/usr/bin/perl -w
use utf8;

use strict;
my $dn = `dirname $0`;chomp($dn);
my $pwd = `pwd`;chomp($pwd);
if ($dn !~ /^\//) { $dn = $pwd . "/" . $dn; }
push @INC,$dn;
my $cverepobase=`dirname $dn`;
chomp($cverepobase);

use POSIX qw/strftime setlocale LC_TIME/;
use List::MoreUtils qw/uniq/;
use DateTime;
use JSON;
use Data::Dumper;

my $jsoncoder = JSON->new->allow_nonref;
$jsoncoder->canonical(1);

require SMASHData;
require CanDBReader;
require UpdateInfoReader;
UpdateInfoReader->import_product_updates();

my %allpatches;

# collect all patches we want to do by product (SLED/SLES, various SPs)

foreach my $product (keys %UpdateInfoReader::patches) {
	my %patches = %{$UpdateInfoReader::patches{$product}};

	next if ($product =~ /SUSE:SLE-/);
	next if ($product =~ /openSUSE 1/);
	next if ($product =~ /openSUSE Ever/);

	print STDERR "scanning patches for $product\n" if (-t STDERR);

	foreach my $patch (keys %patches) {
		next if ($patch =~ / GA /);
		if ($UpdateInfoReader::patchinqa{$patch}) {
			print STDERR "$patch is in QA\n" if (-t STDERR);
			next;
		}
		next unless ($UpdateInfoReader::patchtype{$patch} eq "security");
		$allpatches{$patch} = 1;
	}
}
my @notices = keys %CanDBReader::susenotice2patches;

foreach my $notice (sort @notices) {
	my @patches = sort keys %{$CanDBReader::susenotice2patches{$notice}};

	print "$notice: " . join(";",@patches) . "\n";

	foreach my $xpatch (@patches) {
		delete $allpatches{$xpatch};
	}
}

foreach my $patch (sort keys %allpatches) {
	print "$patch\n";
}
