????

Your IP : 18.191.103.28


Current Path : /scripts/
Upload File :
Current File : //scripts/convert_ea3_profile_to_ea4

#!/usr/local/cpanel/3rdparty/bin/perl
# cpanel - scripts/convert_ea3_profile_to_ea4        Copyright 2015 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 Cpanel::Imports;

use Cpanel::EA4::EA3Map ();
use Cpanel::YAML        ();
use Cpanel::JSON        ();

use File::Path::Tiny ();

sub usage {
    my ($err) = @_;
    warn "$err\n" if defined $err;

    print <<USAGE;
Usage: $0 [--ignore-errors] …/my_ea3.yaml /etc/cpanel/ea4/profiles/custom/my_ea4.json

    Converts an EA3 profile to an EA4 profile.

    The EA3 profile must exist. Intermediate paths will be created if needed for the EA4 profile.

    Custom profiles must be in /etc/cpanel/ea4/profiles/custom (and end in .json and contain no spaces) in order for them to be used by EA4.

    EA3 profiles are in /var/cpanel/easy/apache/profile and /var/cpanel/easy/apache/profile/custom/

      --ignore-errors  Skip all error correcting code. This can result in an uninstallable profile so it is mainly useful for testing.
USAGE

    exit(0);
}

my $idx = 0;

my $ignore_errors = 0;
if ( $ARGV[$idx] eq "--ignore-errors" ) {
    $ignore_errors = 1;
    $idx++;
}

my $fname        = $ARGV[ $idx++ ];
my $output_fname = $ARGV[ $idx++ ];

usage("You must specify an existing EA3 profile.\n") if !defined $fname || !-f $fname;
usage("You must specify a path (including file name) where you want the EA4 profile to be.\n") if !defined $output_fname;

my $ea3_hr = Cpanel::YAML::LoadFile($fname);
my $hr = Cpanel::EA4::EA3Map::convert_ea3_config_to_ea4( $ea3_hr, $ignore_errors );

my $ea4_hr   = $hr->{profile};
my $warnings = $hr->{warnings};

if ( $output_fname =~ m{/} ) {
    File::Path::Tiny::mk_parent($output_fname) or die locale->maketext( "Can not create parent directory for “[_1]”: [_2]", $output_fname, "$!\n" );
}

Cpanel::JSON::DumpFile( $output_fname, $ea4_hr );

foreach my $warn ( @{$warnings} ) {
    warn("$warn\n");
}

1;