The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
installmgr.cpp File Reference
#include <swmgr.h>
#include <installmgr.h>
#include <remotetrans.h>
#include <filemgr.h>
#include <iostream>
#include <map>
#include <swmodule.h>
#include <swoptfilter.h>
#include <stdio.h>
#include <swlog.h>
#include <swversion.h>
+ Include dependency graph for installmgr.cpp:

Go to the source code of this file.

Classes

class  MyInstallMgr
 
class  MyStatusReporter
 

Functions

void createBasicConfig (bool enableRemote, bool addCrossWire, bool unverifiedPeerAllowed)
 
void finish (int status)
 
void init ()
 
void initConfig ()
 
bool isUnverifiedPeerAllowed ()
 
void listModules (SWMgr *otherMgr=0, bool onlyNewAndUpdates=false, bool utilModules=false)
 
void listRemoteSources ()
 
void localDirInstallModule (const char *dir, const char *modName)
 
void localDirListModules (const char *dir)
 
int main (int argc, char **argv)
 
void refreshRemoteSource (const char *sourceName)
 
void remoteDescribeModule (const char *sourceName, const char *modName)
 
void remoteInstallModule (const char *sourceName, const char *modName)
 
void remoteListModules (const char *sourceName, bool onlyNewAndUpdated=false, bool utilModules=false)
 
void syncConfig ()
 
void uninstallModule (const char *modName)
 
void usage (const char *progName=0, const char *error=0)
 

Variables

SWBuf baseDir
 
SWBuf confPath
 
InstallMgrinstallMgr = 0
 
bool isConfirmedByForce
 
bool isUnvPeerAllowed
 
SWMgrmgr = 0
 
StatusReporterstatusReporter = 0
 

Function Documentation

void createBasicConfig ( bool  enableRemote,
bool  addCrossWire,
bool  unverifiedPeerAllowed 
)

Definition at line 200 of file installmgr.cpp.

200  {
201 
203  remove(confPath.c_str());
204 
205  InstallSource is("FTP");
206  is.caption = "CrossWire";
207  is.source = "ftp.crosswire.org";
208  is.directory = "/pub/sword/raw";
209 
210  SWConfig config(confPath.c_str());
211  config["General"]["PassiveFTP"] = "true";
212  config["General"]["TimeoutMillis"] = "10000";
213  config["General"]["UnverifiedPeerAllowed"] = (unverifiedPeerAllowed) ? "true" : "false";
214  if (enableRemote) {
215  config["Sources"]["FTPSource"] = is.getConfEnt();
216  }
217  config.save();
218 }
SWBuf confPath
Definition: installmgr.cpp:50
static int createParent(const char *pName)
Definition: filemgr.cpp:426
virtual void save() const
Definition: swconfig.cpp:115
void finish ( int  status)

Definition at line 185 of file installmgr.cpp.

185  {
186  delete statusReporter;
187  delete installMgr;
188  delete mgr;
189 
190  installMgr = 0;
191  mgr = 0;
192 
193  if (status < 1) {
194  cout << "\n";
195  exit(status);
196  }
197 }
InstallMgr * installMgr
Definition: installmgr.cpp:47
StatusReporter * statusReporter
Definition: installmgr.cpp:48
SWMgr * mgr
Definition: installmgr.cpp:46
void init ( )

Definition at line 164 of file installmgr.cpp.

164  {
165  if (!mgr) {
166  mgr = new SWMgr();
167 
168  if (!mgr->config)
169  usage(0, "ERROR: SWORD configuration not found. Please configure SWORD before using this program.");
170 
171  SWBuf baseDir = FileMgr::getSystemFileMgr()->getHomeDir();
172  if (baseDir.length() < 1) baseDir = ".";
173  baseDir += "/.sword/InstallMgr";
174  confPath = baseDir + "/InstallMgr.conf";
176  installMgr = new MyInstallMgr(baseDir, statusReporter);
177  if (isConfirmedByForce) {
179  }
180  }
181 }
bool isConfirmedByForce
Definition: installmgr.cpp:52
SWBuf baseDir
Definition: installmgr.cpp:49
SWBuf confPath
Definition: installmgr.cpp:50
InstallMgr * installMgr
Definition: installmgr.cpp:47
StatusReporter * statusReporter
Definition: installmgr.cpp:48
void setUserDisclaimerConfirmed(bool val)
Definition: installmgr.h:214
void usage(const char *app)
Definition: imp2gbs.cpp:65
SWMgr * mgr
Definition: installmgr.cpp:46
static FileMgr * getSystemFileMgr()
Definition: filemgr.cpp:101
void initConfig ( )

