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("version")) {
95 cout << "zmart 0.1" << endl;
99 if (vm.count("disable-system-sources"))
101 MIL << "system sources disabled" << endl;
102 gSettings.disable_system_sources = true;
106 if ( geteuid() != 0 )
108 cout << "Sorry, you need root privileges to use system sources, disabling them..." << endl;
109 gSettings.disable_system_sources = true;
110 MIL << "system sources disabled" << endl;
114 MIL << "system sources enabled" << endl;
118 if (vm.count("add-source"))
120 string urlStr = vm["add-source"].as< string >();
125 catch ( const Exception & excpt_r )
127 ZYPP_CAUGHT( excpt_r );
128 cerr << "URL is invalid." << endl;
129 cerr << excpt_r.asUserString() << endl;
134 add_source_by_url(url, "aliasfixme");
136 catch ( const Exception & excpt_r )
138 cerr << excpt_r.asUserString() << endl;
145 if (vm.count("disable-system-resolvables"))
147 MIL << "system resolvables disabled" << endl;
148 cout << "Ignoring installed resolvables..." << endl;
149 gSettings.disable_system_resolvables = true;
152 if (vm.count("install"))
154 vector<string> to_install = vm["install"].as< vector<string> >();
155 //MIL << "Additional installs are: " << to_install << "\n";
156 for ( vector<string>::const_iterator it = to_install.begin(); it != to_install.end(); ++it )
158 gData.packages_to_install = to_install;
162 if (vm.count("sources"))
164 vector<string> sources = vm["sources"].as< vector<string> >();
165 //MIL << "Additional sources are: " << sources << "\n";
166 for ( vector<string>::const_iterator it = sources.begin(); it != sources.end(); ++it )
170 gSettings.additional_sources.push_back(Url(*it));
172 catch ( const Exception &e )
174 cout << "wrong url " << *it << std::endl;
180 const char *logfile = getenv("ZYPP_LOGFILE");
182 zypp::base::LogControl::instance().logfile( logfile );
184 zypp::base::LogControl::instance().logfile( ZYPP_CHECKPATCHES_LOG );
186 std::string previous_token;
191 God = zypp::getZYpp();
193 catch (Exception & excpt_r)
195 ZYPP_CAUGHT (excpt_r);
196 ERR << "a ZYpp transaction is already in progress." << endl;
197 cerr << "a ZYpp transaction is already in progress." << endl;
198 cout << RANDOM_TOKEN;
202 SourceManager_Ptr manager;
203 manager = SourceManager::sourceManager();
205 KeyRingCallbacks keyring_callbacks;
206 DigestCallbacks digest_callbacks;
208 if ( ! gSettings.disable_system_sources )
209 init_system_sources();
211 for ( std::list<Url>::const_iterator it = gSettings.additional_sources.begin(); it != gSettings.additional_sources.end(); ++it )
213 include_source_by_url( *it );
218 if ( gData.sources.empty() )
220 cout << "Warning! No sources. Operating only over the installed resolvables. You will not be able to install stuff" << endl;
224 God->initializeTarget("/");
226 std::string token = calculate_token();
228 if ( token != gSettings.previous_token )
233 if ( ! gSettings.disable_system_resolvables )
236 for ( vector<string>::const_iterator it = gData.packages_to_install.begin(); it != gData.packages_to_install.end(); ++it )
238 mark_package_for_install(*it);
245 if ( gData.security_patches_count > 0 )
248 if ( gData.patches_count > 0 )