]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
cc73339fd9dbae2475dd5bde5db01bea27a3b94a
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.10 1998/11/13 07:09:02 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>
41 #include "acqprogress.h"
45 #include <sys/ioctl.h>
52 ofstream
devnull("/dev/null");
53 unsigned int ScreenWidth
= 80;
55 // YnPrompt - Yes No Prompt. /*{{{*/
56 // ---------------------------------------------------------------------
57 /* Returns true on a Yes.*/
60 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
68 read(STDIN_FILENO
,&C
,1);
69 while (C
!= '\n' && Jnk
!= '\n') read(STDIN_FILENO
,&Jnk
,1);
71 if (!(C
== 'Y' || C
== 'y' || C
== '\n' || C
== '\r'))
76 // ShowList - Show a list /*{{{*/
77 // ---------------------------------------------------------------------
78 /* This prints out a string of space seperated words with a title and
79 a two space indent line wraped to the current screen width. */
80 void ShowList(ostream
&out
,string Title
,string List
)
82 if (List
.empty() == true)
85 // Acount for the leading space
86 int ScreenWidth
= ::ScreenWidth
- 3;
89 string::size_type Start
= 0;
90 while (Start
< List
.size())
92 string::size_type End
;
93 if (Start
+ ScreenWidth
>= List
.size())
96 End
= List
.rfind(' ',Start
+ScreenWidth
);
98 if (End
== string::npos
|| End
< Start
)
99 End
= Start
+ ScreenWidth
;
100 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
105 // ShowBroken - Debugging aide /*{{{*/
106 // ---------------------------------------------------------------------
107 /* This prints out the names of all the packages that are broken along
108 with the name of each each broken dependency and a quite version
110 void ShowBroken(ostream
&out
,pkgDepCache
&Cache
)
112 out
<< "Sorry, but the following packages are broken - this means they have unmet" << endl
;
113 out
<< "dependencies:" << endl
;
114 pkgCache::PkgIterator I
= Cache
.PkgBegin();
115 for (;I
.end() != true; I
++)
117 if (Cache
[I
].InstBroken() == false)
120 // Print out each package and the failed dependencies
121 out
<<" " << I
.Name() << ":";
122 int Indent
= strlen(I
.Name()) + 3;
124 if (Cache
[I
].InstVerIter(Cache
).end() == true)
130 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false; D
++)
132 if (Cache
.IsImportantDep(D
) == false || (Cache
[D
] &
133 pkgDepCache::DepInstall
) != 0)
137 for (int J
= 0; J
!= Indent
; J
++)
141 if (D
->Type
== pkgCache::Dep::Conflicts
)
142 out
<< " Conflicts:" << D
.TargetPkg().Name();
144 out
<< " Depends:" << D
.TargetPkg().Name();
146 // Show a quick summary of the version requirements
147 if (D
.TargetVer() != 0)
148 out
<< " (" << D
.CompType() << " " << D
.TargetVer() <<
151 /* Show a summary of the target package if possible. In the case
152 of virtual packages we show nothing */
154 pkgCache::PkgIterator Targ
= D
.TargetPkg();
155 if (Targ
->ProvidesList
== 0)
158 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
159 if (Ver
.end() == false)
160 out
<< Ver
.VerStr() << " is installed";
163 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
165 if (Targ
->ProvidesList
== 0)
166 out
<< "it is not installable";
168 out
<< "it is a virtual package";
171 out
<< "it is not installed";
180 // ShowNew - Show packages to newly install /*{{{*/
181 // ---------------------------------------------------------------------
183 void ShowNew(ostream
&out
,pkgDepCache
&Dep
)
185 /* Print out a list of packages that are going to be removed extra
186 to what the user asked */
187 pkgCache::PkgIterator I
= Dep
.PkgBegin();
189 for (;I
.end() != true; I
++)
190 if (Dep
[I
].NewInstall() == true)
191 List
+= string(I
.Name()) + " ";
192 ShowList(out
,"The following NEW packages will be installed:",List
);
195 // ShowDel - Show packages to delete /*{{{*/
196 // ---------------------------------------------------------------------
198 void ShowDel(ostream
&out
,pkgDepCache
&Dep
)
200 /* Print out a list of packages that are going to be removed extra
201 to what the user asked */
202 pkgCache::PkgIterator I
= Dep
.PkgBegin();
204 for (;I
.end() != true; I
++)
205 if (Dep
[I
].Delete() == true)
206 List
+= string(I
.Name()) + " ";
207 ShowList(out
,"The following packages will be REMOVED:",List
);
210 // ShowKept - Show kept packages /*{{{*/
211 // ---------------------------------------------------------------------
213 void ShowKept(ostream
&out
,pkgDepCache
&Dep
)
215 pkgCache::PkgIterator I
= Dep
.PkgBegin();
217 for (;I
.end() != true; I
++)
220 if (Dep
[I
].Upgrade() == true || Dep
[I
].Upgradable() == false ||
221 I
->CurrentVer
== 0 || Dep
[I
].Delete() == true)
224 List
+= string(I
.Name()) + " ";
226 ShowList(out
,"The following packages have been kept back",List
);
229 // ShowUpgraded - Show upgraded packages /*{{{*/
230 // ---------------------------------------------------------------------
232 void ShowUpgraded(ostream
&out
,pkgDepCache
&Dep
)
234 pkgCache::PkgIterator I
= Dep
.PkgBegin();
236 for (;I
.end() != true; I
++)
239 if (Dep
[I
].Upgrade() == false || Dep
[I
].NewInstall() == true)
242 List
+= string(I
.Name()) + " ";
244 ShowList(out
,"The following packages will be upgraded",List
);
247 // ShowHold - Show held but changed packages /*{{{*/
248 // ---------------------------------------------------------------------
250 void ShowHold(ostream
&out
,pkgDepCache
&Dep
)
252 pkgCache::PkgIterator I
= Dep
.PkgBegin();
254 for (;I
.end() != true; I
++)
256 if (Dep
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
257 I
->SelectedState
== pkgCache::State::Hold
)
258 List
+= string(I
.Name()) + " ";
261 ShowList(out
,"The following held packages will be changed:",List
);
264 // ShowEssential - Show an essential package warning /*{{{*/
265 // ---------------------------------------------------------------------
266 /* This prints out a warning message that is not to be ignored. It shows
267 all essential packages and their dependents that are to be removed.
268 It is insanely risky to remove the dependents of an essential package! */
269 void ShowEssential(ostream
&out
,pkgDepCache
&Dep
)
271 pkgCache::PkgIterator I
= Dep
.PkgBegin();
273 bool *Added
= new bool[Dep
.HeaderP
->PackageCount
];
274 for (unsigned int I
= 0; I
!= Dep
.HeaderP
->PackageCount
; I
++)
277 for (;I
.end() != true; I
++)
279 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
282 // The essential package is being removed
283 if (Dep
[I
].Delete() == true)
285 if (Added
[I
->ID
] == false)
288 List
+= string(I
.Name()) + " ";
292 if (I
->CurrentVer
== 0)
295 // Print out any essential package depenendents that are to be removed
296 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
298 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
299 if (Dep
[P
].Delete() == true)
301 if (Added
[P
->ID
] == true)
304 List
+= string(P
.Name()) + " ";
309 if (List
.empty() == false)
310 out
<< "WARNING: The following essential packages will be removed" << endl
;
311 ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
316 // Stats - Show some statistics /*{{{*/
317 // ---------------------------------------------------------------------
319 void Stats(ostream
&out
,pkgDepCache
&Dep
)
321 unsigned long Upgrade
= 0;
322 unsigned long Install
= 0;
323 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
325 if (Dep
[I
].NewInstall() == true)
328 if (Dep
[I
].Upgrade() == true)
332 out
<< Upgrade
<< " packages upgraded, " <<
333 Install
<< " newly installed, " <<
334 Dep
.DelCount() << " to remove and " <<
335 Dep
.KeepCount() << " not upgraded." << endl
;
337 if (Dep
.BadCount() != 0)
338 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
342 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
343 // ---------------------------------------------------------------------
353 inline operator pkgDepCache
&() {return *Cache
;};
354 inline pkgDepCache
*operator ->() {return Cache
;};
355 inline pkgDepCache
&operator *() {return *Cache
;};
358 CacheFile() : File(0), Map(0), Cache(0) {};
367 // CacheFile::Open - Open the cache file /*{{{*/
368 // ---------------------------------------------------------------------
369 /* This routine generates the caches and then opens the dependency cache
370 and verifies that the system is OK. */
371 bool CacheFile::Open()
373 // Create a progress class
374 OpTextProgress
Progress(*_config
);
376 // Read the source list
378 if (List
.ReadMainList() == false)
379 return _error
->Error("The list of sources could not be read.");
381 // Build all of the caches
382 pkgMakeStatusCache(List
,Progress
);
383 if (_error
->PendingError() == true)
384 return _error
->Error("The package lists or status file could not be parsed or opened.");
388 // Open the cache file
389 File
= new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly
);
390 if (_error
->PendingError() == true)
393 Map
= new MMap(*File
,MMap::Public
| MMap::ReadOnly
);
394 if (_error
->PendingError() == true)
397 Cache
= new pkgDepCache(*Map
,Progress
);
398 if (_error
->PendingError() == true)
403 // Check that the system is OK
404 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
405 return _error
->Error("Internal Error, non-zero counts");
407 // Apply corrections for half-installed packages
408 if (pkgApplyStatus(*Cache
) == false)
412 if (Cache
->BrokenCount() == 0)
415 // Attempt to fix broken things
416 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
418 c1out
<< "Correcting dependencies..." << flush
;
419 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
421 c1out
<< " failed." << endl
;
422 ShowBroken(c1out
,*this);
424 return _error
->Error("Unable to correct dependencies");
426 if (pkgMinimizeUpgrade(*Cache
) == false)
427 return _error
->Error("Unable to minimize the upgrade set");
429 c1out
<< " Done" << endl
;
433 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
434 ShowBroken(c1out
,*this);
436 return _error
->Error("Unmet dependencies. Try using -f.");
443 // InstallPackages - Actually download and install the packages /*{{{*/
444 // ---------------------------------------------------------------------
445 /* This displays the informative messages describing what is going to
446 happen and then calls the download routines */
447 bool InstallPackages(pkgDepCache
&Cache
,bool ShwKept
,bool Ask
= true)
449 // Show all the various warning indicators
450 ShowDel(c1out
,Cache
);
451 ShowNew(c1out
,Cache
);
453 ShowKept(c1out
,Cache
);
454 ShowHold(c1out
,Cache
);
455 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
456 ShowUpgraded(c1out
,Cache
);
457 ShowEssential(c1out
,Cache
);
461 if (Cache
.BrokenCount() != 0)
463 ShowBroken(c1out
,Cache
);
464 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
467 if (Cache
.DelCount() == 0 && Cache
.InstCount() == 0 &&
468 Cache
.BadCount() == 0)
471 // Run the simulator ..
472 if (_config
->FindB("APT::Get::Simulate") == true)
474 pkgSimulate
PM(Cache
);
475 return PM
.DoInstall();
478 // Create the text record parser
479 pkgRecords
Recs(Cache
);
481 // Create the download object
482 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
483 pkgAcquire
Fetcher(&Stat
);
485 // Read the source list
487 if (List
.ReadMainList() == false)
488 return _error
->Error("The list of sources could not be read.");
490 // Create the package manager and prepare to download
491 pkgPackageManager
PM(Cache
);
492 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false)
495 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
496 unsigned long DebBytes
= Fetcher
.TotalNeeded();
497 if (DebBytes
!= Cache
.DebSize())
498 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
500 c1out
<< "Need to get ";
501 if (DebBytes
!= FetchBytes
)
502 c1out
<< SizeToStr(FetchBytes
) << '/' << SizeToStr(DebBytes
);
504 c1out
<< SizeToStr(DebBytes
);
506 c1out
<< " of archives. After unpacking ";
508 if (Cache
.UsrSize() >= 0)
509 c1out
<< SizeToStr(Cache
.UsrSize()) << " will be used." << endl
;
511 c1out
<< SizeToStr(-1*Cache
.UsrSize()) << " will be freed." << endl
;
513 if (_error
->PendingError() == true)
519 if (_config
->FindI("quiet",0) < 2 ||
520 _config
->FindB("APT::Get::Assume-Yes",false) == false)
521 c2out
<< "Do you want to continue? [Y/n] " << flush
;
522 if (YnPrompt() == false)
527 if (Fetcher
.Run() == false)
534 // DoUpdate - Update the package lists /*{{{*/
535 // ---------------------------------------------------------------------
537 bool DoUpdate(CommandLine
&)
539 // Get the source list
541 if (List
.ReadMainList() == false)
544 // Create the download object
545 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
546 pkgAcquire
Fetcher(&Stat
);
548 // Populate it with the source selection
549 pkgSourceList::const_iterator I
;
550 for (I
= List
.begin(); I
!= List
.end(); I
++)
552 new pkgAcqIndex(&Fetcher
,I
);
553 if (_error
->PendingError() == true)
558 if (Fetcher
.Run() == false)
561 // Clean out any old list files
562 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
563 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
566 // Prepare the cache.
568 if (Cache
.Open() == false)
574 // DoUpgrade - Upgrade all packages /*{{{*/
575 // ---------------------------------------------------------------------
576 /* Upgrade all packages without installing new packages or erasing old
578 bool DoUpgrade(CommandLine
&CmdL
)
581 if (Cache
.Open() == false)
585 if (pkgAllUpgrade(Cache
) == false)
587 ShowBroken(c1out
,Cache
);
588 return _error
->Error("Internal Error, AllUpgrade broke stuff");
591 return InstallPackages(Cache
,true);
594 // DoInstall - Install packages from the command line /*{{{*/
595 // ---------------------------------------------------------------------
596 /* Install named packages */
597 bool DoInstall(CommandLine
&CmdL
)
600 if (Cache
.Open() == false)
603 unsigned int ExpectedInst
= 0;
604 unsigned int Packages
= 0;
605 pkgProblemResolver
Fix(Cache
);
607 bool DefRemove
= false;
608 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
611 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
613 // Duplicate the string
614 unsigned int Length
= strlen(*I
);
616 if (Length
>= sizeof(S
))
620 // See if we are removing the package
621 bool Remove
= DefRemove
;
622 if (S
[Length
- 1] == '-')
627 if (S
[Length
- 1] == '+')
633 // Locate the package
634 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
636 if (Pkg
.end() == true)
637 return _error
->Error("Couldn't find package %s",S
);
639 // Check if there is something new to install
640 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
641 if (State
.CandidateVer
== 0)
643 if (Pkg
->ProvidesList
!= 0)
645 c1out
<< "Package " << S
<< " is a virtual package provided by:" << endl
;
647 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
648 for (; I
.end() == false; I
++)
650 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
652 if ((*Cache
)[Pkg
].CandidateVerIter(*Cache
) == I
.OwnerVer())
653 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
655 if ((*Cache
)[Pkg
].InstVerIter(*Cache
) == I
.OwnerVer())
656 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
657 " [Installed]"<< endl
;
659 c1out
<< "You should explicly select one to install." << endl
;
663 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
664 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
665 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
668 return _error
->Error("Package %s has no installation candidate",S
);
675 Cache
->MarkDelete(Pkg
);
680 Cache
->MarkInstall(Pkg
,false);
681 if (State
.Install() == false)
682 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
686 // Install it with autoinstalling enabled.
687 if (State
.InstBroken() == true)
688 Cache
->MarkInstall(Pkg
,true);
691 // Call the scored problem resolver
692 Fix
.InstallProtect();
693 if (Fix
.Resolve(true) == false)
696 // Now we check the state of the packages,
697 if (Cache
->BrokenCount() != 0)
699 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
700 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
701 c1out
<< "distribution that some required packages have not yet been created" << endl
;
702 c1out
<< "or been moved out of Incoming." << endl
;
706 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
707 c1out
<< "the package is simply not installable and a bug report against" << endl
;
708 c1out
<< "that package should be filed." << endl
;
711 c1out
<< "The following information may help to resolve the situation:" << endl
;
713 ShowBroken(c1out
,Cache
);
714 return _error
->Error("Sorry, broken packages");
717 /* Print out a list of packages that are going to be installed extra
718 to what the user asked */
719 if (Cache
->InstCount() != ExpectedInst
)
722 pkgCache::PkgIterator I
= Cache
->PkgBegin();
723 for (;I
.end() != true; I
++)
725 if ((*Cache
)[I
].Install() == false)
729 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
730 if (strcmp(*J
,I
.Name()) == 0)
734 List
+= string(I
.Name()) + " ";
737 ShowList(c1out
,"The following extra packages will be installed:",List
);
740 // See if we need to prompt
741 if (Cache
->InstCount() != ExpectedInst
|| Cache
->DelCount() != 0)
742 return InstallPackages(Cache
,false,true);
743 return InstallPackages(Cache
,false);
746 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
747 // ---------------------------------------------------------------------
748 /* Intelligent upgrader that will install and remove packages at will */
749 bool DoDistUpgrade(CommandLine
&CmdL
)
752 if (Cache
.Open() == false)
755 c0out
<< "Calculating Upgrade... " << flush
;
756 if (pkgDistUpgrade(*Cache
) == false)
758 c0out
<< "Failed" << endl
;
759 ShowBroken(c1out
,Cache
);
763 c0out
<< "Done" << endl
;
765 return InstallPackages(Cache
,true);
768 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
769 // ---------------------------------------------------------------------
770 /* Follows dselect's selections */
771 bool DoDSelectUpgrade(CommandLine
&CmdL
)
774 if (Cache
.Open() == false)
777 // Install everything with the install flag set
778 pkgCache::PkgIterator I
= Cache
->PkgBegin();
779 for (;I
.end() != true; I
++)
781 /* Install the package only if it is a new install, the autoupgrader
782 will deal with the rest */
783 if (I
->SelectedState
== pkgCache::State::Install
)
784 Cache
->MarkInstall(I
,false);
787 /* Now install their deps too, if we do this above then order of
788 the status file is significant for | groups */
789 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
791 /* Install the package only if it is a new install, the autoupgrader
792 will deal with the rest */
793 if (I
->SelectedState
== pkgCache::State::Install
)
794 Cache
->MarkInstall(I
);
797 // Apply erasures now, they override everything else.
798 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
801 if (I
->SelectedState
== pkgCache::State::DeInstall
||
802 I
->SelectedState
== pkgCache::State::Purge
)
803 Cache
->MarkDelete(I
);
806 /* Use updates smart upgrade to do the rest, it will automatically
808 if (pkgAllUpgrade(Cache
) == false)
810 ShowBroken(c1out
,Cache
);
811 return _error
->Error("Internal Error, AllUpgrade broke stuff");
814 return InstallPackages(Cache
,false);
817 // DoClean - Remove download archives /*{{{*/
818 // ---------------------------------------------------------------------
820 bool DoClean(CommandLine
&CmdL
)
825 // DoCheck - Perform the check operation /*{{{*/
826 // ---------------------------------------------------------------------
827 /* Opening automatically checks the system, this command is mostly used
829 bool DoCheck(CommandLine
&CmdL
)
838 // ShowHelp - Show a help screen /*{{{*/
839 // ---------------------------------------------------------------------
843 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
844 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
846 cout
<< "Usage: apt-get [options] command" << endl
;
847 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
849 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
850 cout
<< "installing packages. The most frequently used commands are update" << endl
;
851 cout
<< "and install." << endl
;
853 cout
<< "Commands:" << endl
;
854 cout
<< " update - Retrieve new lists of packages" << endl
;
855 cout
<< " upgrade - Perform an upgrade" << endl
;
856 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
857 cout
<< " remove - Remove packages" << endl
;
858 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
859 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
860 cout
<< " clean - Erase downloaded archive files" << endl
;
861 cout
<< " check - Verify that there are no broken dependencies" << endl
;
863 cout
<< "Options:" << endl
;
864 cout
<< " -h This help text." << endl
;
865 cout
<< " -q Loggable output - no progress indicator" << endl
;
866 cout
<< " -qq No output except for errors" << endl
;
867 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
868 cout
<< " -s No-act. Perform ordering simulation" << endl
;
869 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
870 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
871 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
872 cout
<< " -u Show a list of upgraded packages as well" << endl
;
873 cout
<< " -c=? Read this configuration file" << endl
;
874 cout
<< " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl
;
875 cout
<< "See the apt-get(8), sources.list(8) and apt.conf(8) manual" << endl
;
876 cout
<< "pages for more information." << endl
;
880 // GetInitialize - Initialize things for apt-get /*{{{*/
881 // ---------------------------------------------------------------------
885 _config
->Set("quiet",0);
886 _config
->Set("help",false);
887 _config
->Set("APT::Get::Download-Only",false);
888 _config
->Set("APT::Get::Simulate",false);
889 _config
->Set("APT::Get::Assume-Yes",false);
890 _config
->Set("APT::Get::Fix-Broken",false);
893 // SigWinch - Window size change signal handler /*{{{*/
894 // ---------------------------------------------------------------------
902 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
903 ScreenWidth
= ws
.ws_col
- 1;
908 int main(int argc
,const char *argv
[])
910 CommandLine::Args Args
[] = {
911 {'h',"help","help",0},
912 {'q',"quiet","quiet",CommandLine::IntLevel
},
913 {'q',"silent","quiet",CommandLine::IntLevel
},
914 {'d',"download-only","APT::Get::Download-Only",0},
915 {'s',"simulate","APT::Get::Simulate",0},
916 {'s',"just-print","APT::Get::Simulate",0},
917 {'s',"recon","APT::Get::Simulate",0},
918 {'s',"no-act","APT::Get::Simulate",0},
919 {'y',"yes","APT::Get::Assume-Yes",0},
920 {'y',"assume-yes","APT::Get::Assume-Yes",0},
921 {'f',"fix-broken","APT::Get::Fix-Broken",0},
922 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
923 {'m',"ignore-missing","APT::Get::Fix-Broken",0},
924 {0,"ignore-hold","APT::Ingore-Hold",0},
925 {'c',"config-file",0,CommandLine::ConfigFile
},
926 {'o',"option",0,CommandLine::ArbItem
},
929 // Parse the command line and initialize the package library
930 CommandLine
CmdL(Args
,_config
);
931 if (pkgInitialize(*_config
) == false ||
932 CmdL
.Parse(argc
,argv
) == false)
934 _error
->DumpErrors();
938 // See if the help should be shown
939 if (_config
->FindB("help") == true ||
940 CmdL
.FileSize() == 0)
943 // Setup the output streams
944 c0out
.rdbuf(cout
.rdbuf());
945 c1out
.rdbuf(cout
.rdbuf());
946 c2out
.rdbuf(cout
.rdbuf());
947 if (_config
->FindI("quiet",0) > 0)
948 c0out
.rdbuf(devnull
.rdbuf());
949 if (_config
->FindI("quiet",0) > 1)
950 c1out
.rdbuf(devnull
.rdbuf());
953 signal(SIGPIPE
,SIG_IGN
);
954 signal(SIGWINCH
,SigWinch
);
957 // Match the operation
961 bool (*Handler
)(CommandLine
&);
962 } Map
[] = {{"update",&DoUpdate
},
963 {"upgrade",&DoUpgrade
},
964 {"install",&DoInstall
},
965 {"remove",&DoInstall
},
966 {"dist-upgrade",&DoDistUpgrade
},
967 {"dselect-upgrade",&DoDSelectUpgrade
},
972 for (I
= 0; Map
[I
].Match
!= 0; I
++)
974 if (strcmp(CmdL
.FileList
[0],Map
[I
].Match
) == 0)
976 if (Map
[I
].Handler(CmdL
) == false && _error
->PendingError() == false)
977 _error
->Error("Handler silently failed");
983 if (Map
[I
].Match
== 0)
984 _error
->Error("Invalid operation %s", CmdL
.FileList
[0]);
986 // Print any errors or warnings found during parsing
987 if (_error
->empty() == false)
989 bool Errors
= _error
->PendingError();
990 _error
->DumpErrors();
992 cout
<< "Returning 100." << endl
;
993 return Errors
== true?100:0;