Definition at line 221 of file installmgr.cpp.

221  {
222  init();
223 
224  bool enable = installMgr->isUserDisclaimerConfirmed();
225  bool allowed = isUnverifiedPeerAllowed();
226 
227  createBasicConfig(enable, true, allowed);
228 
229  cout << "\n\nInitialized basic config file at [" << confPath << "]\n";
230  cout << "with remote source features " << ((enable) ? "ENABLED" : "DISABLED") << "\n";
231  cout << "with unverified peers " << ((allowed) ? "ALLOWED" : "DISALLOWED") << "\n";
232 }
SWBuf confPath
Definition: installmgr.cpp:50
InstallMgr * installMgr
Definition: installmgr.cpp:47
bool isUnverifiedPeerAllowed()
Definition: installmgr.cpp:110
void init()
Definition: installmgr.cpp:164
void createBasicConfig(bool enableRemote, bool addCrossWire, bool unverifiedPeerAllowed)
Definition: installmgr.cpp:200
virtual bool isUserDisclaimerConfirmed() const
Definition: installmgr.cpp:777
bool isUnverifiedPeerAllowed ( )

Definition at line 110 of file installmgr.cpp.

110  {
111  static bool allowed = false;
112 
113  if (isUnvPeerAllowed) {
114  allowed = true;
115  }
116  if (!allowed) {
117  cout << "\n\n";
118  cout << "While connecting to an encrypted install source, SWORD can allow\n";
119  cout << "unverified peers, e.g., self-signed certificates. While this is\n";
120  cout << "generally considered safe because SWORD only retrieves Bible content\n";
121  cout << "and does not send any data to the server, it could still possibly\n";
122  cout << "allow a malicious actor to sit between you and the server, as with\n";
123  cout << "unencrypted sources. Type no to turn this off.\n\n";
124  cout << "Would you like to allow unverified peers? [yes] ";
125 
126  char prompt[10];
127  fgets(prompt, 9, stdin);
128  allowed = (strcmp(prompt, "no\n"));
129  cout << "\n";
130  }
131  return allowed;
132 }
bool isUnvPeerAllowed
Definition: installmgr.cpp:53
void listModules ( SWMgr otherMgr = 0,
bool  onlyNewAndUpdates = false,
bool  utilModules = false 
)

Definition at line 294 of file installmgr.cpp.

294  {
295  init();
296  SWModule *module;
297  if (!otherMgr) otherMgr = mgr;
298  std::map<SWModule *, int> mods = InstallMgr::getModuleStatus(*mgr, *otherMgr, utilModules);
299  for (std::map<SWModule *, int>::iterator it = mods.begin(); it != mods.end(); it++) {
300  module = it->first;
301  SWBuf version = module->getConfigEntry("Version");
302  SWBuf status = " ";
303  if (it->second & InstallMgr::MODSTAT_NEW) status = "*";
304  if (it->second & InstallMgr::MODSTAT_OLDER) status = "-";
305  if (it->second & InstallMgr::MODSTAT_UPDATED) status = "+";
306 
307  if (!onlyNewAndUpdates || status == "*" || status == "+") {
308  cout << status << "[" << module->getName() << "] \t(" << version << ") \t- " << module->getDescription() << "\n";
309  }
310  }
311 }
static const unsigned int MODSTAT_OLDER
Definition: installmgr.h:99
SWText * module
Definition: osis2mod.cpp:105
static const unsigned int MODSTAT_NEW
Definition: installmgr.h:102
static std::map< SWModule *, int > getModuleStatus(const SWMgr &base, const SWMgr &other, bool utilModules=false)
Definition: installmgr.cpp:592
void init()
Definition: installmgr.cpp:164
static const unsigned int MODSTAT_UPDATED
Definition: installmgr.h:101
SWMgr * mgr
Definition: installmgr.cpp:46
void listRemoteSources ( )

