diff options
Diffstat (limited to 'utilities/installmgr.cpp')
-rw-r--r-- | utilities/installmgr.cpp | 160 |
1 files changed, 126 insertions, 34 deletions
diff --git a/utilities/installmgr.cpp b/utilities/installmgr.cpp index 60fc7ce..d4a8cb2 100644 --- a/utilities/installmgr.cpp +++ b/utilities/installmgr.cpp @@ -1,3 +1,20 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program 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 + * General Public License for more details. + * + */ + #include <swmgr.h> #include <installmgr.h> #include <filemgr.h> @@ -16,19 +33,70 @@ using std::map; SWMgr *mgr; InstallMgr *installMgr; +SWBuf baseDir; +SWBuf confPath; + + +class MyInstallMgr : public InstallMgr { +public: + MyInstallMgr(const char *privatePath = "./") : InstallMgr(privatePath) {} + +virtual bool isUserDisclaimerConfirmed() const { + static bool confirmed = false; + if (!confirmed) { + cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; + cout << " -=+* WARNING *+=- -=+* WARNING *+=-\n\n\n"; + cout << "Although Install Manager provides a convenient way for installing\n"; + cout << "and upgrading SWORD components, it also uses a systematic method\n"; + cout << "for accessing sites which gives packet sniffers a target to lock\n"; + cout << "into for singling out users. \n\n\n"; + cout << "IF YOU LIVE IN A PERSECUTED COUNTRY AND DO NOT WISH TO RISK DETECTION,\n"; + cout << "YOU SHOULD *NOT* USE INSTALL MANAGER'S REMOTE SOURCE FEATURES.\n\n\n"; + cout << "Also, Remote Sources other than CrossWire may contain less than\n"; + cout << "quality modules, modules with unorthodox content, or even modules\n"; + cout << "which are not legitimately distributable. Many repositories\n"; + cout << "contain wonderfully useful content. These repositories simply\n"; + cout << "are not reviewed or maintained by CrossWire and CrossWire\n"; + cout << "cannot be held responsible for their content. CAVEAT EMPTOR.\n\n\n"; + cout << "If you understand this and are willing to enable remote source features\n"; + cout << "then type yes at the prompt\n\n"; + cout << "enable? [no] "; + + char prompt[10]; + fgets(prompt, 9, stdin); + confirmed = (!strcmp(prompt, "yes\n")); + } + return confirmed; +} + +}; + +void init() { + mgr = new SWMgr(); + SWBuf baseDir = mgr->getHomeDir(); + if (baseDir.length() < 1) baseDir = "."; + baseDir += "/.sword/InstallMgr"; + confPath = baseDir + "/InstallMgr.conf"; + installMgr = new MyInstallMgr(baseDir); +} + +// clean up and exit if status is 0 or negative error code void finish(int status) { delete installMgr; delete mgr; - cout << "\n"; - exit(status); + if (status < 1) { + cout << "\n"; + exit(status); + } } void usage(const char *progName) { fprintf(stderr, "usage: %s <option>\nOptions:\n" "\t-init\t\t\t\tcreate a basic user config file.\n" + "\t-sc\t\t\t\tsync config with known remote repo list\n" "\t\t\t\t\t\tWARNING: overwrites existing.\n" "\t-l\t\t\t\tlist installed modules\n" "\t-u <modName>\t\t\tuninstall module\n" @@ -44,24 +112,8 @@ void usage(const char *progName) { } -void initConfig() { - cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; - cout << " -=+* WARNING *+=- -=+* WARNING *+=-\n\n\n"; - cout << "Although Install Manager provides a convenient way for installing\n"; - cout << "and upgrading SWORD components, it also uses a systematic method\n"; - cout << "for accessing sites which gives packet sniffers a target to lock\n"; - cout << "into for singling out users. \n\n\n"; - cout << "IF YOU LIVE IN A PERSECUTED COUNTRY AND DO NOT WISH TO RISK DETECTION,\n"; - cout << "YOU SHOULD *NOT* USE INSTALL MANAGER'S REMOTE SOURCE FEATURES.\n\n\n"; - cout << "if you understand this and are willing to enable remote source features\n"; - cout << "then type yes at the prompt\n\n"; - cout << "enable? [no] "; - char prompt[10]; - fgets(prompt, 9, stdin); - bool enable = (!strcmp(prompt, "yes\n")); - char *envhomedir = getenv ("HOME"); - SWBuf confPath = (envhomedir) ? envhomedir : "."; - confPath += "/.sword/InstallMgr/InstallMgr.conf"; +void createBasicConfig(bool enableRemote, bool addCrossWire) { + FileMgr::createParent(confPath.c_str()); remove(confPath.c_str()); @@ -72,21 +124,56 @@ void initConfig() { SWConfig config(confPath.c_str()); config["General"]["PassiveFTP"] = "true"; - if (enable) { + if (enableRemote) { config["Sources"]["FTPSource"] = is.getConfEnt(); } config.Save(); +} + + +void initConfig() { + + bool enable = installMgr->isUserDisclaimerConfirmed(); + + createBasicConfig(enable, true); + cout << "\n\nInitialized basic config file at [" << confPath << "]\n"; cout << "with remote source features " << ((enable) ? "ENABLED" : "DISABLED") << "\n"; } -void listModules(SWMgr *mgr) { +void syncConfig() { + + if (!installMgr->isUserDisclaimerConfirmed()) { // assert disclaimer is accepted + cout << "\n\nDisclaimer not accepted. Aborting."; + return; + } + + if (!FileMgr::existsFile(confPath.c_str())) { + createBasicConfig(true, false); + finish(1); // cleanup and don't exit + init(); // re-init with InstallMgr which uses our new config + } + + if (!installMgr->refreshRemoteSourceConfiguration()) + cout << "\nSync'd config file with master remote source list.\n"; + else cout << "\nFailed to sync config file with master remote source list.\n"; +} + + +void listModules(SWMgr *otherMgr) { cout << "Installed Modules:\n\n"; SWModule *module; - for (ModMap::iterator it = mgr->Modules.begin(); it != mgr->Modules.end(); it++) { - module = it->second; - cout << "[" << module->Name() << "] \t- " << module->Description() << "\n"; + std::map<SWModule *, int> mods = InstallMgr::getModuleStatus(*mgr, *otherMgr); + for (std::map<SWModule *, int>::iterator it = mods.begin(); it != mods.end(); it++) { + module = it->first; + SWBuf version = module->getConfigEntry("Version"); + SWBuf status = " "; + if (it->second & InstallMgr::MODSTAT_NEW) status = "*"; + if (it->second & InstallMgr::MODSTAT_OLDER) status = "-"; + if (it->second & InstallMgr::MODSTAT_UPDATED) status = "+"; + + cout << status << "[" << module->Name() << "] \t(" << version << ") \t- " << module->Description() << "\n"; } } @@ -108,9 +195,9 @@ void listRemoteSources() { cout << "Remote Sources:\n\n"; for (InstallSourceMap::iterator it = installMgr->sources.begin(); it != installMgr->sources.end(); it++) { cout << "[" << it->second->caption << "]\n"; - cout << "\tType ; " << it->second->type << "\n"; - cout << "\tSource ; " << it->second->source << "\n"; - cout << "\tDirectory; " << it->second->directory << "\n"; + cout << "\tType : " << it->second->type << "\n"; + cout << "\tSource : " << it->second->source << "\n"; + cout << "\tDirectory: " << it->second->directory << "\n"; } } @@ -121,6 +208,7 @@ void refreshRemoteSource(const char *sourceName) { fprintf(stderr, "Couldn't find remote source [%s]\n", sourceName); finish(-3); } + if (!installMgr->refreshRemoteSource(source->second)) cout << "Remote Source Refreshed\n"; else cerr << "Error Refreshing Remote Source\n"; @@ -182,6 +270,7 @@ void remoteInstallModule(const char *sourceName, const char *modName) { finish(-4); } module = it->second; + int error = installMgr->installModule(mgr, 0, module->Name(), is); if (error) { cout << "Error installing module: [" << module->Name() << "] (write permissions?)\n"; @@ -207,11 +296,7 @@ void localDirInstallModule(const char *dir, const char *modName) { int main(int argc, char **argv) { - mgr = new SWMgr(); - char *envhomedir = getenv ("HOME"); - SWBuf baseDir = (envhomedir) ? envhomedir : "."; - baseDir += "/.sword/InstallMgr"; - installMgr = new InstallMgr(baseDir); + init(); SWLog::getSystemLog()->setLogLevel(SWLog::LOG_DEBUG); @@ -251,7 +336,14 @@ int main(int argc, char **argv) { uninstallModule(argv[2]); break; case 's': - listRemoteSources(); + switch (argv[1][2]) { + case 0: // -s list sources + listRemoteSources(); + break; + case 'c': // -sc sync config with master + syncConfig(); + break; + } break; case 'r': // remote option switch (argv[1][2]) { |