apt-get.cc 57 KB

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