#!/usr/bin/perl

# some packages list the orig.tar.gz in the source package,
# but not in the changes file; reprepro will complain later if
# it cant find the file in the pool; we include the .dsc to
# make sure that the orig.tar.gz is there

use strict;
use warnings;

my $incoming = "/home/apt/incoming";
my $repo = "/home/apt/repo";
my $cc = "/usr/bin/changestool";
my $cs = "gpg --clearsign";

my @changes = qw(
cyrus-imapd-2.2_2.2.13-6.ius.stable_i386.changes
drbdlinks_1.09-1~ius.3_i386.changes
exigrey_0.1-3_i386.changes
interchange_5.5.1-1.ius.etch.1_i386.changes
libnet-pcap-perl_0.12-hs.1_i386.changes
libnss-ldap_238-1.schlittermann.1_i386.changes
);

for (@changes) {

  my $c = "$incoming/$_";
  my $cmd;

  print "Attempting to add missing upstream sources for [$c] .. ";
  $cmd = "$cc $c includeallsources";
  system($cmd) == 0 or warn "[system($cmd)] failed: [$?] [$!]\n";
  print "done\n";

  print "Attempting to sign updated changes file [$c] .. ";
  $cmd = "$cs $c";
  system($cmd) == 0 or warn "[system($cmd)] failed: [$?] [$!]\n";
  rename("$c.asc", $c) or warn "rename([$c.asc], [$c]) failed: [$!]\n";
  print "done\n";

}
