apt-get.cc 59 KB

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