apt-get.cc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: apt-get.cc,v 1.2 1998/10/08 04:55:05 jgg Exp $
  4. /* ######################################################################
  5. apt-get - Cover for dpkg
  6. This is an allout cover for dpkg implementing a safer front end. It is
  7. based largely on libapt-pkg.
  8. The syntax is different,
  9. apt-get [opt] command [things]
  10. Where command is:
  11. update - Resyncronize the package files from their sources
  12. upgrade - Smart-Download the newest versions of all packages
  13. dselect-upgrade - Follows dselect's changes to the Status: field
  14. and installes new and removes old packages
  15. dist-upgrade - Powerfull upgrader designed to handle the issues with
  16. a new distribution.
  17. install - Download and install a given package (by name, not by .deb)
  18. check - Update the package cache and check for broken packages
  19. clean - Erase the .debs downloaded to /var/cache/apt/archives and
  20. the partial dir too
  21. ##################################################################### */
  22. /*}}}*/
  23. // Include Files /*{{{*/
  24. #include <apt-pkg/error.h>
  25. #include <apt-pkg/cmndline.h>
  26. #include <apt-pkg/init.h>
  27. #include <apt-pkg/depcache.h>
  28. #include <apt-pkg/sourcelist.h>
  29. #include <apt-pkg/pkgcachegen.h>
  30. #include <apt-pkg/algorithms.h>
  31. #include <config.h>
  32. #include <fstream.h>
  33. /*}}}*/
  34. ostream c0out;
  35. ostream c1out;
  36. ostream c2out;
  37. ofstream devnull("/dev/null");
  38. unsigned int ScreenWidth = 80;
  39. // ShowList - Show a list /*{{{*/
  40. // ---------------------------------------------------------------------
  41. /* This prints out a string of space seperated words with a title and
  42. a two space indent line wraped to the current screen width. */
  43. void ShowList(ostream &out,string Title,string List)
  44. {
  45. if (List.empty() == true)
  46. return;
  47. // Acount for the leading space
  48. int ScreenWidth = ::ScreenWidth - 3;
  49. out << Title << endl;
  50. string::size_type Start = 0;
  51. while (Start < List.size())
  52. {
  53. string::size_type End;
  54. if (Start + ScreenWidth >= List.size())
  55. End = List.size();
  56. else
  57. End = List.rfind(' ',Start+ScreenWidth);
  58. if (End == string::npos || End < Start)
  59. End = Start + ScreenWidth;
  60. out << " " << string(List,Start,End - Start) << endl;
  61. Start = End + 1;
  62. }
  63. }
  64. /*}}}*/
  65. // ShowBroken - Debugging aide /*{{{*/
  66. // ---------------------------------------------------------------------
  67. /* This prints out the names of all the packages that are broken along
  68. with the name of each each broken dependency and a quite version
  69. description. */
  70. void ShowBroken(ostream &out,pkgDepCache &Cache)
  71. {
  72. out << "Sorry, but the following packages are broken - this means they have unmet" << endl;
  73. out << "dependencies:" << endl;
  74. pkgCache::PkgIterator I = Cache.PkgBegin();
  75. for (;I.end() != true; I++)
  76. {
  77. if (Cache[I].InstBroken() == true)
  78. {
  79. // Print out each package and the failed dependencies
  80. out <<" " << I.Name() << ":";
  81. int Indent = strlen(I.Name()) + 3;
  82. bool First = true;
  83. for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; D++)
  84. {
  85. if (Cache.IsImportantDep(D) == false || (Cache[D] &
  86. pkgDepCache::DepInstall) != 0)
  87. continue;
  88. if (First == false)
  89. for (int J = 0; J != Indent; J++)
  90. out << ' ';
  91. First = false;
  92. if (D->Type == pkgCache::Dep::Conflicts)
  93. out << " Conflicts:" << D.TargetPkg().Name();
  94. else
  95. out << " Depends:" << D.TargetPkg().Name();
  96. // Show a quick summary of the version requirements
  97. if (D.TargetVer() != 0)
  98. out << " (" << D.CompType() << " " << D.TargetVer() <<
  99. ")";
  100. /* Show a summary of the target package if possible. In the case
  101. of virtual packages we show nothing */
  102. pkgCache::PkgIterator Targ = D.TargetPkg();
  103. if (Targ->ProvidesList == 0)
  104. {
  105. out << " but ";
  106. pkgCache::VerIterator Ver = Cache[Targ].InstVerIter(Cache);
  107. if (Ver.end() == false)
  108. out << Ver.VerStr() << "is installed";
  109. else
  110. out << "it is not installed";
  111. }
  112. out << endl;
  113. }
  114. }
  115. }
  116. }
  117. /*}}}*/
  118. // ShowNew - Show packages to newly install /*{{{*/
  119. // ---------------------------------------------------------------------
  120. /* */
  121. void ShowNew(ostream &out,pkgDepCache &Dep)
  122. {
  123. /* Print out a list of packages that are going to be removed extra
  124. to what the user asked */
  125. pkgCache::PkgIterator I = Dep.PkgBegin();
  126. string List;
  127. for (;I.end() != true; I++)
  128. if (Dep[I].NewInstall() == true)
  129. List += string(I.Name()) + " ";
  130. ShowList(out,"The following NEW packages will be installed:",List);
  131. }
  132. /*}}}*/
  133. // ShowDel - Show packages to delete /*{{{*/
  134. // ---------------------------------------------------------------------
  135. /* */
  136. void ShowDel(ostream &out,pkgDepCache &Dep)
  137. {
  138. /* Print out a list of packages that are going to be removed extra
  139. to what the user asked */
  140. pkgCache::PkgIterator I = Dep.PkgBegin();
  141. string List;
  142. for (;I.end() != true; I++)
  143. if (Dep[I].Delete() == true)
  144. List += string(I.Name()) + " ";
  145. ShowList(out,"The following packages will be REMOVED:",List);
  146. }
  147. /*}}}*/
  148. // ShowKept - Show kept packages /*{{{*/
  149. // ---------------------------------------------------------------------
  150. /* */
  151. void ShowKept(ostream &out,pkgDepCache &Dep)
  152. {
  153. pkgCache::PkgIterator I = Dep.PkgBegin();
  154. string List;
  155. for (;I.end() != true; I++)
  156. {
  157. // Not interesting
  158. if (Dep[I].Upgrade() == true || Dep[I].Upgradable() == false ||
  159. I->CurrentVer == 0 || Dep[I].Delete() == true)
  160. continue;
  161. List += string(I.Name()) + " ";
  162. }
  163. ShowList(out,"The following packages have been kept back",List);
  164. }
  165. /*}}}*/
  166. // ShowUpgraded - Show upgraded packages /*{{{*/
  167. // ---------------------------------------------------------------------
  168. /* */
  169. void ShowUpgraded(ostream &out,pkgDepCache &Dep)
  170. {
  171. pkgCache::PkgIterator I = Dep.PkgBegin();
  172. string List;
  173. for (;I.end() != true; I++)
  174. {
  175. // Not interesting
  176. if (Dep[I].Upgrade() == false || Dep[I].NewInstall() == true)
  177. continue;
  178. List += string(I.Name()) + " ";
  179. }
  180. ShowList(out,"The following packages will be upgraded",List);
  181. }
  182. /*}}}*/
  183. // ShowHold - Show held but changed packages /*{{{*/
  184. // ---------------------------------------------------------------------
  185. /* */
  186. void ShowHold(ostream &out,pkgDepCache &Dep)
  187. {
  188. pkgCache::PkgIterator I = Dep.PkgBegin();
  189. string List;
  190. for (;I.end() != true; I++)
  191. {
  192. if (Dep[I].InstallVer != (pkgCache::Version *)I.CurrentVer() &&
  193. I->SelectedState == pkgCache::State::Hold)
  194. List += string(I.Name()) + " ";
  195. }
  196. ShowList(out,"The following held packages will be changed:",List);
  197. }
  198. /*}}}*/
  199. // ShowEssential - Show an essential package warning /*{{{*/
  200. // ---------------------------------------------------------------------
  201. /* This prints out a warning message that is not to be ignored. It shows
  202. all essential packages and their dependents that are to be removed.
  203. It is insanely risky to remove the dependents of an essential package! */
  204. void ShowEssential(ostream &out,pkgDepCache &Dep)
  205. {
  206. pkgCache::PkgIterator I = Dep.PkgBegin();
  207. string List;
  208. bool *Added = new bool[Dep.HeaderP->PackageCount];
  209. for (int I = 0; I != Dep.HeaderP->PackageCount; I++)
  210. Added[I] = false;
  211. for (;I.end() != true; I++)
  212. {
  213. if ((I->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential)
  214. continue;
  215. // The essential package is being removed
  216. if (Dep[I].Delete() == true)
  217. {
  218. if (Added[I->ID] == false)
  219. {
  220. Added[I->ID] = true;
  221. List += string(I.Name()) + " ";
  222. }
  223. }
  224. if (I->CurrentVer == 0)
  225. continue;
  226. // Print out any essential package depenendents that are to be removed
  227. for (pkgDepCache::DepIterator D = I.CurrentVer().DependsList(); D.end() == false; D++)
  228. {
  229. pkgCache::PkgIterator P = D.SmartTargetPkg();
  230. if (Dep[P].Delete() == true)
  231. {
  232. if (Added[P->ID] == true)
  233. continue;
  234. Added[P->ID] = true;
  235. List += string(P.Name()) + " ";
  236. }
  237. }
  238. }
  239. if (List.empty() == false)
  240. out << "WARNING: The following essential packages will be removed" << endl;
  241. ShowList(out,"This should NOT be done unless you know exactly what you are doing!",List);
  242. delete [] Added;
  243. }
  244. /*}}}*/
  245. // Stats - Show some statistics /*{{{*/
  246. // ---------------------------------------------------------------------
  247. /* */
  248. void Stats(ostream &out,pkgDepCache &Dep)
  249. {
  250. unsigned long Upgrade = 0;
  251. unsigned long Install = 0;
  252. for (pkgCache::PkgIterator I = Dep.PkgBegin(); I.end() == false; I++)
  253. {
  254. if (Dep[I].NewInstall() == true)
  255. Install++;
  256. else
  257. if (Dep[I].Upgrade() == true)
  258. Upgrade++;
  259. }
  260. out << Upgrade << " packages upgraded, " <<
  261. Install << " newly installed, " <<
  262. Dep.DelCount() << " to remove and " <<
  263. Dep.KeepCount() << " not upgraded." << endl;
  264. if (Dep.BadCount() != 0)
  265. out << Dep.BadCount() << " packages not fully installed or removed." << endl;
  266. }
  267. /*}}}*/
  268. // class CacheFile - Cover class for some dependency cache functions /*{{{*/
  269. // ---------------------------------------------------------------------
  270. /* */
  271. class CacheFile
  272. {
  273. public:
  274. FileFd *File;
  275. MMap *Map;
  276. pkgDepCache *Cache;
  277. inline operator pkgDepCache &() {return *Cache;};
  278. inline pkgDepCache *operator ->() {return Cache;};
  279. inline pkgDepCache &operator *() {return *Cache;};
  280. bool Open();
  281. CacheFile() : File(0), Map(0), Cache(0) {};
  282. ~CacheFile()
  283. {
  284. delete Cache;
  285. delete Map;
  286. delete File;
  287. }
  288. };
  289. /*}}}*/
  290. // CacheFile::Open - Open the cache file /*{{{*/
  291. // ---------------------------------------------------------------------
  292. /* This routine generates the caches and then opens the dependency cache
  293. and verifies that the system is OK. */
  294. bool CacheFile::Open()
  295. {
  296. // Create a progress class
  297. OpTextProgress Progress(*_config);
  298. // Read the source list
  299. pkgSourceList List;
  300. if (List.ReadMainList() == false)
  301. return _error->Error("The list of sources could not be read.");
  302. // Build all of the caches
  303. pkgMakeStatusCache(List,Progress);
  304. if (_error->PendingError() == true)
  305. return _error->Error("The package lists or status file could not be parsed or opened.");
  306. Progress.Done();
  307. // Open the cache file
  308. File = new FileFd(_config->FindDir("Dir::Cache::pkgcache"),FileFd::ReadOnly);
  309. if (_error->PendingError() == true)
  310. return false;
  311. Map = new MMap(*File,MMap::Public | MMap::ReadOnly);
  312. if (_error->PendingError() == true)
  313. return false;
  314. Cache = new pkgDepCache(*Map,Progress);
  315. if (_error->PendingError() == true)
  316. return false;
  317. Progress.Done();
  318. // Check that the system is OK
  319. if (Cache->DelCount() != 0 || Cache->InstCount() != 0)
  320. return _error->Error("Internal Error, non-zero counts");
  321. // Apply corrections for half-installed packages
  322. if (pkgApplyStatus(*Cache) == false)
  323. return false;
  324. // Nothing is broken
  325. if (Cache->BrokenCount() == 0)
  326. return true;
  327. // Attempt to fix broken things
  328. if (_config->FindB("APT::Get::Fix-Broken",false) == true)
  329. {
  330. c1out << "Correcting dependencies..." << flush;
  331. if (pkgFixBroken(*Cache) == false || Cache->BrokenCount() != 0)
  332. {
  333. c1out << " failed." << endl;
  334. ShowBroken(c1out,*this);
  335. return _error->Error("Unable to correct dependencies");
  336. }
  337. if (pkgMinimizeUpgrade(*Cache) == false)
  338. return _error->Error("Unable to minimize the upgrade set");
  339. c1out << " Done" << endl;
  340. }
  341. else
  342. {
  343. c1out << "You might want to run `apt-get -f install' to correct these." << endl;
  344. ShowBroken(c1out,*this);
  345. return _error->Error("Unmet dependencies. Try using -f.");
  346. }
  347. return true;
  348. }
  349. /*}}}*/
  350. // InstallPackages - Actually download and install the packages /*{{{*/
  351. // ---------------------------------------------------------------------
  352. /* This displays the informative messages describing what is going to
  353. happen and then calls the download routines */
  354. bool InstallPackages(pkgDepCache &Cache,bool ShwKept)
  355. {
  356. ShowDel(c1out,Cache);
  357. ShowNew(c1out,Cache);
  358. if (ShwKept == true)
  359. ShowKept(c1out,Cache);
  360. ShowHold(c1out,Cache);
  361. if (_config->FindB("APT::Get::Show-Upgraded",false) == true)
  362. ShowUpgraded(c1out,Cache);
  363. ShowEssential(c1out,Cache);
  364. Stats(c1out,Cache);
  365. // Sanity check
  366. if (Cache.BrokenCount() != 0)
  367. {
  368. ShowBroken(c1out,Cache);
  369. return _error->Error("Internal Error, InstallPackages was called with broken packages!");
  370. }
  371. if (Cache.DelCount() == 0 && Cache.InstCount() == 0 &&
  372. Cache.BadCount() == 0)
  373. return true;
  374. return true;
  375. }
  376. /*}}}*/
  377. // DoUpdate - Update the package lists /*{{{*/
  378. // ---------------------------------------------------------------------
  379. /* */
  380. bool DoUpdate(CommandLine &CmdL)
  381. {
  382. }
  383. /*}}}*/
  384. // DoUpgrade - Upgrade all packages /*{{{*/
  385. // ---------------------------------------------------------------------
  386. /* Upgrade all packages without installing new packages or erasing old
  387. packages */
  388. bool DoUpgrade(CommandLine &CmdL)
  389. {
  390. CacheFile Cache;
  391. if (Cache.Open() == false)
  392. return false;
  393. // Do the upgrade
  394. pkgProblemResolver Resolve(Cache);
  395. if (pkgAllUpgrade(Cache) == false)
  396. {
  397. ShowBroken(c1out,Cache);
  398. return _error->Error("Internal Error, AllUpgrade broke stuff");
  399. }
  400. return InstallPackages(Cache,true);
  401. }
  402. /*}}}*/
  403. // DoInstall - Install packages from the command line /*{{{*/
  404. // ---------------------------------------------------------------------
  405. /* Install named packages */
  406. bool DoInstall(CommandLine &CmdL)
  407. {
  408. CacheFile Cache;
  409. if (Cache.Open() == false)
  410. return false;
  411. int ExpectedInst = 0;
  412. pkgProblemResolver Fix(Cache);
  413. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  414. {
  415. // Duplicate the string
  416. unsigned int Length = strlen(*I);
  417. char S[300];
  418. if (Length >= sizeof(S))
  419. continue;
  420. strcpy(S,*I);
  421. // See if we are removing the package
  422. bool Remove = false;
  423. if (S[Length - 1] == '-')
  424. {
  425. Remove = true;
  426. S[--Length] = 0;
  427. }
  428. // Locate the package
  429. pkgCache::PkgIterator Pkg = Cache->FindPkg(S);
  430. if (Pkg.end() == true)
  431. return _error->Error("Couldn't find package %s",S);
  432. // Check if there is something new to install
  433. pkgDepCache::StateCache &State = (*Cache)[Pkg];
  434. if (State.CandidateVer == 0)
  435. return _error->Error("Package %s has no installation candidate",S);
  436. Fix.Protect(Pkg);
  437. if (Remove == true)
  438. {
  439. Cache->MarkDelete(Pkg);
  440. continue;
  441. }
  442. // Install it
  443. Cache->MarkInstall(Pkg,false);
  444. if (State.Install() == false)
  445. c1out << "Sorry, " << S << " is already the newest version" << endl;
  446. else
  447. ExpectedInst++;
  448. // Install it with autoinstalling enabled.
  449. if (State.InstBroken() == true)
  450. Cache->MarkInstall(Pkg,true);
  451. }
  452. // Call the scored problem resolver
  453. if (Fix.Resolve(true) == false)
  454. _error->Discard();
  455. // Now we check the state of the packages,
  456. if (Cache->BrokenCount() != 0)
  457. {
  458. ShowBroken(c1out,Cache);
  459. return _error->Error("Sorry, broken packages");
  460. }
  461. /* Print out a list of packages that are going to be installed extra
  462. to what the user asked */
  463. if (Cache->InstCount() != ExpectedInst)
  464. {
  465. string List;
  466. pkgCache::PkgIterator I = Cache->PkgBegin();
  467. for (;I.end() != true; I++)
  468. {
  469. if ((*Cache)[I].Install() == false)
  470. continue;
  471. const char **J;
  472. for (J = CmdL.FileList + 1; *J != 0; J++)
  473. if (strcmp(*J,I.Name()) == 0)
  474. break;
  475. if (*J == 0)
  476. List += string(I.Name()) + " ";
  477. }
  478. ShowList(c1out,"The following extra packages will be installed:",List);
  479. }
  480. return InstallPackages(Cache,false);
  481. }
  482. /*}}}*/
  483. // DoDistUpgrade - Automatic smart upgrader /*{{{*/
  484. // ---------------------------------------------------------------------
  485. /* Intelligent upgrader that will install and remove packages at will */
  486. bool DoDistUpgrade(CommandLine &CmdL)
  487. {
  488. CacheFile Cache;
  489. if (Cache.Open() == false)
  490. return false;
  491. c0out << "Calculating Upgrade... " << flush;
  492. if (pkgDistUpgrade(*Cache) == false)
  493. {
  494. c0out << "Failed" << endl;
  495. ShowBroken(c1out,Cache);
  496. return false;
  497. }
  498. c0out << "Done" << endl;
  499. return InstallPackages(Cache,true);
  500. }
  501. /*}}}*/
  502. // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
  503. // ---------------------------------------------------------------------
  504. /* Follows dselect's selections */
  505. bool DoDSelectUpgrade(CommandLine &CmdL)
  506. {
  507. CacheFile Cache;
  508. if (Cache.Open() == false)
  509. return false;
  510. // Install everything with the install flag set
  511. pkgCache::PkgIterator I = Cache->PkgBegin();
  512. for (;I.end() != true; I++)
  513. {
  514. /* Install the package only if it is a new install, the autoupgrader
  515. will deal with the rest */
  516. if (I->SelectedState == pkgCache::State::Install)
  517. Cache->MarkInstall(I,false);
  518. }
  519. /* Now install their deps too, if we do this above then order of
  520. the status file is significant for | groups */
  521. for (I = Cache->PkgBegin();I.end() != true; I++)
  522. {
  523. /* Install the package only if it is a new install, the autoupgrader
  524. will deal with the rest */
  525. if (I->SelectedState == pkgCache::State::Install)
  526. Cache->MarkInstall(I);
  527. }
  528. // Apply erasures now, they override everything else.
  529. for (I = Cache->PkgBegin();I.end() != true; I++)
  530. {
  531. // Remove packages
  532. if (I->SelectedState == pkgCache::State::DeInstall ||
  533. I->SelectedState == pkgCache::State::Purge)
  534. Cache->MarkDelete(I);
  535. }
  536. /* Use updates smart upgrade to do the rest, it will automatically
  537. ignore held items */
  538. if (pkgAllUpgrade(Cache) == false)
  539. {
  540. ShowBroken(c1out,Cache);
  541. return _error->Error("Internal Error, AllUpgrade broke stuff");
  542. }
  543. return InstallPackages(Cache,false);
  544. }
  545. /*}}}*/
  546. // DoClean - Remove download archives /*{{{*/
  547. // ---------------------------------------------------------------------
  548. /* */
  549. bool DoClean(CommandLine &CmdL)
  550. {
  551. return true;
  552. }
  553. /*}}}*/
  554. // DoCheck - Perform the check operation /*{{{*/
  555. // ---------------------------------------------------------------------
  556. /* Opening automatically checks the system, this command is mostly used
  557. for debugging */
  558. bool DoCheck(CommandLine &CmdL)
  559. {
  560. CacheFile Cache;
  561. Cache.Open();
  562. return true;
  563. }
  564. /*}}}*/
  565. // ShowHelp - Show a help screen /*{{{*/
  566. // ---------------------------------------------------------------------
  567. /* */
  568. int ShowHelp()
  569. {
  570. cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE <<
  571. " compiled on " << __DATE__ << " " << __TIME__ << endl;
  572. cout << "Usage: apt-get [options] command" << endl;
  573. cout << " apt-get [options] install pkg1 [pkg2 ...]" << endl;
  574. cout << endl;
  575. cout << "apt-get is a simple command line interface for downloading and" << endl;
  576. cout << "installing packages. The most frequently used commands are update" << endl;
  577. cout << "and install." << endl;
  578. cout << endl;
  579. cout << "Commands:" << endl;
  580. cout << " update - Retrieve new lists of packages" << endl;
  581. cout << " upgrade - Perform an upgrade" << endl;
  582. cout << " install - Install new packages (pkg is libc6 not libc6.deb)" << endl;
  583. cout << " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl;
  584. cout << " dselect-upgrade - Follow dselect selections" << endl;
  585. cout << " clean - Erase downloaded archive files" << endl;
  586. cout << " check - Verify that there are no broken dependencies" << endl;
  587. cout << endl;
  588. cout << "Options:" << endl;
  589. cout << " -h This help text." << endl;
  590. cout << " -q Loggable output - no progress indicator" << endl;
  591. cout << " -qq No output except for errors" << endl;
  592. cout << " -d Download only - do NOT install or unpack archives" << endl;
  593. cout << " -s No-act. Perform ordering simulation" << endl;
  594. cout << " -y Assume Yes to all queries and do not prompt" << endl;
  595. cout << " -f Attempt to continue if the integrity check fails" << endl;
  596. cout << " -m Attempt to continue if archives are unlocatable" << endl;
  597. cout << " -u Show a list of upgraded packages as well" << endl;
  598. cout << " -c=? Read this configuration file" << endl;
  599. cout << " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl;
  600. cout << "See the apt-get(8), sources.list(8) and apt.conf(8) manual" << endl;
  601. cout << "pages for more information." << endl;
  602. return 100;
  603. }
  604. /*}}}*/
  605. // GetInitialize - Initialize things for apt-get /*{{{*/
  606. // ---------------------------------------------------------------------
  607. /* */
  608. void GetInitialize()
  609. {
  610. _config->Set("quiet",0);
  611. _config->Set("help",false);
  612. _config->Set("APT::Get::Download-Only",false);
  613. _config->Set("APT::Get::Simulate",false);
  614. _config->Set("APT::Get::Assume-Yes",false);
  615. _config->Set("APT::Get::Fix-Broken",false);
  616. }
  617. /*}}}*/
  618. int main(int argc,const char *argv[])
  619. {
  620. CommandLine::Args Args[] = {
  621. {'h',"help","help",0},
  622. {'q',"quiet","quiet",CommandLine::IntLevel},
  623. {'q',"silent","quiet",CommandLine::IntLevel},
  624. {'d',"download-only","APT::Get::Download-Only",0},
  625. {'s',"simulate","APT::Get::Simulate",0},
  626. {'s',"just-print","APT::Get::Simulate",0},
  627. {'s',"recon","APT::Get::Simulate",0},
  628. {'s',"no-act","APT::Get::Simulate",0},
  629. {'y',"yes","APT::Get::Assume-Yes",0},
  630. {'y',"assume-yes","APT::Get::Assume-Yes",0},
  631. {'f',"fix-broken","APT::Get::Fix-Broken",0},
  632. {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
  633. {'m',"ignore-missing","APT::Get::Fix-Broken",0},
  634. {'c',"config-file",0,CommandLine::ConfigFile},
  635. {'o',"option",0,CommandLine::ArbItem},
  636. {0,0,0,0}};
  637. // Parse the command line and initialize the package library
  638. CommandLine CmdL(Args,_config);
  639. if (pkgInitialize(*_config) == false ||
  640. CmdL.Parse(argc,argv) == false)
  641. {
  642. _error->DumpErrors();
  643. return 100;
  644. }
  645. // See if the help should be shown
  646. if (_config->FindB("help") == true ||
  647. CmdL.FileSize() == 0)
  648. return ShowHelp();
  649. // Setup the output streams
  650. c0out.rdbuf(cout.rdbuf());
  651. c1out.rdbuf(cout.rdbuf());
  652. c2out.rdbuf(cout.rdbuf());
  653. if (_config->FindI("quiet",0) > 0)
  654. c0out.rdbuf(devnull.rdbuf());
  655. if (_config->FindI("quiet",0) > 1)
  656. c1out.rdbuf(devnull.rdbuf());
  657. // Match the operation
  658. struct
  659. {
  660. const char *Match;
  661. bool (*Handler)(CommandLine &);
  662. } Map[] = {{"update",&DoUpdate},
  663. {"upgrade",&DoUpgrade},
  664. {"install",&DoInstall},
  665. {"dist-upgrade",&DoDistUpgrade},
  666. {"dselect-upgrade",&DoDSelectUpgrade},
  667. {"clean",&DoClean},
  668. {"check",&DoCheck},
  669. {0,0}};
  670. int I;
  671. for (I = 0; Map[I].Match != 0; I++)
  672. {
  673. if (strcmp(CmdL.FileList[0],Map[I].Match) == 0)
  674. {
  675. Map[I].Handler(CmdL);
  676. break;
  677. }
  678. }
  679. // No matching name
  680. if (Map[I].Match == 0)
  681. _error->Error("Invalid operation %s", CmdL.FileList[0]);
  682. // Print any errors or warnings found during parsing
  683. if (_error->empty() == false)
  684. {
  685. bool Errors = _error->PendingError();
  686. _error->DumpErrors();
  687. if (Errors == true)
  688. cout << "Returning 100." << endl;
  689. return Errors == true?100:0;
  690. }
  691. return 0;
  692. }