#!/bin/sh
eval 'if [ -x /usr/local/cpanel/3rdparty/bin/perl ]; then exec /usr/local/cpanel/3rdparty/bin/perl -x -- $0 ${1+"$@"}; else exec /usr/bin/perl -x $0 ${1+"$@"}; fi;'
  if 0;

#!/usr/bin/perl
#
# cpanel - cpanel-uninstall                       Copyright(c) 2013 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
#
#
# Zend Guard/Optimizer uninstaller

use lib '/usr/local/cpanel';
use Cpanel::FileUtils ();

my $uninstalled = 0;

my @prefixes = ( '/usr/local', '/usr/local/php4' );
if (@ARGV) {
    @prefixes = @ARGV;
}

foreach my $php_prefix (@prefixes) {
    $php_prefix =~ s/\/$//;
    my $php_ini = $php_prefix . '/lib/php.ini';
    if ( $php_prefix eq '/usr/local/cpanel/3rdparty' || $php_prefix eq '/var/cpanel/3rdparty' ) {
        $php_ini = '/usr/local/cpanel/3rdparty/etc/php.ini';
    }
    unless ( -e $php_ini ) {
        print "Skipping uninstall at $php_prefix, missing php.ini\n";
        next;
    }
    unless ( -e $php_prefix . '/bin/php' ) {
        print "Skipping uninstall at $php_prefix, missing php\n";
        next;
    }
    unless ( -e $php_prefix . '/bin/phpize' ) {
        print "Skipping uninstall at $php_prefix, missing phpize\n";
        next;
    }
    unless ( -e $php_prefix . '/bin/php-config' ) {
        print "Skipping uninstall at $php_prefix, missing php-config\n";
        next;
    }

    print "Removing Zend Optimizer/Guard Loader from ${php_ini}\n";

    my $success = Cpanel::FileUtils::regex_rep_file(
        $php_ini,
        {
            qr{^\s*zend_extension_manager\.optimizer(_ts)?\s*=\s*"?\S+\/Optimizer(_TS)?-[\d\.]+"?\s*$}is           => q{},
            qr{^\s*zend_optimizer\.\S+.*$}is                                                                       => q{},
            qr{^\s*zend_extension(_ts)?\s*=\s*"?\S+Zend(ExtensionManager|Optimizer|GuardLoader)(_TS)?\.so"?\s*$}is => q{},
        },
        {},
    );
    $uninstalled = 1 if $success;
}

if ($uninstalled) {
    exit 0;
}
else {
    exit 1;
}
