apt-get.cc 57 KB

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