#! /usr/bin/perl

use strict;
use warnings;

use Debian::Debhelper::Dh_Lib;
use File::Copy qw/cp/;
use File::Copy::Recursive qw/dircopy/;
use File::Temp qw/tempdir/;
use YAML::XS;

our $VERSION = '0.6';
init();

for my $package (@{ $dh{DOPACKAGES} }) {
  my $t=tmpdir($package);
  my @apps = ();
  my @yamls = sort glob ("$t/usr/share/kaboxer/*.kaboxer.yaml");
  foreach my $y (@yamls) {
      addsubstvar($package, 'misc:Depends', 'kaboxer (>= 0.4~)');
      open Y, $y or die "Unable to open $y";
      my $yaml = '';
      while (<Y>) {
	  $yaml .= $_;
      }
      my $h = YAML::XS::Load($yaml) or die "Unable to parse YAML from $y";
      push @apps, $h->{application}{id};
      if ($h->{container}{type} eq 'docker') {
	  addsubstvar($package, 'misc:Depends', 'docker.io | docker-ce');
      }
  }
  my $apps = join " ", @apps;
  autoscript($package, 'postinst', 'postinst-kaboxer', "s/#APPS#/$apps/g");
  autoscript($package, 'prerm', 'prerm-kaboxer', "s/#APPS#/$apps/g");
}

__END__

=head1 NAME

dh_kaboxer - handle kaboxer

=head1 SYNOPSIS

B<dh_kaboxer> [S<I<debhelper options>>]

=head1 DESCRIPTION

dh_kaboxer is a debhelper program that eases generation and deployment of Kaboxer images

A debhelper addon is also provided.  This makes it possible to just use

  #!/usr/bin/make -f
  %:
          dh $@ --with kaboxer --buildsystem kaboxer

for F<debian/rules>.

=head1 SEE ALSO

L<debhelper(7)>

=head1 COPYRIGHT AND LICENSE

Based on I<dh_perl_openssl> in the I<perl-openssl-defaults> package by Niko Tyni.

Copyright 2010, Ansgar Burchardt <ansgar@debian.org>

Copyright 2016, Niko Tyni <ntyni@debian.org>

Copyright 2019, Roland Mas <lolando@debian.org>

Copyright 2019, Offensive Security

This program is free software, you can redistribute it and/or modify it under
the same terms as Perl itself.
