Software Development Kit

cPanel & WHM's API [+] cPanel & WHM's API [-]


Modules and Plugins [+] Modules and Plugins [-]


cPanel & WHM Hooks [+] cPanel & WHM Hooks [-]


cPAddons (Site Software) [+] cPAddons (Site Software) [-]


System Administration [+] System Administration [-]


Developer Software [+] Developer Software [-]


Back to All Documentation



integrationblogcta.jpg

File List Script

This script creates a list of all files in your cPAddons archive.

#!/usr/bin/perl

# Do this in your cPAddon's .pm file
#    my $meta_info = {
#        ....
#    };
# 
#    # bring in any public_html install support data:
#    if ( defined &Cpanel::cPAddons::proc_keys_named_after_version ) {
#        Cpanel::cPAddons::proc_keys_named_after_version( $meta_info, __PACKAGE__ );
#    }

use strict;
use warnings;

use Archive::Tar ();
use YAML::Syck   ();
use File::Spec  ();

die 'specify version source tarball as only arg' if !defined $ARGV[0];
die 'tarball does not exist' if !-e $ARGV[0];
die 'tarball must be .tar.gz' if $ARGV[0] !~ m{ [.] tar [.] gz \z }xms;

my $tarball = File::Spec->rel2abs( $ARGV[0] );

my @parts   = File::Spec->splitpath( $tarball );
my $name = pop @parts;
$name =~ s{ [.] tar [.] gz \z }{}xms;

if ( !-d File::Spec->catpath( @parts, 'keys_named_after_version' ) ) {
    mkdir File::Spec->catpath( @parts, 'keys_named_after_version' ) 
        or die 'Could not create keys_named_after_version directory';    
}

my $save_as = File::Spec->catfile( @parts, 'keys_named_after_version', $name );

my $data_hr = {
    'public_html_install_files'   => [],
    'public_html_install_unknown' => [],
};

my @files = Archive::Tar->new( $tarball )->list_files();

@files = grep !/ \A [.] \/ \z /xms, @files; # remove './' from archive listing

for my $path (@files) { 
    print "Cleaning $path\n";
    $path =~ s{^[.]/}{}g; # don't want leading ./
    
    if ( $path =~ m{ [/] \z }xms ) {
        print "Adding '$path' to directory list\n".
        push @{ $data_hr->{'public_html_install_unknown'} }, $path
    }
    else {
        print "Adding '$path' to file list\n".
        push @{ $data_hr->{'public_html_install_files'} }, $path        
    }
}

print "\nSaving as '$save_as'\n";
YAML::Syck::DumpFile( $save_as, $data_hr );

Topic revision: r3 - 30 Aug 2011 - 16:00:05 - Main.MelanieSeibert