#!/usr/local/cpanel/3rdparty/bin/perl
# cpanel - autofixer2/centos5_vault_mirror             Copyright 2017 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;

use Cpanel::Version  ();
use Cpanel::Sys::OS  ();
use Cpanel::SafeFile ();

my $cpanel_version = Cpanel::Version::getversionnumber();
my $os_major       = int( Cpanel::Sys::OS::getreleaseversion() );

# This only needs to run on CentOS 5 systems running 11.56
exit unless ( $Cpanel::Version::MAJORVERSION eq '11.56' && Cpanel::Sys::OS::getos() eq 'centos' && $os_major == 5 );

my $base_repos_path = '/etc/yum.repos.d/CentOS-Base.repo';

my $read_lock = Cpanel::SafeFile::safeopen( my $base_repo_fh, '<', $base_repos_path ) or do {
    die qq{Unable to obtain lock on $base_repos_path};
};

my @lines;
while ( my $line = <$base_repo_fh> ) {
    $line =~ s{^baseurl=http://mirrorlist.centos.org/centos/\$releasever}{baseurl=http://vault.centos.org/5.11};
    push @lines, $line;
}

Cpanel::SafeFile::safeclose( $base_repo_fh, $read_lock );

my $update_lock = Cpanel::SafeFile::safeopen( $base_repo_fh, '>', $base_repos_path ) or do {
    die qq{Unable to obtain lock on $base_repos_path};
};

print {$base_repo_fh} join( q{}, @lines );

Cpanel::SafeFile::safeclose( $base_repo_fh, $update_lock );

