[41] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use LATMOS::Accounts; |
---|
| 6 | use LATMOS::Accounts::Synchro; |
---|
| 7 | use Getopt::Long; |
---|
| 8 | use Pod::Usage; |
---|
| 9 | |
---|
| 10 | =head1 NAME |
---|
| 11 | |
---|
| 12 | la-sync - Tools to synchronize base |
---|
| 13 | |
---|
| 14 | =head1 SYNOPSIS |
---|
| 15 | |
---|
| 16 | Show configured bases: |
---|
| 17 | |
---|
[594] | 18 | la-sync [options] |
---|
[41] | 19 | |
---|
| 20 | =cut |
---|
| 21 | |
---|
| 22 | GetOptions( |
---|
[132] | 23 | 'c|config=s' => \my $config, |
---|
| 24 | 'help' => sub { pod2usage(0) }, |
---|
| 25 | 'from=s' => \my $from, |
---|
| 26 | 'to=s' => \my @to, |
---|
| 27 | 'nocreate' => \my $nocreate, |
---|
[861] | 28 | 'nodelete' => \my $nodelete, |
---|
[132] | 29 | 'test' => \my $test, |
---|
| 30 | 'o|object=s' => \my $otype, |
---|
| 31 | 's|syncname=s' => \my $syncname, |
---|
[861] | 32 | 'b|batch' => \my $batch, |
---|
| 33 | 'unexp' => \my $unexp, |
---|
[41] | 34 | ) or pod2usage(); |
---|
| 35 | |
---|
| 36 | =head1 OPTIONS |
---|
| 37 | |
---|
[985] | 38 | =over 4 |
---|
| 39 | |
---|
[861] | 40 | =item -c|--config configdir |
---|
[41] | 41 | |
---|
[861] | 42 | Use this configuration directory instead of the default one. |
---|
[41] | 43 | |
---|
| 44 | =item --from basename |
---|
| 45 | |
---|
[594] | 46 | Specify source base to use |
---|
[41] | 47 | |
---|
| 48 | =item --to basename |
---|
| 49 | |
---|
| 50 | Specify destination base to use, this option can be used |
---|
| 51 | severals times |
---|
| 52 | |
---|
[594] | 53 | =item --nocreate |
---|
| 54 | |
---|
[1375] | 55 | Don't create object, synchronize existing |
---|
[594] | 56 | |
---|
| 57 | =item --test |
---|
| 58 | |
---|
[1375] | 59 | Don't change anything, just test |
---|
[594] | 60 | |
---|
| 61 | =item -s|--syncname name |
---|
| 62 | |
---|
[1375] | 63 | Use synchronisation named C<name> in configuration instead default |
---|
[594] | 64 | |
---|
| 65 | =item -o|object object_type |
---|
| 66 | |
---|
| 67 | Query will be performed on this object. Default is the 'User' object. |
---|
| 68 | |
---|
[578] | 69 | =item -b|--batch |
---|
| 70 | |
---|
| 71 | Don't really perform any synchronisation but try to call daemon process |
---|
| 72 | to perform immediate synchronisation. |
---|
| 73 | |
---|
[861] | 74 | =item --unexp |
---|
| 75 | |
---|
| 76 | Sync unexported objects in source base |
---|
| 77 | |
---|
[985] | 78 | =back |
---|
| 79 | |
---|
[41] | 80 | =cut |
---|
| 81 | |
---|
[457] | 82 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
[41] | 83 | |
---|
[578] | 84 | if ($batch) { |
---|
[1201] | 85 | warn "Using la-sync -b is deprecated, use la-sync-ctl -s instead\n"; |
---|
[578] | 86 | exit ($LA->call_batch_sync ? 0 : 1); |
---|
| 87 | } |
---|
| 88 | |
---|
[73] | 89 | my $sync = $LA->create_synchro( |
---|
[132] | 90 | $syncname, |
---|
[73] | 91 | from => $from, |
---|
| 92 | to => (@to ? [ @to ] : undef), |
---|
[66] | 93 | test => $test, |
---|
[861] | 94 | unexported => $unexp, |
---|
[73] | 95 | ) or die "cannot create sync object\n"; |
---|
| 96 | $sync->load_dest and return; |
---|
[83] | 97 | if ($otype) { |
---|
| 98 | foreach (@ARGV) { |
---|
| 99 | warn "Try to sync $otype: $_\n"; |
---|
[777] | 100 | $sync->sync_object($otype, $_, onepass => 1) or do { |
---|
[197] | 101 | warn "Error while synching $_ ($otype)\n"; |
---|
| 102 | exit 1; |
---|
| 103 | } |
---|
[83] | 104 | } |
---|
| 105 | } else { |
---|
[861] | 106 | $sync->process( |
---|
| 107 | test => $test, |
---|
| 108 | nodelete => $nodelete, |
---|
| 109 | nocreate => $nocreate, |
---|
| 110 | ) or warn "Sync has failed\n"; |
---|
[83] | 111 | } |
---|
[197] | 112 | |
---|
| 113 | exit 0; |
---|