]> git.saurik.com Git - apt.git/blame - cmdline/apt-get.cc
Changed size of offset type
[apt.git] / cmdline / apt-get.cc
CommitLineData
0a8e3465
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
0919e3f9 3// $Id: apt-get.cc,v 1.6 1998/11/11 23:45:56 jgg Exp $
0a8e3465
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
18 dist-upgrade - Powerfull upgrader designed to handle the issues with
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 /*{{{*/
28#include <apt-pkg/error.h>
29#include <apt-pkg/cmndline.h>
30#include <apt-pkg/init.h>
31#include <apt-pkg/depcache.h>
32#include <apt-pkg/sourcelist.h>
33#include <apt-pkg/pkgcachegen.h>
34#include <apt-pkg/algorithms.h>
0919e3f9 35#include <apt-pkg/acquire-item.h>
0a8e3465
AL
36
37#include <config.h>
38
0919e3f9
AL
39#include "acqprogress.h"
40
0a8e3465
AL
41#include <fstream.h>
42 /*}}}*/
43
44ostream c0out;
45ostream c1out;
46ostream c2out;
47ofstream devnull("/dev/null");
48unsigned int ScreenWidth = 80;
49
50// ShowList - Show a list /*{{{*/
51// ---------------------------------------------------------------------
52/* This prints out a string of space seperated words with a title and
53 a two space indent line wraped to the current screen width. */
54void ShowList(ostream &out,string Title,string List)
55{
56 if (List.empty() == true)
57 return;
58
59 // Acount for the leading space
60 int ScreenWidth = ::ScreenWidth - 3;
61
62 out << Title << endl;
63 string::size_type Start = 0;
64 while (Start < List.size())
65 {
66 string::size_type End;
67 if (Start + ScreenWidth >= List.size())
68 End = List.size();
69 else
70 End = List.rfind(' ',Start+ScreenWidth);
71
72 if (End == string::npos || End < Start)
73 End = Start + ScreenWidth;
74 out << " " << string(List,Start,End - Start) << endl;
75 Start = End + 1;
76 }
77}
78 /*}}}*/
79// ShowBroken - Debugging aide /*{{{*/
80// ---------------------------------------------------------------------
81/* This prints out the names of all the packages that are broken along
82 with the name of each each broken dependency and a quite version
83 description. */
84void ShowBroken(ostream &out,pkgDepCache &Cache)
85{
86 out << "Sorry, but the following packages are broken - this means they have unmet" << endl;
87 out << "dependencies:" << endl;
88 pkgCache::PkgIterator I = Cache.PkgBegin();
89 for (;I.end() != true; I++)
90 {
303a1703
AL
91 if (Cache[I].InstBroken() == false)
92 continue;
93
94 // Print out each package and the failed dependencies
95 out <<" " << I.Name() << ":";
96 int Indent = strlen(I.Name()) + 3;
97 bool First = true;
98 if (Cache[I].InstVerIter(Cache).end() == true)
0a8e3465 99 {
303a1703
AL
100 cout << endl;
101 continue;
102 }
103
104 for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; D++)
105 {
106 if (Cache.IsImportantDep(D) == false || (Cache[D] &
107 pkgDepCache::DepInstall) != 0)
108 continue;
109
110 if (First == false)
111 for (int J = 0; J != Indent; J++)
112 out << ' ';
113 First = false;
114
115 if (D->Type == pkgCache::Dep::Conflicts)
116 out << " Conflicts:" << D.TargetPkg().Name();
117 else
118 out << " Depends:" << D.TargetPkg().Name();
119
120 // Show a quick summary of the version requirements
121 if (D.TargetVer() != 0)
122 out << " (" << D.CompType() << " " << D.TargetVer() <<
123 ")";
124
125 /* Show a summary of the target package if possible. In the case
126 of virtual packages we show nothing */
127
128 pkgCache::PkgIterator Targ = D.TargetPkg();
129 if (Targ->ProvidesList == 0)
0a8e3465 130 {
303a1703
AL
131 out << " but ";
132 pkgCache::VerIterator Ver = Cache[Targ].InstVerIter(Cache);
133 if (Ver.end() == false)
134 out << Ver.VerStr() << " is installed";
0a8e3465 135 else
7e798dd7 136 {
303a1703
AL
137 if (Cache[Targ].CandidateVerIter(Cache).end() == true)
138 {
139 if (Targ->ProvidesList == 0)
140 out << "it is not installable";
141 else
142 out << "it is a virtual package";
143 }
7e798dd7
AL
144 else
145 out << "it is not installed";
303a1703
AL
146 }
147 }
148
149 out << endl;
150 }
0a8e3465
AL
151 }
152}
153 /*}}}*/
154// ShowNew - Show packages to newly install /*{{{*/
155// ---------------------------------------------------------------------
156/* */
157void ShowNew(ostream &out,pkgDepCache &Dep)
158{
159 /* Print out a list of packages that are going to be removed extra
160 to what the user asked */
161 pkgCache::PkgIterator I = Dep.PkgBegin();
162 string List;
163 for (;I.end() != true; I++)
164 if (Dep[I].NewInstall() == true)
165 List += string(I.Name()) + " ";
166 ShowList(out,"The following NEW packages will be installed:",List);
167}
168 /*}}}*/
169// ShowDel - Show packages to delete /*{{{*/
170// ---------------------------------------------------------------------
171/* */
172void ShowDel(ostream &out,pkgDepCache &Dep)
173{
174 /* Print out a list of packages that are going to be removed extra
175 to what the user asked */
176 pkgCache::PkgIterator I = Dep.PkgBegin();
177 string List;
178 for (;I.end() != true; I++)
179 if (Dep[I].Delete() == true)
180 List += string(I.Name()) + " ";
181 ShowList(out,"The following packages will be REMOVED:",List);
182}
183 /*}}}*/
184// ShowKept - Show kept packages /*{{{*/
185// ---------------------------------------------------------------------
186/* */
187void ShowKept(ostream &out,pkgDepCache &Dep)
188{
189 pkgCache::PkgIterator I = Dep.PkgBegin();
190 string List;
191 for (;I.end() != true; I++)
192 {
193 // Not interesting
194 if (Dep[I].Upgrade() == true || Dep[I].Upgradable() == false ||
195 I->CurrentVer == 0 || Dep[I].Delete() == true)
196 continue;
197
198 List += string(I.Name()) + " ";
199 }
200 ShowList(out,"The following packages have been kept back",List);
201}
202 /*}}}*/
203// ShowUpgraded - Show upgraded packages /*{{{*/
204// ---------------------------------------------------------------------
205/* */
206void ShowUpgraded(ostream &out,pkgDepCache &Dep)
207{
208 pkgCache::PkgIterator I = Dep.PkgBegin();
209 string List;
210 for (;I.end() != true; I++)
211 {
212 // Not interesting
213 if (Dep[I].Upgrade() == false || Dep[I].NewInstall() == true)
214 continue;
215
216 List += string(I.Name()) + " ";
217 }
218 ShowList(out,"The following packages will be upgraded",List);
219}
220 /*}}}*/
221// ShowHold - Show held but changed packages /*{{{*/
222// ---------------------------------------------------------------------
223/* */
224void ShowHold(ostream &out,pkgDepCache &Dep)
225{
226 pkgCache::PkgIterator I = Dep.PkgBegin();
227 string List;
228 for (;I.end() != true; I++)
229 {
230 if (Dep[I].InstallVer != (pkgCache::Version *)I.CurrentVer() &&
231 I->SelectedState == pkgCache::State::Hold)
232 List += string(I.Name()) + " ";
233 }
234
235 ShowList(out,"The following held packages will be changed:",List);
236}
237 /*}}}*/
238// ShowEssential - Show an essential package warning /*{{{*/
239// ---------------------------------------------------------------------
240/* This prints out a warning message that is not to be ignored. It shows
241 all essential packages and their dependents that are to be removed.
242 It is insanely risky to remove the dependents of an essential package! */
243void ShowEssential(ostream &out,pkgDepCache &Dep)
244{
245 pkgCache::PkgIterator I = Dep.PkgBegin();
246 string List;
247 bool *Added = new bool[Dep.HeaderP->PackageCount];
93641593 248 for (unsigned int I = 0; I != Dep.HeaderP->PackageCount; I++)
0a8e3465
AL
249 Added[I] = false;
250
251 for (;I.end() != true; I++)
252 {
253 if ((I->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential)
254 continue;
255
256 // The essential package is being removed
257 if (Dep[I].Delete() == true)
258 {
259 if (Added[I->ID] == false)
260 {
261 Added[I->ID] = true;
262 List += string(I.Name()) + " ";
263 }
264 }
265
266 if (I->CurrentVer == 0)
267 continue;
268
269 // Print out any essential package depenendents that are to be removed
270 for (pkgDepCache::DepIterator D = I.CurrentVer().DependsList(); D.end() == false; D++)
271 {
272 pkgCache::PkgIterator P = D.SmartTargetPkg();
273 if (Dep[P].Delete() == true)
274 {
275 if (Added[P->ID] == true)
276 continue;
277 Added[P->ID] = true;
278 List += string(P.Name()) + " ";
279 }
280 }
281 }
282
283 if (List.empty() == false)
284 out << "WARNING: The following essential packages will be removed" << endl;
285 ShowList(out,"This should NOT be done unless you know exactly what you are doing!",List);
286
287 delete [] Added;
288}
289 /*}}}*/
290// Stats - Show some statistics /*{{{*/
291// ---------------------------------------------------------------------
292/* */
293void Stats(ostream &out,pkgDepCache &Dep)
294{
295 unsigned long Upgrade = 0;
296 unsigned long Install = 0;
297 for (pkgCache::PkgIterator I = Dep.PkgBegin(); I.end() == false; I++)
298 {
299 if (Dep[I].NewInstall() == true)
300 Install++;
301 else
302 if (Dep[I].Upgrade() == true)
303 Upgrade++;
304 }
305
306 out << Upgrade << " packages upgraded, " <<
307 Install << " newly installed, " <<
308 Dep.DelCount() << " to remove and " <<
309 Dep.KeepCount() << " not upgraded." << endl;
310
311 if (Dep.BadCount() != 0)
312 out << Dep.BadCount() << " packages not fully installed or removed." << endl;
313}
314 /*}}}*/
315
316// class CacheFile - Cover class for some dependency cache functions /*{{{*/
317// ---------------------------------------------------------------------
318/* */
319class CacheFile
320{
321 public:
322
323 FileFd *File;
324 MMap *Map;
325 pkgDepCache *Cache;
326
327 inline operator pkgDepCache &() {return *Cache;};
328 inline pkgDepCache *operator ->() {return Cache;};
329 inline pkgDepCache &operator *() {return *Cache;};
330
331 bool Open();
332 CacheFile() : File(0), Map(0), Cache(0) {};
333 ~CacheFile()
334 {
335 delete Cache;
336 delete Map;
337 delete File;
338 }
339};
340 /*}}}*/
341// CacheFile::Open - Open the cache file /*{{{*/
342// ---------------------------------------------------------------------
343/* This routine generates the caches and then opens the dependency cache
344 and verifies that the system is OK. */
345bool CacheFile::Open()
346{
347 // Create a progress class
348 OpTextProgress Progress(*_config);
349
350 // Read the source list
351 pkgSourceList List;
352 if (List.ReadMainList() == false)
353 return _error->Error("The list of sources could not be read.");
354
355 // Build all of the caches
356 pkgMakeStatusCache(List,Progress);
357 if (_error->PendingError() == true)
358 return _error->Error("The package lists or status file could not be parsed or opened.");
359
360 Progress.Done();
361
362 // Open the cache file
303a1703 363 File = new FileFd(_config->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly);
0a8e3465
AL
364 if (_error->PendingError() == true)
365 return false;
366
367 Map = new MMap(*File,MMap::Public | MMap::ReadOnly);
368 if (_error->PendingError() == true)
369 return false;
370
371 Cache = new pkgDepCache(*Map,Progress);
372 if (_error->PendingError() == true)
373 return false;
374
375 Progress.Done();
376
377 // Check that the system is OK
378 if (Cache->DelCount() != 0 || Cache->InstCount() != 0)
379 return _error->Error("Internal Error, non-zero counts");
380
381 // Apply corrections for half-installed packages
382 if (pkgApplyStatus(*Cache) == false)
383 return false;
384
385 // Nothing is broken
386 if (Cache->BrokenCount() == 0)
387 return true;
388
389 // Attempt to fix broken things
390 if (_config->FindB("APT::Get::Fix-Broken",false) == true)
391 {
392 c1out << "Correcting dependencies..." << flush;
393 if (pkgFixBroken(*Cache) == false || Cache->BrokenCount() != 0)
394 {
395 c1out << " failed." << endl;
396 ShowBroken(c1out,*this);
397
398 return _error->Error("Unable to correct dependencies");
399 }
7e798dd7
AL
400 if (pkgMinimizeUpgrade(*Cache) == false)
401 return _error->Error("Unable to minimize the upgrade set");
0a8e3465
AL
402
403 c1out << " Done" << endl;
404 }
405 else
406 {
407 c1out << "You might want to run `apt-get -f install' to correct these." << endl;
408 ShowBroken(c1out,*this);
409
410 return _error->Error("Unmet dependencies. Try using -f.");
411 }
412
413 return true;
414}
415 /*}}}*/
416
417// InstallPackages - Actually download and install the packages /*{{{*/
418// ---------------------------------------------------------------------
419/* This displays the informative messages describing what is going to
420 happen and then calls the download routines */
421bool InstallPackages(pkgDepCache &Cache,bool ShwKept)
422{
423 ShowDel(c1out,Cache);
424 ShowNew(c1out,Cache);
425 if (ShwKept == true)
426 ShowKept(c1out,Cache);
427 ShowHold(c1out,Cache);
428 if (_config->FindB("APT::Get::Show-Upgraded",false) == true)
429 ShowUpgraded(c1out,Cache);
430 ShowEssential(c1out,Cache);
431 Stats(c1out,Cache);
432
433 // Sanity check
434 if (Cache.BrokenCount() != 0)
435 {
436 ShowBroken(c1out,Cache);
437 return _error->Error("Internal Error, InstallPackages was called with broken packages!");
438 }
439
440 if (Cache.DelCount() == 0 && Cache.InstCount() == 0 &&
441 Cache.BadCount() == 0)
442 return true;
443
444 return true;
445}
446 /*}}}*/
447
448// DoUpdate - Update the package lists /*{{{*/
449// ---------------------------------------------------------------------
450/* */
0919e3f9 451bool DoUpdate(CommandLine &)
0a8e3465 452{
0919e3f9
AL
453 // Get the source list
454 pkgSourceList List;
455 if (List.ReadMainList() == false)
456 return false;
457
458 // Create the download object
459 AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
460 pkgAcquire Fetcher(&Stat);
461
462 // Populate it with the source selection
463 pkgSourceList::const_iterator I;
464 for (I = List.begin(); I != List.end(); I++)
465 {
466 new pkgAcqIndex(&Fetcher,I);
467 if (_error->PendingError() == true)
468 return false;
469 }
470
471 // Run it
472 if (Fetcher.Run() == false)
473 return false;
474
475 // Prepare the cache.
476 CacheFile Cache;
477 if (Cache.Open() == false)
478 return false;
479
480 return true;
0a8e3465
AL
481}
482 /*}}}*/
483// DoUpgrade - Upgrade all packages /*{{{*/
484// ---------------------------------------------------------------------
485/* Upgrade all packages without installing new packages or erasing old
486 packages */
487bool DoUpgrade(CommandLine &CmdL)
488{
489 CacheFile Cache;
490 if (Cache.Open() == false)
491 return false;
492
493 // Do the upgrade
0a8e3465
AL
494 if (pkgAllUpgrade(Cache) == false)
495 {
496 ShowBroken(c1out,Cache);
497 return _error->Error("Internal Error, AllUpgrade broke stuff");
498 }
499
500 return InstallPackages(Cache,true);
501}
502 /*}}}*/
503// DoInstall - Install packages from the command line /*{{{*/
504// ---------------------------------------------------------------------
505/* Install named packages */
506bool DoInstall(CommandLine &CmdL)
507{
508 CacheFile Cache;
509 if (Cache.Open() == false)
510 return false;
511
512 int ExpectedInst = 0;
303a1703 513 int Packages = 0;
0a8e3465
AL
514 pkgProblemResolver Fix(Cache);
515
303a1703
AL
516 bool DefRemove = false;
517 if (strcasecmp(CmdL.FileList[0],"remove") == 0)
518 DefRemove = true;
519
0a8e3465
AL
520 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
521 {
522 // Duplicate the string
523 unsigned int Length = strlen(*I);
524 char S[300];
525 if (Length >= sizeof(S))
526 continue;
527 strcpy(S,*I);
528
529 // See if we are removing the package
303a1703 530 bool Remove = DefRemove;
0a8e3465
AL
531 if (S[Length - 1] == '-')
532 {
533 Remove = true;
534 S[--Length] = 0;
535 }
303a1703
AL
536 if (S[Length - 1] == '+')
537 {
538 Remove = false;
539 S[--Length] = 0;
540 }
0a8e3465
AL
541
542 // Locate the package
543 pkgCache::PkgIterator Pkg = Cache->FindPkg(S);
303a1703 544 Packages++;
0a8e3465
AL
545 if (Pkg.end() == true)
546 return _error->Error("Couldn't find package %s",S);
547
548 // Check if there is something new to install
549 pkgDepCache::StateCache &State = (*Cache)[Pkg];
550 if (State.CandidateVer == 0)
303a1703
AL
551 {
552 if (Pkg->ProvidesList != 0)
553 {
554 c1out << "Package " << S << " is a virtual package provided by:" << endl;
555
556 pkgCache::PrvIterator I = Pkg.ProvidesList();
557 for (; I.end() == false; I++)
558 {
559 pkgCache::PkgIterator Pkg = I.OwnerPkg();
560
561 if ((*Cache)[Pkg].CandidateVerIter(*Cache) == I.OwnerVer())
562 c1out << " " << Pkg.Name() << " " << I.OwnerVer().VerStr() << endl;
563
564 if ((*Cache)[Pkg].InstVerIter(*Cache) == I.OwnerVer())
565 c1out << " " << Pkg.Name() << " " << I.OwnerVer().VerStr() <<
566 " [Installed]"<< endl;
567 }
568 c1out << "You should explicly select one to install." << endl;
569 }
570 else
571 {
572 c1out << "Package " << S << " has no available version, but exists in the database." << endl;
573 c1out << "This typically means that the package was mentioned in a dependency and " << endl;
574 c1out << "never uploaded, or that it is an obsolete package." << endl;
575 }
576
0a8e3465 577 return _error->Error("Package %s has no installation candidate",S);
303a1703 578 }
0a8e3465
AL
579
580 Fix.Protect(Pkg);
581 if (Remove == true)
582 {
303a1703 583 Fix.Remove(Pkg);
0a8e3465
AL
584 Cache->MarkDelete(Pkg);
585 continue;
586 }
587
588 // Install it
589 Cache->MarkInstall(Pkg,false);
590 if (State.Install() == false)
591 c1out << "Sorry, " << S << " is already the newest version" << endl;
592 else
593 ExpectedInst++;
594
595 // Install it with autoinstalling enabled.
596 if (State.InstBroken() == true)
597 Cache->MarkInstall(Pkg,true);
598 }
599
600 // Call the scored problem resolver
303a1703 601 Fix.InstallProtect();
0a8e3465
AL
602 if (Fix.Resolve(true) == false)
603 _error->Discard();
604
605 // Now we check the state of the packages,
606 if (Cache->BrokenCount() != 0)
607 {
303a1703
AL
608 c1out << "Some packages could not be installed. This may mean that you have" << endl;
609 c1out << "requested an impossible situation or if you are using the unstable" << endl;
610 c1out << "distribution that some required packages have not yet been created" << endl;
611 c1out << "or been moved out of Incoming." << endl;
612 if (Packages == 1)
613 {
614 c1out << endl;
615 c1out << "Since you only requested a single operation it is extremely likely that" << endl;
616 c1out << "the package is simply not installable and a bug report against" << endl;
617 c1out << "that package should be filed." << endl;
618 }
619
620 c1out << "The following information may help to resolve the situation:" << endl;
621 c1out << endl;
0a8e3465
AL
622 ShowBroken(c1out,Cache);
623 return _error->Error("Sorry, broken packages");
624 }
625
626 /* Print out a list of packages that are going to be installed extra
627 to what the user asked */
628 if (Cache->InstCount() != ExpectedInst)
629 {
630 string List;
631 pkgCache::PkgIterator I = Cache->PkgBegin();
632 for (;I.end() != true; I++)
633 {
634 if ((*Cache)[I].Install() == false)
635 continue;
636
637 const char **J;
638 for (J = CmdL.FileList + 1; *J != 0; J++)
639 if (strcmp(*J,I.Name()) == 0)
640 break;
641
642 if (*J == 0)
643 List += string(I.Name()) + " ";
644 }
645
646 ShowList(c1out,"The following extra packages will be installed:",List);
647 }
648
649 return InstallPackages(Cache,false);
650}
651 /*}}}*/
652// DoDistUpgrade - Automatic smart upgrader /*{{{*/
653// ---------------------------------------------------------------------
654/* Intelligent upgrader that will install and remove packages at will */
655bool DoDistUpgrade(CommandLine &CmdL)
656{
657 CacheFile Cache;
658 if (Cache.Open() == false)
659 return false;
660
661 c0out << "Calculating Upgrade... " << flush;
662 if (pkgDistUpgrade(*Cache) == false)
663 {
664 c0out << "Failed" << endl;
665 ShowBroken(c1out,Cache);
666 return false;
667 }
668
669 c0out << "Done" << endl;
670
671 return InstallPackages(Cache,true);
672}
673 /*}}}*/
674// DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
675// ---------------------------------------------------------------------
676/* Follows dselect's selections */
677bool DoDSelectUpgrade(CommandLine &CmdL)
678{
679 CacheFile Cache;
680 if (Cache.Open() == false)
681 return false;
682
683 // Install everything with the install flag set
684 pkgCache::PkgIterator I = Cache->PkgBegin();
685 for (;I.end() != true; I++)
686 {
687 /* Install the package only if it is a new install, the autoupgrader
688 will deal with the rest */
689 if (I->SelectedState == pkgCache::State::Install)
690 Cache->MarkInstall(I,false);
691 }
692
693 /* Now install their deps too, if we do this above then order of
694 the status file is significant for | groups */
695 for (I = Cache->PkgBegin();I.end() != true; I++)
696 {
697 /* Install the package only if it is a new install, the autoupgrader
698 will deal with the rest */
699 if (I->SelectedState == pkgCache::State::Install)
700 Cache->MarkInstall(I);
701 }
702
703 // Apply erasures now, they override everything else.
704 for (I = Cache->PkgBegin();I.end() != true; I++)
705 {
706 // Remove packages
707 if (I->SelectedState == pkgCache::State::DeInstall ||
708 I->SelectedState == pkgCache::State::Purge)
709 Cache->MarkDelete(I);
710 }
711
712 /* Use updates smart upgrade to do the rest, it will automatically
713 ignore held items */
714 if (pkgAllUpgrade(Cache) == false)
715 {
716 ShowBroken(c1out,Cache);
717 return _error->Error("Internal Error, AllUpgrade broke stuff");
718 }
719
720 return InstallPackages(Cache,false);
721}
722 /*}}}*/
723// DoClean - Remove download archives /*{{{*/
724// ---------------------------------------------------------------------
725/* */
726bool DoClean(CommandLine &CmdL)
727{
728 return true;
729}
730 /*}}}*/
731// DoCheck - Perform the check operation /*{{{*/
732// ---------------------------------------------------------------------
733/* Opening automatically checks the system, this command is mostly used
734 for debugging */
735bool DoCheck(CommandLine &CmdL)
736{
737 CacheFile Cache;
738 Cache.Open();
739
740 return true;
741}
742 /*}}}*/
743
744// ShowHelp - Show a help screen /*{{{*/
745// ---------------------------------------------------------------------
746/* */
747int ShowHelp()
748{
749 cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE <<
750 " compiled on " << __DATE__ << " " << __TIME__ << endl;
751
752 cout << "Usage: apt-get [options] command" << endl;
753 cout << " apt-get [options] install pkg1 [pkg2 ...]" << endl;
754 cout << endl;
755 cout << "apt-get is a simple command line interface for downloading and" << endl;
756 cout << "installing packages. The most frequently used commands are update" << endl;
757 cout << "and install." << endl;
758 cout << endl;
759 cout << "Commands:" << endl;
760 cout << " update - Retrieve new lists of packages" << endl;
761 cout << " upgrade - Perform an upgrade" << endl;
762 cout << " install - Install new packages (pkg is libc6 not libc6.deb)" << endl;
303a1703 763 cout << " remove - Remove packages" << endl;
0a8e3465
AL
764 cout << " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl;
765 cout << " dselect-upgrade - Follow dselect selections" << endl;
766 cout << " clean - Erase downloaded archive files" << endl;
767 cout << " check - Verify that there are no broken dependencies" << endl;
768 cout << endl;
769 cout << "Options:" << endl;
770 cout << " -h This help text." << endl;
771 cout << " -q Loggable output - no progress indicator" << endl;
772 cout << " -qq No output except for errors" << endl;
773 cout << " -d Download only - do NOT install or unpack archives" << endl;
774 cout << " -s No-act. Perform ordering simulation" << endl;
775 cout << " -y Assume Yes to all queries and do not prompt" << endl;
776 cout << " -f Attempt to continue if the integrity check fails" << endl;
777 cout << " -m Attempt to continue if archives are unlocatable" << endl;
778 cout << " -u Show a list of upgraded packages as well" << endl;
779 cout << " -c=? Read this configuration file" << endl;
780 cout << " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl;
781 cout << "See the apt-get(8), sources.list(8) and apt.conf(8) manual" << endl;
782 cout << "pages for more information." << endl;
783 return 100;
784}
785 /*}}}*/
786// GetInitialize - Initialize things for apt-get /*{{{*/
787// ---------------------------------------------------------------------
788/* */
789void GetInitialize()
790{
791 _config->Set("quiet",0);
792 _config->Set("help",false);
793 _config->Set("APT::Get::Download-Only",false);
794 _config->Set("APT::Get::Simulate",false);
795 _config->Set("APT::Get::Assume-Yes",false);
796 _config->Set("APT::Get::Fix-Broken",false);
797}
798 /*}}}*/
799
800int main(int argc,const char *argv[])
801{
802 CommandLine::Args Args[] = {
803 {'h',"help","help",0},
804 {'q',"quiet","quiet",CommandLine::IntLevel},
805 {'q',"silent","quiet",CommandLine::IntLevel},
806 {'d',"download-only","APT::Get::Download-Only",0},
807 {'s',"simulate","APT::Get::Simulate",0},
808 {'s',"just-print","APT::Get::Simulate",0},
809 {'s',"recon","APT::Get::Simulate",0},
810 {'s',"no-act","APT::Get::Simulate",0},
811 {'y',"yes","APT::Get::Assume-Yes",0},
812 {'y',"assume-yes","APT::Get::Assume-Yes",0},
813 {'f',"fix-broken","APT::Get::Fix-Broken",0},
814 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
815 {'m',"ignore-missing","APT::Get::Fix-Broken",0},
c88edf1d 816 {0,"ignore-hold","APT::Ingore-Hold",0},
0a8e3465
AL
817 {'c',"config-file",0,CommandLine::ConfigFile},
818 {'o',"option",0,CommandLine::ArbItem},
819 {0,0,0,0}};
820
821 // Parse the command line and initialize the package library
822 CommandLine CmdL(Args,_config);
823 if (pkgInitialize(*_config) == false ||
824 CmdL.Parse(argc,argv) == false)
825 {
826 _error->DumpErrors();
827 return 100;
828 }
829
830 // See if the help should be shown
831 if (_config->FindB("help") == true ||
832 CmdL.FileSize() == 0)
833 return ShowHelp();
834
835 // Setup the output streams
836 c0out.rdbuf(cout.rdbuf());
837 c1out.rdbuf(cout.rdbuf());
838 c2out.rdbuf(cout.rdbuf());
839 if (_config->FindI("quiet",0) > 0)
840 c0out.rdbuf(devnull.rdbuf());
841 if (_config->FindI("quiet",0) > 1)
842 c1out.rdbuf(devnull.rdbuf());
843
844 // Match the operation
845 struct
846 {
847 const char *Match;
848 bool (*Handler)(CommandLine &);
849 } Map[] = {{"update",&DoUpdate},
850 {"upgrade",&DoUpgrade},
851 {"install",&DoInstall},
303a1703 852 {"remove",&DoInstall},
0a8e3465
AL
853 {"dist-upgrade",&DoDistUpgrade},
854 {"dselect-upgrade",&DoDSelectUpgrade},
855 {"clean",&DoClean},
856 {"check",&DoCheck},
857 {0,0}};
858 int I;
859 for (I = 0; Map[I].Match != 0; I++)
860 {
861 if (strcmp(CmdL.FileList[0],Map[I].Match) == 0)
862 {
0919e3f9
AL
863 if (Map[I].Handler(CmdL) == false && _error->PendingError() == false)
864 _error->Error("Handler silently failed");
0a8e3465
AL
865 break;
866 }
867 }
868
869 // No matching name
870 if (Map[I].Match == 0)
871 _error->Error("Invalid operation %s", CmdL.FileList[0]);
872
873 // Print any errors or warnings found during parsing
874 if (_error->empty() == false)
875 {
876 bool Errors = _error->PendingError();
877 _error->DumpErrors();
878 if (Errors == true)
879 cout << "Returning 100." << endl;
880 return Errors == true?100:0;
881 }
882
883 return 0;
884}