apt-get.cc 59 KB

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