#! /usr/bin/perl
#
# Hook for automatic backports.
#
# Target dist: Ubuntu Karmic

use warnings;
use strict;
use Carp;

open(F, "debian/control") or croak;
my $first = 1;
my $file;
my $field = '';
while(<F>) {
  chomp();
  if (/^(\S+):/) {
    $field = $1;
  }
  if ($first) {
    $file .= $_;
    $first = 0;
  } elsif (/^$/) {
    $file .= "\n";
  } elsif ($field eq 'Description' || /^[^ ]/ || /^$/) {
    $file .= "\n" . $_;
  } else {
    $file .= $_;
  }
}
close(F);

$file .= "\n";

$file =~ s/(\nBuild-Depends: )/\1quilt, /g;
$file =~ s/(\nBuild-Depends: [^\n]+)exim4/\1postfix/g;
$file =~ s/(\nBuild-Depends: [^\n]+)libcelt-dev[^\)]+\)/\1/g;
$file =~ s/(\nDepends: [^\n]+)exim4/\1postfix/g;
$file =~ s/(\nDepends: [^\n]+)libcelt0 [^,]+,/\1/g;

open(F, ">debian/control") or croak;
print F $file;
close(F);

$file = '';
open(F, "debian/mumble.install") or croak;
while (<F>) {
  $file .= $_;
}
close(F);

$file =~ s/(\n#)/\n/g;

open(F, ">debian/mumble.install") or croak;
print F $file;
close(F);

$file = '';
open(F, "debian/rules") or croak;
while (<F>) {
  $file .= $_;
}
close(F);

$file =~ s/#QUILT //g;

open(F, ">debian/rules") or croak;
print F $file;
close(F);

open(F, ">debian/source/format") or croak;
print F "1.0\n";
close(F);
