]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
85373d874702d9fc3958b977df33200760a7627b
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.9 1998/11/13 04:24:03 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>
36 #include <apt-pkg/dpkgpm.h>
40 #include "acqprogress.h"
44 #include <sys/ioctl.h>
51 ofstream
devnull("/dev/null");
52 unsigned int ScreenWidth
= 80;
54 // ShowList - Show a list /*{{{*/
55 // ---------------------------------------------------------------------
56 /* This prints out a string of space seperated words with a title and
57 a two space indent line wraped to the current screen width. */
58 void ShowList(ostream
&out
,string Title
,string List
)
60 if (List
.empty() == true)
63 // Acount for the leading space
64 int ScreenWidth
= ::ScreenWidth
- 3;
67 string::size_type Start
= 0;
68 while (Start
< List
.size())
70 string::size_type End
;
71 if (Start
+ ScreenWidth
>= List
.size())
74 End
= List
.rfind(' ',Start
+ScreenWidth
);
76 if (End
== string::npos
|| End
< Start
)
77 End
= Start
+ ScreenWidth
;
78 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
83 // ShowBroken - Debugging aide /*{{{*/
84 // ---------------------------------------------------------------------
85 /* This prints out the names of all the packages that are broken along
86 with the name of each each broken dependency and a quite version
88 void ShowBroken(ostream
&out
,pkgDepCache
&Cache
)
90 out
<< "Sorry, but the following packages are broken - this means they have unmet" << endl
;
91 out
<< "dependencies:" << endl
;
92 pkgCache::PkgIterator I
= Cache
.PkgBegin();
93 for (;I
.end() != true; I
++)
95 if (Cache
[I
].InstBroken() == false)
98 // Print out each package and the failed dependencies
99 out
<<" " << I
.Name() << ":";
100 int Indent
= strlen(I
.Name()) + 3;
102 if (Cache
[I
].InstVerIter(Cache
).end() == true)
108 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false; D
++)
110 if (Cache
.IsImportantDep(D
) == false || (Cache
[D
] &
111 pkgDepCache::DepInstall
) != 0)
115 for (int J
= 0; J
!= Indent
; J
++)
119 if (D
->Type
== pkgCache::Dep::Conflicts
)
120 out
<< " Conflicts:" << D
.TargetPkg().Name();
122 out
<< " Depends:" << D
.TargetPkg().Name();
124 // Show a quick summary of the version requirements
125 if (D
.TargetVer() != 0)
126 out
<< " (" << D
.CompType() << " " << D
.TargetVer() <<
129 /* Show a summary of the target package if possible. In the case
130 of virtual packages we show nothing */
132 pkgCache::PkgIterator Targ
= D
.TargetPkg();
133 if (Targ
->ProvidesList
== 0)
136 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
137 if (Ver
.end() == false)
138 out
<< Ver
.VerStr() << " is installed";
141 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
143 if (Targ
->ProvidesList
== 0)
144 out
<< "it is not installable";
146 out
<< "it is a virtual package";
149 out
<< "it is not installed";
158 // ShowNew - Show packages to newly install /*{{{*/
159 // ---------------------------------------------------------------------
161 void ShowNew(ostream
&out
,pkgDepCache
&Dep
)
163 /* Print out a list of packages that are going to be removed extra
164 to what the user asked */
165 pkgCache::PkgIterator I
= Dep
.PkgBegin();
167 for (;I
.end() != true; I
++)
168 if (Dep
[I
].NewInstall() == true)
169 List
+= string(I
.Name()) + " ";
170 ShowList(out
,"The following NEW packages will be installed:",List
);
173 // ShowDel - Show packages to delete /*{{{*/
174 // ---------------------------------------------------------------------
176 void ShowDel(ostream
&out
,pkgDepCache
&Dep
)
178 /* Print out a list of packages that are going to be removed extra
179 to what the user asked */
180 pkgCache::PkgIterator I
= Dep
.PkgBegin();
182 for (;I
.end() != true; I
++)
183 if (Dep
[I
].Delete() == true)
184 List
+= string(I
.Name()) + " ";
185 ShowList(out
,"The following packages will be REMOVED:",List
);
188 // ShowKept - Show kept packages /*{{{*/
189 // ---------------------------------------------------------------------
191 void ShowKept(ostream
&out
,pkgDepCache
&Dep
)
193 pkgCache::PkgIterator I
= Dep
.PkgBegin();
195 for (;I
.end() != true; I
++)
198 if (Dep
[I
].Upgrade() == true || Dep
[I
].Upgradable() == false ||
199 I
->CurrentVer
== 0 || Dep
[I
].Delete() == true)
202 List
+= string(I
.Name()) + " ";
204 ShowList(out
,"The following packages have been kept back",List
);
207 // ShowUpgraded - Show upgraded packages /*{{{*/
208 // ---------------------------------------------------------------------
210 void ShowUpgraded(ostream
&out
,pkgDepCache
&Dep
)
212 pkgCache::PkgIterator I
= Dep
.PkgBegin();
214 for (;I
.end() != true; I
++)
217 if (Dep
[I
].Upgrade() == false || Dep
[I
].NewInstall() == true)
220 List
+= string(I
.Name()) + " ";
222 ShowList(out
,"The following packages will be upgraded",List
);
225 // ShowHold - Show held but changed packages /*{{{*/
226 // ---------------------------------------------------------------------
228 void ShowHold(ostream
&out
,pkgDepCache
&Dep
)
230 pkgCache::PkgIterator I
= Dep
.PkgBegin();
232 for (;I
.end() != true; I
++)
234 if (Dep
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
235 I
->SelectedState
== pkgCache::State::Hold
)
236 List
+= string(I
.Name()) + " ";
239 ShowList(out
,"The following held packages will be changed:",List
);
242 // ShowEssential - Show an essential package warning /*{{{*/
243 // ---------------------------------------------------------------------
244 /* This prints out a warning message that is not to be ignored. It shows
245 all essential packages and their dependents that are to be removed.
246 It is insanely risky to remove the dependents of an essential package! */
247 void ShowEssential(ostream
&out
,pkgDepCache
&Dep
)
249 pkgCache::PkgIterator I
= Dep
.PkgBegin();
251 bool *Added
= new bool[Dep
.HeaderP
->PackageCount
];
252 for (unsigned int I
= 0; I
!= Dep
.HeaderP
->PackageCount
; I
++)
255 for (;I
.end() != true; I
++)
257 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
260 // The essential package is being removed
261 if (Dep
[I
].Delete() == true)
263 if (Added
[I
->ID
] == false)
266 List
+= string(I
.Name()) + " ";
270 if (I
->CurrentVer
== 0)
273 // Print out any essential package depenendents that are to be removed
274 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
276 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
277 if (Dep
[P
].Delete() == true)
279 if (Added
[P
->ID
] == true)
282 List
+= string(P
.Name()) + " ";
287 if (List
.empty() == false)
288 out
<< "WARNING: The following essential packages will be removed" << endl
;
289 ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
294 // Stats - Show some statistics /*{{{*/
295 // ---------------------------------------------------------------------
297 void Stats(ostream
&out
,pkgDepCache
&Dep
)
299 unsigned long Upgrade
= 0;
300 unsigned long Install
= 0;
301 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
303 if (Dep
[I
].NewInstall() == true)
306 if (Dep
[I
].Upgrade() == true)
310 out
<< Upgrade
<< " packages upgraded, " <<
311 Install
<< " newly installed, " <<
312 Dep
.DelCount() << " to remove and " <<
313 Dep
.KeepCount() << " not upgraded." << endl
;
315 if (Dep
.BadCount() != 0)
316 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
320 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
321 // ---------------------------------------------------------------------
331 inline operator pkgDepCache
&() {return *Cache
;};
332 inline pkgDepCache
*operator ->() {return Cache
;};
333 inline pkgDepCache
&operator *() {return *Cache
;};
336 CacheFile() : File(0), Map(0), Cache(0) {};
345 // CacheFile::Open - Open the cache file /*{{{*/
346 // ---------------------------------------------------------------------
347 /* This routine generates the caches and then opens the dependency cache
348 and verifies that the system is OK. */
349 bool CacheFile::Open()
351 // Create a progress class
352 OpTextProgress
Progress(*_config
);
354 // Read the source list
356 if (List
.ReadMainList() == false)
357 return _error
->Error("The list of sources could not be read.");
359 // Build all of the caches
360 pkgMakeStatusCache(List
,Progress
);
361 if (_error
->PendingError() == true)
362 return _error
->Error("The package lists or status file could not be parsed or opened.");
366 // Open the cache file
367 File
= new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly
);
368 if (_error
->PendingError() == true)
371 Map
= new MMap(*File
,MMap::Public
| MMap::ReadOnly
);
372 if (_error
->PendingError() == true)
375 Cache
= new pkgDepCache(*Map
,Progress
);
376 if (_error
->PendingError() == true)
381 // Check that the system is OK
382 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
383 return _error
->Error("Internal Error, non-zero counts");
385 // Apply corrections for half-installed packages
386 if (pkgApplyStatus(*Cache
) == false)
390 if (Cache
->BrokenCount() == 0)
393 // Attempt to fix broken things
394 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
396 c1out
<< "Correcting dependencies..." << flush
;
397 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
399 c1out
<< " failed." << endl
;
400 ShowBroken(c1out
,*this);
402 return _error
->Error("Unable to correct dependencies");
404 if (pkgMinimizeUpgrade(*Cache
) == false)
405 return _error
->Error("Unable to minimize the upgrade set");
407 c1out
<< " Done" << endl
;
411 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
412 ShowBroken(c1out
,*this);
414 return _error
->Error("Unmet dependencies. Try using -f.");
421 // InstallPackages - Actually download and install the packages /*{{{*/
422 // ---------------------------------------------------------------------
423 /* This displays the informative messages describing what is going to
424 happen and then calls the download routines */
425 bool InstallPackages(pkgDepCache
&Cache
,bool ShwKept
,bool Ask
= true)
427 ShowDel(c1out
,Cache
);
428 ShowNew(c1out
,Cache
);
430 ShowKept(c1out
,Cache
);
431 ShowHold(c1out
,Cache
);
432 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
433 ShowUpgraded(c1out
,Cache
);
434 ShowEssential(c1out
,Cache
);
438 if (Cache
.BrokenCount() != 0)
440 ShowBroken(c1out
,Cache
);
441 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
444 if (Cache
.DelCount() == 0 && Cache
.InstCount() == 0 &&
445 Cache
.BadCount() == 0)
448 // Run the simulator ..
449 if (_config
->FindB("APT::Get::Simulate") == true)
451 pkgSimulate
PM(Cache
);
452 return PM
.DoInstall();
455 // Create the text record parser
456 pkgRecords
Recs(Cache
);
458 // Create the download object
459 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
460 pkgAcquire
Fetcher(&Stat
);
462 // Read the source list
464 if (List
.ReadMainList() == false)
465 return _error
->Error("The list of sources could not be read.");
467 // Create the package manager and prepare to download
468 pkgPackageManager
PM(Cache
);
469 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false)
473 if (Fetcher
.Run() == false)
480 // DoUpdate - Update the package lists /*{{{*/
481 // ---------------------------------------------------------------------
483 bool DoUpdate(CommandLine
&)
485 // Get the source list
487 if (List
.ReadMainList() == false)
490 // Create the download object
491 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
492 pkgAcquire
Fetcher(&Stat
);
494 // Populate it with the source selection
495 pkgSourceList::const_iterator I
;
496 for (I
= List
.begin(); I
!= List
.end(); I
++)
498 new pkgAcqIndex(&Fetcher
,I
);
499 if (_error
->PendingError() == true)
504 if (Fetcher
.Run() == false)
507 // Clean out any old list files
508 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
509 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
512 // Prepare the cache.
514 if (Cache
.Open() == false)
520 // DoUpgrade - Upgrade all packages /*{{{*/
521 // ---------------------------------------------------------------------
522 /* Upgrade all packages without installing new packages or erasing old
524 bool DoUpgrade(CommandLine
&CmdL
)
527 if (Cache
.Open() == false)
531 if (pkgAllUpgrade(Cache
) == false)
533 ShowBroken(c1out
,Cache
);
534 return _error
->Error("Internal Error, AllUpgrade broke stuff");
537 return InstallPackages(Cache
,true);
540 // DoInstall - Install packages from the command line /*{{{*/
541 // ---------------------------------------------------------------------
542 /* Install named packages */
543 bool DoInstall(CommandLine
&CmdL
)
546 if (Cache
.Open() == false)
549 int ExpectedInst
= 0;
551 pkgProblemResolver
Fix(Cache
);
553 bool DefRemove
= false;
554 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
557 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
559 // Duplicate the string
560 unsigned int Length
= strlen(*I
);
562 if (Length
>= sizeof(S
))
566 // See if we are removing the package
567 bool Remove
= DefRemove
;
568 if (S
[Length
- 1] == '-')
573 if (S
[Length
- 1] == '+')
579 // Locate the package
580 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
582 if (Pkg
.end() == true)
583 return _error
->Error("Couldn't find package %s",S
);
585 // Check if there is something new to install
586 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
587 if (State
.CandidateVer
== 0)
589 if (Pkg
->ProvidesList
!= 0)
591 c1out
<< "Package " << S
<< " is a virtual package provided by:" << endl
;
593 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
594 for (; I
.end() == false; I
++)
596 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
598 if ((*Cache
)[Pkg
].CandidateVerIter(*Cache
) == I
.OwnerVer())
599 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
601 if ((*Cache
)[Pkg
].InstVerIter(*Cache
) == I
.OwnerVer())
602 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
603 " [Installed]"<< endl
;
605 c1out
<< "You should explicly select one to install." << endl
;
609 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
610 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
611 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
614 return _error
->Error("Package %s has no installation candidate",S
);
621 Cache
->MarkDelete(Pkg
);
626 Cache
->MarkInstall(Pkg
,false);
627 if (State
.Install() == false)
628 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
632 // Install it with autoinstalling enabled.
633 if (State
.InstBroken() == true)
634 Cache
->MarkInstall(Pkg
,true);
637 // Call the scored problem resolver
638 Fix
.InstallProtect();
639 if (Fix
.Resolve(true) == false)
642 // Now we check the state of the packages,
643 if (Cache
->BrokenCount() != 0)
645 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
646 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
647 c1out
<< "distribution that some required packages have not yet been created" << endl
;
648 c1out
<< "or been moved out of Incoming." << endl
;
652 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
653 c1out
<< "the package is simply not installable and a bug report against" << endl
;
654 c1out
<< "that package should be filed." << endl
;
657 c1out
<< "The following information may help to resolve the situation:" << endl
;
659 ShowBroken(c1out
,Cache
);
660 return _error
->Error("Sorry, broken packages");
663 /* Print out a list of packages that are going to be installed extra
664 to what the user asked */
665 if (Cache
->InstCount() != ExpectedInst
)
668 pkgCache::PkgIterator I
= Cache
->PkgBegin();
669 for (;I
.end() != true; I
++)
671 if ((*Cache
)[I
].Install() == false)
675 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
676 if (strcmp(*J
,I
.Name()) == 0)
680 List
+= string(I
.Name()) + " ";
683 ShowList(c1out
,"The following extra packages will be installed:",List
);
686 // See if we need to prompt
687 if (Cache
->InstCount() != ExpectedInst
|| Cache
->DelCount() != 0)
688 return InstallPackages(Cache
,false,true);
689 return InstallPackages(Cache
,false);
692 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
693 // ---------------------------------------------------------------------
694 /* Intelligent upgrader that will install and remove packages at will */
695 bool DoDistUpgrade(CommandLine
&CmdL
)
698 if (Cache
.Open() == false)
701 c0out
<< "Calculating Upgrade... " << flush
;
702 if (pkgDistUpgrade(*Cache
) == false)
704 c0out
<< "Failed" << endl
;
705 ShowBroken(c1out
,Cache
);
709 c0out
<< "Done" << endl
;
711 return InstallPackages(Cache
,true);
714 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
715 // ---------------------------------------------------------------------
716 /* Follows dselect's selections */
717 bool DoDSelectUpgrade(CommandLine
&CmdL
)
720 if (Cache
.Open() == false)
723 // Install everything with the install flag set
724 pkgCache::PkgIterator I
= Cache
->PkgBegin();
725 for (;I
.end() != true; I
++)
727 /* Install the package only if it is a new install, the autoupgrader
728 will deal with the rest */
729 if (I
->SelectedState
== pkgCache::State::Install
)
730 Cache
->MarkInstall(I
,false);
733 /* Now install their deps too, if we do this above then order of
734 the status file is significant for | groups */
735 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
737 /* Install the package only if it is a new install, the autoupgrader
738 will deal with the rest */
739 if (I
->SelectedState
== pkgCache::State::Install
)
740 Cache
->MarkInstall(I
);
743 // Apply erasures now, they override everything else.
744 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
747 if (I
->SelectedState
== pkgCache::State::DeInstall
||
748 I
->SelectedState
== pkgCache::State::Purge
)
749 Cache
->MarkDelete(I
);
752 /* Use updates smart upgrade to do the rest, it will automatically
754 if (pkgAllUpgrade(Cache
) == false)
756 ShowBroken(c1out
,Cache
);
757 return _error
->Error("Internal Error, AllUpgrade broke stuff");
760 return InstallPackages(Cache
,false);
763 // DoClean - Remove download archives /*{{{*/
764 // ---------------------------------------------------------------------
766 bool DoClean(CommandLine
&CmdL
)
771 // DoCheck - Perform the check operation /*{{{*/
772 // ---------------------------------------------------------------------
773 /* Opening automatically checks the system, this command is mostly used
775 bool DoCheck(CommandLine
&CmdL
)
784 // ShowHelp - Show a help screen /*{{{*/
785 // ---------------------------------------------------------------------
789 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
790 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
792 cout
<< "Usage: apt-get [options] command" << endl
;
793 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
795 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
796 cout
<< "installing packages. The most frequently used commands are update" << endl
;
797 cout
<< "and install." << endl
;
799 cout
<< "Commands:" << endl
;
800 cout
<< " update - Retrieve new lists of packages" << endl
;
801 cout
<< " upgrade - Perform an upgrade" << endl
;
802 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
803 cout
<< " remove - Remove packages" << endl
;
804 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
805 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
806 cout
<< " clean - Erase downloaded archive files" << endl
;
807 cout
<< " check - Verify that there are no broken dependencies" << endl
;
809 cout
<< "Options:" << endl
;
810 cout
<< " -h This help text." << endl
;
811 cout
<< " -q Loggable output - no progress indicator" << endl
;
812 cout
<< " -qq No output except for errors" << endl
;
813 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
814 cout
<< " -s No-act. Perform ordering simulation" << endl
;
815 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
816 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
817 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
818 cout
<< " -u Show a list of upgraded packages as well" << endl
;
819 cout
<< " -c=? Read this configuration file" << endl
;
820 cout
<< " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl
;
821 cout
<< "See the apt-get(8), sources.list(8) and apt.conf(8) manual" << endl
;
822 cout
<< "pages for more information." << endl
;
826 // GetInitialize - Initialize things for apt-get /*{{{*/
827 // ---------------------------------------------------------------------
831 _config
->Set("quiet",0);
832 _config
->Set("help",false);
833 _config
->Set("APT::Get::Download-Only",false);
834 _config
->Set("APT::Get::Simulate",false);
835 _config
->Set("APT::Get::Assume-Yes",false);
836 _config
->Set("APT::Get::Fix-Broken",false);
839 // SigWinch - Window size change signal handler /*{{{*/
840 // ---------------------------------------------------------------------
848 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
849 ScreenWidth
= ws
.ws_col
- 1;
854 int main(int argc
,const char *argv
[])
856 CommandLine::Args Args
[] = {
857 {'h',"help","help",0},
858 {'q',"quiet","quiet",CommandLine::IntLevel
},
859 {'q',"silent","quiet",CommandLine::IntLevel
},
860 {'d',"download-only","APT::Get::Download-Only",0},
861 {'s',"simulate","APT::Get::Simulate",0},
862 {'s',"just-print","APT::Get::Simulate",0},
863 {'s',"recon","APT::Get::Simulate",0},
864 {'s',"no-act","APT::Get::Simulate",0},
865 {'y',"yes","APT::Get::Assume-Yes",0},
866 {'y',"assume-yes","APT::Get::Assume-Yes",0},
867 {'f',"fix-broken","APT::Get::Fix-Broken",0},
868 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
869 {'m',"ignore-missing","APT::Get::Fix-Broken",0},
870 {0,"ignore-hold","APT::Ingore-Hold",0},
871 {'c',"config-file",0,CommandLine::ConfigFile
},
872 {'o',"option",0,CommandLine::ArbItem
},
875 // Parse the command line and initialize the package library
876 CommandLine
CmdL(Args
,_config
);
877 if (pkgInitialize(*_config
) == false ||
878 CmdL
.Parse(argc
,argv
) == false)
880 _error
->DumpErrors();
884 // See if the help should be shown
885 if (_config
->FindB("help") == true ||
886 CmdL
.FileSize() == 0)
889 // Setup the output streams
890 c0out
.rdbuf(cout
.rdbuf());
891 c1out
.rdbuf(cout
.rdbuf());
892 c2out
.rdbuf(cout
.rdbuf());
893 if (_config
->FindI("quiet",0) > 0)
894 c0out
.rdbuf(devnull
.rdbuf());
895 if (_config
->FindI("quiet",0) > 1)
896 c1out
.rdbuf(devnull
.rdbuf());
899 signal(SIGPIPE
,SIG_IGN
);
900 signal(SIGWINCH
,SigWinch
);
903 // Match the operation
907 bool (*Handler
)(CommandLine
&);
908 } Map
[] = {{"update",&DoUpdate
},
909 {"upgrade",&DoUpgrade
},
910 {"install",&DoInstall
},
911 {"remove",&DoInstall
},
912 {"dist-upgrade",&DoDistUpgrade
},
913 {"dselect-upgrade",&DoDSelectUpgrade
},
918 for (I
= 0; Map
[I
].Match
!= 0; I
++)
920 if (strcmp(CmdL
.FileList
[0],Map
[I
].Match
) == 0)
922 if (Map
[I
].Handler(CmdL
) == false && _error
->PendingError() == false)
923 _error
->Error("Handler silently failed");
929 if (Map
[I
].Match
== 0)
930 _error
->Error("Invalid operation %s", CmdL
.FileList
[0]);
932 // Print any errors or warnings found during parsing
933 if (_error
->empty() == false)
935 bool Errors
= _error
->PendingError();
936 _error
->DumpErrors();
938 cout
<< "Returning 100." << endl
;
939 return Errors
== true?100:0;