apt-get.cc 57 KB

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