File: //scripts.20110531.215904.25158/cPpkgversions.pm
package cPpkgversions;
# cpanel - cPpkgversions.pm 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 Cpanel::HttpRequest ();
use Cpanel::Config ();
my $cPhttpClient = Cpanel::HttpRequest->new( 'hideOutput' => 0 );
sub getpkgversioninfo {
my ($pv) = @_;
my $tree = gettree();
my $vif;
print "Fetching version information from http://httpupdate.cpanel.net/${pv}install/version ($tree)....";
eval {
local $SIG{'ALRM'} = sub { die 'Timeout while fetching version information'; };
alarm 45;
$vif = $cPhttpClient->request(
'host' => 'httpupdate.cpanel.net',
'url' => '/' . $pv . 'install/version',
'protocol' => 0,
);
};
alarm 0;
if ( $@ && $@ =~ m{ Timeout }xms ) { # Retry
sleep 2;
eval {
local $SIG{'ALRM'} = sub { die 'Timeout while fetching version information'; };
alarm 45;
$vif = $cPhttpClient->request(
'host' => 'httpupdate.cpanel.net',
'url' => '/' . $pv . 'install/version',
'protocol' => 0,
);
};
alarm 0;
}
if ( !$vif ) {
die "Unable to retrieve version info: $!";
}
my @VERINFO = split( /\n/, $vif );
my %VINFO;
foreach my $vinfo (@VERINFO) {
next if !$vinfo;
chomp $vinfo;
my ( $trees, $pkg, $version, $release, $flags, $pkgs ) = split( /:/, $vinfo );
my @TREES = split( /\,/, $trees );
foreach my $testtree (@TREES) {
if ( $testtree eq $tree ) {
$VINFO{$pkg}{'version'} = $version;
$VINFO{$pkg}{'release'} = $release;
$VINFO{$pkg}{'flags'} = $flags;
$VINFO{$pkg}{'pkgs'} = $pkgs;
}
}
}
print "Done\n";
return wantarray ? %VINFO : \%VINFO;
}
sub gettree {
if ( -e '/var/cpanel/dnsonly' ) {
return 'DNSONLY';
}
if ( !-e '/etc/cpupdate.conf' ) {
return 'RELEASE';
}
my $upconf_ref = Cpanel::Config::loadConfig('/etc/cpupdate.conf');
if ( !defined $upconf_ref || !exists $upconf_ref->{'CPANEL'} ) {
return 'RELEASE';
}
else {
if ( $upconf_ref->{'CPANEL'} eq 'stable'
|| $upconf_ref->{'CPANEL'} eq 'manual' ) {
return 'STABLE';
}
elsif ($upconf_ref->{'CPANEL'} eq 'manual-edge'
|| $upconf_ref->{'CPANEL'} =~ /demo/i
|| $upconf_ref->{'CPANEL'} eq 'edge' ) {
return 'EDGE';
}
elsif ($upconf_ref->{'CPANEL'} eq 'manual-current'
|| $upconf_ref->{'CPANEL'} eq 'current' ) {
return 'CURRENT';
}
elsif ($upconf_ref->{'CPANEL'} eq 'manual-dnsonly'
|| $upconf_ref->{'CPANEL'} eq 'dnsonly' ) {
return 'DNSONLY';
}
elsif ($upconf_ref->{'CPANEL'} =~ /^\d+$/
|| $upconf_ref->{'CPANEL'} =~ /nightly/i
|| $upconf_ref->{'CPANEL'} eq 'manual-beta'
|| $upconf_ref->{'CPANEL'} eq 'beta' ) {
return 'BETA';
}
else {
return 'RELEASE';
}
}
return 'RELEASE';
}
1;