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