PNG  IHDR* pHYs+ IDATx]n#; cdLb Ǚ[at¤_:uP}>!Usă cag޿ ֵNu`ݼTâabO7uL&y^wFٝA"l[|ŲHLN밪4*sG3|Dv}?+y߉{OuOAt4Jj.u]Gz*҉sP'VQKbA1u\`& Af;HWj hsO;ogTu uj7S3/QzUr&wS`M$X_L7r2;aE+ώ%vikDA:dR+%KzƉo>eOth$z%: :{WwaQ:wz%4foɹE[9<]#ERINƻv溂E%P1i01 |Jvҗ&{b?9g=^wζXn/lK::90KwrюO\!ջ3uzuGv^;騢wq<Iatv09:tt~hEG`v;3@MNZD.1]L:{ծI3`L(÷ba")Y.iljCɄae#I"1 `3*Bdz>j<fU40⨬%O$3cGt]j%Fߠ_twJ;ABU8vP3uEԑwQ V:h%))LfraqX-ۿX]v-\9I gl8tzX ]ecm)-cgʒ#Uw=Wlێn(0hPP/ӨtQ“&J35 $=]r1{tLuǮ*i0_;NƝ8;-vݏr8+U-kruȕYr0RnC]*ެ(M:]gE;{]tg(#ZJ9y>utRDRMdr9㪩̞zֹb<ģ&wzJM"iI( .ꮅX)Qw:9,i좜\Ԛi7&N0:asϓc];=ΗOӣ APqz93 y $)A*kVHZwBƺnWNaby>XMN*45~ղM6Nvm;A=jֲ.~1}(9`KJ/V F9[=`~[;sRuk]rєT!)iQO)Y$V ی ۤmzWz5IM Zb )ˆC`6 rRa}qNmUfDsWuˤV{ Pݝ'=Kֳbg,UҘVz2ﴻnjNgBb{? ߮tcsͻQuxVCIY۠:(V뺕 ٥2;t`@Fo{Z9`;]wMzU~%UA蛚dI vGq\r82iu +St`cR.6U/M9IENDB` REDROOM
PHP 5.6.40
Preview: ea_install_profile Size: 7.10 KB
//usr/local/bin/ea_install_profile

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

package ea_install_profile;

use strict;

use Cpanel::JSON;
use Cpanel::PackMan;
use Cpanel::Config::Httpd;
use Data::Dumper;
use Path::Tiny 'path';

sub usage {
    my ($msg) = @_;

    print "Error: $msg\n" if defined $msg;
    print "usage: ea_install_profile [--firstinstall|--install] profile_file\n";
    print "\n";
    print "   With no flags, $0 will only do conflict resolution on the profile.\n";
    print "\n";
    print "   --install: Resolve conflicts and install the profile.\n";
    print "   --firstinstall: Attempt to do the install without conflict resolution and fallback\n";
    print "                   to doing --install if it fails.  This is only intended to be used\n";
    print "                   on a fresh cPanel install.\n";
    print "\n";
    exit( $msg ? 1 : 0 );
}

