]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
8daaf05f438df4fb4e0db1181b45290ff4947fc3
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.8 1998/11/12 05:30:10 jgg Exp $
4 /* ######################################################################
6 apt-get - Cover for dpkg
8 This is an allout cover for dpkg implementing a safer front end. It is
9 based largely on libapt-pkg.
11 The syntax is different,
12 apt-get [opt] command [things]
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
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
25 ##################################################################### */
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>
35 #include <apt-pkg/acquire-item.h>
39 #include "acqprogress.h"
43 #include <sys/ioctl.h>
50 ofstream
devnull("/dev/null");
51 unsigned int ScreenWidth
= 80;
53 // ShowList - Show a list /*{{{*/
54 // ---------------------------------------------------------------------
55 /* This prints out a string of space seperated words with a title and
56 a two space indent line wraped to the current screen width. */
57 void ShowList(ostream
&out
,string Title
,string List
)
59 if (List
.empty() == true)
62 // Acount for the leading space
63 int ScreenWidth
= ::ScreenWidth
- 3;
66 string::size_type Start
= 0;
67 while (Start
< List
.size())
69 string::size_type End
;
70 if (Start
+ ScreenWidth
>= List
.size())
73 End
= List
.rfind(' ',Start
+ScreenWidth
);
75 if (End
== string::npos
|| End
< Start
)
76 End
= Start
+ ScreenWidth
;
77 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
82 // ShowBroken - Debugging aide /*{{{*/
83 // ---------------------------------------------------------------------
84 /* This prints out the names of all the packages that are broken along
85 with the name of each each broken dependency and a quite version
87 void ShowBroken(ostream
&out
,pkgDepCache
&Cache
)
89 out
<< "Sorry, but the following packages are broken - this means they have unmet" << endl
;
90 out
<< "dependencies:" << endl
;
91 pkgCache::PkgIterator I
= Cache
.PkgBegin();
92 for (;I
.end() != true; I
++)
94 if (Cache
[I
].InstBroken() == false)
97 // Print out each package and the failed dependencies
98 out
<<" " << I
.Name() << ":";
99 int Indent
= strlen(I
.Name()) + 3;
101 if (Cache
[I
].InstVerIter(Cache
).end() == true)
107 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false; D
++)
109 if (Cache
.IsImportantDep(D
) == false || (Cache
[D
] &
110 pkgDepCache::DepInstall
) != 0)
114 for (int J
= 0; J
!= Indent
; J
++)
118 if (D
->Type
== pkgCache::Dep::Conflicts
)
119 out
<< " Conflicts:" << D
.TargetPkg().Name();
121 out
<< " Depends:" << D
.TargetPkg().Name();
123 // Show a quick summary of the version requirements
124 if (D
.TargetVer() != 0)
125 out
<< " (" << D
.CompType() << " " << D
.TargetVer() <<
128 /* Show a summary of the target package if possible. In the case
129 of virtual packages we show nothing */
131 pkgCache::PkgIterator Targ
= D
.TargetPkg();
132 if (Targ
->ProvidesList
== 0)
135 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
136 if (Ver
.end() == false)
137 out
<< Ver
.VerStr() << " is installed";
140 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
142 if (Targ
->ProvidesList
== 0)
143 out
<< "it is not installable";
145 out
<< "it is a virtual package";
148 out
<< "it is not installed";
157 // ShowNew - Show packages to newly install /*{{{*/
158 // ---------------------------------------------------------------------
160 void ShowNew(ostream
&out
,pkgDepCache
&Dep
)
162 /* Print out a list of packages that are going to be removed extra
163 to what the user asked */
164 pkgCache::PkgIterator I
= Dep
.PkgBegin();
166 for (;I
.end() != true; I
++)
167 if (Dep
[I
].NewInstall() == true)
168 List
+= string(I
.Name()) + " ";
169 ShowList(out
,"The following NEW packages will be installed:",List
);
172 // ShowDel - Show packages to delete /*{{{*/
173 // ---------------------------------------------------------------------
175 void ShowDel(ostream
&out
,pkgDepCache
&Dep
)
177 /* Print out a list of packages that are going to be removed extra
178 to what the user asked */
179 pkgCache::PkgIterator I
= Dep
.PkgBegin();
181 for (;I
.end() != true; I
++)
182 if (Dep
[I
].Delete() == true)
183 List
+= string(I
.Name()) + " ";
184 ShowList(out
,"The following packages will be REMOVED:",List
);
187 // ShowKept - Show kept packages /*{{{*/
188 // ---------------------------------------------------------------------
190 void ShowKept(ostream
&out
,pkgDepCache
&Dep
)
192 pkgCache::PkgIterator I
= Dep
.PkgBegin();
194 for (;I
.end() != true; I
++)
197 if (Dep
[I
].Upgrade() == true || Dep
[I
].Upgradable() == false ||
198 I
->CurrentVer
== 0 || Dep
[I
].Delete() == true)
201 List
+= string(I
.Name()) + " ";
203 ShowList(out
,"The following packages have been kept back",List
);
206 // ShowUpgraded - Show upgraded packages /*{{{*/
207 // ---------------------------------------------------------------------
209 void ShowUpgraded(ostream
&out
,pkgDepCache
&Dep
)
211 pkgCache::PkgIterator I
= Dep
.PkgBegin();
213 for (;I
.end() != true; I
++)
216 if (Dep
[I
].Upgrade() == false || Dep
[I
].NewInstall() == true)
219 List
+= string(I
.Name()) + " ";
221 ShowList(out
,"The following packages will be upgraded",List
);
224 // ShowHold - Show held but changed packages /*{{{*/
225 // ---------------------------------------------------------------------
227 void ShowHold(ostream
&out
,pkgDepCache
&Dep
)
229 pkgCache::PkgIterator I
= Dep
.PkgBegin();
231 for (;I
.end() != true; I
++)
233 if (Dep
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
234 I
->SelectedState
== pkgCache::State::Hold
)
235 List
+= string(I
.Name()) + " ";
238 ShowList(out
,"The following held packages will be changed:",List
);
241 // ShowEssential - Show an essential package warning /*{{{*/
242 // ---------------------------------------------------------------------
243 /* This prints out a warning message that is not to be ignored. It shows
244 all essential packages and their dependents that are to be removed.
245 It is insanely risky to remove the dependents of an essential package! */
246 void ShowEssential(ostream
&out
,pkgDepCache
&Dep
)
248 pkgCache::PkgIterator I
= Dep
.PkgBegin();
250 bool *Added
= new bool[Dep
.HeaderP
->PackageCount
];
251 for (unsigned int I
= 0; I
!= Dep
.HeaderP
->PackageCount
; I
++)
254 for (;I
.end() != true; I
++)
256 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
259 // The essential package is being removed
260 if (Dep
[I
].Delete() == true)
262 if (Added
[I
->ID
] == false)
265 List
+= string(I
.Name()) + " ";
269 if (I
->CurrentVer
== 0)
272 // Print out any essential package depenendents that are to be removed
273 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
275 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
276 if (Dep
[P
].Delete() == true)
278 if (Added
[P
->ID
] == true)
281 List
+= string(P
.Name()) + " ";
286 if (List
.empty() == false)
287 out
<< "WARNING: The following essential packages will be removed" << endl
;
288 ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
293 // Stats - Show some statistics /*{{{*/
294 // ---------------------------------------------------------------------
296 void Stats(ostream
&out
,pkgDepCache
&Dep
)
298 unsigned long Upgrade
= 0;
299 unsigned long Install
= 0;
300 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
302 if (Dep
[I
].NewInstall() == true)
305 if (Dep
[I
].Upgrade() == true)
309 out
<< Upgrade
<< " packages upgraded, " <<
310 Install
<< " newly installed, " <<
311 Dep
.DelCount() << " to remove and " <<
312 Dep
.KeepCount() << " not upgraded." << endl
;
314 if (Dep
.BadCount() != 0)
315 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
319 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
320 // ---------------------------------------------------------------------
330 inline operator pkgDepCache
&() {return *Cache
;};
331 inline pkgDepCache
*operator ->() {return Cache
;};
332 inline pkgDepCache
&operator *() {return *Cache
;};
335 CacheFile() : File(0), Map(0), Cache(0) {};
344 // CacheFile::Open - Open the cache file /*{{{*/
345 // ---------------------------------------------------------------------
346 /* This routine generates the caches and then opens the dependency cache
347 and verifies that the system is OK. */
348 bool CacheFile::Open()
350 // Create a progress class
351 OpTextProgress
Progress(*_config
);
353 // Read the source list
355 if (List
.ReadMainList() == false)
356 return _error
->Error("The list of sources could not be read.");
358 // Build all of the caches
359 pkgMakeStatusCache(List
,Progress
);
360 if (_error
->PendingError() == true)
361 return _error
->Error("The package lists or status file could not be parsed or opened.");
365 // Open the cache file
366 File
= new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly
);
367 if (_error
->PendingError() == true)
370 Map
= new MMap(*File
,MMap::Public
| MMap::ReadOnly
);
371 if (_error
->PendingError() == true)
374 Cache
= new pkgDepCache(*Map
,Progress
);
375 if (_error
->PendingError() == true)
380 // Check that the system is OK
381 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
382 return _error
->Error("Internal Error, non-zero counts");
384 // Apply corrections for half-installed packages
385 if (pkgApplyStatus(*Cache
) == false)
389 if (Cache
->BrokenCount() == 0)
392 // Attempt to fix broken things
393 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
395 c1out
<< "Correcting dependencies..." << flush
;
396 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
398 c1out
<< " failed." << endl
;
399 ShowBroken(c1out
,*this);
401 return _error
->Error("Unable to correct dependencies");
403 if (pkgMinimizeUpgrade(*Cache
) == false)
404 return _error
->Error("Unable to minimize the upgrade set");
406 c1out
<< " Done" << endl
;
410 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
411 ShowBroken(c1out
,*this);
413 return _error
->Error("Unmet dependencies. Try using -f.");
420 // InstallPackages - Actually download and install the packages /*{{{*/
421 // ---------------------------------------------------------------------
422 /* This displays the informative messages describing what is going to
423 happen and then calls the download routines */
424 bool InstallPackages(pkgDepCache
&Cache
,bool ShwKept
)
426 ShowDel(c1out
,Cache
);
427 ShowNew(c1out
,Cache
);
429 ShowKept(c1out
,Cache
);
430 ShowHold(c1out
,Cache
);
431 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
432 ShowUpgraded(c1out
,Cache
);
433 ShowEssential(c1out
,Cache
);
437 if (Cache
.BrokenCount() != 0)
439 ShowBroken(c1out
,Cache
);
440 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
443 if (Cache
.DelCount() == 0 && Cache
.InstCount() == 0 &&
444 Cache
.BadCount() == 0)
451 // DoUpdate - Update the package lists /*{{{*/
452 // ---------------------------------------------------------------------
454 bool DoUpdate(CommandLine
&)
456 // Get the source list
458 if (List
.ReadMainList() == false)
461 // Create the download object
462 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
463 pkgAcquire
Fetcher(&Stat
);
465 // Populate it with the source selection
466 pkgSourceList::const_iterator I
;
467 for (I
= List
.begin(); I
!= List
.end(); I
++)
469 new pkgAcqIndex(&Fetcher
,I
);
470 if (_error
->PendingError() == true)
475 if (Fetcher
.Run() == false)
478 // Clean out any old list files
479 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
480 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
483 // Prepare the cache.
485 if (Cache
.Open() == false)
491 // DoUpgrade - Upgrade all packages /*{{{*/
492 // ---------------------------------------------------------------------
493 /* Upgrade all packages without installing new packages or erasing old
495 bool DoUpgrade(CommandLine
&CmdL
)
498 if (Cache
.Open() == false)
502 if (pkgAllUpgrade(Cache
) == false)
504 ShowBroken(c1out
,Cache
);
505 return _error
->Error("Internal Error, AllUpgrade broke stuff");
508 return InstallPackages(Cache
,true);
511 // DoInstall - Install packages from the command line /*{{{*/
512 // ---------------------------------------------------------------------
513 /* Install named packages */
514 bool DoInstall(CommandLine
&CmdL
)
517 if (Cache
.Open() == false)
520 int ExpectedInst
= 0;
522 pkgProblemResolver
Fix(Cache
);
524 bool DefRemove
= false;
525 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
528 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
530 // Duplicate the string
531 unsigned int Length
= strlen(*I
);
533 if (Length
>= sizeof(S
))
537 // See if we are removing the package
538 bool Remove
= DefRemove
;
539 if (S
[Length
- 1] == '-')
544 if (S
[Length
- 1] == '+')
550 // Locate the package
551 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
553 if (Pkg
.end() == true)
554 return _error
->Error("Couldn't find package %s",S
);
556 // Check if there is something new to install
557 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
558 if (State
.CandidateVer
== 0)
560 if (Pkg
->ProvidesList
!= 0)
562 c1out
<< "Package " << S
<< " is a virtual package provided by:" << endl
;
564 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
565 for (; I
.end() == false; I
++)
567 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
569 if ((*Cache
)[Pkg
].CandidateVerIter(*Cache
) == I
.OwnerVer())
570 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
572 if ((*Cache
)[Pkg
].InstVerIter(*Cache
) == I
.OwnerVer())
573 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
574 " [Installed]"<< endl
;
576 c1out
<< "You should explicly select one to install." << endl
;
580 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
581 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
582 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
585 return _error
->Error("Package %s has no installation candidate",S
);
592 Cache
->MarkDelete(Pkg
);
597 Cache
->MarkInstall(Pkg
,false);
598 if (State
.Install() == false)
599 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
603 // Install it with autoinstalling enabled.
604 if (State
.InstBroken() == true)
605 Cache
->MarkInstall(Pkg
,true);
608 // Call the scored problem resolver
609 Fix
.InstallProtect();
610 if (Fix
.Resolve(true) == false)
613 // Now we check the state of the packages,
614 if (Cache
->BrokenCount() != 0)
616 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
617 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
618 c1out
<< "distribution that some required packages have not yet been created" << endl
;
619 c1out
<< "or been moved out of Incoming." << endl
;
623 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
624 c1out
<< "the package is simply not installable and a bug report against" << endl
;
625 c1out
<< "that package should be filed." << endl
;
628 c1out
<< "The following information may help to resolve the situation:" << endl
;
630 ShowBroken(c1out
,Cache
);
631 return _error
->Error("Sorry, broken packages");
634 /* Print out a list of packages that are going to be installed extra
635 to what the user asked */
636 if (Cache
->InstCount() != ExpectedInst
)
639 pkgCache::PkgIterator I
= Cache
->PkgBegin();
640 for (;I
.end() != true; I
++)
642 if ((*Cache
)[I
].Install() == false)
646 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
647 if (strcmp(*J
,I
.Name()) == 0)
651 List
+= string(I
.Name()) + " ";
654 ShowList(c1out
,"The following extra packages will be installed:",List
);
657 return InstallPackages(Cache
,false);
660 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
661 // ---------------------------------------------------------------------
662 /* Intelligent upgrader that will install and remove packages at will */
663 bool DoDistUpgrade(CommandLine
&CmdL
)
666 if (Cache
.Open() == false)
669 c0out
<< "Calculating Upgrade... " << flush
;
670 if (pkgDistUpgrade(*Cache
) == false)
672 c0out
<< "Failed" << endl
;
673 ShowBroken(c1out
,Cache
);
677 c0out
<< "Done" << endl
;
679 return InstallPackages(Cache
,true);
682 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
683 // ---------------------------------------------------------------------
684 /* Follows dselect's selections */
685 bool DoDSelectUpgrade(CommandLine
&CmdL
)
688 if (Cache
.Open() == false)
691 // Install everything with the install flag set
692 pkgCache::PkgIterator I
= Cache
->PkgBegin();
693 for (;I
.end() != true; I
++)
695 /* Install the package only if it is a new install, the autoupgrader
696 will deal with the rest */
697 if (I
->SelectedState
== pkgCache::State::Install
)
698 Cache
->MarkInstall(I
,false);
701 /* Now install their deps too, if we do this above then order of
702 the status file is significant for | groups */
703 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
705 /* Install the package only if it is a new install, the autoupgrader
706 will deal with the rest */
707 if (I
->SelectedState
== pkgCache::State::Install
)
708 Cache
->MarkInstall(I
);
711 // Apply erasures now, they override everything else.
712 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
715 if (I
->SelectedState
== pkgCache::State::DeInstall
||
716 I
->SelectedState
== pkgCache::State::Purge
)
717 Cache
->MarkDelete(I
);
720 /* Use updates smart upgrade to do the rest, it will automatically
722 if (pkgAllUpgrade(Cache
) == false)
724 ShowBroken(c1out
,Cache
);
725 return _error
->Error("Internal Error, AllUpgrade broke stuff");
728 return InstallPackages(Cache
,false);
731 // DoClean - Remove download archives /*{{{*/
732 // ---------------------------------------------------------------------
734 bool DoClean(CommandLine
&CmdL
)
739 // DoCheck - Perform the check operation /*{{{*/
740 // ---------------------------------------------------------------------
741 /* Opening automatically checks the system, this command is mostly used
743 bool DoCheck(CommandLine
&CmdL
)
752 // ShowHelp - Show a help screen /*{{{*/
753 // ---------------------------------------------------------------------
757 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
758 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
760 cout
<< "Usage: apt-get [options] command" << endl
;
761 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
763 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
764 cout
<< "installing packages. The most frequently used commands are update" << endl
;
765 cout
<< "and install." << endl
;
767 cout
<< "Commands:" << endl
;
768 cout
<< " update - Retrieve new lists of packages" << endl
;
769 cout
<< " upgrade - Perform an upgrade" << endl
;
770 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
771 cout
<< " remove - Remove packages" << endl
;
772 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
773 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
774 cout
<< " clean - Erase downloaded archive files" << endl
;
775 cout
<< " check - Verify that there are no broken dependencies" << endl
;
777 cout
<< "Options:" << endl
;
778 cout
<< " -h This help text." << endl
;
779 cout
<< " -q Loggable output - no progress indicator" << endl
;
780 cout
<< " -qq No output except for errors" << endl
;
781 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
782 cout
<< " -s No-act. Perform ordering simulation" << endl
;
783 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
784 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
785 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
786 cout
<< " -u Show a list of upgraded packages as well" << endl
;
787 cout
<< " -c=? Read this configuration file" << endl
;
788 cout
<< " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl
;
789 cout
<< "See the apt-get(8), sources.list(8) and apt.conf(8) manual" << endl
;
790 cout
<< "pages for more information." << endl
;
794 // GetInitialize - Initialize things for apt-get /*{{{*/
795 // ---------------------------------------------------------------------
799 _config
->Set("quiet",0);
800 _config
->Set("help",false);
801 _config
->Set("APT::Get::Download-Only",false);
802 _config
->Set("APT::Get::Simulate",false);
803 _config
->Set("APT::Get::Assume-Yes",false);
804 _config
->Set("APT::Get::Fix-Broken",false);
807 // SigWinch - Window size change signal handler /*{{{*/
808 // ---------------------------------------------------------------------
816 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
817 ScreenWidth
= ws
.ws_col
- 1;
822 int main(int argc
,const char *argv
[])
824 CommandLine::Args Args
[] = {
825 {'h',"help","help",0},
826 {'q',"quiet","quiet",CommandLine::IntLevel
},
827 {'q',"silent","quiet",CommandLine::IntLevel
},
828 {'d',"download-only","APT::Get::Download-Only",0},
829 {'s',"simulate","APT::Get::Simulate",0},
830 {'s',"just-print","APT::Get::Simulate",0},
831 {'s',"recon","APT::Get::Simulate",0},
832 {'s',"no-act","APT::Get::Simulate",0},
833 {'y',"yes","APT::Get::Assume-Yes",0},
834 {'y',"assume-yes","APT::Get::Assume-Yes",0},
835 {'f',"fix-broken","APT::Get::Fix-Broken",0},
836 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
837 {'m',"ignore-missing","APT::Get::Fix-Broken",0},
838 {0,"ignore-hold","APT::Ingore-Hold",0},
839 {'c',"config-file",0,CommandLine::ConfigFile
},
840 {'o',"option",0,CommandLine::ArbItem
},
843 // Parse the command line and initialize the package library
844 CommandLine
CmdL(Args
,_config
);
845 if (pkgInitialize(*_config
) == false ||
846 CmdL
.Parse(argc
,argv
) == false)
848 _error
->DumpErrors();
852 // See if the help should be shown
853 if (_config
->FindB("help") == true ||
854 CmdL
.FileSize() == 0)
857 // Setup the output streams
858 c0out
.rdbuf(cout
.rdbuf());
859 c1out
.rdbuf(cout
.rdbuf());
860 c2out
.rdbuf(cout
.rdbuf());
861 if (_config
->FindI("quiet",0) > 0)
862 c0out
.rdbuf(devnull
.rdbuf());
863 if (_config
->FindI("quiet",0) > 1)
864 c1out
.rdbuf(devnull
.rdbuf());
867 signal(SIGPIPE
,SIG_IGN
);
868 signal(SIGWINCH
,SigWinch
);
871 // Match the operation
875 bool (*Handler
)(CommandLine
&);
876 } Map
[] = {{"update",&DoUpdate
},
877 {"upgrade",&DoUpgrade
},
878 {"install",&DoInstall
},
879 {"remove",&DoInstall
},
880 {"dist-upgrade",&DoDistUpgrade
},
881 {"dselect-upgrade",&DoDSelectUpgrade
},
886 for (I
= 0; Map
[I
].Match
!= 0; I
++)
888 if (strcmp(CmdL
.FileList
[0],Map
[I
].Match
) == 0)
890 if (Map
[I
].Handler(CmdL
) == false && _error
->PendingError() == false)
891 _error
->Error("Handler silently failed");
897 if (Map
[I
].Match
== 0)
898 _error
->Error("Invalid operation %s", CmdL
.FileList
[0]);
900 // Print any errors or warnings found during parsing
901 if (_error
->empty() == false)
903 bool Errors
= _error
->PendingError();
904 _error
->DumpErrors();
906 cout
<< "Returning 100." << endl
;
907 return Errors
== true?100:0;