Apache-Voodoo
view release on metacpan or search on metacpan
lib/Apache/Voodoo/Install/Distribution.pm view on Meta::CPAN
my $unpack_dir = "/tmp/av_unpack_$$";
if (-e $unpack_dir) {
die "ERROR: $unpack_dir already exists\n";
}
mkdir($unpack_dir,0700) || die "Can't create directory $unpack_dir: $!";
chdir($unpack_dir) || die "Can't change to direcotyr $unpack_dir: $!";
$self->info("- Unpacking distribution to $unpack_dir");
if ($file =~ /\.gz$/) {
system("tar","xzf",$file) && die "Can't unpack $file: $!";
}
else {
system("tar","xjf",$file) && die "Can't unpack $file: $!";
}
$self->{'unpack_dir'} = $unpack_dir;
}
################################################################################
# Checks for an existing installation of the app. If it exists, it saves
# it's site specific config data, and returns it's version number.
################################################################################
sub check_existing {
my $self = shift;
my $conf_file = $self->{'conf_file'};
if (-e $conf_file) {
$self->{'is_existing'} = 1;
$self->info("Found one. We will be performing an upgrade");
my $old_config = Config::General->new($conf_file);
my %old_cdata = $old_config->getall();
# save old (maybe customized?) config variables
foreach ('session_dir','devel_mode','debug','devel_mode','cookie_name','database') {
$self->{'old_conf_data'}->{$_} = $old_cdata{$_};
}
my $dbhost = $old_cdata{'database'}->{'connect'};
my $dbname = $old_cdata{'database'}->{'connect'};
$dbhost =~ s/.*\bhost=//;
$dbhost =~ s/[^\w\.-]+.*$//;
$dbname =~ s/.*\bdatabase=//;
$dbname =~ s/[^\w\.-]+.*$//;
$self->{'dbhost'} ||= $dbhost;
$self->{'dbname'} ||= $dbname;
$self->{'dbuser'} ||= $old_cdata{'database'}->{'username'};
$self->{'dbpass'} ||= $old_cdata{'database'}->{'password'};
}
else {
$self->info("not found. This will be a fresh install.");
}
}
sub update_conf_file {
my $self = shift;
my $new_conf = File::Spec->catfile($self->{'unpack_dir'},$self->{'ac'}->conf_file());
my $config = Config::General->new($new_conf);
my %cdata = $config->getall();
foreach (keys %{$self->{'old_conf_data'}}) {
$self->debug("Merging config data: $_");
$cdata{$_} = $self->{'old_conf_data'}->{$_};
}
$self->debug("Merging database config");
$cdata{'database'}->{'username'} = $self->{'dbuser'} if $self->{'dbuser'};
$cdata{'database'}->{'password'} = $self->{'dbpass'} if $self->{'dbpass'};
$cdata{'database'}->{'connect'} =~ s/\bdatabase=[^;"]+/database=$self->{'dbname'}/ if $self->{'dbname'};
$cdata{'database'}->{'connect'} =~ s/\bhost=[^;"]+/host=$self->{'dbhost'}/ if $self->{'dbhost'};
$self->{'pretend'} || $config->save_file($new_conf,\%cdata);
}
sub install_files {
my $self = shift;
my $unpack_dir = $self->{'unpack_dir'};
my $install_path = $self->{'install_path'};
if ($self->{'verbose'} >= 0) {
$self->mesg("\n* Preparing to install. Press ctrl-c to abort *\n");
$self->mesg("* Installing in ");
foreach (5,4,3,2,1) {
$self->mesg("$_");
$self->{'pretend'} || sleep(1);
}
$self->mesg("\n");
$self->mesg("- Installing files:");
}
$self->{'pretend'} || ExtUtils::Install::install({$unpack_dir => $install_path});
}
1;
################################################################################
# Copyright (c) 2005-2010 Steven Edwards (maverick@smurfbane.org).
# All rights reserved.
#
# You may use and distribute Apache::Voodoo under the terms described in the
# LICENSE file include in this package. The summary is it's a legalese version
# of the Artistic License :)
#
################################################################################
( run in 0.837 second using v1.01-cache-2.11-cpan-437f7b0c052 )