sub script {
    my (@args) = @_;

    die "May only be run if you are using EasyApache 4" if ( !Cpanel::Config::Httpd::is_ea4() );

    my $profile;
    my $install      = 0;
    my $firstinstall = 0;

    my $idx = 0;
    if ( $args[$idx] eq "--firstinstall" ) {
        $idx++;
        $firstinstall = 1;
    }
    if ( $args[$idx] eq "--install" ) {
        $idx++;
        $install = 1;
    }

    usage() if ( !defined $args[$idx] );

    $profile = $args[$idx];

    if ( !-f $profile ) {
        $profile = "/etc/cpanel/ea4/profiles/custom/" . $profile;
        usage("Cannot find profile") if !-f $profile;
    }

    my @addl_prefixes = eval {
        map { $_->basename } path("/etc/cpanel/ea4/additional-pkg-prefixes/")->children;
    };

    print "Loading profile …\n";
    my %server_pkgs;
    @server_pkgs{ Cpanel::PackMan->instance->list( 'prefix' => 'ea-' ) } = ();
    for my $prefix (@addl_prefixes) {
        @server_pkgs{ Cpanel::PackMan->instance->list( 'prefix' => "$prefix-" ) } = ();
    }

    my $data = Cpanel::JSON::LoadFile($profile);

    # 1. Fix ea-apachae24 package names with underscores for Ubuntu and with dashes for RHEL if needed (See ZC-11501 for why this is necessary)
    my $pkgmgr  = -x '/usr/bin/apt' ? 'deb' : 'rpm';
    my $changed = 0;

    if ( $pkgmgr eq 'deb' ) {
        foreach my $pkg ( @{ $data->{pkgs} } ) {
            my $new_pkg = _normalize_pkg_for_ubuntu($pkg);
            if ( $new_pkg ne $pkg ) {
                $pkg     = $new_pkg;
                $changed = 1;
            }
        }
    }
    elsif ( $pkgmgr eq 'rpm' ) {
        foreach my $pkg ( @{ $data->{pkgs} } ) {
            my $new_pkg = _normalize_pkg_for_rhel( $pkg, \%server_pkgs );
            if ( $new_pkg ne $pkg ) {
                $pkg     = $new_pkg;
                $changed = 1;
            }
        }
    }
    else {
        die "How did we get here? `pkgmgr` is neither `rpm` nor `deb` ($pkgmgr)\n";
    }

    path($profile)->spew( Cpanel::JSON::pretty_dump($data) ) if $changed;

    # 2. detect any packages in the profile that do not exist on the server
    my %not_on_server = ( map { !exists $server_pkgs{$_} ? ( $_ => undef ) : () } @{ $data->{pkgs} } );

    # 3. remove %not_on_server from $profile->{pkgs}
    $data->{pkgs} = [ grep { !exists $not_on_server{$_} } @{ $data->{pkgs} } ];

    # 4. Tell them about the ones we are ignoring
    my $derps = 0;
    for my $derppkg ( sort keys %not_on_server ) {
        warn "    * Warning! ignored package: $derppkg. It is in the profile’s package list but does not exist on this server.\n";
        $derps++;
    }
    print "\n" if $derps;

    if ( $data->{pre} ) {
        print "Installing prereqs …\n";
        my $sys = Cpanel::PackMan->instance->sys;

        $sys->install( @{ $data->{pre} } );    # apt, yum, and dnf’s `install` will install if its not installed, upgrade if its old, noop if its already the latest
        $sys->cache;                           # this is needed in case a new package repo was put in place
        print " … prereqs done!\n\n";
    }

    if ($firstinstall) {
        print "The system is running in first install mode and will install the requested packages without resolving conflicts …\n";
        local $@;
        eval { Cpanel::PackMan->instance->sys->install( @{ $data->{pkgs} } ); };
        print " … done!\n";
        if ($@) {
            warn "First install method failed ($@).";
            warn "The system will fall back to doing a full install.";
            $install = 1;
        }
        else {
            return 0;
        }
    }

    print "The system is resolving package dependencies and conflicts. This may take some time …\n";
    my $resolve_method = defined &Cpanel::PackMan::resolve_multi_op_ns ? 'resolve_multi_op_ns' : 'resolve_multi_op';

    my $res = Cpanel::PackMan->instance->$resolve_method( $data->{'pkgs'}, 'ea' );
    for my $prefix (@addl_prefixes) {
        my $prefix_res = eval { Cpanel::PackMan->instance->$resolve_method( $data->{'pkgs'}, $prefix ) };
        if ($@) {
            if ( $@ =~ m/Unknown namespace/ ) {
                warn "!!!! Your system is not new enough to support EA4 pkg prefixes besides `ea-`, other prefixes will be left out !!\n";
                last;
            }
            else {
                chomp $@;
                warn "!!!! There was a problem with the additional-pkg-prefix “$prefix”, it will be left out !!\n\tError: $@\n";
                next;
            }
        }

        for my $field (qw(uninstall unaffected upgrade install)) {
            push @{ $res->{$field} }, @{ $prefix_res->{$field} };
        }
    }

    print " … done!\n";

    if ($install) {
        print "Installing …\n";
        my $actions = Cpanel::PackMan->instance->multi_op($res);
        if ( !$actions ) {
            print " … nothing to do.\n";
        }
        else {
            print " … done!\n";
        }
    }
    else {
        print Dumper($res);
    }

    return 0;
}

sub _normalize_pkg_for_ubuntu {
    my ($pkg) = @_;

    $pkg =~ s/_/-/g;

    return $pkg;
}

