| 1 | package Tapper::Installer::Precondition::Package; | ||||||||||||||||||||||||||
| 2 | 7 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||
| 3 | 7 | $Tapper::Installer::Precondition::Package::VERSION = '5.0.3'; | |||||||||||||||||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 5 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 6 | 7 | ▶ | use 5.010; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Tapper::Installer::Precondition::Exec; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 9 | 7 | ▶ | use File::Basename; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 10 | 7 | ▶ | use Moose; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 11 | 7 | extends 'Tapper::Installer::Precondition'; | |||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||
| 15 | sub install | ||||||||||||||||||||||||||
| 16 | 5 | ▶ | { | ||||||||||||||||||||||||
|
Subroutine
install: called CC=16 SCAR=33.7
Pod
documented
| |||||||||||||||||||||||||||
| 17 | 5 | my ($self, $package) = @_; | |||||||||||||||||||||||||
| 18 | 5 | ▶ | if ($package->{url}) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 19 | 1 | my ($proto, $fullpath) = $package->{url} =~ m|^(\w+)://(.+)$|; | |||||||||||||||||||||||||
| 20 | 1 | ▶ | if ($proto eq 'nfs') { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 21 | 1 | my $nfs_dir='/mnt/nfs'; | |||||||||||||||||||||||||
| 22 | 1 | $self->makedir($nfs_dir); | |||||||||||||||||||||||||
| 23 | 1 | my $path = dirname $fullpath; | |||||||||||||||||||||||||
| 24 | 1 | my $filename = basename $fullpath; | |||||||||||||||||||||||||
| 25 | 1 | my ($error, $retval) = $self->log_and_exec("mount $path $nfs_dir"); | |||||||||||||||||||||||||
| 26 | 1 | ▶ | return ("Can't mount nfs share $path to $nfs_dir: $retval") if $error; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 27 | 1 | delete $package->{url}; | |||||||||||||||||||||||||
| 28 | 1 | $package->{filename} = "$nfs_dir/$filename"; | |||||||||||||||||||||||||
| 29 | 1 | $self->install($package); | |||||||||||||||||||||||||
| 30 | 1 | ($error, $retval) = $self->log_and_exec("umount $nfs_dir"); | |||||||||||||||||||||||||
| 31 | 1 | return 0; | |||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||
| 33 | 0 | else { return ("Procol'$proto' is not supported") } | |||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||
| 37 | 4 | my $filename = $package->{filename}; | |||||||||||||||||||||||||
| 38 | 4 | $self->log->debug("installing $filename"); | |||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||
| 40 | 4 | my $basedir = $self->cfg->{paths}{base_dir}; | |||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||
| 42 | # install into subdir | ||||||||||||||||||||||||||
| 43 | 4 | ▶ | if ($package->{target_directory}) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 44 | 0 | $basedir .= $package->{target_directory}; | |||||||||||||||||||||||||
| 45 | 0 | ▶ | $self->makedir($basedir) if not -d $basedir; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||
| 48 | 4 | my $package_dir = ''; | |||||||||||||||||||||||||
| 49 | 4 | $package_dir = $self->cfg->{paths}{package_dir}; | |||||||||||||||||||||||||
| 50 | 4 | my $pkg = $filename; | |||||||||||||||||||||||||
| 51 | 4 | ▶ | $pkg = "$package_dir/$filename" unless $filename =~ m(^/); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||
| 53 | 4 | my ($error, $type) = $self->get_file_type("$pkg"); | |||||||||||||||||||||||||
| 54 | 4 | ▶ | return("Can't get file type of $filename: $type") if $error; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||
| 57 | 4 | my $output; | |||||||||||||||||||||||||
| 58 | 4 | $self->log->debug("type is $type"); | |||||||||||||||||||||||||
| 59 | 4 | ▶ | if ($type eq "gzip") { | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 60 | 2 | ($error, $output) = $self->log_and_exec("tar --no-same-owner -C $basedir -xzf $pkg"); | |||||||||||||||||||||||||
| 61 | 2 | ▶ | return("can't unpack package $filename: $output\n") if $error; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||
| 63 | elsif ($type eq "tar") { | ||||||||||||||||||||||||||
| 64 | 0 | ($error, $output) = $self->log_and_exec("tar --no-same-owner -C $basedir -xf $pkg"); | |||||||||||||||||||||||||
| 65 | 0 | ▶ | return("can't unpack package $filename: $output\n") if $error; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||
| 67 | elsif ($type eq "bz2") { | ||||||||||||||||||||||||||
| 68 | 0 | ($error, $output) = $self->log_and_exec("tar --no-same-owner -C $basedir -xjf $pkg"); | |||||||||||||||||||||||||
| 69 | 0 | ▶ | return("can't unpack package $filename: $output\n") if $error; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||
| 71 | elsif ($type eq "deb") { | ||||||||||||||||||||||||||
| 72 | 2 | system("cp $pkg $basedir/"); | |||||||||||||||||||||||||
| 73 | 2 | $pkg = basename $pkg; | |||||||||||||||||||||||||
| 74 | 2 | my $exec = Tapper::Installer::Precondition::Exec->new($self->cfg); | |||||||||||||||||||||||||
| 75 | 2 | return $exec->install({command => "dpkg -i $pkg"}); | |||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||
| 77 | elsif ($type eq "rpm") { | ||||||||||||||||||||||||||
| 78 | 0 | system("cp $pkg $basedir/"); | |||||||||||||||||||||||||
| 79 | 0 | $pkg = basename $pkg; | |||||||||||||||||||||||||
| 80 | 0 | my $exec = Tapper::Installer::Precondition::Exec->new($self->cfg); | |||||||||||||||||||||||||
| 81 | # use -U to overwrite possibly existing older package | ||||||||||||||||||||||||||
| 82 | 0 | return $exec->install({command => "rpm -U $pkg"}); | |||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||
| 84 | else { | ||||||||||||||||||||||||||
| 85 | 0 | $self->log->warn(qq($pkg is of unrecognised file type "$type")); | |||||||||||||||||||||||||
| 86 | 0 | return(qq($pkg is of unrecognised file type "$type")); | |||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||
| 88 | 2 | return(0); | |||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||
| 91 | 7 | 1; | |||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||