App-DistSync

 view release on metacpan or  search on metacpan

bin/distsync  view on Meta::CPAN

=back

=head1 DESCRIPTION

Launcher of synchronization via App::DistSync

See C<README> file for details

=head1 AUTHOR

Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cpan.orgE<gt>

=head1 COPYRIGHT

Copyright (C) 1998-2025 D&D Corporation. All Rights Reserved

=head1 LICENSE

This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

See L<https://dev.perl.org/licenses/>

=cut

use Getopt::Long;
use Pod::Usage;

use Cwd qw/getcwd/;
use File::Spec;

use App::DistSync;
use App::DistSync::LockFile;
use App::DistSync::Util;

binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';


use constant {
    PIDFILE     => 'distsync.pid',
    CMDDEFAULT  => 'sync',
    COMMANDS    => [qw/init status sync manifest mkmani/],
};

$| = 1;  # Autoflush on

my $options = {};
Getopt::Long::Configure ("bundling");
GetOptions($options,
    # Information and debug
    "help|usage|h",         # Show help page
    "longhelp|H|?",         # Show long help page
    "debug|devel|d",        # Debug mode
    "verbose|v",            # Verbose mode
    "version|ver|V",        # Print VERSION of the project

    # Client options
    "proxy|x=s",            # Proxy URL
    "insecure|k",           # Insecure connection
    "timeout|T=i",          # Timeoute value in seconds. Default - 60

    # Project
    "directory|dir|D=s",    # Directory
    "delay|i=i",            # Delay. 0 - off, 1-n - secs, default - 3600
) || pod2usage(-exitval => 1, -verbose => 0, -output => \*STDERR);
pod2usage(-exitval => 0, -verbose => 1) if $options->{help};
pod2usage(-exitval => 0, -verbose => 2) if $options->{longhelp};
printf("DistSync v%s\n", App::DistSync->VERSION) && exit(0) if $options->{version};

# Get command
my $command   = @ARGV ? shift @ARGV : CMDDEFAULT;
pod2usage(-exitval => 1, -verbose => 99, -sections => 'SYNOPSIS|OPTIONS|COMMANDS', -output => \*STDERR)
    unless scalar grep {$_ eq $command} @{(COMMANDS)};

# Work directory
my $dir = $options->{directory} || shift(@ARGV) || getcwd();
die sprintf("Directory \"%s\" not exists", $dir) unless $dir && (-e $dir) && (-d $dir or -l $dir);

# Debugging on
$App::DistSync::Util::DEBUG = $App::DistSync::DEBUG = 1 if $options->{debug};

# Start process
my $started = time;
debug("%s START", tms);

# Lock file
my $lock = App::DistSync::LockFile->new(
        file => File::Spec->catfile($dir, App::DistSync::MANILOCK()),
        $options->{delay} ? (delay => $options->{delay}) : (),
        pid => $$,
    );
if ($lock->lock->error) {
    warn $lock->error . "\n";
    goto FINISH;
}

# Create instance
my $ds = App::DistSync->new(
    dir     => $dir,
    pid     => $$,
    timeout => $options->{timeout},
    verbose => $options->{verbose},
    insecure=> $options->{insecure},
    proxy   => $options->{proxy},
);

my $exitval = 1; # error

# Init
if ($command eq 'init') {
    $ds->init or goto FINISH;
    say "The work directory has been successfully initialized";
    printf "Your files are in \"%s\"\n", $ds->dir if $options->{verbose};
    $exitval = 0; # Ok
}

# Status
elsif ($command eq 'status') {
    if ($ds->status) {
        $ds->_show_summary;



( run in 2.597 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )