###
### Copyright 2000-2007 University of Illinois Board of Trustees
### All rights reserved.
###
### PSGConf::Action::UntarFile - canned untar action type for psgconf
###
### Campus Information Technologies and Educational Services
### University of Illinois at Urbana-Champaign
###
package PSGConf::Action::UntarFile;
use strict;
use PSGConf::Action;
use PSGConf::Util;
our @ISA = qw(PSGConf::Action);
###############################################################################
### internal routine so I do not have to duplicate code...
###############################################################################
sub _generate_cmd
{
my ($self, $psgconf) = @_;
my ($cmdstr);
$cmdstr = $self->{tar_cmd} . ' -C ' . $self->{name};
if ( $psgconf->{verbose} ) {
$cmdstr .= ' -xvpf - ';
} else {
$cmdstr .= ' -xpf - ';
}
if (exists $self->{user} && $self->{user} ne 'root')
{
$cmdstr = 'su ' . $self->{user} . ' -c ' . qq("$cmdstr");
}
if (exists $self->{uncompress_cmd})
{
$cmdstr = $self->{uncompress_cmd} . ' < '
. $self->{tarball} . ' | '
. $cmdstr;
} else {
$cmdstr = '/bin/cat '
. $self->{tarball} . ' | '
. $cmdstr;
}
return $cmdstr;
}
###############################################################################
### check method
###############################################################################
sub check
{
my ($self, $psgconf) = @_;
$self->{changed} = 1;
return 1;
}
###############################################################################
### do method
###############################################################################
sub do
{
my ($self, $psgconf) = @_;
my ($cmdstr) = $self->_generate_cmd($psgconf);
if (&PSGConf::Util::RunCommand($cmdstr, 1))
{
warn "\n\t!!! can't untar file (" . $self->{tarball} . ") in " . $self->{name} . "\n";
return 0;
}
unlink "$self->{tarball}"
if (exists $self->{delete} && $self->{delete}
&& exists $psgconf->{rm_tmpfiles} && $psgconf->{rm_tmpfiles});
}
###############################################################################
### diff method
###############################################################################
sub diff
{
my ($self, $psgconf) = @_;
my ($cmdstr) = $self->_generate_cmd($psgconf);
print "###############################################################################\n";
print "### DIFF FOR $self->{name}\n";
print "###############################################################################\n";
print "+ $cmdstr\n";
print "+ unlink \"$self->{tarball}\"\n" if ($self->{delete});
print "\n";
}
###############################################################################
### documentation
###############################################################################
1;
__END__
=head1 NAME
PSGConf::Action::UntarFile - file untar action class for PSGConf
=head1 SYNOPSIS
use PSGConf::Action::UntarFile;
$psgconf->register_actions(
PSGConf::Action::UntarFile->new(
'name' => '/path/to/directory',
'user' => login to run the tar command as,
'tar_cmd' => '/path/to/tar',
'tarball' => '/path/to/tarball',
'uncompress_cmd' => '/path/to/uncompress',
'delete' => [0,1] 1 if the tarball should be
deleted after the operation
),
...
);
=head1 DESCRIPTION
The B<PSGConf::Action::UntarFile> module provides a B<PSGConf> action class
for untarring a tape archive file
The B<PSGConf::Action::UntarFile> class is derived from the
B<PSGConf::Action> class, but it defines/overrides the
following methods:
=over 4
=item check()
Verifies that the tarball exists and is a valid tape archive.
=item diff()
Prints a diff message for the directory that is to be updated
=item do()
Untars the file into the specified directory, then deletes the
tar file if necessary.
=back
In addition to the attributes supported by the B<PSGConf::Action>
class, the B<PSGConf::Action::UntarFile> class supports the following
attributes:
=over 4
=item I<name>
The name of the directory where the tar file is to be extracted.
=item I<tarball>
The tar file to be extracted.
=item I<compressed>
1 if the tar file is compressed (gziped), 0 if it is uncompressed.
=item I<delete>
1 if the tar file is to be deleted after the extraction.
=back
=head1 SEE ALSO
L<perl>
L<PSGConf>
L<PSGConf::Action::File>
=cut
syntax highlighted by Code2HTML, v. 0.9.1