Definition at line 268 of file installmgr.cpp.

268  {
269  init();
270  cout << "Remote Sources:\n\n";
271  for (InstallSourceMap::iterator it = installMgr->sources.begin(); it != installMgr->sources.end(); it++) {
272  cout << "[" << it->second->caption << "]\n";
273  cout << "\tType : " << it->second->type << "\n";
274  cout << "\tSource : " << it->second->source << "\n";
275  cout << "\tDirectory: " << it->second->directory << "\n";
276  }
277 }
InstallMgr * installMgr
Definition: installmgr.cpp:47
void init()
Definition: installmgr.cpp:164
InstallSourceMap sources
Definition: installmgr.h:111
void localDirInstallModule ( const char *  dir,
const char *  modName 
)

Definition at line 383 of file installmgr.cpp.

383  {
384  init();
385  SWMgr lmgr(dir);
386  SWModule *module = lmgr.getModule(modName);
387  if (!module) {
388  fprintf(stderr, "Module [%s] not available at path [%s]\n", modName, dir);
389  finish(-4);
390  }
391  int error = installMgr->installModule(mgr, dir, module->getName());
392  if (error) {
393  cout << "\nError installing module: [" << module->getName() << "] (write permissions?)\n";
394  } else cout << "\nInstalled module: [" << module->getName() << "]\n";
395 }
void finish(int status)
Definition: installmgr.cpp:185
InstallMgr * installMgr
Definition: installmgr.cpp:47
SWText * module
Definition: osis2mod.cpp:105
void init()
Definition: installmgr.cpp:164
virtual int installModule(SWMgr *destMgr, const char *fromLocation, const char *modName, InstallSource *is=0)
Definition: installmgr.cpp:394
SWMgr * mgr
Definition: installmgr.cpp:46
void localDirListModules ( const char *  dir)

Definition at line 354 of file installmgr.cpp.

354  {
355  cout << "Available Modules:\n\n";
356  SWMgr mgr(dir);
357  listModules(&mgr);
358 }
void listModules(SWMgr *otherMgr=0, bool onlyNewAndUpdates=false, bool utilModules=false)
Definition: installmgr.cpp:294
SWMgr * mgr
Definition: installmgr.cpp:46
int main ( int  argc,
char **  argv 
)

Definition at line 436 of file installmgr.cpp.

