apt-get.cc 59 KB

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