| 1 | 2 | ▶ | use v5.14.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package OS::Package::Plugin::Solaris::SVR4; | ||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: Solaris 10 package plugin. | ||||||||||
| 7 | 2 | our $VERSION = '0.2.6'; # VERSION | |||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | use Cwd; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use Env qw( $HOME ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use Time::Piece; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ▶ | use Types::Standard qw( Str ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 2 | ▶ | use Template; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 2 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 2 | ▶ | use File::ShareDir qw(dist_file); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 2 | ▶ | use File::Basename qw( basename dirname ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 2 | ▶ | use OS::Package::Config qw($OSPKG_CONFIG); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 2 | ▶ | use OS::Package::Log; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 2 | ▶ | use IPC::Cmd qw( can_run run ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 2 | extends 'OS::Package'; | |||||||||
| 23 | |||||||||||
| 24 | has user => ( | ||||||||||
| 25 | is => 'rw', | ||||||||||
| 26 | isa => Str, | ||||||||||
| 27 | required => 1, | ||||||||||
| 28 | 0 | ▶ | default => sub { $OSPKG_CONFIG->{package}{user} } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 29 | 2 | ); | |||||||||
| 30 | |||||||||||
| 31 | has group => ( | ||||||||||
| 32 | is => 'rw', | ||||||||||
| 33 | isa => Str, | ||||||||||
| 34 | required => 1, | ||||||||||
| 35 | 0 | ▶ | default => sub { $OSPKG_CONFIG->{package}{group} } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 36 | 2 | ); | |||||||||
| 37 | |||||||||||
| 38 | has category => ( | ||||||||||
| 39 | is => 'rw', | ||||||||||
| 40 | isa => Str, | ||||||||||
| 41 | required => 1, | ||||||||||
| 42 | 0 | ▶ | default => sub { $OSPKG_CONFIG->{package}{category} } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 43 | 2 | ); | |||||||||
| 44 | |||||||||||
| 45 | has pstamp => ( | ||||||||||
| 46 | is => 'rw', | ||||||||||
| 47 | isa => Str, | ||||||||||
| 48 | 2 | ▶ | default => sub { my $t = localtime; return $t->datetime; } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 49 | 2 | ); | |||||||||
| 50 | |||||||||||
| 51 | has pkgfile => ( | ||||||||||
| 52 | is => 'rw', | ||||||||||
| 53 | isa => Str, | ||||||||||
| 54 | required => 1, | ||||||||||
| 55 | default => sub { | ||||||||||
| 56 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 57 | 2 | my $system = OS::Package::System->new; | |||||||||
| 58 | |||||||||||
| 59 | 2 | ▶ | my $version = | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | $self->build_id | ||||||||||
| 61 | ? sprintf( '%s-b%s', $self->application->version, | ||||||||||
| 62 | $self->build_id ) | ||||||||||
| 63 | : $self->application->version; | ||||||||||
| 64 | |||||||||||
| 65 | 2 | return sprintf( '%s-%s-%s-%s.pkg', | |||||||||
| 66 | $self->name, $version, | ||||||||||
| 67 | $system->os, $system->type ); | ||||||||||
| 68 | } | ||||||||||
| 69 | 2 | ); | |||||||||
| 70 | |||||||||||
| 71 | sub _generate_pkginfo { | ||||||||||
| 72 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_generate_pkginfo: not called CC=3 SCAR=24.8
| |||||||||||
| 73 | |||||||||||
| 74 | 0 | $LOGGER->info('generating: pkginfo'); | |||||||||
| 75 | |||||||||||
| 76 | 0 | my $template = | |||||||||
| 77 | dist_file( 'OS-Package', 'plugin/Solaris/SVR4/pkginfo.tt2' ); | ||||||||||
| 78 | |||||||||||
| 79 | 0 | my $ttcfg = { INCLUDE_PATH => dirname($template) }; | |||||||||
| 80 | |||||||||||
| 81 | 0 | my $tt = Template->new($ttcfg); | |||||||||
| 82 | |||||||||||
| 83 | 0 | my $pkginfo = sprintf '%s/%s/pkginfo', path( $self->fakeroot ), | |||||||||
| 84 | $self->prefix; | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | my $version = | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | $self->build_id | ||||||||||
| 88 | ? sprintf '%s-b%s', $self->application->version, $self->build_id | ||||||||||
| 89 | : $self->application->version; | ||||||||||
| 90 | |||||||||||
| 91 | 0 | ▶ | $tt->process( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | basename($template), | ||||||||||
| 93 | { pkgname => $self->name, | ||||||||||
| 94 | name => $self->application->name, | ||||||||||
| 95 | description => $self->description, | ||||||||||
| 96 | arch => $self->system->type, | ||||||||||
| 97 | version => $version, | ||||||||||
| 98 | category => $self->category, | ||||||||||
| 99 | vendor => $self->maintainer->by_line, | ||||||||||
| 100 | pstamp => $self->pstamp, | ||||||||||
| 101 | basedir => $self->prefix, | ||||||||||
| 102 | }, | ||||||||||
| 103 | $pkginfo | ||||||||||
| 104 | ) or $LOGGER->logdie( $tt->error ); | ||||||||||
| 105 | |||||||||||
| 106 | 0 | return 1; | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | sub _generate_prototype { | ||||||||||
| 110 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_generate_prototype: not called CC=6 SCAR=37.4
| |||||||||||
| 111 | |||||||||||
| 112 | 0 | $LOGGER->info('generating: prototype'); | |||||||||
| 113 | |||||||||||
| 114 | 0 | my $pkg_path = sprintf '%s/%s', path( $self->fakeroot ), $self->prefix; | |||||||||
| 115 | |||||||||||
| 116 | 0 | chdir path($pkg_path); | |||||||||
| 117 | |||||||||||
| 118 | 0 | my $command = [ can_run('pkgproto'), '.' ]; | |||||||||
| 119 | |||||||||||
| 120 | 0 | my ( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = | |||||||||
| 121 | run( command => $command ); | ||||||||||
| 122 | |||||||||||
| 123 | 0 | foreach ( @{$full_buf} ) { | |||||||||
| 124 | 0 | $LOGGER->debug($_); | |||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | 0 | ▶ | if ( !$success ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 128 | 0 | $LOGGER->error( sprintf "pkgproto failed: %s\n", $error_message ); | |||||||||
| 129 | |||||||||||
| 130 | 0 | return 2; | |||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | 0 | my @prototype = ("i pkginfo\n"); | |||||||||
| 134 | |||||||||||
| 135 | 0 | my @lines = split "\n", join( q{}, @{$stdout_buf} ); | |||||||||
| 136 | |||||||||||
| 137 | 0 | foreach my $line (@lines) { | |||||||||
| 138 | 0 | my ( $file_type, $class, $pathname, $mode, $owner, $group ) = | |||||||||
| 139 | split q{ }, $line; | ||||||||||
| 140 | |||||||||||
| 141 | 0 | ▶ | next if ( $pathname =~ qr{pkginfo|prototype}xms ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 142 | |||||||||||
| 143 | 0 | ▶ | if ( defined $mode ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 144 | 0 | push @prototype, | |||||||||
| 145 | sprintf( "%s %s %s %s %s %s\n", | ||||||||||
| 146 | $file_type, $class, $pathname, $mode, $self->user, | ||||||||||
| 147 | $self->group ); | ||||||||||
| 148 | } | ||||||||||
| 149 | else { | ||||||||||
| 150 | 0 | push @prototype, | |||||||||
| 151 | sprintf( "%s %s %s\n", $file_type, $class, $pathname ); | ||||||||||
| 152 | } | ||||||||||
| 153 | } | ||||||||||
| 154 | |||||||||||
| 155 | 0 | path( sprintf( '%s/prototype', $pkg_path ) )->spew( \@prototype ); | |||||||||
| 156 | |||||||||||
| 157 | 0 | chdir $HOME; | |||||||||
| 158 | |||||||||||
| 159 | 0 | return 1; | |||||||||
| 160 | } | ||||||||||
| 161 | |||||||||||
| 162 | sub _generate_package { | ||||||||||
| 163 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_generate_package: not called CC=8 SCAR=42.8
| |||||||||||
| 164 | |||||||||||
| 165 | 0 | $LOGGER->info( sprintf 'generating package: %s', $self->name ); | |||||||||
| 166 | |||||||||||
| 167 | 0 | my $pkg_path = sprintf '%s/%s', path( $self->fakeroot ), $self->prefix; | |||||||||
| 168 | |||||||||||
| 169 | 0 | chdir path($pkg_path); | |||||||||
| 170 | |||||||||||
| 171 | 0 | ▶ | if (-d sprintf( '%s/%s', path( $OSPKG_CONFIG->dir->packages ), | ||||||||
|
Branch: 1 branch
| |||||||||||
| 172 | $self->name ) ) | ||||||||||
| 173 | { | ||||||||||
| 174 | 0 | $LOGGER->debug('removing existing package spool directory'); | |||||||||
| 175 | 0 | my $spool_dir = sprintf( '%s/%s', | |||||||||
| 176 | path( $OSPKG_CONFIG->dir->packages ), | ||||||||||
| 177 | $self->name ); | ||||||||||
| 178 | 0 | path($spool_dir)->remove_tree( { safe => 0 } ); | |||||||||
| 179 | } | ||||||||||
| 180 | |||||||||||
| 181 | 0 | ▶ | if (-f sprintf( '%s/%s', | ||||||||
|
Branch: 1 branch
| |||||||||||
| 182 | path( $OSPKG_CONFIG->dir->packages ), | ||||||||||
| 183 | $self->pkgfile ) | ||||||||||
| 184 | ) | ||||||||||
| 185 | { | ||||||||||
| 186 | 0 | $LOGGER->debug('removing existing package file from spool directory'); | |||||||||
| 187 | 0 | my $pkg_file = sprintf( '%s/%s', | |||||||||
| 188 | path( $OSPKG_CONFIG->dir->packages ), | ||||||||||
| 189 | $self->pkgfile ); | ||||||||||
| 190 | 0 | path($pkg_file)->remove; | |||||||||
| 191 | } | ||||||||||
| 192 | |||||||||||
| 193 | 0 | my $command = [ | |||||||||
| 194 | can_run('pkgmk'), '-o', '-r', cwd, '-d', | ||||||||||
| 195 | path( $OSPKG_CONFIG->dir->packages ) | ||||||||||
| 196 | ]; | ||||||||||
| 197 | |||||||||||
| 198 | 0 | my ( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = | |||||||||
| 199 | run( command => $command ); | ||||||||||
| 200 | |||||||||||
| 201 | 0 | foreach ( @{$full_buf} ) { | |||||||||
| 202 | 0 | $LOGGER->debug($_); | |||||||||
| 203 | } | ||||||||||
| 204 | |||||||||||
| 205 | 0 | ▶ | if ( !$success ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 206 | 0 | $LOGGER->error( sprintf "pkgproto failed: %s\n", $error_message ); | |||||||||
| 207 | |||||||||||
| 208 | 0 | return 2; | |||||||||
| 209 | } | ||||||||||
| 210 | |||||||||||
| 211 | $command = [ | ||||||||||
| 212 | 0 | can_run('pkgtrans'), '-s', | |||||||||
| 213 | path( $OSPKG_CONFIG->dir->packages ), $self->pkgfile, | ||||||||||
| 214 | $self->name | ||||||||||
| 215 | ]; | ||||||||||
| 216 | |||||||||||
| 217 | 0 | ( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = | |||||||||
| 218 | run( command => $command ); | ||||||||||
| 219 | |||||||||||
| 220 | 0 | foreach ( @{$full_buf} ) { | |||||||||
| 221 | 0 | $LOGGER->debug($_); | |||||||||
| 222 | } | ||||||||||
| 223 | |||||||||||
| 224 | 0 | ▶ | if ( !$success ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 225 | 0 | $LOGGER->error( sprintf "pkgtrans failed: %s\n", $error_message ); | |||||||||
| 226 | |||||||||||
| 227 | 0 | return 2; | |||||||||
| 228 | } | ||||||||||
| 229 | |||||||||||
| 230 | 0 | ▶ | if (-d sprintf( '%s/%s', path( $OSPKG_CONFIG->dir->packages ), | ||||||||
|
Branch: 1 branch
| |||||||||||
| 231 | $self->name ) ) | ||||||||||
| 232 | { | ||||||||||
| 233 | 0 | $LOGGER->debug('removing existing package spool directory'); | |||||||||
| 234 | 0 | my $spool_dir = sprintf( '%s/%s', | |||||||||
| 235 | path( $OSPKG_CONFIG->dir->packages ), | ||||||||||
| 236 | $self->name ); | ||||||||||
| 237 | 0 | path($spool_dir)->remove_tree( { safe => 0 } ); | |||||||||
| 238 | } | ||||||||||
| 239 | |||||||||||
| 240 | 0 | chdir $HOME; | |||||||||
| 241 | |||||||||||
| 242 | 0 | $LOGGER->info( | |||||||||
| 243 | sprintf 'created package: %s/%s', | ||||||||||
| 244 | path( $OSPKG_CONFIG->dir->packages ), | ||||||||||
| 245 | $self->pkgfile | ||||||||||
| 246 | ); | ||||||||||
| 247 | |||||||||||
| 248 | 0 | return 1; | |||||||||
| 249 | } | ||||||||||
| 250 | |||||||||||
| 251 | sub create { | ||||||||||
| 252 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
create: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 253 | |||||||||||
| 254 | 0 | $LOGGER->info('generating: Solaris SVR4 package'); | |||||||||
| 255 | |||||||||||
| 256 | 0 | $self->_generate_pkginfo; | |||||||||
| 257 | |||||||||||
| 258 | 0 | $self->_generate_prototype; | |||||||||
| 259 | |||||||||||
| 260 | 0 | $self->_generate_package; | |||||||||
| 261 | |||||||||||
| 262 | 0 | return 1; | |||||||||
| 263 | } | ||||||||||
| 264 | |||||||||||
| 265 | 2 | 1; | |||||||||
| 266 | |||||||||||
| 267 | __END__ | ||||||||||
| 268 | |||||||||||
| 269 | =pod | ||||||||||
| 270 | |||||||||||
| 271 | =encoding UTF-8 | ||||||||||
| 272 | |||||||||||
| 273 | =head1 NAME | ||||||||||
| 274 | |||||||||||
| 275 | OS::Package::Plugin::Solaris::SVR4 - Solaris 10 package plugin. | ||||||||||
| 276 | |||||||||||
| 277 | =head1 VERSION | ||||||||||
| 278 | |||||||||||
| 279 | version 0.2.6 | ||||||||||
| 280 | |||||||||||
| 281 | =head1 METHODS | ||||||||||
| 282 | |||||||||||
| 283 | =head2 create | ||||||||||
| 284 | |||||||||||
| 285 | Create Solaris SVR4 package. | ||||||||||
| 286 | |||||||||||
| 287 | =head2 pkgfile_suffix | ||||||||||
| 288 | |||||||||||
| 289 | Returns file extension for SVR4 package. | ||||||||||
| 290 | |||||||||||
| 291 | =head1 AUTHOR | ||||||||||
| 292 | |||||||||||
| 293 | James F Wilkus <jfwilkus@cpan.org> | ||||||||||
| 294 | |||||||||||
| 295 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 296 | |||||||||||
| 297 | This software is Copyright (c) 2014 by James F Wilkus. | ||||||||||
| 298 | |||||||||||
| 299 | This is free software, licensed under: | ||||||||||
| 300 | |||||||||||
| 301 | The (three-clause) BSD License | ||||||||||
| 302 | |||||||||||
| 303 | =cut | ||||||||||