sub _normalize_pkg_for_rhel {
    my ( $orig_pkg, $server_pkgs_hr ) = @_;

    # Short-circuit if there is an exact match:
    return $orig_pkg if exists $server_pkgs_hr->{$orig_pkg};

    my $pkg    = $orig_pkg;
    my $prefix = 'ea-apache24-mod';

    if ( $pkg =~ m/^($prefix)(.*)/ ) {
        my $name = $2;
        $name =~ s/-/_/g;    # Apache module packages tend to use underscores, so start with that.
        $pkg = $prefix . $name;

        # If that also fails, search through the entire list:
        if ( !exists $server_pkgs_hr->{$pkg} ) {
            my $re_pkg  = $prefix . ( $name =~ s/_/[-_]/gr );
            my @results = grep { m/^$re_pkg$/ } keys %$server_pkgs_hr;
            $pkg = $results[0] if scalar @results > 0;

            warn "!!!! Multiple inexact matches for '$orig_pkg' when treating underscores and dashes as equivalent; using '$pkg'!" if scalar @results > 1;
        }
    }

    return $pkg;
}

exit( script(@ARGV) ) unless caller();

1;

Directory Contents

Dirs: 0 × Files: 40

Name Size Perms Modified Actions
222 B lrwxr-xr-x 2025-04-06 23:03:47
Edit Download
433 B lrwxr-xr-x 2025-04-17 10:03:18
Edit Download
3.13 MB lrwxr-xr-x 2025-12-30 12:40:17
Edit Download
8.06 KB lr-xr-xr-x 2025-04-06 18:11:50
Edit Download
4.19 KB lr-xr-xr-x 2025-04-06 18:11:51
Edit Download
582 B lrwxr-xr-x 2025-04-19 08:34:29
Edit Download
1.87 MB lrwxr-xr-x 2026-01-30 23:01:17
Edit Download
218 B lrwxr-xr-x 2025-04-06 23:03:44
Edit Download
4.71 MB lrwxr-xr-x 2026-01-08 19:54:50
Edit Download
5.39 MB lrwxr-xr-x 2026-01-08 20:24:48
Edit Download
4.90 MB lrwxr-xr-x 2025-11-18 19:03:31
Edit Download
5.95 MB lrwxr-xr-x 2026-01-09 16:25:02
Edit Download
6.05 MB lrwxr-xr-x 2026-01-08 21:03:29
Edit Download
6.32 MB lrwxr-xr-x 2026-01-08 21:19:07
Edit Download
6.73 MB lrwxr-xr-x 2026-01-08 21:35:12
Edit Download
4.62 MB lrwxr-xr-x 2026-01-08 21:51:04
Edit Download
6.09 MB lrwxr-xr-x 2025-11-18 20:35:28
Edit Download
7.62 MB lrwxr-xr-x 2025-11-18 20:44:43
Edit Download
7.72 MB lrwxr-xr-x 2026-01-08 22:09:51
Edit Download
7.78 MB lrwxr-xr-x 2026-01-08 22:26:27
Edit Download
7.80 MB lrwxr-xr-x 2026-01-27 02:31:15
Edit Download
7.86 MB lrwxr-xr-x 2026-01-27 02:45:38
Edit Download
110 B lrwxr-xr-x 2025-10-17 23:01:20
Edit Download
39.85 KB lrwxr-xr-x 2026-01-16 17:45:08
Edit Download
8.43 KB lrwxr-xr-x 2026-01-16 17:45:08
Edit Download
7.10 KB lrwxr-xr-x 2026-01-16 17:45:08
Edit Download
6.73 KB lrwxr-xr-x 2026-01-16 17:45:08
Edit Download
910 B lrw-r--r-- 2026-01-03 22:38:46
Edit Download
221 B lrwxr-xr-x 2025-04-06 23:03:46
Edit Download
3.80 MB lrw-r--r-- 2021-12-08 06:31:58
Edit Download
224 B lrwxr-xr-x 2025-04-06 23:03:47
Edit Download
14 B lrwxr-xr-x 2025-04-11 01:53:34
Edit Download
6.85 KB lr-xr-xr-x 2025-04-06 18:12:06
Edit Download
937 B lrwxr-xr-x 2025-04-03 11:08:35
Edit Download
3.59 MB lrwxr-xr-x 2026-01-30 23:01:18
Edit Download
223 B lrwxr-xr-x 2025-04-06 23:03:46
Edit Download
935 B lrwxr-xr-x 2025-04-03 11:08:35
Edit Download
933 B lrwxr-xr-x 2025-04-03 11:08:35
Edit Download
6.72 MB lrwxr-xr-x 2025-04-11 01:12:41
Edit Download
112 B lrwx------ 2026-01-14 17:56:25
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).
© 2026 REDROOM — Secure File Manager. All rights reserved. Built with ❤️ & Red Dark UI