File Coverage

blib/lib/Rex/Apache/Deploy/Package/deb.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4             # vim: set ts=3 sw=3 tw=0:
5             # vim: set expandtab:
6              
7             =head1 NAME
8              
9             Rex::Apache::Deploy::deb - Deploy deb package
10              
11             =head1 DESCRIPTION
12              
13             With this module you can deploy a Debian package.
14              
15             If the package is not build yet, it will pass all the arguments to the build() function and executes the build on the local machine.
16              
17             =head1 SYNOPSIS
18              
19             deploy "my-software.deb";
20            
21             deploy "my-software",
22             type => "deb",
23             version => "1.0",
24             # below this, it is all optional
25             source => "/path/to/your/software",
26             path => "/path/to/deploy/target",
27             description => "some description of your package",
28             url => "website of the package",
29             depends => [qw/httpd perl/],
30             release => 1,
31             epoch => 1,
32             vendor => "some vendor",
33             license => "your license for ex. GPL2",
34             section => "some/section",
35             conflicts => [qw/somepkg/],
36             provides => "some-package-name",
37             arch => "x86_64",
38             target => "linux / the platform",
39             post_install => "filename or script to run after installation",
40             pre_install => "filename or script to run before installation",
41             post_uninstall => "filename or script to run after uninstall",
42             pre_uninstall => "filename or script to run before uninstall",
43             exclude => [qw/file1 file2/],
44             maintainer => "your name",
45             config_files => [qw/special files for configuration mostly for etc directory/];
46              
47              
48             =cut
49              
50              
51              
52             package Rex::Apache::Deploy::Package::deb;
53              
54 1     1   2643 use strict;
  1         2  
  1         35  
55 1     1   5 use warnings;
  1         3  
  1         27  
56              
57 1     1   44 use Rex::Apache::Deploy::Package::Base;
  0            
  0            
58             use base qw(Rex::Apache::Deploy::Package::Base);
59              
60             use Rex::Commands;
61             use Rex::Commands::Fs;
62             use Rex::Commands::Run;
63             use Rex::Commands::Upload;
64             use Rex::Apache::Build;
65             use Data::Dumper;
66              
67             sub new {
68             my $that = shift;
69             my $proto = ref($that) || $that;
70             my $self = $proto->SUPER::new(@_);
71              
72             bless($self, $proto);
73              
74             if($self->{arch} eq "x86_64") {
75             $self->{arch} = "amd64";
76             }
77              
78             return $self;
79             }
80              
81             sub deploy {
82             my ($self, $package_name, %option) = @_;
83              
84             LOCAL {
85             if(! -f $package_name) {
86             $package_name = $self->name . "_" . $self->version . "_" . $self->arch . ".deb";
87              
88             if(! -f $package_name) {
89             build($self->name, %option);
90             }
91             }
92             };
93              
94             upload $package_name, "/tmp";
95              
96             run "dpkg -i /tmp/$package_name";
97             if($? != 0) {
98             # try to install deps
99             run "apt-get -y -f install";
100             if($? != 0) {
101             unlink "/tmp/$package_name";
102             die("Error installing $package_name");
103             }
104              
105             my $pkg = Rex::Pkg->get;
106             if(! $pkg->is_installed($self->name)) {
107             unlink "/tmp/$package_name";
108             die("Error installing $package_name");
109             }
110             }
111              
112             Rex::Logger::info("Package $package_name installed.");
113              
114             unlink "/tmp/$package_name";
115             }
116              
117             1;