File: //proc/self/root/scripts.20110531.215904.25158/installsqlite3
#!/usr/bin/perl
# cpanel - installsqlite3 Copyright(c) 2010 cPanel, Inc.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cpanel license. Unauthorized copying is prohibited
use strict;
use warnings;
BEGIN { unshift @INC, '/usr/local/cpanel'; }
use Cpanel::Tar ();
use Cpanel::Logger ();
use Cpanel::OSSys ();
use Cpanel::SysPkgs ();
use Cpanel::Usage ();
use Cpanel::SafeRun::Errors ();
my ( $force, $source );
Cpanel::Usage::wrap_options( \@ARGV, \&usage, { 'force' => \$force, 'source' => \$source } );
my $system = Cpanel::OSSys::get_system();
my $prefix = $system eq 'freebsd' ? '/usr/local' : '/usr';
my $src_dir = '/usr/local/cpanel/src/3rdparty/other';
my $app = 'sqlite';
my %dir = ( 'sqlite' => '3.7.0.1' );
my %archive_types = (
'.tar.gz' => '-z',
'.tar.bz2' => '-j',
'.tgz' => '-z',
);
my $logger = Cpanel::Logger->new();
if ( !has_sqlite3() || $force ) {
unless ($source) {
my $syspkgs = Cpanel::SysPkgs->new();
if ( !$syspkgs ) { die print "Could not create SysPkgs object\n"; }
# This list is overly inclusive to cover all possible naming schemes.
print "Attempting to install OS provided sqlite3\n";
$syspkgs->ensure( 'pkglist' => [ 'sqlite', 'sqlite-devel', 'sqlite-dev', 'sqlite3', 'sqlite3-devel', 'sqlite3-dev' ] );
if ( has_sqlite3() ) {
print "Sqlite3 was installed successfully using the OS package manager\n";
exit 0;
}
print "Failed to install sqlite3 using operating system package manager.\n";
}
print "Installing $app version $dir{$app} from source\n";
my $check_output = Cpanel::SafeRun::Errors::saferunallerrors('/scripts/checkccompiler');
if ( $? != 0 ) {
print "The C compiler does not appear to be functional on this system\n";
print "Output from compiler test:\n\n";
print $check_output . "\n";
print "Sqlite3 could not be installed\n";
exit 1;
}
my $tarcfg = Cpanel::Tar::load_tarcfg();
my $basedir = '/home/cp' . $app . 'build';
system 'rm', '-rf', $basedir;
system 'mkdir', $basedir;
chdir $basedir or $logger->die("Unable to chdir $basedir: $!");
my $app_source_base = $app . '-' . $dir{$app};
my $app_source;
my $decompression_flag;
foreach my $archive_extension ( keys %archive_types ) {
if ( -e $src_dir . '/' . $app_source_base . $archive_extension ) {
$app_source = $app_source_base . $archive_extension;
$decompression_flag = $archive_types{$archive_extension};
last;
}
}
if ( !$app_source ) {
$logger->warn("Unable to locate source for $app");
}
system $tarcfg->{'bin'}, '-x', '-p', $tarcfg->{'no_same_owner'}, $decompression_flag, '-C', $basedir, '-f', $src_dir . '/' . $app_source;
if ( !-d $basedir . '/' . $app_source_base ) {
$logger->warn("Failed to decompress source for $app");
}
print "Using Dir: $basedir/$app_source_base\n";
if ( !chdir( $basedir . '/' . $app_source_base ) ) {
$logger->warn("Unable to chdir to $basedir/$app_source_base failed.");
}
system './configure', "--prefix=$prefix";
system 'make';
system 'make install';
print "Removing source directory $basedir\n";
system 'rm', '-rf', $basedir;
if ( has_sqlite3() ) {
print "Sqlite3 was installed successfully from source\n";
exit 0;
}
else {
print "The install of sqlite3 from source appears to have failed\n";
exit 1;
}
}
sub has_sqlite3 {
foreach my $path ( '/usr/', '/usr/local/' ) {
return 1 if ( -e "${path}bin/sqlite3" && -e "${path}include/sqlite3.h" );
}
return 0;
}
sub usage {
print <<EO_USAGE;
installsqlite3 [options]
Options:
--help Brief help message
--force Force installation even if sqlite3 already appears installed
--source Do not attempt to install pacakges provided by the OS vendor
EO_USAGE
exit 0;
}