MOON
Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4
System: Linux vps.panamaemb.org.sg 3.10.0-1160.80.1.vz7.191.4 #1 SMP Thu Dec 15 20:31:06 MSK 2022 x86_64
User: panama (500)
PHP: 5.2.17
Disabled: NONE
Upload Files
File: //proc/3/task/3/cwd/installd/perl588installer/install
#!/usr/bin/perl
# cpanel - install                                Copyright(c) 2011 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

use Cwd ();

$| = 1;

# Description of bootstrap modules.
#  pkgname - the name of the bootstrap package minus the version
#  version - version numner for the package
#  opt_size - true if the module should only be bootstrapped if optimizing for memory
#             false is the module should always be bootstrapped.
my @MODULE_DESC = (
    { 'pkgname' => 'IO-Tty',             'version' => '1.07',   'opt_size' => 0 },
    { 'pkgname' => 'Expect',             'version' => '1.21',   'opt_size' => 0 },
    { 'pkgname' => 'Scalar-List-Utils',  'version' => '1.19',   'opt_size' => 0 },
    { 'pkgname' => 'IO-Compress-Base',   'version' => '2.015',  'opt_size' => 1 },
    { 'pkgname' => 'IO-Compress-Zlib',   'version' => '2.015',  'opt_size' => 1 },
    { 'pkgname' => 'Compress-Raw-Zlib',  'version' => '2.015',  'opt_size' => 1 },
    { 'pkgname' => 'Compress-Zlib',      'version' => '2.015',  'opt_size' => 1 },
    { 'pkgname' => 'File-HomeDir',       'version' => '0.82',   'opt_size' => 1 },
    { 'pkgname' => 'DBI',                'version' => '1.607',  'opt_size' => 1 },
    { 'pkgname' => 'libwww-perl',        'version' => '5.823',  'opt_size' => 1 },
    { 'pkgname' => 'CPAN',               'version' => '1.9301', 'opt_size' => 0 },
    { 'pkgname' => 'CPAN-DistnameInfo',  'version' => '0.07',   'opt_size' => 0 },
    { 'pkgname' => 'DBD-SQLite',         'version' => '1.14',   'opt_size' => 1 },
    { 'pkgname' => 'CPAN-SQLite',        'version' => '0.196',  'opt_size' => 1 },
    { 'pkgname' => 'ExtUtils-MakeMaker', 'version' => '6.50',   'opt_size' => 0 },
);

my $ver      = '5.8.8';
my $startdir = Cwd::getcwd();

my $gcc_Version   = `gcc --version`;
my $patch_Version = `patch --version`;

if ( ( !$gcc_Version || !$patch_Version ) && -x '/scripts/ensurerpm' ) {
    system '/scripts/ensurerpm', 'gcc', 'patch', 'glibc-devel';
}

# Update /scripts
unless ( -x '/scripts/perlmods' && -x '/scripts/perlinstaller' ) {
    die("cPanel does not appear to be sufficiently installed in order for the perlinstaller to succeed. Exiting.");
}

# Download and extract perl
system '/scripts/fetchfile', 'perl-' . $ver . '.tar.gz';
if ( !-e 'perl-' . $ver . '.tar.gz' ) {
    die "Unable to retrieve Perl source";
}
system 'tar', 'xfzv', 'perl-' . $ver . '.tar.gz';
schdir( 'perl-' . $ver );

# http://secunia.com/advisories/27546/
print "Patching sources to resolve regex unicode buffer overflow\n";
system 'patch -p0 <../regcomp-5.8.8.diff';
system 'patch -p0 <../libpm-5.8.8.diff';
system 'patch -p1 <../perl588-SysV.patch';

my $is_debian = -e '/etc/debian_version' ? 1 : 0;

my $flags = '';
my $optimize_memory = grep( /-optimize-memory/i, @ARGV ) ? 1 : 0;

# Add configure options and remove the locally installed copy of version.pm
if ($optimize_memory) {

    # /scripts/vps_optimizer needs to change if this line gets changed
    $flags .= qq{ '-Doptimize=-Os' -Duseshrplib -Dusemymalloc='y' };
}

# Get a list of installed modules.
my @INSTALLEDMODS = split( /\n/, `/scripts/perlmods -l` );

# CPAN should always be marked as uninstalled so we are sure to install it.
@INSTALLEDMODS = grep( !/^CPAN=/, @INSTALLEDMODS );

$ENV{'PERL_BUILD_EXPAND_CONFIG_VARS'} = 1;

mark_progress("Building and installing Perl v$ver");

# Run configure. Make sure it defaults correctly by removing files which mark perl as partially configured.
system( 'rm', 'Policy.sh' ) if -e 'Policy.sh';
system( 'rm', 'config.sh' ) if -e 'config.sh';
if ( is_64bit_os() ) {
    my $libpth = q{-Dlibpth='/usr/local/lib64 /lib64 /usr/lib64'};
    if ($is_debian) {
        system "( ./configure.gnu --prefix=/usr/local $flags \"-Dotherlibdirs=/usr/share/perl5 $libpth -Accflags='-fPIC -DPIC -m64' -Aldflags='-L/usr/lib64 -L/lib64 -lresolv -lnsl -ldl -lm -lcrypt -lutil -lc'\" && perl -i~ -nle 'print unless /<(command-line)>/' makefile x2p/makefile && make && make install )";
    }
    else {
        system "( ./Configure -des -Dprefix=/usr/local  $flags -Accflags='-fPIC -DPIC -m64' $libpth -Aldflags='-L/usr/lib64 -L/lib64 -lresolv -lnsl -ldl -lm -lcrypt -lutil -lc' && perl -i~ -nle 'print unless /<(command-line)>/' makefile x2p/makefile && make && make install )";
    }
}
else {
    if ($is_debian) {
        system "( ./configure.gnu --prefix=/usr/local $flags  \"-Dotherlibdirs=/usr/share/perl5\" && perl -i~ -nle 'print unless /<(command-line)>/' makefile x2p/makefile && make && make install )";
    }
    else {
        system "( ./configure.gnu --prefix=/usr/local $flags && perl -i~ -nle 'print unless /<(command-line)>/' makefile x2p/makefile && make && make install )";
    }
}

