1
/* This file is part of Strigi Desktop Search
3
* Copyright (C) 2006 Flavio Castelli <flavio.castelli@gmail.com>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public License
16
* along with this library; see the file COPYING.LIB. If not, write to
17
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
28
#include "daemonconfigurator.h"
30
#include "strigilogging.h"
35
* Check if log4cxx file exists, otherwise creates a default one
38
checkLogConf(const string& filename) {
39
std::fstream confFile;
40
confFile.open(filename.c_str(), std::ios::in);
41
if (!confFile.is_open()){
42
/*create the default configuration file*/
43
confFile.open(filename.c_str(), std::ios::out);
44
confFile << "# Set root logger level to DEBUG and its only appender to A1.\n";
45
confFile << "log4j.rootLogger=DEBUG, A1\n\n";
46
confFile << "# A1 is set to be a ConsoleAppender.\n";
47
confFile << "log4j.appender.A1=org.apache.log4j.ConsoleAppender\n";
48
confFile << "# A1 uses PatternLayout.\n";
49
confFile << "log4j.appender.A1.layout=org.apache.log4j.PatternLayout\n";
50
confFile << "log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n\n";
55
void loadConfFile(string file, set<string>& entries, string name)
60
unsigned int counter = 0;
62
confFile.open(file.c_str(), ios::in);
64
if (confFile.is_open())
67
while (!confFile.eof())
69
confFile.getline(buffer, 500);
74
set<string>::iterator iter;
75
iter = find(entries.begin(), entries.end(), line);
77
if (iter == entries.end())
81
entries.insert (line);
89
printf ("added %i new %s\n",counter, name.c_str());
94
printf ("Usage: strigiconfupdaterman [options]\n");
95
printf ("\t--merge-filters\tmerge old filters with new ones\n");
96
printf ("\t--merge-path\tmerge old paths with new ones\n");
97
printf ("\t-s\t\tsimulate, print to stdout\n");
98
printf ("\t-o filename\tsave new conf to filename\n");
101
int main(int argc,char *argv[])
109
string homedir = getenv("HOME");
110
string daemondir = homedir+"/.strigi";
111
string dirsfile = daemondir+"/dirstoindex";
112
string pathfilterfile = daemondir+"/pathfilter.conf";
113
string patternfilterfile = daemondir+"/patternfilter.conf";
114
string conffile = daemondir+"/daemon.conf";
115
string logconffile = daemondir+"/log.conf";
116
string confout = conffile;
117
bool mergeFilters = false;
118
bool mergePath = false;
123
checkLogConf(logconffile);
124
STRIGI_LOG_INIT(logconffile);
128
int option_index = 0;
131
static struct option long_options[] = {
132
{"merge-filters", 0, 0, 1},
133
{"merge-path", 0, 0, 2},
138
c = getopt_long (argc, argv, "h:o:s",
139
long_options, &option_index);
154
confout = string(optarg);
169
// init daemon configurator
170
DaemonConfigurator config (conffile);
172
// load path filtering rules
174
if (mergeFilters) // read existing rules, avoid duplicate rules creation
177
entries = config.readFilteringRules();
180
printf ("restoring ");
181
printf ("path filtering rules\n");
183
loadConfFile (pathfilterfile, entries, "path filtering rules");
184
config.saveFilteringRules(entries, PathFilter::RTTI, false);
188
// load pattern filtering rules
189
printf ("restoring pattern filtering rules\n");
190
loadConfFile (patternfilterfile, entries, "pattern filtering rules");
191
config.saveFilteringRules(entries, PatternFilter::RTTI, true);
195
// load dirs to index
198
entries = config.getIndexedDirectories();
202
printf ("restoring ");
203
printf ("indexed directories paths\n");
205
loadConfFile (dirsfile, entries, "indexed dirs paths");
206
config.setIndexedDirectories( entries, "localhost", mergePath);
210
printf ("writing new configuration file\n");
211
config.save (confout.c_str());
214
cout << endl << endl << config;