apt-get.cc 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: apt-get.cc,v 1.156 2004/08/28 01:05:16 mdz 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 - Powerful 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 <config.h>
  25. #include <apt-pkg/acquire-item.h>
  26. #include <apt-pkg/algorithms.h>
  27. #include <apt-pkg/aptconfiguration.h>
  28. #include <apt-pkg/cachefile.h>
  29. #include <apt-pkg/cacheset.h>
  30. #include <apt-pkg/clean.h>
  31. #include <apt-pkg/cmndline.h>
  32. #include <apt-pkg/debmetaindex.h>
  33. #include <apt-pkg/depcache.h>
  34. #include <apt-pkg/error.h>
  35. #include <apt-pkg/fileutl.h>
  36. #include <apt-pkg/indexfile.h>
  37. #include <apt-pkg/indexrecords.h>
  38. #include <apt-pkg/init.h>
  39. #include <apt-pkg/md5.h>
  40. #include <apt-pkg/metaindex.h>
  41. #include <apt-pkg/pkgrecords.h>
  42. #include <apt-pkg/pkgsystem.h>
  43. #include <apt-pkg/progress.h>
  44. #include <apt-pkg/sourcelist.h>
  45. #include <apt-pkg/srcrecords.h>
  46. #include <apt-pkg/strutl.h>
  47. #include <apt-pkg/version.h>
  48. #include <apt-pkg/acquire.h>
  49. #include <apt-pkg/configuration.h>
  50. #include <apt-pkg/macros.h>
  51. #include <apt-pkg/pkgcache.h>
  52. #include <apt-pkg/cacheiterators.h>
  53. #include <apt-pkg/upgrade.h>
  54. #include <apt-private/acqprogress.h>
  55. #include <apt-private/private-cacheset.h>
  56. #include <apt-private/private-cachefile.h>
  57. #include <apt-private/private-cmndline.h>
  58. #include <apt-private/private-download.h>
  59. #include <apt-private/private-install.h>
  60. #include <apt-private/private-main.h>
  61. #include <apt-private/private-moo.h>
  62. #include <apt-private/private-output.h>
  63. #include <apt-private/private-update.h>
  64. #include <apt-private/private-upgrade.h>
  65. #include <apt-private/private-utils.h>
  66. #include <errno.h>
  67. #include <signal.h>
  68. #include <stddef.h>
  69. #include <stdio.h>
  70. #include <stdlib.h>
  71. #include <string.h>
  72. #include <sys/ioctl.h>
  73. #include <sys/stat.h>
  74. #include <sys/wait.h>
  75. #include <unistd.h>
  76. #include <pwd.h>
  77. #include <grp.h>
  78. #include <algorithm>
  79. #include <fstream>
  80. #include <iostream>
  81. #include <sstream>
  82. #include <set>
  83. #include <string>
  84. #include <vector>
  85. #include <apti18n.h>
  86. /*}}}*/
  87. using namespace std;
  88. // TryToInstallBuildDep - Try to install a single package /*{{{*/
  89. // ---------------------------------------------------------------------
  90. /* This used to be inlined in DoInstall, but with the advent of regex package
  91. name matching it was split out.. */
  92. static bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache,
  93. pkgProblemResolver &Fix,bool Remove,bool BrokenFix,
  94. bool AllowFail = true)
  95. {
  96. if (Cache[Pkg].CandidateVer == 0 && Pkg->ProvidesList != 0)
  97. {
  98. CacheSetHelperAPTGet helper(c1out);
  99. helper.showErrors(false);
  100. pkgCache::VerIterator Ver = helper.canNotFindNewestVer(Cache, Pkg);
  101. if (Ver.end() == false)
  102. Pkg = Ver.ParentPkg();
  103. else if (helper.showVirtualPackageErrors(Cache) == false)
  104. return AllowFail;
  105. }
  106. if (_config->FindB("Debug::BuildDeps",false) == true)
  107. {
  108. if (Remove == true)
  109. cout << " Trying to remove " << Pkg << endl;
  110. else
  111. cout << " Trying to install " << Pkg << endl;
  112. }
  113. if (Remove == true)
  114. {
  115. TryToRemove RemoveAction(Cache, &Fix);
  116. RemoveAction(Pkg.VersionList());
  117. } else if (Cache[Pkg].CandidateVer != 0) {
  118. TryToInstall InstallAction(Cache, &Fix, BrokenFix);
  119. InstallAction(Cache[Pkg].CandidateVerIter(Cache));
  120. InstallAction.doAutoInstall();
  121. } else
  122. return AllowFail;
  123. return true;
  124. }
  125. /*}}}*/
  126. // GetReleaseForSourceRecord - Return Suite for the given srcrecord /*{{{*/
  127. // ---------------------------------------------------------------------
  128. /* */
  129. static std::string GetReleaseForSourceRecord(pkgSourceList *SrcList,
  130. pkgSrcRecords::Parser *Parse)
  131. {
  132. // try to find release
  133. const pkgIndexFile& CurrentIndexFile = Parse->Index();
  134. for (pkgSourceList::const_iterator S = SrcList->begin();
  135. S != SrcList->end(); ++S)
  136. {
  137. vector<pkgIndexFile *> *Indexes = (*S)->GetIndexFiles();
  138. for (vector<pkgIndexFile *>::const_iterator IF = Indexes->begin();
  139. IF != Indexes->end(); ++IF)
  140. {
  141. if (&CurrentIndexFile == (*IF))
  142. {
  143. std::string const path = (*S)->LocalFileName();
  144. if (path != "")
  145. {
  146. indexRecords records;
  147. records.Load(path);
  148. return records.GetSuite();
  149. }
  150. }
  151. }
  152. }
  153. return "";
  154. }
  155. /*}}}*/
  156. // FindSrc - Find a source record /*{{{*/
  157. // ---------------------------------------------------------------------
  158. /* */
  159. #if APT_PKG_ABI >= 413
  160. static pkgSrcRecords::Parser *FindSrc(const char *Name,
  161. #else
  162. static pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
  163. #endif
  164. pkgSrcRecords &SrcRecs,string &Src,
  165. CacheFile &CacheFile)
  166. {
  167. string VerTag, UserRequestedVerTag;
  168. string ArchTag = "";
  169. string RelTag = _config->Find("APT::Default-Release");
  170. string TmpSrc = Name;
  171. pkgDepCache *Cache = CacheFile.GetDepCache();
  172. // extract release
  173. size_t found = TmpSrc.find_last_of("/");
  174. if (found != string::npos)
  175. {
  176. RelTag = TmpSrc.substr(found+1);
  177. TmpSrc = TmpSrc.substr(0,found);
  178. }
  179. // extract the version
  180. found = TmpSrc.find_last_of("=");
  181. if (found != string::npos)
  182. {
  183. VerTag = UserRequestedVerTag = TmpSrc.substr(found+1);
  184. TmpSrc = TmpSrc.substr(0,found);
  185. }
  186. // extract arch
  187. found = TmpSrc.find_last_of(":");
  188. if (found != string::npos)
  189. {
  190. ArchTag = TmpSrc.substr(found+1);
  191. TmpSrc = TmpSrc.substr(0,found);
  192. }
  193. /* Lookup the version of the package we would install if we were to
  194. install a version and determine the source package name, then look
  195. in the archive for a source package of the same name. */
  196. bool MatchSrcOnly = _config->FindB("APT::Get::Only-Source");
  197. pkgCache::PkgIterator Pkg;
  198. if (ArchTag != "")
  199. Pkg = Cache->FindPkg(TmpSrc, ArchTag);
  200. else
  201. Pkg = Cache->FindPkg(TmpSrc);
  202. // if we can't find a package but the user qualified with a arch,
  203. // error out here
  204. if (Pkg.end() && ArchTag != "")
  205. {
  206. Src = Name;
  207. _error->Error(_("Can not find a package for architecture '%s'"),
  208. ArchTag.c_str());
  209. return 0;
  210. }
  211. if (MatchSrcOnly == false && Pkg.end() == false)
  212. {
  213. if(VerTag != "" || RelTag != "" || ArchTag != "")
  214. {
  215. bool fuzzy = false;
  216. // we have a default release, try to locate the pkg. we do it like
  217. // this because GetCandidateVer() will not "downgrade", that means
  218. // "apt-get source -t stable apt" won't work on a unstable system
  219. for (pkgCache::VerIterator Ver = Pkg.VersionList();; ++Ver)
  220. {
  221. // try first only exact matches, later fuzzy matches
  222. if (Ver.end() == true)
  223. {
  224. if (fuzzy == true)
  225. break;
  226. fuzzy = true;
  227. Ver = Pkg.VersionList();
  228. // exit right away from the Pkg.VersionList() loop if we
  229. // don't have any versions
  230. if (Ver.end() == true)
  231. break;
  232. }
  233. // ignore arches that are not for us
  234. if (ArchTag != "" && Ver.Arch() != ArchTag)
  235. continue;
  236. // pick highest version for the arch unless the user wants
  237. // something else
  238. if (ArchTag != "" && VerTag == "" && RelTag == "")
  239. if(Cache->VS().CmpVersion(VerTag, Ver.VerStr()) < 0)
  240. VerTag = Ver.VerStr();
  241. // We match against a concrete version (or a part of this version)
  242. if (VerTag.empty() == false &&
  243. (fuzzy == true || Cache->VS().CmpVersion(VerTag, Ver.VerStr()) != 0) && // exact match
  244. (fuzzy == false || strncmp(VerTag.c_str(), Ver.VerStr(), VerTag.size()) != 0)) // fuzzy match
  245. continue;
  246. for (pkgCache::VerFileIterator VF = Ver.FileList();
  247. VF.end() == false; ++VF)
  248. {
  249. /* If this is the status file, and the current version is not the
  250. version in the status file (ie it is not installed, or somesuch)
  251. then it is not a candidate for installation, ever. This weeds
  252. out bogus entries that may be due to config-file states, or
  253. other. */
  254. if ((VF.File()->Flags & pkgCache::Flag::NotSource) ==
  255. pkgCache::Flag::NotSource && Pkg.CurrentVer() != Ver)
  256. continue;
  257. // or we match against a release
  258. if(VerTag.empty() == false ||
  259. (VF.File().Archive() != 0 && VF.File().Archive() == RelTag) ||
  260. (VF.File().Codename() != 0 && VF.File().Codename() == RelTag))
  261. {
  262. // the Version we have is possibly fuzzy or includes binUploads,
  263. // so we use the Version of the SourcePkg (empty if same as package)
  264. #if APT_PKG_ABI >= 413
  265. Src = Ver.SourcePkgName();
  266. VerTag = Ver.SourceVerStr();
  267. #else
  268. pkgRecords::Parser &Parse = Recs.Lookup(VF);
  269. Src = Parse.SourcePkg();
  270. // no SourcePkg name, so it is the "binary" name
  271. if (Src.empty() == true)
  272. Src = TmpSrc;
  273. VerTag = Parse.SourceVer();
  274. if (VerTag.empty() == true)
  275. VerTag = Ver.VerStr();
  276. #endif
  277. break;
  278. }
  279. }
  280. if (Src.empty() == false)
  281. break;
  282. }
  283. }
  284. if (Src == "" && ArchTag != "")
  285. {
  286. if (VerTag != "")
  287. _error->Error(_("Can not find a package '%s' with version '%s'"),
  288. Pkg.FullName().c_str(), VerTag.c_str());
  289. if (RelTag != "")
  290. _error->Error(_("Can not find a package '%s' with release '%s'"),
  291. Pkg.FullName().c_str(), RelTag.c_str());
  292. Src = Name;
  293. return 0;
  294. }
  295. if (Src.empty() == true)
  296. {
  297. // if we don't have found a fitting package yet so we will
  298. // choose a good candidate and proceed with that.
  299. // Maybe we will find a source later on with the right VerTag
  300. // or RelTag
  301. pkgCache::VerIterator Ver = Cache->GetCandidateVer(Pkg);
  302. if (Ver.end() == false)
  303. {
  304. #if APT_PKG_ABI >= 413
  305. if (strcmp(Ver.SourcePkgName(),Ver.ParentPkg().Name()) != 0)
  306. Src = Ver.SourcePkgName();
  307. if (VerTag.empty() == true && strcmp(Ver.SourceVerStr(),Ver.VerStr()) != 0)
  308. VerTag = Ver.SourceVerStr();
  309. #else
  310. pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
  311. Src = Parse.SourcePkg();
  312. if (VerTag.empty() == true)
  313. VerTag = Parse.SourceVer();
  314. #endif
  315. }
  316. }
  317. }
  318. if (Src.empty() == true)
  319. {
  320. Src = TmpSrc;
  321. }
  322. else
  323. {
  324. /* if we have a source pkg name, make sure to only search
  325. for srcpkg names, otherwise apt gets confused if there
  326. is a binary package "pkg1" and a source package "pkg1"
  327. with the same name but that comes from different packages */
  328. MatchSrcOnly = true;
  329. if (Src != TmpSrc)
  330. {
  331. ioprintf(c1out, _("Picking '%s' as source package instead of '%s'\n"), Src.c_str(), TmpSrc.c_str());
  332. }
  333. }
  334. // The best hit
  335. pkgSrcRecords::Parser *Last = 0;
  336. unsigned long Offset = 0;
  337. string Version;
  338. pkgSourceList *SrcList = CacheFile.GetSourceList();
  339. /* Iterate over all of the hits, which includes the resulting
  340. binary packages in the search */
  341. pkgSrcRecords::Parser *Parse;
  342. while (true)
  343. {
  344. SrcRecs.Restart();
  345. while ((Parse = SrcRecs.Find(Src.c_str(), MatchSrcOnly)) != 0)
  346. {
  347. const string Ver = Parse->Version();
  348. // See if we need to look for a specific release tag
  349. if (RelTag != "" && UserRequestedVerTag == "")
  350. {
  351. const string Rel = GetReleaseForSourceRecord(SrcList, Parse);
  352. if (Rel == RelTag)
  353. {
  354. Last = Parse;
  355. Offset = Parse->Offset();
  356. Version = Ver;
  357. }
  358. }
  359. // Ignore all versions which doesn't fit
  360. if (VerTag.empty() == false &&
  361. Cache->VS().CmpVersion(VerTag, Ver) != 0) // exact match
  362. continue;
  363. // Newer version or an exact match? Save the hit
  364. if (Last == 0 || Cache->VS().CmpVersion(Version,Ver) < 0) {
  365. Last = Parse;
  366. Offset = Parse->Offset();
  367. Version = Ver;
  368. }
  369. // was the version check above an exact match?
  370. // If so, we don't need to look further
  371. if (VerTag.empty() == false && (VerTag == Ver))
  372. break;
  373. }
  374. if (UserRequestedVerTag == "" && Version != "" && RelTag != "")
  375. ioprintf(c1out, "Selected version '%s' (%s) for %s\n",
  376. Version.c_str(), RelTag.c_str(), Src.c_str());
  377. if (Last != 0 || VerTag.empty() == true)
  378. break;
  379. _error->Error(_("Can not find version '%s' of package '%s'"), VerTag.c_str(), TmpSrc.c_str());
  380. return 0;
  381. }
  382. if (Last == 0 || Last->Jump(Offset) == false)
  383. return 0;
  384. return Last;
  385. }
  386. /*}}}*/
  387. /* mark packages as automatically/manually installed. {{{*/
  388. static bool DoMarkAuto(CommandLine &CmdL)
  389. {
  390. bool Action = true;
  391. int AutoMarkChanged = 0;
  392. OpTextProgress progress;
  393. CacheFile Cache;
  394. if (Cache.Open() == false)
  395. return false;
  396. if (strcasecmp(CmdL.FileList[0],"markauto") == 0)
  397. Action = true;
  398. else if (strcasecmp(CmdL.FileList[0],"unmarkauto") == 0)
  399. Action = false;
  400. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  401. {
  402. const char *S = *I;
  403. // Locate the package
  404. pkgCache::PkgIterator Pkg = Cache->FindPkg(S);
  405. if (Pkg.end() == true) {
  406. return _error->Error(_("Couldn't find package %s"),S);
  407. }
  408. else
  409. {
  410. if (!Action)
  411. ioprintf(c1out,_("%s set to manually installed.\n"), Pkg.Name());
  412. else
  413. ioprintf(c1out,_("%s set to automatically installed.\n"),
  414. Pkg.Name());
  415. Cache->MarkAuto(Pkg,Action);
  416. AutoMarkChanged++;
  417. }
  418. }
  419. _error->Notice(_("This command is deprecated. Please use 'apt-mark auto' and 'apt-mark manual' instead."));
  420. if (AutoMarkChanged && ! _config->FindB("APT::Get::Simulate",false))
  421. return Cache->writeStateFile(NULL);
  422. return false;
  423. }
  424. /*}}}*/
  425. // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
  426. // ---------------------------------------------------------------------
  427. /* Follows dselect's selections */
  428. static bool DoDSelectUpgrade(CommandLine &)
  429. {
  430. CacheFile Cache;
  431. if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
  432. return false;
  433. pkgDepCache::ActionGroup group(Cache);
  434. // Install everything with the install flag set
  435. pkgCache::PkgIterator I = Cache->PkgBegin();
  436. for (;I.end() != true; ++I)
  437. {
  438. /* Install the package only if it is a new install, the autoupgrader
  439. will deal with the rest */
  440. if (I->SelectedState == pkgCache::State::Install)
  441. Cache->MarkInstall(I,false);
  442. }
  443. /* Now install their deps too, if we do this above then order of
  444. the status file is significant for | groups */
  445. for (I = Cache->PkgBegin();I.end() != true; ++I)
  446. {
  447. /* Install the package only if it is a new install, the autoupgrader
  448. will deal with the rest */
  449. if (I->SelectedState == pkgCache::State::Install)
  450. Cache->MarkInstall(I,true);
  451. }
  452. // Apply erasures now, they override everything else.
  453. for (I = Cache->PkgBegin();I.end() != true; ++I)
  454. {
  455. // Remove packages
  456. if (I->SelectedState == pkgCache::State::DeInstall ||
  457. I->SelectedState == pkgCache::State::Purge)
  458. Cache->MarkDelete(I,I->SelectedState == pkgCache::State::Purge);
  459. }
  460. /* Resolve any problems that dselect created, allupgrade cannot handle
  461. such things. We do so quite aggressively too.. */
  462. if (Cache->BrokenCount() != 0)
  463. {
  464. pkgProblemResolver Fix(Cache);
  465. // Hold back held packages.
  466. if (_config->FindB("APT::Ignore-Hold",false) == false)
  467. {
  468. for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; ++I)
  469. {
  470. if (I->SelectedState == pkgCache::State::Hold)
  471. {
  472. Fix.Protect(I);
  473. Cache->MarkKeep(I);
  474. }
  475. }
  476. }
  477. if (Fix.Resolve() == false)
  478. {
  479. ShowBroken(c1out,Cache,false);
  480. return _error->Error(_("Internal error, problem resolver broke stuff"));
  481. }
  482. }
  483. // Now upgrade everything
  484. if (APT::Upgrade::Upgrade(Cache, APT::Upgrade::FORBID_REMOVE_PACKAGES | APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES) == false)
  485. {
  486. ShowBroken(c1out,Cache,false);
  487. return _error->Error(_("Internal error, problem resolver broke stuff"));
  488. }
  489. return InstallPackages(Cache,false);
  490. }
  491. /*}}}*/
  492. // DoClean - Remove download archives /*{{{*/
  493. // ---------------------------------------------------------------------
  494. /* */
  495. static bool DoClean(CommandLine &)
  496. {
  497. std::string const archivedir = _config->FindDir("Dir::Cache::archives");
  498. std::string const listsdir = _config->FindDir("Dir::state::lists");
  499. if (_config->FindB("APT::Get::Simulate") == true)
  500. {
  501. std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache");
  502. std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache");
  503. cout << "Del " << archivedir << "* " << archivedir << "partial/*"<< endl
  504. << "Del " << listsdir << "partial/*" << endl
  505. << "Del " << pkgcache << " " << srcpkgcache << endl;
  506. return true;
  507. }
  508. pkgAcquire Fetcher;
  509. Fetcher.GetLock(archivedir);
  510. Fetcher.Clean(archivedir);
  511. Fetcher.Clean(archivedir + "partial/");
  512. Fetcher.GetLock(listsdir);
  513. Fetcher.Clean(listsdir + "partial/");
  514. pkgCacheFile::RemoveCaches();
  515. return true;
  516. }
  517. /*}}}*/
  518. // DoAutoClean - Smartly remove downloaded archives /*{{{*/
  519. // ---------------------------------------------------------------------
  520. /* This is similar to clean but it only purges things that cannot be
  521. downloaded, that is old versions of cached packages. */
  522. class LogCleaner : public pkgArchiveCleaner
  523. {
  524. protected:
  525. virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St)
  526. {
  527. c1out << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "B]" << endl;
  528. if (_config->FindB("APT::Get::Simulate") == false)
  529. unlink(File);
  530. };
  531. };
  532. static bool DoAutoClean(CommandLine &)
  533. {
  534. // Lock the archive directory
  535. FileFd Lock;
  536. if (_config->FindB("Debug::NoLocking",false) == false)
  537. {
  538. int lock_fd = GetLock(_config->FindDir("Dir::Cache::Archives") + "lock");
  539. if (lock_fd < 0)
  540. return _error->Error(_("Unable to lock the download directory"));
  541. Lock.Fd(lock_fd);
  542. }
  543. CacheFile Cache;
  544. if (Cache.Open() == false)
  545. return false;
  546. LogCleaner Cleaner;
  547. return Cleaner.Go(_config->FindDir("Dir::Cache::archives"),*Cache) &&
  548. Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache);
  549. }
  550. /*}}}*/
  551. // DoDownload - download a binary /*{{{*/
  552. // ---------------------------------------------------------------------
  553. static bool DoDownload(CommandLine &CmdL)
  554. {
  555. CacheFile Cache;
  556. if (Cache.ReadOnlyOpen() == false)
  557. return false;
  558. APT::CacheSetHelper helper;
  559. APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache,
  560. CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
  561. if (verset.empty() == true)
  562. return false;
  563. AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
  564. pkgAcquire Fetcher(&Stat);
  565. pkgRecords Recs(Cache);
  566. pkgSourceList *SrcList = Cache.GetSourceList();
  567. // reuse the usual acquire methods for deb files, but don't drop them into
  568. // the usual directories - keep everything in the current directory
  569. std::vector<std::string> storefile(verset.size());
  570. std::string const cwd = SafeGetCWD();
  571. _config->Set("Dir::Cache::Archives", cwd);
  572. int i = 0;
  573. for (APT::VersionSet::const_iterator Ver = verset.begin();
  574. Ver != verset.end(); ++Ver, ++i)
  575. {
  576. pkgAcquire::Item *I = new pkgAcqArchive(&Fetcher, SrcList, &Recs, *Ver, storefile[i]);
  577. if (storefile[i].empty())
  578. continue;
  579. std::string const filename = cwd + flNotDir(storefile[i]);
  580. storefile[i].assign(filename);
  581. I->DestFile.assign(filename);
  582. }
  583. // Just print out the uris and exit if the --print-uris flag was used
  584. if (_config->FindB("APT::Get::Print-URIs") == true)
  585. {
  586. pkgAcquire::UriIterator I = Fetcher.UriBegin();
  587. for (; I != Fetcher.UriEnd(); ++I)
  588. cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
  589. I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
  590. return true;
  591. }
  592. // Disable drop-privs if "_apt" can not write to the target dir
  593. CheckDropPrivsMustBeDisabled(Fetcher);
  594. if (_error->PendingError() == true || CheckAuth(Fetcher, false) == false)
  595. return false;
  596. bool Failed = false;
  597. if (AcquireRun(Fetcher, 0, &Failed, NULL) == false)
  598. return false;
  599. // copy files in local sources to the current directory
  600. for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
  601. {
  602. std::string const filename = cwd + flNotDir((*I)->DestFile);
  603. if ((*I)->Local == true &&
  604. filename != (*I)->DestFile &&
  605. (*I)->Status == pkgAcquire::Item::StatDone)
  606. {
  607. std::ifstream src((*I)->DestFile.c_str(), std::ios::binary);
  608. std::ofstream dst(filename.c_str(), std::ios::binary);
  609. dst << src.rdbuf();
  610. }
  611. }
  612. return Failed == false;
  613. }
  614. /*}}}*/
  615. // DoCheck - Perform the check operation /*{{{*/
  616. // ---------------------------------------------------------------------
  617. /* Opening automatically checks the system, this command is mostly used
  618. for debugging */
  619. static bool DoCheck(CommandLine &)
  620. {
  621. CacheFile Cache;
  622. Cache.Open();
  623. Cache.CheckDeps();
  624. return true;
  625. }
  626. /*}}}*/
  627. // DoSource - Fetch a source archive /*{{{*/
  628. // ---------------------------------------------------------------------
  629. /* Fetch souce packages */
  630. struct DscFile
  631. {
  632. string Package;
  633. string Version;
  634. string Dsc;
  635. };
  636. static bool DoSource(CommandLine &CmdL)
  637. {
  638. CacheFile Cache;
  639. if (Cache.Open(false) == false)
  640. return false;
  641. if (CmdL.FileSize() <= 1)
  642. return _error->Error(_("Must specify at least one package to fetch source for"));
  643. // Read the source list
  644. if (Cache.BuildSourceList() == false)
  645. return false;
  646. pkgSourceList *List = Cache.GetSourceList();
  647. // Create the text record parsers
  648. #if APT_PKG_ABI < 413
  649. pkgRecords Recs(Cache);
  650. #endif
  651. pkgSrcRecords SrcRecs(*List);
  652. if (_error->PendingError() == true)
  653. return false;
  654. // Create the download object
  655. AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
  656. pkgAcquire Fetcher(&Stat);
  657. SPtrArray<DscFile> Dsc = new DscFile[CmdL.FileSize()];
  658. // insert all downloaded uris into this set to avoid downloading them
  659. // twice
  660. set<string> queued;
  661. // Diff only mode only fetches .diff files
  662. bool const diffOnly = _config->FindB("APT::Get::Diff-Only", false);
  663. // Tar only mode only fetches .tar files
  664. bool const tarOnly = _config->FindB("APT::Get::Tar-Only", false);
  665. // Dsc only mode only fetches .dsc files
  666. bool const dscOnly = _config->FindB("APT::Get::Dsc-Only", false);
  667. // Load the requestd sources into the fetcher
  668. unsigned J = 0;
  669. std::string UntrustedList;
  670. for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
  671. {
  672. string Src;
  673. #if APT_PKG_ABI >= 413
  674. pkgSrcRecords::Parser *Last = FindSrc(*I,SrcRecs,Src,Cache);
  675. #else
  676. pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
  677. #endif
  678. if (Last == 0) {
  679. return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
  680. }
  681. if (Last->Index().IsTrusted() == false)
  682. UntrustedList += Src + " ";
  683. string srec = Last->AsStr();
  684. string::size_type pos = srec.find("\nVcs-");
  685. while (pos != string::npos)
  686. {
  687. pos += strlen("\nVcs-");
  688. string vcs = srec.substr(pos,srec.find(":",pos)-pos);
  689. if(vcs == "Browser")
  690. {
  691. pos = srec.find("\nVcs-", pos);
  692. continue;
  693. }
  694. pos += vcs.length()+2;
  695. string::size_type epos = srec.find("\n", pos);
  696. string uri = srec.substr(pos,epos-pos).c_str();
  697. ioprintf(c1out, _("NOTICE: '%s' packaging is maintained in "
  698. "the '%s' version control system at:\n"
  699. "%s\n"),
  700. Src.c_str(), vcs.c_str(), uri.c_str());
  701. if(vcs == "Bzr")
  702. ioprintf(c1out,_("Please use:\n"
  703. "bzr branch %s\n"
  704. "to retrieve the latest (possibly unreleased) "
  705. "updates to the package.\n"),
  706. uri.c_str());
  707. break;
  708. }
  709. // Back track
  710. vector<pkgSrcRecords::File2> Lst;
  711. if (Last->Files2(Lst) == false) {
  712. return false;
  713. }
  714. // Load them into the fetcher
  715. for (vector<pkgSrcRecords::File2>::const_iterator I = Lst.begin();
  716. I != Lst.end(); ++I)
  717. {
  718. // Try to guess what sort of file it is we are getting.
  719. if (I->Type == "dsc")
  720. {
  721. Dsc[J].Package = Last->Package();
  722. Dsc[J].Version = Last->Version();
  723. Dsc[J].Dsc = flNotDir(I->Path);
  724. }
  725. // Handle the only options so that multiple can be used at once
  726. if (diffOnly == true || tarOnly == true || dscOnly == true)
  727. {
  728. if ((diffOnly == true && I->Type == "diff") ||
  729. (tarOnly == true && I->Type == "tar") ||
  730. (dscOnly == true && I->Type == "dsc"))
  731. ; // Fine, we want this file downloaded
  732. else
  733. continue;
  734. }
  735. // don't download the same uri twice (should this be moved to
  736. // the fetcher interface itself?)
  737. if(queued.find(Last->Index().ArchiveURI(I->Path)) != queued.end())
  738. continue;
  739. queued.insert(Last->Index().ArchiveURI(I->Path));
  740. // check if we have a file with that md5 sum already localy
  741. std::string localFile = flNotDir(I->Path);
  742. if (FileExists(localFile) == true)
  743. if(I->Hashes.VerifyFile(localFile) == true)
  744. {
  745. ioprintf(c1out,_("Skipping already downloaded file '%s'\n"),
  746. localFile.c_str());
  747. continue;
  748. }
  749. // see if we have a hash (Acquire::ForceHash is the only way to have none)
  750. if (I->Hashes.usable() == false && _config->FindB("APT::Get::AllowUnauthenticated",false) == false)
  751. {
  752. ioprintf(c1out, "Skipping download of file '%s' as requested hashsum is not available for authentication\n",
  753. localFile.c_str());
  754. continue;
  755. }
  756. new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path),
  757. I->Hashes, I->FileSize, Last->Index().SourceInfo(*Last,*I), Src);
  758. }
  759. }
  760. // Display statistics
  761. unsigned long long FetchBytes = Fetcher.FetchNeeded();
  762. unsigned long long FetchPBytes = Fetcher.PartialPresent();
  763. unsigned long long DebBytes = Fetcher.TotalNeeded();
  764. if (CheckFreeSpaceBeforeDownload(".", (FetchBytes - FetchPBytes)) == false)
  765. return false;
  766. // Number of bytes
  767. if (DebBytes != FetchBytes)
  768. //TRANSLATOR: The required space between number and unit is already included
  769. // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
  770. ioprintf(c1out,_("Need to get %sB/%sB of source archives.\n"),
  771. SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str());
  772. else
  773. //TRANSLATOR: The required space between number and unit is already included
  774. // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
  775. ioprintf(c1out,_("Need to get %sB of source archives.\n"),
  776. SizeToStr(DebBytes).c_str());
  777. if (_config->FindB("APT::Get::Simulate",false) == true)
  778. {
  779. for (unsigned I = 0; I != J; I++)
  780. ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str());
  781. return true;
  782. }
  783. // Just print out the uris an exit if the --print-uris flag was used
  784. if (_config->FindB("APT::Get::Print-URIs") == true)
  785. {
  786. pkgAcquire::UriIterator I = Fetcher.UriBegin();
  787. for (; I != Fetcher.UriEnd(); ++I)
  788. cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
  789. I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
  790. return true;
  791. }
  792. // Disable drop-privs if "_apt" can not write to the target dir
  793. CheckDropPrivsMustBeDisabled(Fetcher);
  794. // check authentication status of the source as well
  795. if (UntrustedList != "" && !AuthPrompt(UntrustedList, false))
  796. return false;
  797. // Run it
  798. bool Failed = false;
  799. if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
  800. {
  801. return _error->Error(_("Failed to fetch some archives."));
  802. }
  803. if (_config->FindB("APT::Get::Download-only",false) == true)
  804. {
  805. c1out << _("Download complete and in download only mode") << endl;
  806. return true;
  807. }
  808. // Unpack the sources
  809. pid_t Process = ExecFork();
  810. if (Process == 0)
  811. {
  812. bool const fixBroken = _config->FindB("APT::Get::Fix-Broken", false);
  813. for (unsigned I = 0; I != J; ++I)
  814. {
  815. string Dir = Dsc[I].Package + '-' + Cache->VS().UpstreamVersion(Dsc[I].Version.c_str());
  816. // Diff only mode only fetches .diff files
  817. if (_config->FindB("APT::Get::Diff-Only",false) == true ||
  818. _config->FindB("APT::Get::Tar-Only",false) == true ||
  819. Dsc[I].Dsc.empty() == true)
  820. continue;
  821. // See if the package is already unpacked
  822. struct stat Stat;
  823. if (fixBroken == false && stat(Dir.c_str(),&Stat) == 0 &&
  824. S_ISDIR(Stat.st_mode) != 0)
  825. {
  826. ioprintf(c0out ,_("Skipping unpack of already unpacked source in %s\n"),
  827. Dir.c_str());
  828. }
  829. else
  830. {
  831. // Call dpkg-source
  832. std::string const sourceopts = _config->Find("DPkg::Source-Options", "-x");
  833. std::string S;
  834. strprintf(S, "%s %s %s",
  835. _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
  836. sourceopts.c_str(), Dsc[I].Dsc.c_str());
  837. if (system(S.c_str()) != 0)
  838. {
  839. fprintf(stderr, _("Unpack command '%s' failed.\n"), S.c_str());
  840. fprintf(stderr, _("Check if the 'dpkg-dev' package is installed.\n"));
  841. _exit(1);
  842. }
  843. }
  844. // Try to compile it with dpkg-buildpackage
  845. if (_config->FindB("APT::Get::Compile",false) == true)
  846. {
  847. string buildopts = _config->Find("APT::Get::Host-Architecture");
  848. if (buildopts.empty() == false)
  849. buildopts = "-a" + buildopts + " ";
  850. // get all active build profiles
  851. std::string const profiles = APT::Configuration::getBuildProfilesString();
  852. if (profiles.empty() == false)
  853. buildopts.append(" -P").append(profiles).append(" ");
  854. buildopts.append(_config->Find("DPkg::Build-Options","-b -uc"));
  855. // Call dpkg-buildpackage
  856. std::string S;
  857. strprintf(S, "cd %s && %s %s",
  858. Dir.c_str(),
  859. _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
  860. buildopts.c_str());
  861. if (system(S.c_str()) != 0)
  862. {
  863. fprintf(stderr, _("Build command '%s' failed.\n"), S.c_str());
  864. _exit(1);
  865. }
  866. }
  867. }
  868. _exit(0);
  869. }
  870. // Wait for the subprocess
  871. int Status = 0;
  872. while (waitpid(Process,&Status,0) != Process)
  873. {
  874. if (errno == EINTR)
  875. continue;
  876. return _error->Errno("waitpid","Couldn't wait for subprocess");
  877. }
  878. if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
  879. return _error->Error(_("Child process failed"));
  880. return true;
  881. }
  882. /*}}}*/
  883. // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
  884. // ---------------------------------------------------------------------
  885. /* This function will look at the build depends list of the given source
  886. package and install the necessary packages to make it true, or fail. */
  887. static bool DoBuildDep(CommandLine &CmdL)
  888. {
  889. CacheFile Cache;
  890. _config->Set("APT::Install-Recommends", false);
  891. if (Cache.Open(true) == false)
  892. return false;
  893. if (CmdL.FileSize() <= 1)
  894. return _error->Error(_("Must specify at least one package to check builddeps for"));
  895. // Read the source list
  896. if (Cache.BuildSourceList() == false)
  897. return false;
  898. pkgSourceList *List = Cache.GetSourceList();
  899. // Create the text record parsers
  900. pkgSrcRecords SrcRecs(*List);
  901. if (_error->PendingError() == true)
  902. return false;
  903. bool StripMultiArch;
  904. string hostArch = _config->Find("APT::Get::Host-Architecture");
  905. if (hostArch.empty() == false)
  906. {
  907. std::vector<std::string> archs = APT::Configuration::getArchitectures();
  908. if (std::find(archs.begin(), archs.end(), hostArch) == archs.end())
  909. return _error->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch.c_str());
  910. StripMultiArch = false;
  911. }
  912. else
  913. StripMultiArch = true;
  914. unsigned J = 0;
  915. for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
  916. {
  917. string Src;
  918. pkgSrcRecords::Parser *Last = 0;
  919. SPtr<pkgSrcRecords::Parser> LastOwner;
  920. // an unpacked debian source tree
  921. using APT::String::Startswith;
  922. if ((Startswith(*I, "./") || Startswith(*I, "/")) &&
  923. DirectoryExists(*I))
  924. {
  925. ioprintf(c1out, _("Note, using directory '%s' to get the build dependencies\n"), *I);
  926. // FIXME: how can we make this more elegant?
  927. std::string TypeName = "Debian control file";
  928. pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
  929. if(Type != NULL)
  930. LastOwner = Last = Type->CreateSrcPkgParser(*I);
  931. }
  932. // if its a local file (e.g. .dsc) use this
  933. else if (FileExists(*I))
  934. {
  935. ioprintf(c1out, _("Note, using file '%s' to get the build dependencies\n"), *I);
  936. // see if we can get a parser for this pkgIndexFile type
  937. string TypeName = "Debian " + flExtension(*I) + " file";
  938. pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
  939. if(Type != NULL)
  940. LastOwner = Last = Type->CreateSrcPkgParser(*I);
  941. } else {
  942. // normal case, search the cache for the source file
  943. #if APT_PKG_ABI >= 413
  944. Last = FindSrc(*I,SrcRecs,Src,Cache);
  945. #else
  946. Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
  947. #endif
  948. }
  949. if (Last == 0)
  950. return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
  951. // Process the build-dependencies
  952. vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps;
  953. // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary
  954. if (hostArch.empty() == false)
  955. {
  956. std::string nativeArch = _config->Find("APT::Architecture");
  957. _config->Set("APT::Architecture", hostArch);
  958. bool Success = Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch);
  959. _config->Set("APT::Architecture", nativeArch);
  960. if (Success == false)
  961. return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
  962. }
  963. else if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false)
  964. return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
  965. // Also ensure that build-essential packages are present
  966. Configuration::Item const *Opts = _config->Tree("APT::Build-Essential");
  967. if (Opts)
  968. Opts = Opts->Child;
  969. for (; Opts; Opts = Opts->Next)
  970. {
  971. if (Opts->Value.empty() == true)
  972. continue;
  973. pkgSrcRecords::Parser::BuildDepRec rec;
  974. rec.Package = Opts->Value;
  975. rec.Type = pkgSrcRecords::Parser::BuildDependIndep;
  976. rec.Op = 0;
  977. BuildDeps.push_back(rec);
  978. }
  979. if (BuildDeps.empty() == true)
  980. {
  981. ioprintf(c1out,_("%s has no build depends.\n"),Src.c_str());
  982. continue;
  983. }
  984. // Install the requested packages
  985. vector <pkgSrcRecords::Parser::BuildDepRec>::iterator D;
  986. pkgProblemResolver Fix(Cache);
  987. bool skipAlternatives = false; // skip remaining alternatives in an or group
  988. for (D = BuildDeps.begin(); D != BuildDeps.end(); ++D)
  989. {
  990. bool hasAlternatives = (((*D).Op & pkgCache::Dep::Or) == pkgCache::Dep::Or);
  991. if (skipAlternatives == true)
  992. {
  993. /*
  994. * if there are alternatives, we've already picked one, so skip
  995. * the rest
  996. *
  997. * TODO: this means that if there's a build-dep on A|B and B is
  998. * installed, we'll still try to install A; more importantly,
  999. * if A is currently broken, we cannot go back and try B. To fix
  1000. * this would require we do a Resolve cycle for each package we
  1001. * add to the install list. Ugh
  1002. */
  1003. if (!hasAlternatives)
  1004. skipAlternatives = false; // end of or group
  1005. continue;
  1006. }
  1007. if ((*D).Type == pkgSrcRecords::Parser::BuildConflict ||
  1008. (*D).Type == pkgSrcRecords::Parser::BuildConflictIndep)
  1009. {
  1010. pkgCache::GrpIterator Grp = Cache->FindGrp((*D).Package);
  1011. // Build-conflicts on unknown packages are silently ignored
  1012. if (Grp.end() == true)
  1013. continue;
  1014. for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))
  1015. {
  1016. pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache);
  1017. /*
  1018. * Remove if we have an installed version that satisfies the
  1019. * version criteria
  1020. */
  1021. if (IV.end() == false &&
  1022. Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true)
  1023. TryToInstallBuildDep(Pkg,Cache,Fix,true,false);
  1024. }
  1025. }
  1026. else // BuildDep || BuildDepIndep
  1027. {
  1028. if (_config->FindB("Debug::BuildDeps",false) == true)
  1029. cout << "Looking for " << (*D).Package << "...\n";
  1030. pkgCache::PkgIterator Pkg;
  1031. // Cross-Building?
  1032. if (StripMultiArch == false && D->Type != pkgSrcRecords::Parser::BuildDependIndep)
  1033. {
  1034. size_t const colon = D->Package.find(":");
  1035. if (colon != string::npos)
  1036. {
  1037. if (strcmp(D->Package.c_str() + colon, ":any") == 0 || strcmp(D->Package.c_str() + colon, ":native") == 0)
  1038. Pkg = Cache->FindPkg(D->Package.substr(0,colon));
  1039. else
  1040. Pkg = Cache->FindPkg(D->Package);
  1041. }
  1042. else
  1043. Pkg = Cache->FindPkg(D->Package, hostArch);
  1044. // a bad version either is invalid or doesn't satify dependency
  1045. #define BADVER(Ver) (Ver.end() == true || \
  1046. (D->Version.empty() == false && \
  1047. Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false))
  1048. APT::VersionList verlist;
  1049. if (Pkg.end() == false)
  1050. {
  1051. pkgCache::VerIterator Ver = (*Cache)[Pkg].InstVerIter(*Cache);
  1052. if (BADVER(Ver) == false)
  1053. verlist.insert(Ver);
  1054. Ver = (*Cache)[Pkg].CandidateVerIter(*Cache);
  1055. if (BADVER(Ver) == false)
  1056. verlist.insert(Ver);
  1057. }
  1058. if (verlist.empty() == true)
  1059. {
  1060. pkgCache::PkgIterator BuildPkg = Cache->FindPkg(D->Package, "native");
  1061. if (BuildPkg.end() == false && Pkg != BuildPkg)
  1062. {
  1063. pkgCache::VerIterator Ver = (*Cache)[BuildPkg].InstVerIter(*Cache);
  1064. if (BADVER(Ver) == false)
  1065. verlist.insert(Ver);
  1066. Ver = (*Cache)[BuildPkg].CandidateVerIter(*Cache);
  1067. if (BADVER(Ver) == false)
  1068. verlist.insert(Ver);
  1069. }
  1070. }
  1071. #undef BADVER
  1072. string forbidden;
  1073. // We need to decide if host or build arch, so find a version we can look at
  1074. APT::VersionList::const_iterator Ver = verlist.begin();
  1075. for (; Ver != verlist.end(); ++Ver)
  1076. {
  1077. forbidden.clear();
  1078. if (Ver->MultiArch == pkgCache::Version::None || Ver->MultiArch == pkgCache::Version::All)
  1079. {
  1080. if (colon == string::npos)
  1081. Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
  1082. else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
  1083. forbidden = "Multi-Arch: none";
  1084. else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
  1085. Pkg = Ver.ParentPkg().Group().FindPkg("native");
  1086. }
  1087. else if (Ver->MultiArch == pkgCache::Version::Same)
  1088. {
  1089. if (colon == string::npos)
  1090. Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
  1091. else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
  1092. forbidden = "Multi-Arch: same";
  1093. else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
  1094. Pkg = Ver.ParentPkg().Group().FindPkg("native");
  1095. }
  1096. else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
  1097. {
  1098. if (colon == string::npos)
  1099. Pkg = Ver.ParentPkg().Group().FindPkg("native");
  1100. else if (strcmp(D->Package.c_str() + colon, ":any") == 0 ||
  1101. strcmp(D->Package.c_str() + colon, ":native") == 0)
  1102. forbidden = "Multi-Arch: foreign";
  1103. }
  1104. else if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
  1105. {
  1106. if (colon == string::npos)
  1107. Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
  1108. else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
  1109. {
  1110. // prefer any installed over preferred non-installed architectures
  1111. pkgCache::GrpIterator Grp = Ver.ParentPkg().Group();
  1112. // we don't check for version here as we are better of with upgrading than remove and install
  1113. for (Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))
  1114. if (Pkg.CurrentVer().end() == false)
  1115. break;
  1116. if (Pkg.end() == true)
  1117. Pkg = Grp.FindPreferredPkg(true);
  1118. }
  1119. else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
  1120. Pkg = Ver.ParentPkg().Group().FindPkg("native");
  1121. }
  1122. if (forbidden.empty() == false)
  1123. {
  1124. if (_config->FindB("Debug::BuildDeps",false) == true)
  1125. cout << D->Package.substr(colon, string::npos) << " is not allowed from " << forbidden << " package " << (*D).Package << " (" << Ver.VerStr() << ")" << endl;
  1126. continue;
  1127. }
  1128. //we found a good version
  1129. break;
  1130. }
  1131. if (Ver == verlist.end())
  1132. {
  1133. if (_config->FindB("Debug::BuildDeps",false) == true)
  1134. cout << " No multiarch info as we have no satisfying installed nor candidate for " << D->Package << " on build or host arch" << endl;
  1135. if (forbidden.empty() == false)
  1136. {
  1137. if (hasAlternatives)
  1138. continue;
  1139. return _error->Error(_("%s dependency for %s can't be satisfied "
  1140. "because %s is not allowed on '%s' packages"),
  1141. Last->BuildDepType(D->Type), Src.c_str(),
  1142. D->Package.c_str(), forbidden.c_str());
  1143. }
  1144. }
  1145. }
  1146. else
  1147. Pkg = Cache->FindPkg(D->Package);
  1148. if (Pkg.end() == true || (Pkg->VersionList == 0 && Pkg->ProvidesList == 0))
  1149. {
  1150. if (_config->FindB("Debug::BuildDeps",false) == true)
  1151. cout << " (not found)" << (*D).Package << endl;
  1152. if (hasAlternatives)
  1153. continue;
  1154. return _error->Error(_("%s dependency for %s cannot be satisfied "
  1155. "because the package %s cannot be found"),
  1156. Last->BuildDepType((*D).Type),Src.c_str(),
  1157. (*D).Package.c_str());
  1158. }
  1159. pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache);
  1160. if (IV.end() == false)
  1161. {
  1162. if (_config->FindB("Debug::BuildDeps",false) == true)
  1163. cout << " Is installed\n";
  1164. if (D->Version.empty() == true ||
  1165. Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true)
  1166. {
  1167. skipAlternatives = hasAlternatives;
  1168. continue;
  1169. }
  1170. if (_config->FindB("Debug::BuildDeps",false) == true)
  1171. cout << " ...but the installed version doesn't meet the version requirement\n";
  1172. if (((*D).Op & pkgCache::Dep::LessEq) == pkgCache::Dep::LessEq)
  1173. return _error->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
  1174. Last->BuildDepType((*D).Type), Src.c_str(), Pkg.FullName(true).c_str());
  1175. }
  1176. // Only consider virtual packages if there is no versioned dependency
  1177. if ((*D).Version.empty() == true)
  1178. {
  1179. /*
  1180. * If this is a virtual package, we need to check the list of
  1181. * packages that provide it and see if any of those are
  1182. * installed
  1183. */
  1184. pkgCache::PrvIterator Prv = Pkg.ProvidesList();
  1185. for (; Prv.end() != true; ++Prv)
  1186. {
  1187. if (_config->FindB("Debug::BuildDeps",false) == true)
  1188. cout << " Checking provider " << Prv.OwnerPkg().FullName() << endl;
  1189. if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false)
  1190. break;
  1191. }
  1192. if (Prv.end() == false)
  1193. {
  1194. if (_config->FindB("Debug::BuildDeps",false) == true)
  1195. cout << " Is provided by installed package " << Prv.OwnerPkg().FullName() << endl;
  1196. skipAlternatives = hasAlternatives;
  1197. continue;
  1198. }
  1199. }
  1200. else // versioned dependency
  1201. {
  1202. pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache);
  1203. if (CV.end() == true ||
  1204. Cache->VS().CheckDep(CV.VerStr(),(*D).Op,(*D).Version.c_str()) == false)
  1205. {
  1206. if (hasAlternatives)
  1207. continue;
  1208. else if (CV.end() == false)
  1209. return _error->Error(_("%s dependency for %s cannot be satisfied "
  1210. "because candidate version of package %s "
  1211. "can't satisfy version requirements"),
  1212. Last->BuildDepType(D->Type), Src.c_str(),
  1213. D->Package.c_str());
  1214. else
  1215. return _error->Error(_("%s dependency for %s cannot be satisfied "
  1216. "because package %s has no candidate version"),
  1217. Last->BuildDepType(D->Type), Src.c_str(),
  1218. D->Package.c_str());
  1219. }
  1220. }
  1221. if (TryToInstallBuildDep(Pkg,Cache,Fix,false,false,false) == true)
  1222. {
  1223. // We successfully installed something; skip remaining alternatives
  1224. skipAlternatives = hasAlternatives;
  1225. if(_config->FindB("APT::Get::Build-Dep-Automatic", false) == true)
  1226. Cache->MarkAuto(Pkg, true);
  1227. continue;
  1228. }
  1229. else if (hasAlternatives)
  1230. {
  1231. if (_config->FindB("Debug::BuildDeps",false) == true)
  1232. cout << " Unsatisfiable, trying alternatives\n";
  1233. continue;
  1234. }
  1235. else
  1236. {
  1237. return _error->Error(_("Failed to satisfy %s dependency for %s: %s"),
  1238. Last->BuildDepType((*D).Type),
  1239. Src.c_str(),
  1240. (*D).Package.c_str());
  1241. }
  1242. }
  1243. }
  1244. if (Fix.Resolve(true) == false)
  1245. _error->Discard();
  1246. // Now we check the state of the packages,
  1247. if (Cache->BrokenCount() != 0)
  1248. {
  1249. ShowBroken(cout, Cache, false);
  1250. return _error->Error(_("Build-dependencies for %s could not be satisfied."),*I);
  1251. }
  1252. }
  1253. if (InstallPackages(Cache, false, true) == false)
  1254. return _error->Error(_("Failed to process build dependencies"));
  1255. return true;
  1256. }
  1257. /*}}}*/
  1258. // DoChangelog - Get changelog from the command line /*{{{*/
  1259. static bool DoChangelog(CommandLine &CmdL)
  1260. {
  1261. CacheFile Cache;
  1262. if (Cache.ReadOnlyOpen() == false)
  1263. return false;
  1264. APT::CacheSetHelper helper;
  1265. APT::VersionList verset = APT::VersionList::FromCommandLine(Cache,
  1266. CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
  1267. if (verset.empty() == true)
  1268. return false;
  1269. pkgAcquire Fetcher;
  1270. AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
  1271. Fetcher.SetLog(&Stat);
  1272. bool const downOnly = _config->FindB("APT::Get::Download-Only", false);
  1273. bool const printOnly = _config->FindB("APT::Get::Print-URIs", false);
  1274. for (APT::VersionList::const_iterator Ver = verset.begin();
  1275. Ver != verset.end();
  1276. ++Ver)
  1277. {
  1278. if (printOnly)
  1279. new pkgAcqChangelog(&Fetcher, Ver, "/dev/null");
  1280. else if (downOnly)
  1281. new pkgAcqChangelog(&Fetcher, Ver, ".");
  1282. else
  1283. new pkgAcqChangelog(&Fetcher, Ver);
  1284. }
  1285. if (printOnly == false)
  1286. {
  1287. // Disable drop-privs if "_apt" can not write to the target dir
  1288. CheckDropPrivsMustBeDisabled(Fetcher);
  1289. if (_error->PendingError() == true)
  1290. return false;
  1291. bool Failed = false;
  1292. if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
  1293. return false;
  1294. }
  1295. if (downOnly == false || printOnly == true)
  1296. {
  1297. bool Failed = false;
  1298. for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
  1299. {
  1300. if (printOnly)
  1301. {
  1302. if ((*I)->ErrorText.empty() == false)
  1303. {
  1304. Failed = true;
  1305. _error->Error("%s", (*I)->ErrorText.c_str());
  1306. }
  1307. else
  1308. cout << '\'' << (*I)->DescURI() << "' " << flNotDir((*I)->DestFile) << std::endl;
  1309. }
  1310. else
  1311. DisplayFileInPager((*I)->DestFile);
  1312. }
  1313. return Failed == false;
  1314. }
  1315. return true;
  1316. }
  1317. /*}}}*/
  1318. // DoFiles - Lists all IndexTargets /*{{{*/
  1319. static std::string format_key(std::string key)
  1320. {
  1321. // deb822 is case-insensitive, but the human eye prefers candy
  1322. std::transform(key.begin(), key.end(), key.begin(), ::tolower);
  1323. key[0] = ::toupper(key[0]);
  1324. size_t found = key.find("_uri");
  1325. if (found != std::string::npos)
  1326. key.replace(found, 4, "-URI");
  1327. while ((found = key.find('_')) != std::string::npos)
  1328. {
  1329. key[found] = '-';
  1330. key[found + 1] = ::toupper(key[found + 1]);
  1331. }
  1332. return key;
  1333. }
  1334. static bool DoFiles(CommandLine &CmdL)
  1335. {
  1336. pkgCacheFile CacheFile;
  1337. pkgSourceList *SrcList = CacheFile.GetSourceList();
  1338. if (SrcList == NULL)
  1339. return false;
  1340. std::string const Format = _config->Find("APT::Get::Files::Format");
  1341. bool const ReleaseInfo = _config->FindB("APT::Get::Files::ReleaseInfo", true);
  1342. bool Filtered = CmdL.FileSize() > 1;
  1343. for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); ++S)
  1344. {
  1345. std::vector<IndexTarget> const targets = (*S)->GetIndexTargets();
  1346. std::map<std::string, string> AddOptions;
  1347. if (ReleaseInfo)
  1348. {
  1349. AddOptions.insert(std::make_pair("TRUSTED", ((*S)->IsTrusted() ? "yes" : "no")));
  1350. pkgCache &Cache = *CacheFile.GetPkgCache();
  1351. pkgCache::RlsFileIterator const RlsFile = (*S)->FindInCache(Cache, false);
  1352. if (RlsFile.end())
  1353. continue;
  1354. #define APT_RELEASE(X,Y) if (RlsFile.Y() != NULL) AddOptions.insert(std::make_pair(X, RlsFile.Y()))
  1355. APT_RELEASE("CODENAME", Codename);
  1356. APT_RELEASE("SUITE", Archive);
  1357. APT_RELEASE("VERSION", Version);
  1358. APT_RELEASE("ORIGIN", Origin);
  1359. APT_RELEASE("LABEL", Label);
  1360. #undef APT_RELEASE
  1361. }
  1362. for (std::vector<IndexTarget>::const_iterator T = targets.begin(); T != targets.end(); ++T)
  1363. {
  1364. std::string filename = T->Option(ReleaseInfo ? IndexTarget::EXISTING_FILENAME : IndexTarget::FILENAME);
  1365. if (filename.empty())
  1366. continue;
  1367. std::ostringstream stanza;
  1368. if (Filtered || Format.empty())
  1369. {
  1370. stanza << "MetaKey: " << T->MetaKey << "\n"
  1371. << "ShortDesc: " << T->ShortDesc << "\n"
  1372. << "Description: " << T->Description << "\n"
  1373. << "URI: " << T->URI << "\n"
  1374. << "Filename: " << filename << "\n"
  1375. << "Optional: " << (T->IsOptional ? "yes" : "no") << "\n";
  1376. for (std::map<std::string,std::string>::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O)
  1377. stanza << format_key(O->first) << ": " << O->second << "\n";
  1378. for (std::map<std::string,std::string>::const_iterator O = T->Options.begin(); O != T->Options.end(); ++O)
  1379. stanza << format_key(O->first) << ": " << O->second << "\n";
  1380. stanza << "\n";
  1381. if (Filtered)
  1382. {
  1383. // that is a bit crude, but good enough for now
  1384. bool found = true;
  1385. std::string haystack = std::string("\n") + stanza.str() + "\n";
  1386. std::transform(haystack.begin(), haystack.end(), haystack.begin(), ::tolower);
  1387. size_t const filesize = CmdL.FileSize() - 1;
  1388. for (size_t i = 0; i != filesize; ++i)
  1389. {
  1390. std::string needle = std::string("\n") + CmdL.FileList[i + 1] + "\n";
  1391. std::transform(needle.begin(), needle.end(), needle.begin(), ::tolower);
  1392. if (haystack.find(needle) != std::string::npos)
  1393. continue;
  1394. found = false;
  1395. break;
  1396. }
  1397. if (found == false)
  1398. continue;
  1399. }
  1400. }
  1401. if (Format.empty())
  1402. cout << stanza.str();
  1403. else
  1404. {
  1405. std::string out = SubstVar(Format, "$(FILENAME)", filename);
  1406. out = T->Format(out);
  1407. for (std::map<std::string,std::string>::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O)
  1408. out = SubstVar(out, std::string("$(") + O->first + ")", O->second);
  1409. cout << out << std::endl;
  1410. }
  1411. }
  1412. }
  1413. return true;
  1414. }
  1415. /*}}}*/
  1416. // ShowHelp - Show a help screen /*{{{*/
  1417. // ---------------------------------------------------------------------
  1418. /* */
  1419. static bool ShowHelp(CommandLine &)
  1420. {
  1421. ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
  1422. if (_config->FindB("version") == true)
  1423. {
  1424. cout << _("Supported modules:") << endl;
  1425. for (unsigned I = 0; I != pkgVersioningSystem::GlobalListLen; I++)
  1426. {
  1427. pkgVersioningSystem *VS = pkgVersioningSystem::GlobalList[I];
  1428. if (_system != 0 && _system->VS == VS)
  1429. cout << '*';
  1430. else
  1431. cout << ' ';
  1432. cout << "Ver: " << VS->Label << endl;
  1433. /* Print out all the packaging systems that will work with
  1434. this VS */
  1435. for (unsigned J = 0; J != pkgSystem::GlobalListLen; J++)
  1436. {
  1437. pkgSystem *Sys = pkgSystem::GlobalList[J];
  1438. if (_system == Sys)
  1439. cout << '*';
  1440. else
  1441. cout << ' ';
  1442. if (Sys->VS->TestCompatibility(*VS) == true)
  1443. cout << "Pkg: " << Sys->Label << " (Priority " << Sys->Score(*_config) << ")" << endl;
  1444. }
  1445. }
  1446. for (unsigned I = 0; I != pkgSourceList::Type::GlobalListLen; I++)
  1447. {
  1448. pkgSourceList::Type *Type = pkgSourceList::Type::GlobalList[I];
  1449. cout << " S.L: '" << Type->Name << "' " << Type->Label << endl;
  1450. }
  1451. for (unsigned I = 0; I != pkgIndexFile::Type::GlobalListLen; I++)
  1452. {
  1453. pkgIndexFile::Type *Type = pkgIndexFile::Type::GlobalList[I];
  1454. cout << " Idx: " << Type->Label << endl;
  1455. }
  1456. return true;
  1457. }
  1458. cout <<
  1459. _("Usage: apt-get [options] command\n"
  1460. " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
  1461. " apt-get [options] source pkg1 [pkg2 ...]\n"
  1462. "\n"
  1463. "apt-get is a simple command line interface for downloading and\n"
  1464. "installing packages. The most frequently used commands are update\n"
  1465. "and install.\n"
  1466. "\n"
  1467. "Commands:\n"
  1468. " update - Retrieve new lists of packages\n"
  1469. " upgrade - Perform an upgrade\n"
  1470. " install - Install new packages (pkg is libc6 not libc6.deb)\n"
  1471. " remove - Remove packages\n"
  1472. " autoremove - Remove automatically all unused packages\n"
  1473. " purge - Remove packages and config files\n"
  1474. " source - Download source archives\n"
  1475. " build-dep - Configure build-dependencies for source packages\n"
  1476. " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
  1477. " dselect-upgrade - Follow dselect selections\n"
  1478. " clean - Erase downloaded archive files\n"
  1479. " autoclean - Erase old downloaded archive files\n"
  1480. " check - Verify that there are no broken dependencies\n"
  1481. " changelog - Download and display the changelog for the given package\n"
  1482. " download - Download the binary package into the current directory\n"
  1483. "\n"
  1484. "Options:\n"
  1485. " -h This help text.\n"
  1486. " -q Loggable output - no progress indicator\n"
  1487. " -qq No output except for errors\n"
  1488. " -d Download only - do NOT install or unpack archives\n"
  1489. " -s No-act. Perform ordering simulation\n"
  1490. " -y Assume Yes to all queries and do not prompt\n"
  1491. " -f Attempt to correct a system with broken dependencies in place\n"
  1492. " -m Attempt to continue if archives are unlocatable\n"
  1493. " -u Show a list of upgraded packages as well\n"
  1494. " -b Build the source package after fetching it\n"
  1495. " -V Show verbose version numbers\n"
  1496. " -c=? Read this configuration file\n"
  1497. " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
  1498. "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
  1499. "pages for more information and options.\n"
  1500. " This APT has Super Cow Powers.\n");
  1501. return true;
  1502. }
  1503. /*}}}*/
  1504. int main(int argc,const char *argv[]) /*{{{*/
  1505. {
  1506. CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate},
  1507. {"upgrade",&DoUpgrade},
  1508. {"install",&DoInstall},
  1509. {"remove",&DoInstall},
  1510. {"purge",&DoInstall},
  1511. {"autoremove",&DoInstall},
  1512. {"markauto",&DoMarkAuto},
  1513. {"unmarkauto",&DoMarkAuto},
  1514. {"dist-upgrade",&DoDistUpgrade},
  1515. {"dselect-upgrade",&DoDSelectUpgrade},
  1516. {"build-dep",&DoBuildDep},
  1517. {"clean",&DoClean},
  1518. {"autoclean",&DoAutoClean},
  1519. {"check",&DoCheck},
  1520. {"source",&DoSource},
  1521. {"download",&DoDownload},
  1522. {"changelog",&DoChangelog},
  1523. {"files",&DoFiles},
  1524. {"moo",&DoMoo},
  1525. {"help",&ShowHelp},
  1526. {0,0}};
  1527. std::vector<CommandLine::Args> Args = getCommandArgs("apt-get", CommandLine::GetCommand(Cmds, argc, argv));
  1528. // Set up gettext support
  1529. setlocale(LC_ALL,"");
  1530. textdomain(PACKAGE);
  1531. // Parse the command line and initialize the package library
  1532. CommandLine CmdL;
  1533. ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
  1534. // see if we are in simulate mode
  1535. CheckSimulateMode(CmdL);
  1536. // Init the signals
  1537. InitSignals();
  1538. // Setup the output streams
  1539. InitOutput();
  1540. // Match the operation
  1541. CmdL.DispatchArg(Cmds);
  1542. // Print any errors or warnings found during parsing
  1543. bool const Errors = _error->PendingError();
  1544. if (_config->FindI("quiet",0) > 0)
  1545. _error->DumpErrors();
  1546. else
  1547. _error->DumpErrors(GlobalError::DEBUG);
  1548. return Errors == true ? 100 : 0;
  1549. }
  1550. /*}}}*/