436  {
437 
438  isConfirmedByForce = false;
439  isUnvPeerAllowed = false;
440 
441  if (argc < 2) usage(*argv);
442 
443  for (int i = 1; i < argc; i++) {
444  if (!strcmp(argv[i], "-d")) {
446  }
447  else if (!strcmp(argv[i], "--allow-internet-access-and-risk-tracing-and-jail-or-martyrdom")) {
448  isConfirmedByForce = true;
449  }
450  else if (!strcmp(argv[i], "--allow-unverified-tls-peer")) {
451  isUnvPeerAllowed = true;
452  }
453  else if (!strcmp(argv[i], "-init")) {
454  initConfig();
455  }
456  else if (!strcmp(argv[i], "-l")) { // list installed user modules
457  cout << "Installed User Modules:\n\n";
458  listModules();
459  }
460  else if (!strcmp(argv[i], "-lu")) { // list installed utility modules
461  cout << "Installed Utility Modules:\n\n";
462  listModules(0, false, true);
463  }
464  else if (!strcmp(argv[i], "-ll")) { // list from local directory
465  if (i+1 < argc) localDirListModules(argv[++i]);
466  else usage(*argv, "-ll requires <path>");
467  }
468  else if (!strcmp(argv[i], "-li")) { // install from local directory
469  if (i+2 < argc) {
470  const char *path = argv[++i];
471  const char *modName = argv[++i];
472  localDirInstallModule(path, modName);
473  }
474  else usage(*argv, "-li requires <path> <modName>");
475  }
476  else if (!strcmp(argv[i], "-u")) { // uninstall module
477  if (i+1 < argc) uninstallModule(argv[++i]);
478  else usage(*argv, "-u requires <modName>");
479  }
480  else if (!strcmp(argv[i], "-s")) { // list sources
482  }
483  else if (!strcmp(argv[i], "-sc")) { // sync config with master
484  syncConfig();
485  }
486  else if (!strcmp(argv[i], "-r")) { // refresh remote source
487  if (i+1 < argc) refreshRemoteSource(argv[++i]);
488  else usage(*argv, "-r requires <remoteSrcName>");
489  }
490  else if (!strcmp(argv[i], "-rl")) { // list remote user modules
491  if (i+1 < argc) remoteListModules(argv[++i]);
492  else usage(*argv, "-rl requires <remoteSrcName>");
493  }
494  else if (!strcmp(argv[i], "-rlu")) { // list remote utility modules
495  if (i+1 < argc) remoteListModules(argv[++i], false, true);
496  else usage(*argv, "-rlu requires <remoteSrcName>");
497  }
498  else if (!strcmp(argv[i], "-rd")) { // list differences between remote source and installed user modules
499  if (i+1 < argc) remoteListModules(argv[++i], true);
500  else usage(*argv, "-rd requires <remoteSrcName>");
501  }
502  else if (!strcmp(argv[i], "-rdu")) { // list differences between remote source and installed utility modules
503  if (i+1 < argc) remoteListModules(argv[++i], true, true);
504  else usage(*argv, "-rdu requires <remoteSrcName>");
505  }
506  else if (!strcmp(argv[i], "-rdesc")) { // describe remove module
507  if (i+2 < argc) {
508  const char *source = argv[++i];
509  const char *modName = argv[++i];
510  remoteDescribeModule(source, modName);
511  }
512  else usage(*argv, "-rdesc requires <remoteSrcName> <modName>");
513  }
514  else if (!strcmp(argv[i], "-ri")) { // install from remote directory
515  if (i+2 < argc) {
516  const char *source = argv[++i];
517  const char *modName = argv[++i];
518  remoteInstallModule(source, modName);
519  }
520  else usage(*argv, "-ri requires <remoteSrcName> <modName>");
521  }
522  else usage(*argv, (((SWBuf)"Unknown argument: ")+ argv[i]).c_str());
523  }
524 
525  finish(0);
526 
527  return 0;
528 }
bool isConfirmedByForce
Definition: installmgr.cpp:52
void finish(int status)
Definition: installmgr.cpp:185
void remoteListModules(const char *sourceName, bool onlyNewAndUpdated=false, bool utilModules=false)
Definition: installmgr.cpp:314
static SWLog * getSystemLog()
Definition: swlog.cpp:53
void localDirListModules(const char *dir)
Definition: installmgr.cpp:354
void initConfig()
Definition: installmgr.cpp:221
void syncConfig()
Definition: installmgr.cpp:235
void refreshRemoteSource(const char *sourceName)
Definition: installmgr.cpp:280
void uninstallModule(const char *modName)
Definition: installmgr.cpp:256
void localDirInstallModule(const char *dir, const char *modName)
Definition: installmgr.cpp:383
void listModules(SWMgr *otherMgr=0, bool onlyNewAndUpdates=false, bool utilModules=false)
Definition: installmgr.cpp:294
bool isUnvPeerAllowed
Definition: installmgr.cpp:53
void usage(const char *app)
Definition: imp2gbs.cpp:65
void listRemoteSources()
Definition: installmgr.cpp:268
void setLogLevel(char level)
Definition: swlog.h:54
void remoteInstallModule(const char *sourceName, const char *modName)
Definition: installmgr.cpp:361
void remoteDescribeModule(const char *sourceName, const char *modName)
Definition: installmgr.cpp:326
static const char LOG_DEBUG
Definition: swlog.h:46
void refreshRemoteSource ( const char *  sourceName)

