#!/usr/bin/perl

use strict;
use warnings;
use Cpanel::StringFunc ();

my $rpm_bin = -x '/usr/bin/rpm' ? '/usr/bin/rpm' : -x '/bin/rpm' ? '/bin/rpm' : '';

exit if !$rpm_bin;

my $bind_chroot = `$rpm_bin -q bind-chroot`;
chomp $bind_chroot;

if ( $bind_chroot =~ m/is\s+not\s+installed/im ) {
    print "bind-chroot is not installed.\n";
    exit;
}

print "Removing conflicting bind-chroot rpm from database.\n";
system 'rpm', '-e', '--justdb', 'bind-chroot';

my $file = '/etc/sysconfig/named';
print "Rmoving ROOTDIR from $file.\n";
Cpanel::StringFunc::remlinefile( $file, 'ROOTDIR=', 'begin' ) if -f $file;
print "Done.\n";
