cPanel-SyncUtil
view release on metacpan or search on metacpan
0.5 Thu Aug 12 19:27:35 CDT 2010
- sort cpanelsync file list
0.4 Thu Aug 5 12:24:08 CDT 2010
- perltidy
- dropped 'use version'
- Added "Your webserver and cpanelsync aware directories" to POD
0.0.3 Thu Nov 8 09:07:00 2007
- added Ben Thomas' build_cpanelsync(), compress_files(), get_files_from_cpanelsync(), bzip_file(), _read_dir_recursively(), _get_bzip_binary(), and _chown_recursively() functions/tests to help make it easier to work with
- created POD for those changes
0.0.2 Mon Jun 19 10:31:02 2006
- fixed problem with sample script, no change to module except version
0.0.1 Wed Mar 22 14:44:49 2006
- original version; created by h2xs 1.23 with options
-AXc -n cPanel::SyncUtil
lib/cPanel/SyncUtil.pm view on Meta::CPAN
build_cpanelsync
get_mode_string
get_mode_string_preserve_setuid
compress_files
_write_file
_read_dir
_read_dir_recursively
_lock
_unlock
_safe_cpsync_dir
_chown_pwd_recursively
_chown_recursively
_raw_dir
_sync_touchlock_pwd
_get_opts_hash
);
our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK );
our $bzip;
sub get_mode_string {
lib/cPanel/SyncUtil.pm view on Meta::CPAN
my $dir = shift;
return 1
if defined $dir
&& $dir !~ m/\.bak$/
&& $dir !~ m/^\./
&& -d $dir
&& !-l $dir;
return 0;
}
sub _chown_pwd_recursively {
my ( $user, $group ) = @_;
_chown_recursively( $user, $group, '.' );
}
sub _chown_recursively {
my ( $user, $group, $dir );
if ( @_ == 3 ) {
( $user, $group, $dir ) = @_;
}
elsif ( @_ == 2 ) {
( $user, $dir ) = @_;
}
else {
Carp::croak('improper arguments');
}
my $chown = defined $group ? "$user:$group" : $user;
Carp::croak 'User [and group] must be ^\w+$' if $chown !~ m{^\w+(\:\w+)?$};
Carp::croak "Invalid directory $dir" if !-d $dir;
system 'chown', '-R', $chown, $dir;
}
sub _raw_dir {
my ( $base, $archive, $verbose, @files ) = @_;
my $args_hr = ref($verbose) ? $verbose : { 'verbose' => $verbose };
my $bz2_opt = $args_hr->{'verbose'} ? '-fkv' : '-fk';
my $pwd = Cwd::cwd();
if ( !-d $base ) {
Carp::cluck "Invalid base directory $base";
lib/cPanel/SyncUtil.pm view on Meta::CPAN
If you have binaries that need to be setuid you can use \&cPanel::SycnUtil::get_mode_string_preserve_setuid or roll your own instead (e.g. to only preserve setuid on specific ones and warn about files that are setuid that need review).
=back
=head2 compress_files
Creates the compressed files for the given directory. Arguments are a directory (required) and a boolean to turn on verbose output.
If no .cpanelsync database is located then build_cpanelsync will be called prior to compressing and files.
=head2 _chown_pwd_recursively
Takes as its first argument a user that matches ^\w+$ (and optionally a group as its second argument, also matching ^\w+$)
and recursively chown's the current working directory to the given user (and group if given).
Currently the return value is from a system() call to chown.
=head2 get_files_from_cpanelsync
Returns an array (array ref in scalar context) of files in a given cpanelsync file. If none is passed it uses the one in the current directory.
=head2 bzip_file
Creates the .bz2 version of the given file. A second boolean argument can be passed for verbosity. Returns true if it worked false otherwise.
=head2 get_mode_string
lib/cPanel/SyncUtil.pm view on Meta::CPAN
Returns an array (array ref in scalar context ) of all files recursively in the given directory.
@articles = @files;
The list is sorted by directories, files, then symlinks and those are each sorted case-insensitively
You can add file names to ignore as keys in %cPanel::SyncUtil::ignore_name which has by default '.svn' and '.git'.
The name can be the file name only or the path (that will start w/ the path given to _read_dir_recursively()).
=head2 _chown_recursively()
Like _chown_pwd_recursively but takes a third argument of the path to process.
It can take 2 args : 'user, dir' or 3 args: 'user, group, dir'
=head2 _safe_cpsync_dir
Returns true if the given argument is a directory that it is safe to be cpanelsync'ified.
See the simple, scripts/cpanelsync_build_dir script for example useage while recursing directories.
=head2 _raw_dir
scripts/cpanelsync_build_cpaddons_dir view on Meta::CPAN
push @cmds, "-$_", $options{$_};
}
system $0, '-a', 'bz2', @cmds;
system $0, '-a', 'unlock', @cmds;
system $0, '-a', 'sync', @cmds;
exit;
}
cPanel::SyncUtil::_chown_pwd_recursively( $user, $group );
if ($clustersync) {
if ( -x $clustersync ) {
exec $clustersync, @ARGV if $options{'a'} eq 'sync';
}
else {
die "$clustersync is not executable";
}
}
scripts/cpanelsync_build_cpaddons_dir view on Meta::CPAN
if defined $options{'c'} && $options{'c'} ne '' && !-d "$root/$options{'c'}";
chdir $root or die "Could not go into $root: $!";
ROOT:
for my $dir ( cPanel::SyncUtil::_read_dir($root) ) {
next ROOT
if !cPanel::SyncUtil::_safe_cpsync_dir($dir)
|| ( defined $options{'c'} && $options{'c'} ne '' && $dir ne $options{'c'} );
cPanel::SyncUtil::_chown_pwd_recursively( $user, $group );
SUBDIR:
for my $name ( cPanel::SyncUtil::_read_dir($dir) ) {
next SUBDIR
if $name =~ /^\./
|| !cPanel::SyncUtil::_safe_cpsync_dir("$dir/$name")
|| ( defined $options{'n'} && $options{'n'} ne '' && $name !~ /^$options{'n'}/ );
if ( $options{'a'} eq 'bz2' ) {
system 'bzip2', '-k', "$dir/$name.pm";
cPanel::SyncUtil::_raw_dir( "$dir", $name, 1 )
or warn "cPanel::SyncUtil::_raw_dir $root/$dir: $!";
cPanel::SyncUtil::_sync_touchlock_pwd();
}
elsif ( $options{'a'} eq 'lock' ) {
cPanel::SyncUtil::_lock("$dir/$name/");
}
elsif ( $options{'a'} eq 'unlock' ) {
cPanel::SyncUtil::_unlock("$dir/$name/");
}
cPanel::SyncUtil::_chown_pwd_recursively( $user, $group );
}
}
scripts/cpanelsync_build_dir view on Meta::CPAN
#!/usr/bin/perl
# cpanel10 - cpanelsync_build_dir Copyright(c) 2006 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 warnings;
use Cwd;
use cPanel::SyncUtil qw(_raw_dir _chown_pwd_recursively _safe_cpsync_dir);
# recursiveley do pwd or directopry given as argument
my $root = defined $ARGV[0] && -d $ARGV[0] ? $ARGV[0] : '.';
# set these however you wish
my $user = $<;
my ($group) = split /\s+/, $(;
my $recurse; # since $recurse uses itself...
$recurse = sub {
my ($root) = @_;
my $start = Cwd::cwd();
_raw_dir( $start, $root );
chdir $root or die "Could not go up into $root: $!";
_chown_pwd_recursively( $user, $group );
ROOTS:
for my $dir ( cPanel::SyncUtil::_read_dir('.') ) {
next ROOTS if !_safe_cpsync_dir($dir);
$recurse->($dir);
}
chdir $start or die "Could not go back into $start: $!";
};
( run in 0.992 second using v1.01-cache-2.11-cpan-5511b514fd6 )