Definition at line 280 of file installmgr.cpp.

280  {
281  init();
282  InstallSourceMap::iterator source = installMgr->sources.find(sourceName);
283  if (source == installMgr->sources.end()) {
284  fprintf(stderr, "Couldn't find remote source [%s]\n", sourceName);
285  finish(-3);
286  }
287 
288  if (!installMgr->refreshRemoteSource(source->second))
289  cout << "\nRemote Source Refreshed\n";
290  else cerr << "\nError Refreshing Remote Source\n";
291 }
void finish(int status)
Definition: installmgr.cpp:185
InstallMgr * installMgr
Definition: installmgr.cpp:47
void init()
Definition: installmgr.cpp:164
InstallSourceMap sources
Definition: installmgr.h:111
virtual int refreshRemoteSource(InstallSource *is)
Definition: installmgr.cpp:550
void remoteDescribeModule ( const char *  sourceName,
const char *  modName 
)

Definition at line 326 of file installmgr.cpp.

326  {
327  init();
328  InstallSourceMap::iterator source = installMgr->sources.find(sourceName);
329  if (source == installMgr->sources.end()) {
330  fprintf(stderr, "Couldn't find remote source [%s]\n", sourceName);
331  finish(-3);
332  }
333  SWMgr *mgr = source->second->getMgr();
334  SWModule *m = mgr->getModule(modName);
335  if (!m) {
336  fprintf(stderr, "Couldn't find module [%s] in source [%s]\n", modName, sourceName);
337  finish(-3);
338  }
339  cout << "Module Description\n\n";
340  for (ConfigEntMap::const_iterator it = m->getConfig().begin(); it != m->getConfig().end(); ++it) {
341  cout << "[" << it->first << "]:" << it->second << "\n";
342  }
343  cout << "\nOption Features available for module: " << m->getName() << "\n\n";
344  for (OptionFilterList::const_iterator it = m->getOptionFilters().begin(); it != m->getOptionFilters().end(); ++it) {
345  cout << (*it)->getOptionName() << " (" << (*it)->getOptionTip() << ")\n";
346  StringList optionValues = (*it)->getOptionValues();
347  for (StringList::const_iterator it2 = optionValues.begin(); it2 != optionValues.end(); ++it2) {
348  cout << "\t" << *it2 << "\n";
349  }
350  }
351 }
void finish(int status)
Definition: installmgr.cpp:185
InstallMgr * installMgr
Definition: installmgr.cpp:47
void init()
Definition: installmgr.cpp:164
std::list< SWBuf > StringList
Definition: swmodule.cpp:91
InstallSourceMap sources
Definition: installmgr.h:111
SWMgr * mgr
Definition: installmgr.cpp:46
void remoteInstallModule ( const char *  sourceName,
const char *  modName 
)

Definition at line 361 of file installmgr.cpp.

361  {
362  init();
363  InstallSourceMap::iterator source = installMgr->sources.find(sourceName);
364  if (source == installMgr->sources.end()) {
365  fprintf(stderr, "Couldn't find remote source [%s]\n", sourceName);
366  finish(-3);
367  }
368  InstallSource *is = source->second;
369  SWMgr *rmgr = is->getMgr();
370  SWModule *module = rmgr->getModule(modName);
371  if (!module) {
372  fprintf(stderr, "Remote source [%s] does not make available module [%s]\n", sourceName, modName);
373  finish(-4);
374  }
375 
376  int error = installMgr->installModule(mgr, 0, module->getName(), is);
377  if (error) {
378  cout << "\nError installing module: [" << module->getName() << "] (write permissions?)\n";
379  } else cout << "\nInstalled module: [" << module->getName() << "]\n";
380 }
void finish(int status)
Definition: installmgr.cpp:185
SWMgr * getMgr()
Definition: installmgr.cpp:749
InstallMgr * installMgr
Definition: installmgr.cpp:47
SWText * module
Definition: osis2mod.cpp:105
void init()
Definition: installmgr.cpp:164
InstallSourceMap sources
Definition: installmgr.h:111
virtual int installModule(SWMgr *destMgr, const char *fromLocation, const char *modName, InstallSource *is=0)
Definition: installmgr.cpp:394
SWMgr * mgr
Definition: installmgr.cpp:46
void remoteListModules ( const char *  sourceName,
bool  onlyNewAndUpdated = false,
bool  utilModules = false 
)

