]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
42ef548ec9a5e0d4eeec4db6e71274180aaec44f
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.19 1998/11/24 02:35:32 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>
37 #include <apt-pkg/dpkginit.h>
42 #include "acqprogress.h"
46 #include <sys/ioctl.h>
54 ofstream
devnull("/dev/null");
55 unsigned int ScreenWidth
= 80;
57 // YnPrompt - Yes No Prompt. /*{{{*/
58 // ---------------------------------------------------------------------
59 /* Returns true on a Yes.*/
62 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
70 read(STDIN_FILENO
,&C
,1);
71 while (C
!= '\n' && Jnk
!= '\n') read(STDIN_FILENO
,&Jnk
,1);
73 if (!(C
== 'Y' || C
== 'y' || C
== '\n' || C
== '\r'))
78 // ShowList - Show a list /*{{{*/
79 // ---------------------------------------------------------------------
80 /* This prints out a string of space seperated words with a title and
81 a two space indent line wraped to the current screen width. */
82 void ShowList(ostream
&out
,string Title
,string List
)
84 if (List
.empty() == true)
87 // Acount for the leading space
88 int ScreenWidth
= ::ScreenWidth
- 3;
91 string::size_type Start
= 0;
92 while (Start
< List
.size())
94 string::size_type End
;
95 if (Start
+ ScreenWidth
>= List
.size())
98 End
= List
.rfind(' ',Start
+ScreenWidth
);
100 if (End
== string::npos
|| End
< Start
)
101 End
= Start
+ ScreenWidth
;
102 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
107 // ShowBroken - Debugging aide /*{{{*/
108 // ---------------------------------------------------------------------
109 /* This prints out the names of all the packages that are broken along
110 with the name of each each broken dependency and a quite version
112 void ShowBroken(ostream
&out
,pkgDepCache
&Cache
)
114 out
<< "Sorry, but the following packages have unmet dependencies:" << endl
;
115 pkgCache::PkgIterator I
= Cache
.PkgBegin();
116 for (;I
.end() != true; I
++)
118 if (Cache
[I
].InstBroken() == false)
121 // Print out each package and the failed dependencies
122 out
<<" " << I
.Name() << ":";
123 int Indent
= strlen(I
.Name()) + 3;
125 if (Cache
[I
].InstVerIter(Cache
).end() == true)
131 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
133 // Compute a single dependency element (glob or)
134 pkgCache::DepIterator Start
;
135 pkgCache::DepIterator End
;
138 if (Cache
.IsImportantDep(End
) == false ||
139 (Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
143 for (int J
= 0; J
!= Indent
; J
++)
147 cout
<< ' ' << End
.DepType() << ": " << End
.TargetPkg().Name();
149 // Show a quick summary of the version requirements
150 if (End
.TargetVer() != 0)
151 out
<< " (" << End
.CompType() << " " << End
.TargetVer() <<
154 /* Show a summary of the target package if possible. In the case
155 of virtual packages we show nothing */
157 pkgCache::PkgIterator Targ
= End
.TargetPkg();
158 if (Targ
->ProvidesList
== 0)
161 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
162 if (Ver
.end() == false)
163 out
<< Ver
.VerStr() << " is installed";
166 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
168 if (Targ
->ProvidesList
== 0)
169 out
<< "it is not installable";
171 out
<< "it is a virtual package";
174 out
<< "it is not installed";
183 // ShowNew - Show packages to newly install /*{{{*/
184 // ---------------------------------------------------------------------
186 void ShowNew(ostream
&out
,pkgDepCache
&Dep
)
188 /* Print out a list of packages that are going to be removed extra
189 to what the user asked */
190 pkgCache::PkgIterator I
= Dep
.PkgBegin();
192 for (;I
.end() != true; I
++)
193 if (Dep
[I
].NewInstall() == true)
194 List
+= string(I
.Name()) + " ";
195 ShowList(out
,"The following NEW packages will be installed:",List
);
198 // ShowDel - Show packages to delete /*{{{*/
199 // ---------------------------------------------------------------------
201 void ShowDel(ostream
&out
,pkgDepCache
&Dep
)
203 /* Print out a list of packages that are going to be removed extra
204 to what the user asked */
205 pkgCache::PkgIterator I
= Dep
.PkgBegin();
207 for (;I
.end() != true; I
++)
208 if (Dep
[I
].Delete() == true)
209 List
+= string(I
.Name()) + " ";
210 ShowList(out
,"The following packages will be REMOVED:",List
);
213 // ShowKept - Show kept packages /*{{{*/
214 // ---------------------------------------------------------------------
216 void ShowKept(ostream
&out
,pkgDepCache
&Dep
)
218 pkgCache::PkgIterator I
= Dep
.PkgBegin();
220 for (;I
.end() != true; I
++)
223 if (Dep
[I
].Upgrade() == true || Dep
[I
].Upgradable() == false ||
224 I
->CurrentVer
== 0 || Dep
[I
].Delete() == true)
227 List
+= string(I
.Name()) + " ";
229 ShowList(out
,"The following packages have been kept back",List
);
232 // ShowUpgraded - Show upgraded packages /*{{{*/
233 // ---------------------------------------------------------------------
235 void ShowUpgraded(ostream
&out
,pkgDepCache
&Dep
)
237 pkgCache::PkgIterator I
= Dep
.PkgBegin();
239 for (;I
.end() != true; I
++)
242 if (Dep
[I
].Upgrade() == false || Dep
[I
].NewInstall() == true)
245 List
+= string(I
.Name()) + " ";
247 ShowList(out
,"The following packages will be upgraded",List
);
250 // ShowHold - Show held but changed packages /*{{{*/
251 // ---------------------------------------------------------------------
253 void ShowHold(ostream
&out
,pkgDepCache
&Dep
)
255 pkgCache::PkgIterator I
= Dep
.PkgBegin();
257 for (;I
.end() != true; I
++)
259 if (Dep
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
260 I
->SelectedState
== pkgCache::State::Hold
)
261 List
+= string(I
.Name()) + " ";
264 ShowList(out
,"The following held packages will be changed:",List
);
267 // ShowEssential - Show an essential package warning /*{{{*/
268 // ---------------------------------------------------------------------
269 /* This prints out a warning message that is not to be ignored. It shows
270 all essential packages and their dependents that are to be removed.
271 It is insanely risky to remove the dependents of an essential package! */
272 void ShowEssential(ostream
&out
,pkgDepCache
&Dep
)
274 pkgCache::PkgIterator I
= Dep
.PkgBegin();
276 bool *Added
= new bool[Dep
.HeaderP
->PackageCount
];
277 for (unsigned int I
= 0; I
!= Dep
.HeaderP
->PackageCount
; I
++)
280 for (;I
.end() != true; I
++)
282 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
285 // The essential package is being removed
286 if (Dep
[I
].Delete() == true)
288 if (Added
[I
->ID
] == false)
291 List
+= string(I
.Name()) + " ";
295 if (I
->CurrentVer
== 0)
298 // Print out any essential package depenendents that are to be removed
299 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
301 // Skip everything but depends
302 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
303 D
->Type
!= pkgCache::Dep::Depends
)
306 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
307 if (Dep
[P
].Delete() == true)
309 if (Added
[P
->ID
] == true)
314 sprintf(S
,"%s (due to %s) ",P
.Name(),I
.Name());
320 if (List
.empty() == false)
321 out
<< "WARNING: The following essential packages will be removed" << endl
;
322 ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
327 // Stats - Show some statistics /*{{{*/
328 // ---------------------------------------------------------------------
330 void Stats(ostream
&out
,pkgDepCache
&Dep
)
332 unsigned long Upgrade
= 0;
333 unsigned long Install
= 0;
334 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
336 if (Dep
[I
].NewInstall() == true)
339 if (Dep
[I
].Upgrade() == true)
343 out
<< Upgrade
<< " packages upgraded, " <<
344 Install
<< " newly installed, " <<
345 Dep
.DelCount() << " to remove and " <<
346 Dep
.KeepCount() << " not upgraded." << endl
;
348 if (Dep
.BadCount() != 0)
349 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
353 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
354 // ---------------------------------------------------------------------
365 inline operator pkgDepCache
&() {return *Cache
;};
366 inline pkgDepCache
*operator ->() {return Cache
;};
367 inline pkgDepCache
&operator *() {return *Cache
;};
370 CacheFile() : File(0), Map(0), Cache(0) {};
379 // CacheFile::Open - Open the cache file /*{{{*/
380 // ---------------------------------------------------------------------
381 /* This routine generates the caches and then opens the dependency cache
382 and verifies that the system is OK. */
383 bool CacheFile::Open()
385 if (_error
->PendingError() == true)
388 // Create a progress class
389 OpTextProgress
Progress(*_config
);
391 // Read the source list
393 if (List
.ReadMainList() == false)
394 return _error
->Error("The list of sources could not be read.");
396 // Build all of the caches
397 pkgMakeStatusCache(List
,Progress
);
398 if (_error
->PendingError() == true)
399 return _error
->Error("The package lists or status file could not be parsed or opened.");
403 // Open the cache file
404 File
= new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly
);
405 if (_error
->PendingError() == true)
408 Map
= new MMap(*File
,MMap::Public
| MMap::ReadOnly
);
409 if (_error
->PendingError() == true)
412 Cache
= new pkgDepCache(*Map
,Progress
);
413 if (_error
->PendingError() == true)
418 // Check that the system is OK
419 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
420 return _error
->Error("Internal Error, non-zero counts");
422 // Apply corrections for half-installed packages
423 if (pkgApplyStatus(*Cache
) == false)
427 if (Cache
->BrokenCount() == 0)
430 // Attempt to fix broken things
431 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
433 c1out
<< "Correcting dependencies..." << flush
;
434 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
436 c1out
<< " failed." << endl
;
437 ShowBroken(c1out
,*this);
439 return _error
->Error("Unable to correct dependencies");
441 if (pkgMinimizeUpgrade(*Cache
) == false)
442 return _error
->Error("Unable to minimize the upgrade set");
444 c1out
<< " Done" << endl
;
448 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
449 ShowBroken(c1out
,*this);
451 return _error
->Error("Unmet dependencies. Try using -f.");
458 // InstallPackages - Actually download and install the packages /*{{{*/
459 // ---------------------------------------------------------------------
460 /* This displays the informative messages describing what is going to
461 happen and then calls the download routines */
462 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true)
464 // Show all the various warning indicators
465 ShowDel(c1out
,Cache
);
466 ShowNew(c1out
,Cache
);
468 ShowKept(c1out
,Cache
);
469 ShowHold(c1out
,Cache
);
470 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
471 ShowUpgraded(c1out
,Cache
);
472 ShowEssential(c1out
,Cache
);
476 if (Cache
->BrokenCount() != 0)
478 ShowBroken(c1out
,Cache
);
479 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
482 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
483 Cache
->BadCount() == 0)
486 // Run the simulator ..
487 if (_config
->FindB("APT::Get::Simulate") == true)
489 pkgSimulate
PM(Cache
);
490 return PM
.DoInstall();
493 // Create the text record parser
494 pkgRecords
Recs(Cache
);
496 // Lock the archive directory
497 if (_config
->FindB("Debug::NoLocking",false) == false)
499 FileFd
Lock(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
500 if (_error
->PendingError() == true)
501 return _error
->Error("Unable to lock the download directory");
504 // Create the download object
505 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
506 pkgAcquire
Fetcher(&Stat
);
508 // Read the source list
510 if (List
.ReadMainList() == false)
511 return _error
->Error("The list of sources could not be read.");
513 // Create the package manager and prepare to download
515 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false)
518 // Display statistics
519 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
520 unsigned long DebBytes
= Fetcher
.TotalNeeded();
521 if (DebBytes
!= Cache
->DebSize())
523 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
524 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
528 c1out
<< "Need to get ";
529 if (DebBytes
!= FetchBytes
)
530 c1out
<< SizeToStr(FetchBytes
) << '/' << SizeToStr(DebBytes
);
532 c1out
<< SizeToStr(DebBytes
);
534 c1out
<< " of archives. After unpacking ";
537 if (Cache
->UsrSize() >= 0)
538 c1out
<< SizeToStr(Cache
->UsrSize()) << " will be used." << endl
;
540 c1out
<< SizeToStr(-1*Cache
->UsrSize()) << " will be freed." << endl
;
542 if (_error
->PendingError() == true)
545 // Prompt to continue
548 if (_config
->FindI("quiet",0) < 2 ||
549 _config
->FindB("APT::Get::Assume-Yes",false) == false)
550 c2out
<< "Do you want to continue? [Y/n] " << flush
;
551 if (YnPrompt() == false)
556 if (Fetcher
.Run() == false)
561 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
563 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
564 (*I
)->Complete
== true)
567 cerr
<< "Failed to fetch " << (*I
)->Describe() << endl
;
568 cerr
<< " " << (*I
)->ErrorText
<< endl
;
572 if (Failed
== true && _config
->FindB("APT::Fix-Missing",false) == false)
573 return _error
->Error("Unable to fetch some archives, maybe try with --fix-missing?");
575 // Try to deal with missing package files
576 if (PM
.FixMissing() == false)
578 cerr
<< "Unable to correct missing packages." << endl
;
579 return _error
->Error("Aborting Install.");
583 return PM
.DoInstall();
587 // DoUpdate - Update the package lists /*{{{*/
588 // ---------------------------------------------------------------------
590 bool DoUpdate(CommandLine
&)
592 // Get the source list
594 if (List
.ReadMainList() == false)
597 // Lock the list directory
598 if (_config
->FindB("Debug::NoLocking",false) == false)
600 FileFd
Lock(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
601 if (_error
->PendingError() == true)
602 return _error
->Error("Unable to lock the list directory");
605 // Create the download object
606 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
607 pkgAcquire
Fetcher(&Stat
);
609 // Populate it with the source selection
610 pkgSourceList::const_iterator I
;
611 for (I
= List
.begin(); I
!= List
.end(); I
++)
613 new pkgAcqIndex(&Fetcher
,I
);
614 if (_error
->PendingError() == true)
619 if (Fetcher
.Run() == false)
622 // Clean out any old list files
623 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
624 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
627 // Prepare the cache.
629 if (Cache
.Open() == false)
635 // DoUpgrade - Upgrade all packages /*{{{*/
636 // ---------------------------------------------------------------------
637 /* Upgrade all packages without installing new packages or erasing old
639 bool DoUpgrade(CommandLine
&CmdL
)
642 if (Cache
.Open() == false)
646 if (pkgAllUpgrade(Cache
) == false)
648 ShowBroken(c1out
,Cache
);
649 return _error
->Error("Internal Error, AllUpgrade broke stuff");
652 return InstallPackages(Cache
,true);
655 // DoInstall - Install packages from the command line /*{{{*/
656 // ---------------------------------------------------------------------
657 /* Install named packages */
658 bool DoInstall(CommandLine
&CmdL
)
661 if (Cache
.Open() == false)
664 unsigned int ExpectedInst
= 0;
665 unsigned int Packages
= 0;
666 pkgProblemResolver
Fix(Cache
);
668 bool DefRemove
= false;
669 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
672 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
674 // Duplicate the string
675 unsigned int Length
= strlen(*I
);
677 if (Length
>= sizeof(S
))
681 // See if we are removing the package
682 bool Remove
= DefRemove
;
683 if (Cache
->FindPkg(S
).end() == true)
685 // Handle an optional end tag indicating what to do
686 if (S
[Length
- 1] == '-')
691 if (S
[Length
- 1] == '+')
698 // Locate the package
699 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
701 if (Pkg
.end() == true)
702 return _error
->Error("Couldn't find package %s",S
);
704 // Handle the no-upgrade case
705 if (_config
->FindB("APT::Get::no-upgrade",false) == true &&
706 Pkg
->CurrentVer
!= 0)
708 c1out
<< "Skipping " << Pkg
.Name() << ", it is already installed and no-upgrade is set." << endl
;
712 // Check if there is something new to install
713 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
714 if (State
.CandidateVer
== 0)
716 if (Pkg
->ProvidesList
!= 0)
718 c1out
<< "Package " << S
<< " is a virtual package provided by:" << endl
;
720 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
721 for (; I
.end() == false; I
++)
723 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
725 if ((*Cache
)[Pkg
].CandidateVerIter(*Cache
) == I
.OwnerVer())
726 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
728 if ((*Cache
)[Pkg
].InstVerIter(*Cache
) == I
.OwnerVer())
729 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
730 " [Installed]"<< endl
;
732 c1out
<< "You should explicly select one to install." << endl
;
736 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
737 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
738 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
741 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
742 for (; Dep
.end() == false; Dep
++)
744 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
746 List
+= string(Dep
.ParentPkg().Name()) + " ";
748 ShowList(c1out
,"However the following packages replace it:",List
);
751 return _error
->Error("Package %s has no installation candidate",S
);
758 Cache
->MarkDelete(Pkg
);
763 Cache
->MarkInstall(Pkg
,false);
764 if (State
.Install() == false)
765 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
769 // Install it with autoinstalling enabled.
770 if (State
.InstBroken() == true)
771 Cache
->MarkInstall(Pkg
,true);
774 // Call the scored problem resolver
775 Fix
.InstallProtect();
776 if (Fix
.Resolve(true) == false)
779 // Now we check the state of the packages,
780 if (Cache
->BrokenCount() != 0)
782 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
783 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
784 c1out
<< "distribution that some required packages have not yet been created" << endl
;
785 c1out
<< "or been moved out of Incoming." << endl
;
789 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
790 c1out
<< "the package is simply not installable and a bug report against" << endl
;
791 c1out
<< "that package should be filed." << endl
;
794 c1out
<< "The following information may help to resolve the situation:" << endl
;
796 ShowBroken(c1out
,Cache
);
797 return _error
->Error("Sorry, broken packages");
800 /* Print out a list of packages that are going to be installed extra
801 to what the user asked */
802 if (Cache
->InstCount() != ExpectedInst
)
805 pkgCache::PkgIterator I
= Cache
->PkgBegin();
806 for (;I
.end() != true; I
++)
808 if ((*Cache
)[I
].Install() == false)
812 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
813 if (strcmp(*J
,I
.Name()) == 0)
817 List
+= string(I
.Name()) + " ";
820 ShowList(c1out
,"The following extra packages will be installed:",List
);
823 // See if we need to prompt
824 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
825 return InstallPackages(Cache
,false,false);
827 return InstallPackages(Cache
,false);
830 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
831 // ---------------------------------------------------------------------
832 /* Intelligent upgrader that will install and remove packages at will */
833 bool DoDistUpgrade(CommandLine
&CmdL
)
836 if (Cache
.Open() == false)
839 c0out
<< "Calculating Upgrade... " << flush
;
840 if (pkgDistUpgrade(*Cache
) == false)
842 c0out
<< "Failed" << endl
;
843 ShowBroken(c1out
,Cache
);
847 c0out
<< "Done" << endl
;
849 return InstallPackages(Cache
,true);
852 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
853 // ---------------------------------------------------------------------
854 /* Follows dselect's selections */
855 bool DoDSelectUpgrade(CommandLine
&CmdL
)
858 if (Cache
.Open() == false)
861 // Install everything with the install flag set
862 pkgCache::PkgIterator I
= Cache
->PkgBegin();
863 for (;I
.end() != true; I
++)
865 /* Install the package only if it is a new install, the autoupgrader
866 will deal with the rest */
867 if (I
->SelectedState
== pkgCache::State::Install
)
868 Cache
->MarkInstall(I
,false);
871 /* Now install their deps too, if we do this above then order of
872 the status file is significant for | groups */
873 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
875 /* Install the package only if it is a new install, the autoupgrader
876 will deal with the rest */
877 if (I
->SelectedState
== pkgCache::State::Install
)
878 Cache
->MarkInstall(I
);
881 // Apply erasures now, they override everything else.
882 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
885 if (I
->SelectedState
== pkgCache::State::DeInstall
||
886 I
->SelectedState
== pkgCache::State::Purge
)
887 Cache
->MarkDelete(I
);
890 /* Use updates smart upgrade to do the rest, it will automatically
892 if (pkgAllUpgrade(Cache
) == false)
894 ShowBroken(c1out
,Cache
);
895 return _error
->Error("Internal Error, AllUpgrade broke stuff");
898 return InstallPackages(Cache
,false);
901 // DoClean - Remove download archives /*{{{*/
902 // ---------------------------------------------------------------------
904 bool DoClean(CommandLine
&CmdL
)
907 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
908 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
912 // DoCheck - Perform the check operation /*{{{*/
913 // ---------------------------------------------------------------------
914 /* Opening automatically checks the system, this command is mostly used
916 bool DoCheck(CommandLine
&CmdL
)
925 // ShowHelp - Show a help screen /*{{{*/
926 // ---------------------------------------------------------------------
930 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
931 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
933 cout
<< "Usage: apt-get [options] command" << endl
;
934 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
936 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
937 cout
<< "installing packages. The most frequently used commands are update" << endl
;
938 cout
<< "and install." << endl
;
940 cout
<< "Commands:" << endl
;
941 cout
<< " update - Retrieve new lists of packages" << endl
;
942 cout
<< " upgrade - Perform an upgrade" << endl
;
943 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
944 cout
<< " remove - Remove packages" << endl
;
945 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
946 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
947 cout
<< " clean - Erase downloaded archive files" << endl
;
948 cout
<< " check - Verify that there are no broken dependencies" << endl
;
950 cout
<< "Options:" << endl
;
951 cout
<< " -h This help text." << endl
;
952 cout
<< " -q Loggable output - no progress indicator" << endl
;
953 cout
<< " -qq No output except for errors" << endl
;
954 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
955 cout
<< " -s No-act. Perform ordering simulation" << endl
;
956 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
957 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
958 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
959 cout
<< " -u Show a list of upgraded packages as well" << endl
;
960 cout
<< " -c=? Read this configuration file" << endl
;
961 cout
<< " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl
;
962 cout
<< "See the apt-get(8), sources.list(8) and apt.conf(8) manual" << endl
;
963 cout
<< "pages for more information." << endl
;
967 // GetInitialize - Initialize things for apt-get /*{{{*/
968 // ---------------------------------------------------------------------
972 _config
->Set("quiet",0);
973 _config
->Set("help",false);
974 _config
->Set("APT::Get::Download-Only",false);
975 _config
->Set("APT::Get::Simulate",false);
976 _config
->Set("APT::Get::Assume-Yes",false);
977 _config
->Set("APT::Get::Fix-Broken",false);
980 // SigWinch - Window size change signal handler /*{{{*/
981 // ---------------------------------------------------------------------
989 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
990 ScreenWidth
= ws
.ws_col
- 1;
995 int main(int argc
,const char *argv
[])
997 CommandLine::Args Args
[] = {
998 {'h',"help","help",0},
999 {'q',"quiet","quiet",CommandLine::IntLevel
},
1000 {'q',"silent","quiet",CommandLine::IntLevel
},
1001 {'d',"download-only","APT::Get::Download-Only",0},
1002 {'s',"simulate","APT::Get::Simulate",0},
1003 {'s',"just-print","APT::Get::Simulate",0},
1004 {'s',"recon","APT::Get::Simulate",0},
1005 {'s',"no-act","APT::Get::Simulate",0},
1006 {'y',"yes","APT::Get::Assume-Yes",0},
1007 {'y',"assume-yes","APT::Get::Assume-Yes",0},
1008 {'f',"fix-broken","APT::Get::Fix-Broken",0},
1009 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
1010 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
1011 {0,"fix-missing","APT::Get::Fix-Missing",0},
1012 {0,"ignore-hold","APT::Ingore-Hold",0},
1013 {0,"no-upgrade","APT::Get::no-upgrade",0},
1014 {'c',"config-file",0,CommandLine::ConfigFile
},
1015 {'o',"option",0,CommandLine::ArbItem
},
1018 // Parse the command line and initialize the package library
1019 CommandLine
CmdL(Args
,_config
);
1020 if (pkgInitialize(*_config
) == false ||
1021 CmdL
.Parse(argc
,argv
) == false)
1023 _error
->DumpErrors();
1027 // See if the help should be shown
1028 if (_config
->FindB("help") == true ||
1029 CmdL
.FileSize() == 0)
1032 // Setup the output streams
1033 c0out
.rdbuf(cout
.rdbuf());
1034 c1out
.rdbuf(cout
.rdbuf());
1035 c2out
.rdbuf(cout
.rdbuf());
1036 if (_config
->FindI("quiet",0) > 0)
1037 c0out
.rdbuf(devnull
.rdbuf());
1038 if (_config
->FindI("quiet",0) > 1)
1039 c1out
.rdbuf(devnull
.rdbuf());
1041 // Setup the signals
1042 signal(SIGPIPE
,SIG_IGN
);
1043 signal(SIGWINCH
,SigWinch
);
1046 // Match the operation
1050 bool (*Handler
)(CommandLine
&);
1051 } Map
[] = {{"update",&DoUpdate
},
1052 {"upgrade",&DoUpgrade
},
1053 {"install",&DoInstall
},
1054 {"remove",&DoInstall
},
1055 {"dist-upgrade",&DoDistUpgrade
},
1056 {"dselect-upgrade",&DoDSelectUpgrade
},
1061 for (I
= 0; Map
[I
].Match
!= 0; I
++)
1063 if (strcmp(CmdL
.FileList
[0],Map
[I
].Match
) == 0)
1065 if (Map
[I
].Handler(CmdL
) == false && _error
->PendingError() == false)
1066 _error
->Error("Handler silently failed");
1072 if (Map
[I
].Match
== 0)
1073 _error
->Error("Invalid operation %s", CmdL
.FileList
[0]);
1075 // Print any errors or warnings found during parsing
1076 if (_error
->empty() == false)
1078 bool Errors
= _error
->PendingError();
1079 _error
->DumpErrors();
1081 cout
<< "Returning 100." << endl
;
1082 return Errors
== true?100:0;