#!/bin/sh
eval 'if [ -x /usr/local/cpanel/3rdparty/bin/perl ]; then exec /usr/local/cpanel/3rdparty/bin/perl -x -- $0 ${1+"$@"}; else exec /usr/bin/perl -x $0 ${1+"$@"}; fi;'
if 0;
#!/usr/bin/perl
BEGIN {
#use File::Basename;
use Cwd qw(abs_path realpath);
use File::Basename qw(&basename &dirname);
my $scriptDir = dirname(abs_path($0));
my $rvframeworkpath = dirname(dirname(abs_path($scriptDir)));
use lib dirname(dirname(dirname(abs_path(__FILE__)))).'/tests/xunit';
use lib dirname(dirname(dirname(abs_path(__FILE__)))).'/lib/perl5/x86_64-linux';
use lib dirname(dirname(dirname(abs_path(__FILE__)))).'/lib/perl5';
use lib dirname(dirname(dirname(abs_path(__FILE__)))).'/lib';
use lib dirname(dirname(dirname(abs_path(__FILE__))));
use lib dirname(dirname(abs_path(__FILE__))).'/tests/xunit';
use lib dirname(dirname(abs_path(__FILE__))).'/lib/perl5/x86_64-linux';
use lib dirname(dirname(abs_path(__FILE__))).'/lib/perl5';
use lib dirname(dirname(abs_path(__FILE__))).'/lib';
use lib dirname(dirname(abs_path(__FILE__)));
}
use strict;
use warnings;
use Cwd;
use Cwd 'realpath';
use File::Basename qw(&basename &dirname);
use Getopt::Long;
#Debug
#use Data::Dumper;
my $debug = 0;
#print Dumper(\@INC);
#my ($etcPath) = realpath(dirname(__FILE__));
#my ($frameworkPath) = realpath(dirname(dirname(__FILE__)));
my ($etcPath) = dirname(realpath(__FILE__));
my ($frameworkPath) = dirname(dirname(dirname(realpath(__FILE__))));
my (@moduleList) = glob("$frameworkPath/modules/*");
chdir($etcPath);
my (@cPanConfPath) = ($etcPath);
push(@cPanConfPath, @moduleList);
print $etcPath . " " . $frameworkPath . "\n";
foreach (@moduleList) {
print $_ . "\n";
}
#GET PARAM
my %allowModule = ( 'rvskinallcp' => 'rvskinallcp', 'exploitscanner' => 'exploitscanner',
'rvsubversion' => 'rvsubversion' , 'symantecvip' => 'symantecvip');
my $MODULE = "";
GetOptions( "module=s" => \$MODULE );
my ($cmd);
my (@reqsPkg) = (
'lib-0.63.tar.gz',
);
foreach my $file (@reqsPkg) {
$cmd = "perl cpanm -L $frameworkPath $etcPath/cpan/$file";
command($cmd);
}
my (@reqModule, @customPkg, $installLog, @aCpanList);
my $cpanList = '';
#Install from file
my $pathCpanSources = $etcPath . '/cpan';
if(opendir(my $dh, $pathCpanSources)){
my @fileAllCpan = grep { !/^\./ && -f "$pathCpanSources/$_" } readdir($dh);
closedir $dh;
foreach my $eachFile (@fileAllCpan) {
my ($moduleName, $moduleVersion) = split(/-\d+/, $eachFile, 2);
$moduleName =~s/-/\::/gi;
print "-------------------------------------------------------------\n";
print "Check Module $moduleName " ;
my $moduleexist = validateModuleExist($moduleName);
print $moduleexist == 1 ?" [ \e[1m\e[36mPass\e[0m ]\n":"[ \e[1m\e[31mInstall\e[0m ]\n";
next if($moduleexist);
$cmd = "perl cpanm -n -L $frameworkPath $etcPath/cpan/$eachFile";
push(@aCpanList, $cmd);
}
}
#Install from cpan.conf
foreach my $lookup (@cPanConfPath) {
if (-f "$lookup/cpan.conf") {
open(FD,'<', "$lookup/cpan.conf");
foreach my $line (<FD>) {
chomp($line);
if ($line =~/^(cpanm|mcpan)=/gi) {
my ($key, $value) = split(/=/, $line, 2);
chomp($key); chomp($value);
print "-------------------------------------------------------------\n";
print "Check Module $key : $value " ;
my $moduleexist = validateModuleExist($value);
print $moduleexist == 1 ?" [ \e[1m\e[36mPass\e[0m ]\n":"[ \e[1m\e[31mInstall\e[0m ]\n";
next if($moduleexist);
next if (defined $installLog->{$value});
if ($key eq 'cpanm') {
if (!-f "$etcPath/cpan/$value") {
#$cmd = "perl cpanm -f -L $frameworkPath " . $value;
$cpanList .= "$value ";
} else {
$cmd = "perl cpanm -n -f -L $frameworkPath $etcPath/cpan/$value";
push(@aCpanList, $cmd);
}
#command($cmd);
} elsif ($key eq 'mcpan') {
$cmd = "PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install $value'";
push(@aCpanList, $cmd);
#command($cmd);
}
$installLog->{$value} = 1;
}
}
close(FD);
print "-------------------------------------------------------------\n";
}
}
# Priority Run CPAN
foreach my $cmd (@aCpanList) {
command($cmd);
}
if ($cpanList ne "") {
command("perl cpanm -n -f -L $frameworkPath $cpanList");
}
sub command{
my ($cmd) = $_[0];
print "########################################################################\n";
print "# Command: $cmd\n";
print "########################################################################\n";
system $cmd;
# my $pid3 = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $cmd);
# my $selector = IO::Select->new();
# $selector->add(*CMD_ERR, *CMD_OUT);
# my (@ready, $fh, $line);
# while(@ready = $selector->can_read()) {
# foreach $fh (@ready) {
# if(fileno($fh) == fileno(CMD_ERR)) {
# $line = scalar <CMD_ERR>;
# print $line if $line;
# } else {
# $line = scalar <CMD_OUT>;
# print $line if $line;
# }
#
# $selector->remove($fh) if eof($fh);
# }
# }
# close(CMD_IN);
# close(CMD_ERR);
# close(CMD_OUT);
#
# waitpid($pid3, 0);
print "\n";
}
sub validate_module {
my $res = 1;
if ($MODULE eq '') {
$res = 0;
print "Not found module\n\n";
} elsif (!exists $allowModule{$MODULE}) {
$res = 0;
print "Module $MODULE is not allow\n\n";
}
if ($res == 0) {
print "Please run " . $etcPath . "/buildcpan.pl -module=??\n\n";
exit;
}
return $res;
}
sub validateModuleExist {
my $ModuleName = $_[0];
#Check Module Name
return 0 if(!defined $ModuleName || $ModuleName eq '' || $ModuleName =~/.tar.gz$/);
#Chack can call
#$eval("use $ModuleName");
eval "use $ModuleName;" ;
#if use module error goto install module
if ($@) {
if($debug){
print "Error:";
print $@;
print "\n";
}
return 0;
#print "Install cpan module $eachCpanModuldeName\n";
#system($scriptInstallcpan . ' ' . $eachCpanModuldeName);
}
return 1;
# #do check @INC path is from rvglobalsoft to test use module
# my $package = $ModuleName;
# $package =~s/::/\//g;
# $package =~s/$/.pm/;
# if (defined $INC{$package} && $INC{$package} =~/rvglobalsoft/ig ) {
# if ($debug) {
# print "\n".$ModuleName." installed at path ".$INC{$package}."\n";
# }
# return 1;
# }
# if ($debug) {
# print "\n".$ModuleName." NOT install "."\n";
# }
# return 0;
# work1
# #Chack can call
# #$eval("use $ModuleName");
# eval "use $ModuleName;" ;
# #if use module error goto install module
# if ($@) {
# if($debug){
# print "Error:";
# print $@;
# print "\n";
# }
# return 0;
# #print "Install cpan module $eachCpanModuldeName\n";
# #system($scriptInstallcpan . ' ' . $eachCpanModuldeName);
# }
# return 1;
}
1;
=pod
HOW RUN
perl dirname(realpath(__FILE__))/buildcpan.pl
=cut
=begin Install 'curl-config'
# yum install curl-devel
# yum install curl
=cut
Copyright 2K16 - 2K18 Indonesian Hacker Rulez