apt-get.cc 59 KB

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