mark_progress("Validating install");

# Check installed Perl
if ( -x '/usr/local/bin/perl' ) {
    my $perl_version_text = `/usr/local/bin/perl -V:version`;
    if ( $perl_version_text =~ m/(\d\.\d\.\d)/m ) {
        if ( $1 ne $ver ) {
            die "Failed to update /usr/local/bin/perl to version $ver. Found version $1\n";
        }
        else {
            print "Perl updated to version $ver. Beginning module reinstallation.\n";
        }
    }
    else {
        die "Failed to determine version of /usr/local/bin/perl\n";
    }
}
else {
    die "Failed to install Perl!\n";
}

mark_progress("Symlinking /usr/bin/perl");

# Update /usr/bin/perl to newly installed version
if ( -e '/usr/bin/perl' ) {
    if ( -l '/usr/bin/perl' ) {
        unlink '/usr/bin/perl';
    }
    else {
        rename '/usr/bin/perl', '/usr/bin/perl.' . time;
    }
}
symlink '../local/bin/perl', '/usr/bin/perl';

# Mark bootstrap modules. opt_size effectivley matches the truthfullness of the command line flag -optimize-memory
my @BOOTSTRAP_MODULES =
  grep { $optimize_memory || 0 == $_->{'opt_size'} } @MODULE_DESC;

mark_progress("Bootstrapping trouble modules.") if (@BOOTSTRAP_MODULES);
foreach my $bootdesc (@BOOTSTRAP_MODULES) {
    next if is_installed_ok($bootdesc);
    my $bootmod = "$bootdesc->{'pkgname'}-$bootdesc->{'version'}";
    schdir($startdir);
    system 'tar', 'xfvz', $bootmod . '.tar.gz';
    schdir($bootmod);
    system '/usr/local/bin/perl', 'Makefile.PL' and do {
        print "Failure installing $bootmod!\n";
        next;
    };
    system 'gmake';
    system 'gmake', 'install';
    schdir($startdir);
}

if ( !grep( /nomodules/, @ARGV ) ) {
    mark_progress("Installing a basic set of modules from CPAN.");
    schdir($startdir);
    schdir('installscripts');
    system './install';
}

schdir($startdir);

if ( @INSTALLEDMODS && -x '/scripts/perlinstaller' ) {

    my @MODS;
    foreach my $mod (@INSTALLEDMODS) {
        my ( $modname, $ver ) = split( /=/, $mod );
        next if ( $modname eq 'Perl' );
        push @MODS, $modname;
        print "*** Will restore site module '$modname'\n";
    }
    if (@MODS) {
        mark_progress("Building perl modules also found with the distro");
        system '/scripts/perlinstaller', '--force', @MODS;    #we might have changed the malloc
        system '/scripts/perlinstaller', @MODS;               #twice
        system '/scripts/perlinstaller', @MODS;               #then again
        print "Done\n";
    }
    else {
        mark_progress("NOTE: No site installed modules were found with your distro's perl.");
    }
}

#Twice just in case
if ( -x '/scripts/checkperlmodules' ) {
    mark_progress("Running checkperlmodules");
    for ( 0 .. 1 ) {
        system '/scripts/checkperlmodules', '--bootstrap';
        system '/scripts/checkperlmodules', '--full';
        system('/usr/local/cpanel/install/perlmods') if ( -x '/usr/local/cpanel/install/perlmods' );
    }
}

if ( -x '/usr/local/cpanel/bin/rrdtoolcheck' ) {
    mark_progress("Setting up rrdtool");
    system '/usr/local/cpanel/bin/rrdtoolcheck';
}

if ( -x '/scripts/magicloader' ) {
    mark_progress("Setting up magicloader");
    system '/scripts/magicloader';
}

sub schdir {
    my $dir = shift;
    my $cwd = Cwd::getcwd();
    chdir($dir) || die "Cannot chdir to $dir, cwd was: $cwd";
}

sub is_installed_ok {
    my $bootdesc = shift;

    my $test_mod = $bootdesc->{'pkgname'};
    $test_mod =~ s/-/::/g;

    if ( $test_mod =~ /libwww/ )              { $test_mod = 'LWP'; }
    if ( $test_mod =~ /Scalar::List::Utils/ ) { $test_mod = 'Scalar::Util'; }
    if ( $test_mod =~ /IO::Compress::Zlib/ )  { $test_mod = 'IO::Compress::Gzip'; }
    my $check = `/scripts/cpcpan_check_installed $test_mod`;

    if ( $check =~ /version=([\d\.]+)/ ) {
        my $version = $1;
        if ( !$version || $version < $bootdesc->{'version'} ) {
            return 0;
        }
    }
    if ( $check =~ /^$test_mod is installed/ ) {
        return 1;
    }
    return 0;
}

#
# The core of this code was copied from Cpanel::OSSys::Bits. The module may
# not be available at the point in time that this script is run. The code is
# also simple enough that copying it is not likely to be in error.
sub is_64bit_os {

    # 64 bits is 8 bytes
    return 8 == length( pack( 'l!', 1000 ) );
}

sub mark_progress {
    my $progress = shift or return;
    print '*' x 60 . "\n";
    chomp $progress;
    print "$progress\n";

}