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