-
Notifications
You must be signed in to change notification settings - Fork 9
/
syncdiff
executable file
·151 lines (122 loc) · 4.76 KB
/
syncdiff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/perl
###########################################################################
# Copyright (C) 2014 John 'Warthog9' Hawley #
# #
# This file is originally part of SyncDiff(erent). #
# #
# This library is free software; you can redistribute it and/or #
# modify it under the terms of the GNU Lesser General Public #
# License as published by the Free Software Foundation; either #
# version 2.1 of the License, or (at your option) any later version. #
# #
# This library is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
# Lesser General Public License for more details. #
# #
# You should have received a copy of the GNU Lesser General Public #
# License along with this library; if not, write to the: #
# Free Software Foundation, Inc. #
# 51 Franklin Street #
# Fifth Floor #
# Boston, MA 02110-1301 #
# USA #
# #
# Or, see <http://www.gnu.org/licenses/>. #
###########################################################################
# Standard includes:
use Getopt::Long;
Getopt::Long::Configure(
qw(
bundling
no_getopt_compat
posix_default
no_ignore_case
gnu_compat
));
use POSIX ":sys_wait_h";
# Local program includes
use FileSync::SyncDiff::Config;
use FileSync::SyncDiff::Scanner;
use FileSync::SyncDiff::DB;
use FileSync::SyncDiff::File;
use FileSync::SyncDiff::Server;
use FileSync::SyncDiff::Client;
# Debugging includes
use Data::Dumper;
## End includes
# Setup things:
$main::VERSION = '0.01';
sub display_help {
print "Right now, there is no helping anyone.\n";
print "If you are running this you had better be John 'Warthog9' Hawley\n";
}
#
# Run something
#
# Setup the argument handling, can't do much
# till we've procssed all of that
my $config_file;
my $run_as_server;
my $get_version;
my $get_help;
my $run_only_scan;
GetOptions (
"c|config=s" => \$config_file, # string
"s|server" => \$run_as_server,
"scan" => \$run_only_scan,
"v|version" => \$get_version,
"h|?|help" => \$get_help,
);
print "Config File: ". $config_file ."\n";
print "Run as Server? ". $run_as_server ."\n";
print "Get Version? ". $get_version ."\n";
if( $get_version ){
print "Version: ". $main::VERSION ."\n";
exit(0);
}
if( $get_help ){
display_help();
exit(0);
}
#
# Load up the Configuration file
#
if( ! defined $config_file ){
$config_file = "syncdiff.cfg";
}
#print "---------------------------\n";
#print "config file:\n";
#print "---------------------------\n";
#print Dumper $config_file;
#print "^^^^^^^^^^^^^^^^^^^^^^^^^^^\n";
my $config = FileSync::SyncDiff::Config->new();
$config->read_config( $config_file );
# End opening and parsing the config file
# $config now exists and can be passed around
# as needed
my $dbconnection = FileSync::SyncDiff::DB->new( config => $config );
$dbconnection->file( "psync.sqlite" );
$dbconnection->connect_and_fork();
if( $run_only_scan ){
FileSync::SyncDiff::Scanner->full_scan( $config, $dbconnection );
exit(0);
} # end if( $run_only_scan )
if( $run_as_server ){
my $server = FileSync::SyncDiff::Server->new( config => $config->config, dbref => $dbconnection );
$server->run();
exit(0);
}
#print Dumper $config->config;
foreach $group_name ( keys %{ $config->config->{groups} } ){
print "Main client loop - group: ". $group_name ."\n";
foreach $base ( @{ $config->config->{groups}->{$group_name}->{patterns} } ){
my $client = FileSync::SyncDiff::Client->new( config_options => $config->get_group_config( $group_name ), group => $group_name, groupbase => $base, groupbase_path => $config->get_truepath( $base ), dbref => $dbconnection );
$client->fork_and_connect();
} # end base foreach
} # end group_name foreach
#my $config = FileSync::SyncDiff::Config->new();
#
#$config->read_config('csync2.cfg');