Definition at line 314 of file installmgr.cpp.

314  {
315  init();
316  cout << "Available Modules:\n(be sure to refresh remote source (-r) first for most current list)\n\n";
317  InstallSourceMap::iterator source = installMgr->sources.find(sourceName);
318  if (source == installMgr->sources.end()) {
319  fprintf(stderr, "Couldn't find remote source [%s]\n", sourceName);
320  finish(-3);
321  }
322  listModules(source->second->getMgr(), onlyNewAndUpdated, utilModules);
323 }
void finish(int status)
Definition: installmgr.cpp:185
InstallMgr * installMgr
Definition: installmgr.cpp:47
void init()
Definition: installmgr.cpp:164
void listModules(SWMgr *otherMgr=0, bool onlyNewAndUpdates=false, bool utilModules=false)
Definition: installmgr.cpp:294
InstallSourceMap sources
Definition: installmgr.h:111
void syncConfig ( )

Definition at line 235 of file installmgr.cpp.

235  {
236  init();
237 
238  if (!installMgr->isUserDisclaimerConfirmed()) { // assert disclaimer is accepted
239  cout << "\n\nDisclaimer not accepted. Aborting.";
240  return;
241  }
242 
243  // be sure we have at least some config file already out there
244  if (!FileMgr::existsFile(confPath.c_str())) {
245  createBasicConfig(true, false, false);
246  finish(1); // cleanup and don't exit
247  init(); // re-init with InstallMgr which uses our new config
248  }
249 
251  cout << "\nSync'd config file with master remote source list.\n";
252  else cout << "\nFailed to sync config file with master remote source list.\n";
253 }
static signed char existsFile(const char *ipath, const char *ifileName=0)
Definition: filemgr.cpp:337
virtual int refreshRemoteSourceConfiguration()
Definition: installmgr.cpp:645
void finish(int status)
Definition: installmgr.cpp:185
SWBuf confPath
Definition: installmgr.cpp:50
InstallMgr * installMgr
Definition: installmgr.cpp:47
void init()
Definition: installmgr.cpp:164
void createBasicConfig(bool enableRemote, bool addCrossWire, bool unverifiedPeerAllowed)
Definition: installmgr.cpp:200
virtual bool isUserDisclaimerConfirmed() const
Definition: installmgr.cpp:777
void uninstallModule ( const char *  modName)

Definition at line 256 of file installmgr.cpp.

256  {
257  init();
258  SWModule *module = mgr->getModule(modName);
259  if (!module) {
260  fprintf(stderr, "Couldn't find module [%s] to remove\n", modName);
261  finish(-2);
262  }
263  installMgr->removeModule(mgr, module->getName());
264  cout << "Removed module: [" << modName << "]\n";
265 }
void finish(int status)
Definition: installmgr.cpp:185
InstallMgr * installMgr
Definition: installmgr.cpp:47
SWText * module
Definition: osis2mod.cpp:105
void init()
Definition: installmgr.cpp:164
virtual int removeModule(SWMgr *manager, const char *modName)
Definition: installmgr.cpp:241
SWMgr * mgr
Definition: installmgr.cpp:46
void usage ( const char *  progName = 0,
const char *  error = 0 
)

Variable Documentation

SWBuf baseDir

Definition at line 49 of file installmgr.cpp.

SWBuf confPath

Definition at line 50 of file installmgr.cpp.

InstallMgr* installMgr = 0

Definition at line 47 of file installmgr.cpp.

bool isConfirmedByForce

Definition at line 52 of file installmgr.cpp.

bool isUnvPeerAllowed

Definition at line 53 of file installmgr.cpp.

SWMgr* mgr = 0

Definition at line 46 of file installmgr.cpp.

StatusReporter* statusReporter = 0

Definition at line 48 of file installmgr.cpp.