#!/usr/bin/perl
# cpanel - autofixer/horde_sqmail_current_fix     Copyright(c) 2014 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

BEGIN { unshift @INC, '/usr/local/cpanel'; }

use strict;
use warnings;
use Cpanel::HttpRequest;
use POSIX;

open( my $ver_fh, '<', '/usr/local/cpanel/version' );
my $ver = readline($ver_fh);
chomp($ver);
close($ver_fh);

if ( $ver !~ /14658/ ) {
    print "This auto fixer is for build 14658 only.\n";
    exit(1);
}

chdir '/usr/local/cpanel/src/3rdparty/gpl' or die "Unable to chdir: $!";

foreach my $file ( 'horde-3.1.3p2.cpanel.tar.gz', 'squirrelmail_files-1.4.9a.tar', 'squirrelmail-1.4.9a.tar' ) {
    my $url = 'http://httpupdate.cpanel.net/cpanelsync/EDGE/src/3rdparty/gpl/' . $file;
    my $httpClient = Cpanel::HttpRequest->new( 'hideOutput' => 0, 'signed' => 1 );
    $httpClient->download( $url, $file );
    if ( !-e $file ) {
        die "Unable to fetch file $file: $!";
    }
}
system '/usr/local/cpanel/bin/update-horde';
system '/usr/local/cpanel/bin/update-squirrelmail';
print "Done\n";

