7 #include <boost/program_options.hpp>
10 #include "zmart-sources.h"
11 #include "zmart-misc.h"
13 #include "zmart-rpm-callbacks.h"
14 #include "zmart-keyring-callbacks.h"
15 #include "zmart-source-callbacks.h"
17 using namespace zypp::detail;
21 using namespace boost;
23 namespace po = boost::program_options;
29 RpmCallbacks rpm_callbacks;
30 SourceCallbacks source_callbacks;
32 int main(int argc, char **argv)
34 po::positional_options_description pos_options;
35 pos_options.add("command", -1);
37 po::options_description general_options("General options");
38 general_options.add_options()
39 ("help,h", "produce a help message")
40 ("version,v", "output the version number")
43 po::options_description operation_options("Operations");
44 operation_options.add_options()
45 ("install,i", po::value< vector<string> >(), "install packages or resolvables")
46 ("list-system-sources,l", "Show available system sources")
47 ("add-source,a", po::value< string >(), "Add a new source from a URL")
50 po::options_description source_options("Source options");
51 source_options.add_options()
52 ("disable-system-sources,D", "Don't read the system sources.")
53 ("sources,S", po::value< vector<string> >(), "Read from additional sources")
56 po::options_description target_options("Target options");
57 target_options.add_options()
58 ("disable-system-resolvables,T", "Don't read system installed resolvables.")
61 // Declare an options description instance which will include
63 po::options_description all_options("Allowed options");
64 all_options.add(general_options).add(source_options).add(operation_options).add(target_options);
66 // Declare an options description instance which will be shown
68 po::options_description visible_options("Allowed options");
69 visible_options.add(general_options).add(source_options).add(operation_options).add(target_options);
72 //po::store(po::parse_command_line(argc, argv, visible_options), vm);
73 po::store(po::command_line_parser(argc, argv).options(visible_options).positional(pos_options).run(), vm);
77 if (vm.count("list-system-sources"))
81 cout << "Sorry, you need root privileges to view system sources." << endl;
85 list_system_sources();
89 if (vm.count("help")) {
90 cout << visible_options << "\n";
94 if (vm.count("disable-system-sources"))
96 MIL << "system sources disabled" << endl;
97 gSettings.disable_system_sources = true;
101 if ( geteuid() != 0 )
103 cout << "Sorry, you need root privileges to use system sources, disabling them..." << endl;
104 gSettings.disable_system_sources = true;
105 MIL << "system sources disabled" << endl;
109 MIL << "system sources enabled" << endl;
113 if (vm.count("add-source"))
115 string urlStr = vm["add-source"].as< string >();
120 catch ( const Exception & excpt_r )
122 ZYPP_CAUGHT( excpt_r );
123 cerr << "URL is invalid." << endl;
124 cerr << excpt_r.asUserString() << endl;
129 add_source_by_url(url, "aliasfixme");
131 catch ( const Exception & excpt_r )
133 cerr << excpt_r.asUserString() << endl;
140 if (vm.count("disable-system-resolvables"))
142 MIL << "system resolvables disabled" << endl;
143 cout << "Ignoring installed resolvables..." << endl;
144 gSettings.disable_system_resolvables = true;
147 if (vm.count("install"))
149 vector<string> to_install = vm["install"].as< vector<string> >();
150 //MIL << "Additional installs are: " << to_install << "\n";
151 for ( vector<string>::const_iterator it = to_install.begin(); it != to_install.end(); ++it )
153 gData.packages_to_install = to_install;
157 if (vm.count("sources"))
159 vector<string> sources = vm["sources"].as< vector<string> >();
160 //MIL << "Additional sources are: " << sources << "\n";
161 for ( vector<string>::const_iterator it = sources.begin(); it != sources.end(); ++it )
165 gSettings.additional_sources.push_back(Url(*it));
167 catch ( const Exception &e )
169 cout << "wrong url " << *it << std::endl;
175 const char *logfile = getenv("ZYPP_LOGFILE");
177 zypp::base::LogControl::instance().logfile( logfile );
179 zypp::base::LogControl::instance().logfile( ZYPP_CHECKPATCHES_LOG );
181 std::string previous_token;
186 God = zypp::getZYpp();
188 catch (Exception & excpt_r)
190 ZYPP_CAUGHT (excpt_r);
191 ERR << "a ZYpp transaction is already in progress." << endl;
192 cerr << "a ZYpp transaction is already in progress." << endl;
193 cout << RANDOM_TOKEN;
197 SourceManager_Ptr manager;
198 manager = SourceManager::sourceManager();
200 KeyRingCallbacks keyring_callbacks;
201 DigestCallbacks digest_callbacks;
203 if ( ! gSettings.disable_system_sources )
204 init_system_sources();
206 for ( std::list<Url>::const_iterator it = gSettings.additional_sources.begin(); it != gSettings.additional_sources.end(); ++it )
208 include_source_by_url( *it );
213 if ( gData.sources.empty() )
215 cout << "Warning! No sources. Operating only over the installed resolvables. You will not be able to install stuff" << endl;
219 God->initializeTarget("/");
221 std::string token = calculate_token();
223 if ( token != gSettings.previous_token )
228 if ( ! gSettings.disable_system_resolvables )
231 for ( vector<string>::const_iterator it = gData.packages_to_install.begin(); it != gData.packages_to_install.end(); ++it )
233 mark_package_for_install(*it);
240 if ( gData.security_patches_count > 0 )
243 if ( gData.patches_count > 0 )