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