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

use lib '/scripts';
use strict;
use warnings;
use SafeFile;
require '/scripts/regsrep.pl';

eval {
    require Cpanel::Config;
    if ( defined &Cpanel::Config::is_ea3 ) {
        if ( Cpanel::Config::is_ea3() ) {
            print "This module is now managed via easyapache.\n";
            print "To keep this message from appearing: ";
            print "Remove its entry from /var/cpanel/addonmodules\n";
            exit;
        }
    }
};

print "Now uninstalling mod_mono (.aspx support) files...";

my @UD;
my $dirlock = SafeFile::safeopen( \*UD, "+<", "uninstall.dir" );
while (<UD>) {
    push( @UD, $_ );
}
seek( UD, 0, 0 );
foreach (@UD) {
    chomp();
    system("rm -rf $_");
}
SafeFile::safeclose( \*UD, $dirlock );

my @UF;
my $filelock = SafeFile::safeopen( \*UF, "+<", "uninstall.files" );
while (<UF>) {
    push( @UF, $_ );
}
seek( UF, 0, 0 );
foreach (@UF) {
    chomp();
    unlink("$_");
}
SafeFile::safeclose( \*UF, $dirlock );

system 'rm', '-rf', '/usr/src/mod_mono-1.0.2';
system 'rm', '-f',  '/var/cpanel/apachemod/modmono.apache';
print "Done\n";

print "Cleaning up the httpd.conf...";
regsrep( "/usr/local/apache/conf/httpd.conf", "LoadModule[\\s]*mono_module[\\s]*libexec/mod_mono.so", "#LoadModule mono_module        libexec/mod_mono.so" );
regsrep( "/usr/local/apache/conf/httpd.conf", "AddModule[\\s]*mod_mono.c", "#AddModule mod_mono.c" );
print "Done\n";
