]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
e99c832c4ae30f8ca744037d1eef7beb50178c22
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.39 1999/02/07 08:40:34 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>
38 #include <apt-pkg/strutl.h>
39 #include <apt-pkg/clean.h>
43 #include "acqprogress.h"
47 #include <sys/ioctl.h>
56 ofstream
devnull("/dev/null");
57 unsigned int ScreenWidth
= 80;
59 // YnPrompt - Yes No Prompt. /*{{{*/
60 // ---------------------------------------------------------------------
61 /* Returns true on a Yes.*/
64 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
72 read(STDIN_FILENO
,&C
,1);
73 while (C
!= '\n' && Jnk
!= '\n') read(STDIN_FILENO
,&Jnk
,1);
75 if (!(C
== 'Y' || C
== 'y' || C
== '\n' || C
== '\r'))
80 // ShowList - Show a list /*{{{*/
81 // ---------------------------------------------------------------------
82 /* This prints out a string of space seperated words with a title and
83 a two space indent line wraped to the current screen width. */
84 bool ShowList(ostream
&out
,string Title
,string List
)
86 if (List
.empty() == true)
89 // Acount for the leading space
90 int ScreenWidth
= ::ScreenWidth
- 3;
93 string::size_type Start
= 0;
94 while (Start
< List
.size())
96 string::size_type End
;
97 if (Start
+ ScreenWidth
>= List
.size())
100 End
= List
.rfind(' ',Start
+ScreenWidth
);
102 if (End
== string::npos
|| End
< Start
)
103 End
= Start
+ ScreenWidth
;
104 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
110 // ShowBroken - Debugging aide /*{{{*/
111 // ---------------------------------------------------------------------
112 /* This prints out the names of all the packages that are broken along
113 with the name of each each broken dependency and a quite version
115 void ShowBroken(ostream
&out
,pkgDepCache
&Cache
)
117 out
<< "Sorry, but the following packages have unmet dependencies:" << endl
;
118 pkgCache::PkgIterator I
= Cache
.PkgBegin();
119 for (;I
.end() != true; I
++)
121 if (Cache
[I
].InstBroken() == false)
124 // Print out each package and the failed dependencies
125 out
<<" " << I
.Name() << ":";
126 int Indent
= strlen(I
.Name()) + 3;
128 if (Cache
[I
].InstVerIter(Cache
).end() == true)
134 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
136 // Compute a single dependency element (glob or)
137 pkgCache::DepIterator Start
;
138 pkgCache::DepIterator End
;
141 if (Cache
.IsImportantDep(End
) == false ||
142 (Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
146 for (int J
= 0; J
!= Indent
; J
++)
150 cout
<< ' ' << End
.DepType() << ": " << End
.TargetPkg().Name();
152 // Show a quick summary of the version requirements
153 if (End
.TargetVer() != 0)
154 out
<< " (" << End
.CompType() << " " << End
.TargetVer() <<
157 /* Show a summary of the target package if possible. In the case
158 of virtual packages we show nothing */
160 pkgCache::PkgIterator Targ
= End
.TargetPkg();
161 if (Targ
->ProvidesList
== 0)
164 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
165 if (Ver
.end() == false)
166 out
<< Ver
.VerStr() << " is installed";
169 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
171 if (Targ
->ProvidesList
== 0)
172 out
<< "it is not installable";
174 out
<< "it is a virtual package";
177 out
<< "it is not installed";
186 // ShowNew - Show packages to newly install /*{{{*/
187 // ---------------------------------------------------------------------
189 void ShowNew(ostream
&out
,pkgDepCache
&Dep
)
191 /* Print out a list of packages that are going to be removed extra
192 to what the user asked */
193 pkgCache::PkgIterator I
= Dep
.PkgBegin();
195 for (;I
.end() != true; I
++)
196 if (Dep
[I
].NewInstall() == true)
197 List
+= string(I
.Name()) + " ";
198 ShowList(out
,"The following NEW packages will be installed:",List
);
201 // ShowDel - Show packages to delete /*{{{*/
202 // ---------------------------------------------------------------------
204 void ShowDel(ostream
&out
,pkgDepCache
&Dep
)
206 /* Print out a list of packages that are going to be removed extra
207 to what the user asked */
208 pkgCache::PkgIterator I
= Dep
.PkgBegin();
210 for (;I
.end() != true; I
++)
211 if (Dep
[I
].Delete() == true)
212 List
+= string(I
.Name()) + " ";
214 ShowList(out
,"The following packages will be REMOVED:",List
);
217 // ShowKept - Show kept packages /*{{{*/
218 // ---------------------------------------------------------------------
220 void ShowKept(ostream
&out
,pkgDepCache
&Dep
)
222 pkgCache::PkgIterator I
= Dep
.PkgBegin();
224 for (;I
.end() != true; I
++)
227 if (Dep
[I
].Upgrade() == true || Dep
[I
].Upgradable() == false ||
228 I
->CurrentVer
== 0 || Dep
[I
].Delete() == true)
231 List
+= string(I
.Name()) + " ";
233 ShowList(out
,"The following packages have been kept back",List
);
236 // ShowUpgraded - Show upgraded packages /*{{{*/
237 // ---------------------------------------------------------------------
239 void ShowUpgraded(ostream
&out
,pkgDepCache
&Dep
)
241 pkgCache::PkgIterator I
= Dep
.PkgBegin();
243 for (;I
.end() != true; I
++)
246 if (Dep
[I
].Upgrade() == false || Dep
[I
].NewInstall() == true)
249 List
+= string(I
.Name()) + " ";
251 ShowList(out
,"The following packages will be upgraded",List
);
254 // ShowHold - Show held but changed packages /*{{{*/
255 // ---------------------------------------------------------------------
257 bool ShowHold(ostream
&out
,pkgDepCache
&Dep
)
259 pkgCache::PkgIterator I
= Dep
.PkgBegin();
261 for (;I
.end() != true; I
++)
263 if (Dep
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
264 I
->SelectedState
== pkgCache::State::Hold
)
265 List
+= string(I
.Name()) + " ";
268 return ShowList(out
,"The following held packages will be changed:",List
);
271 // ShowEssential - Show an essential package warning /*{{{*/
272 // ---------------------------------------------------------------------
273 /* This prints out a warning message that is not to be ignored. It shows
274 all essential packages and their dependents that are to be removed.
275 It is insanely risky to remove the dependents of an essential package! */
276 bool ShowEssential(ostream
&out
,pkgDepCache
&Dep
)
278 pkgCache::PkgIterator I
= Dep
.PkgBegin();
280 bool *Added
= new bool[Dep
.HeaderP
->PackageCount
];
281 for (unsigned int I
= 0; I
!= Dep
.HeaderP
->PackageCount
; I
++)
284 for (;I
.end() != true; I
++)
286 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
289 // The essential package is being removed
290 if (Dep
[I
].Delete() == true)
292 if (Added
[I
->ID
] == false)
295 List
+= string(I
.Name()) + " ";
299 if (I
->CurrentVer
== 0)
302 // Print out any essential package depenendents that are to be removed
303 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
305 // Skip everything but depends
306 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
307 D
->Type
!= pkgCache::Dep::Depends
)
310 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
311 if (Dep
[P
].Delete() == true)
313 if (Added
[P
->ID
] == true)
318 sprintf(S
,"%s (due to %s) ",P
.Name(),I
.Name());
325 if (List
.empty() == false)
326 out
<< "WARNING: The following essential packages will be removed" << endl
;
327 return ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
330 // Stats - Show some statistics /*{{{*/
331 // ---------------------------------------------------------------------
333 void Stats(ostream
&out
,pkgDepCache
&Dep
)
335 unsigned long Upgrade
= 0;
336 unsigned long Install
= 0;
337 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
339 if (Dep
[I
].NewInstall() == true)
342 if (Dep
[I
].Upgrade() == true)
346 out
<< Upgrade
<< " packages upgraded, " <<
347 Install
<< " newly installed, " <<
348 Dep
.DelCount() << " to remove and " <<
349 Dep
.KeepCount() << " not upgraded." << endl
;
351 if (Dep
.BadCount() != 0)
352 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
356 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
357 // ---------------------------------------------------------------------
368 inline operator pkgDepCache
&() {return *Cache
;};
369 inline pkgDepCache
*operator ->() {return Cache
;};
370 inline pkgDepCache
&operator *() {return *Cache
;};
372 bool Open(bool AllowBroken
= false);
373 CacheFile() : File(0), Map(0), Cache(0) {};
382 // CacheFile::Open - Open the cache file /*{{{*/
383 // ---------------------------------------------------------------------
384 /* This routine generates the caches and then opens the dependency cache
385 and verifies that the system is OK. */
386 bool CacheFile::Open(bool AllowBroken
)
388 if (_error
->PendingError() == true)
391 // Create a progress class
392 OpTextProgress
Progress(*_config
);
394 // Read the source list
396 if (List
.ReadMainList() == false)
397 return _error
->Error("The list of sources could not be read.");
399 // Build all of the caches
400 pkgMakeStatusCache(List
,Progress
);
401 if (_error
->PendingError() == true)
402 return _error
->Error("The package lists or status file could not be parsed or opened.");
403 if (_error
->empty() == false)
404 _error
->Warning("You may want to run apt-get update to correct theses missing files");
408 // Open the cache file
409 File
= new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly
);
410 if (_error
->PendingError() == true)
413 Map
= new MMap(*File
,MMap::Public
| MMap::ReadOnly
);
414 if (_error
->PendingError() == true)
417 Cache
= new pkgDepCache(*Map
,Progress
);
418 if (_error
->PendingError() == true)
423 // Check that the system is OK
424 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
425 return _error
->Error("Internal Error, non-zero counts");
427 // Apply corrections for half-installed packages
428 if (pkgApplyStatus(*Cache
) == false)
432 if (Cache
->BrokenCount() == 0 || AllowBroken
== true)
435 // Attempt to fix broken things
436 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
438 c1out
<< "Correcting dependencies..." << flush
;
439 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
441 c1out
<< " failed." << endl
;
442 ShowBroken(c1out
,*this);
444 return _error
->Error("Unable to correct dependencies");
446 if (pkgMinimizeUpgrade(*Cache
) == false)
447 return _error
->Error("Unable to minimize the upgrade set");
449 c1out
<< " Done" << endl
;
453 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
454 ShowBroken(c1out
,*this);
456 return _error
->Error("Unmet dependencies. Try using -f.");
463 // InstallPackages - Actually download and install the packages /*{{{*/
464 // ---------------------------------------------------------------------
465 /* This displays the informative messages describing what is going to
466 happen and then calls the download routines */
467 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true)
471 // Show all the various warning indicators
472 ShowDel(c1out
,Cache
);
473 ShowNew(c1out
,Cache
);
475 ShowKept(c1out
,Cache
);
476 Fail
|= !ShowHold(c1out
,Cache
);
477 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
478 ShowUpgraded(c1out
,Cache
);
479 Fail
|= !ShowEssential(c1out
,Cache
);
483 if (Cache
->BrokenCount() != 0)
485 ShowBroken(c1out
,Cache
);
486 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
489 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
490 Cache
->BadCount() == 0)
493 // Run the simulator ..
494 if (_config
->FindB("APT::Get::Simulate") == true)
496 pkgSimulate
PM(Cache
);
497 return PM
.DoInstall();
500 // Create the text record parser
501 pkgRecords
Recs(Cache
);
502 if (_error
->PendingError() == true)
505 // Lock the archive directory
506 if (_config
->FindB("Debug::NoLocking",false) == false)
508 FileFd
Lock(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
509 if (_error
->PendingError() == true)
510 return _error
->Error("Unable to lock the download directory");
513 // Create the download object
514 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
515 pkgAcquire
Fetcher(&Stat
);
517 // Read the source list
519 if (List
.ReadMainList() == false)
520 return _error
->Error("The list of sources could not be read.");
522 // Create the package manager and prepare to download
524 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false)
527 // Display statistics
528 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
529 unsigned long DebBytes
= Fetcher
.TotalNeeded();
530 if (DebBytes
!= Cache
->DebSize())
532 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
533 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
537 c2out
<< "Need to get ";
538 if (DebBytes
!= FetchBytes
)
539 c2out
<< SizeToStr(FetchBytes
) << "b/" << SizeToStr(DebBytes
) << 'b';
541 c2out
<< SizeToStr(DebBytes
) << 'b';
543 c1out
<< " of archives. After unpacking ";
546 if (Cache
->UsrSize() >= 0)
547 c2out
<< SizeToStr(Cache
->UsrSize()) << "b will be used." << endl
;
549 c2out
<< SizeToStr(-1*Cache
->UsrSize()) << "b will be freed." << endl
;
551 if (_error
->PendingError() == true)
555 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
557 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
558 return _error
->Error("There are problems and -y was used without --force-yes");
561 // Prompt to continue
564 if (_config
->FindI("quiet",0) < 2 ||
565 _config
->FindB("APT::Get::Assume-Yes",false) == false)
566 c2out
<< "Do you want to continue? [Y/n] " << flush
;
568 if (YnPrompt() == false)
572 if (_config
->FindB("APT::Get::Print-URIs") == true)
574 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
575 for (; I
!= Fetcher
.UriEnd(); I
++)
576 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
577 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
582 if (Fetcher
.Run() == false)
587 bool Transient
= false;
588 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
590 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
591 (*I
)->Complete
== true)
594 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
601 cerr
<< "Failed to fetch " << (*I
)->Describe() << endl
;
602 cerr
<< " " << (*I
)->ErrorText
<< endl
;
606 if (_config
->FindB("APT::Get::Download-Only",false) == true)
609 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
611 if (Transient
== true)
613 c2out
<< "Upgrading with disk swapping is not supported in this version." << endl
;
614 c2out
<< "Try running multiple times with --fix-missing" << endl
;
617 return _error
->Error("Unable to fetch some archives, maybe try with --fix-missing?");
620 // Try to deal with missing package files
621 if (PM
.FixMissing() == false)
623 cerr
<< "Unable to correct missing packages." << endl
;
624 return _error
->Error("Aborting Install.");
628 return PM
.DoInstall();
632 // DoUpdate - Update the package lists /*{{{*/
633 // ---------------------------------------------------------------------
635 bool DoUpdate(CommandLine
&)
637 // Get the source list
639 if (List
.ReadMainList() == false)
642 // Lock the list directory
643 if (_config
->FindB("Debug::NoLocking",false) == false)
645 FileFd
Lock(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
646 if (_error
->PendingError() == true)
647 return _error
->Error("Unable to lock the list directory");
650 // Create the download object
651 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
652 pkgAcquire
Fetcher(&Stat
);
654 // Populate it with the source selection
655 pkgSourceList::const_iterator I
;
656 for (I
= List
.begin(); I
!= List
.end(); I
++)
658 new pkgAcqIndex(&Fetcher
,I
);
659 if (_error
->PendingError() == true)
664 if (Fetcher
.Run() == false)
667 // Clean out any old list files
668 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
669 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
672 // Prepare the cache.
674 if (Cache
.Open() == false)
680 // DoUpgrade - Upgrade all packages /*{{{*/
681 // ---------------------------------------------------------------------
682 /* Upgrade all packages without installing new packages or erasing old
684 bool DoUpgrade(CommandLine
&CmdL
)
687 if (Cache
.Open() == false)
691 if (pkgAllUpgrade(Cache
) == false)
693 ShowBroken(c1out
,Cache
);
694 return _error
->Error("Internal Error, AllUpgrade broke stuff");
697 return InstallPackages(Cache
,true);
700 // DoInstall - Install packages from the command line /*{{{*/
701 // ---------------------------------------------------------------------
702 /* Install named packages */
703 bool DoInstall(CommandLine
&CmdL
)
706 if (Cache
.Open(CmdL
.FileSize() != 1) == false)
709 // Enter the special broken fixing mode if the user specified arguments
710 bool BrokenFix
= false;
711 if (Cache
->BrokenCount() != 0)
714 unsigned int ExpectedInst
= 0;
715 unsigned int Packages
= 0;
716 pkgProblemResolver
Fix(Cache
);
718 bool DefRemove
= false;
719 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
722 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
724 // Duplicate the string
725 unsigned int Length
= strlen(*I
);
727 if (Length
>= sizeof(S
))
731 // See if we are removing the package
732 bool Remove
= DefRemove
;
733 if (Cache
->FindPkg(S
).end() == true)
735 // Handle an optional end tag indicating what to do
736 if (S
[Length
- 1] == '-')
741 if (S
[Length
- 1] == '+')
748 // Locate the package
749 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
751 if (Pkg
.end() == true)
752 return _error
->Error("Couldn't find package %s",S
);
754 // Handle the no-upgrade case
755 if (_config
->FindB("APT::Get::no-upgrade",false) == true &&
756 Pkg
->CurrentVer
!= 0)
758 c1out
<< "Skipping " << Pkg
.Name() << ", it is already installed and no-upgrade is set." << endl
;
762 // Check if there is something new to install
763 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
764 if (State
.CandidateVer
== 0)
766 if (Pkg
->ProvidesList
!= 0)
768 c1out
<< "Package " << S
<< " is a virtual package provided by:" << endl
;
770 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
771 for (; I
.end() == false; I
++)
773 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
775 if ((*Cache
)[Pkg
].CandidateVerIter(*Cache
) == I
.OwnerVer())
777 if ((*Cache
)[Pkg
].Install() == true && (*Cache
)[Pkg
].NewInstall() == false)
778 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
779 " [Installed]"<< endl
;
781 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
784 c1out
<< "You should explicly select one to install." << endl
;
788 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
789 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
790 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
793 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
794 for (; Dep
.end() == false; Dep
++)
796 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
798 List
+= string(Dep
.ParentPkg().Name()) + " ";
800 ShowList(c1out
,"However the following packages replace it:",List
);
803 return _error
->Error("Package %s has no installation candidate",S
);
810 Cache
->MarkDelete(Pkg
);
815 Cache
->MarkInstall(Pkg
,false);
816 if (State
.Install() == false)
817 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
821 // Install it with autoinstalling enabled.
822 if (State
.InstBroken() == true && BrokenFix
== false)
823 Cache
->MarkInstall(Pkg
,true);
826 /* If we are in the Broken fixing mode we do not attempt to fix the
827 problems. This is if the user invoked install without -f and gave
829 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
831 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
832 ShowBroken(c1out
,Cache
);
834 return _error
->Error("Unmet dependencies. Try using -f.");
837 // Call the scored problem resolver
838 Fix
.InstallProtect();
839 if (Fix
.Resolve(true) == false)
842 // Now we check the state of the packages,
843 if (Cache
->BrokenCount() != 0)
845 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
846 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
847 c1out
<< "distribution that some required packages have not yet been created" << endl
;
848 c1out
<< "or been moved out of Incoming." << endl
;
852 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
853 c1out
<< "the package is simply not installable and a bug report against" << endl
;
854 c1out
<< "that package should be filed." << endl
;
857 c1out
<< "The following information may help to resolve the situation:" << endl
;
859 ShowBroken(c1out
,Cache
);
860 return _error
->Error("Sorry, broken packages");
863 /* Print out a list of packages that are going to be installed extra
864 to what the user asked */
865 if (Cache
->InstCount() != ExpectedInst
)
868 pkgCache::PkgIterator I
= Cache
->PkgBegin();
869 for (;I
.end() != true; I
++)
871 if ((*Cache
)[I
].Install() == false)
875 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
876 if (strcmp(*J
,I
.Name()) == 0)
880 List
+= string(I
.Name()) + " ";
883 ShowList(c1out
,"The following extra packages will be installed:",List
);
886 // See if we need to prompt
887 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
888 return InstallPackages(Cache
,false,false);
890 return InstallPackages(Cache
,false);
893 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
894 // ---------------------------------------------------------------------
895 /* Intelligent upgrader that will install and remove packages at will */
896 bool DoDistUpgrade(CommandLine
&CmdL
)
899 if (Cache
.Open() == false)
902 c0out
<< "Calculating Upgrade... " << flush
;
903 if (pkgDistUpgrade(*Cache
) == false)
905 c0out
<< "Failed" << endl
;
906 ShowBroken(c1out
,Cache
);
910 c0out
<< "Done" << endl
;
912 return InstallPackages(Cache
,true);
915 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
916 // ---------------------------------------------------------------------
917 /* Follows dselect's selections */
918 bool DoDSelectUpgrade(CommandLine
&CmdL
)
921 if (Cache
.Open() == false)
924 // Install everything with the install flag set
925 pkgCache::PkgIterator I
= Cache
->PkgBegin();
926 for (;I
.end() != true; I
++)
928 /* Install the package only if it is a new install, the autoupgrader
929 will deal with the rest */
930 if (I
->SelectedState
== pkgCache::State::Install
)
931 Cache
->MarkInstall(I
,false);
934 /* Now install their deps too, if we do this above then order of
935 the status file is significant for | groups */
936 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
938 /* Install the package only if it is a new install, the autoupgrader
939 will deal with the rest */
940 if (I
->SelectedState
== pkgCache::State::Install
)
941 Cache
->MarkInstall(I
,true);
944 // Apply erasures now, they override everything else.
945 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
948 if (I
->SelectedState
== pkgCache::State::DeInstall
||
949 I
->SelectedState
== pkgCache::State::Purge
)
950 Cache
->MarkDelete(I
);
953 /* Resolve any problems that dselect created, allupgrade cannot handle
954 such things. We do so quite agressively too.. */
955 if (Cache
->BrokenCount() != 0)
957 pkgProblemResolver
Fix(Cache
);
959 // Hold back held packages.
960 if (_config
->FindB("APT::Ingore-Hold",false) == false)
962 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
964 if (I
->SelectedState
== pkgCache::State::Hold
)
972 if (Fix
.Resolve() == false)
974 ShowBroken(c1out
,Cache
);
975 return _error
->Error("Internal Error, problem resolver broke stuff");
979 // Now upgrade everything
980 if (pkgAllUpgrade(Cache
) == false)
982 ShowBroken(c1out
,Cache
);
983 return _error
->Error("Internal Error, problem resolver broke stuff");
986 return InstallPackages(Cache
,false);
989 // DoClean - Remove download archives /*{{{*/
990 // ---------------------------------------------------------------------
992 bool DoClean(CommandLine
&CmdL
)
995 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
996 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1000 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1001 // ---------------------------------------------------------------------
1002 /* This is similar to clean but it only purges things that cannot be
1003 downloaded, that is old versions of cached packages. */
1004 bool DoAutoClean(CommandLine
&CmdL
)
1007 if (Cache
.Open(true) == false)
1010 class LogCleaner
: public pkgArchiveCleaner
1013 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1015 cout
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "b]" << endl
;
1019 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1020 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1023 // DoCheck - Perform the check operation /*{{{*/
1024 // ---------------------------------------------------------------------
1025 /* Opening automatically checks the system, this command is mostly used
1027 bool DoCheck(CommandLine
&CmdL
)
1036 // ShowHelp - Show a help screen /*{{{*/
1037 // ---------------------------------------------------------------------
1039 bool ShowHelp(CommandLine
&CmdL
)
1041 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
1042 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
1043 if (_config
->FindB("version") == true)
1046 cout
<< "Usage: apt-get [options] command" << endl
;
1047 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
1049 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
1050 cout
<< "installing packages. The most frequently used commands are update" << endl
;
1051 cout
<< "and install." << endl
;
1053 cout
<< "Commands:" << endl
;
1054 cout
<< " update - Retrieve new lists of packages" << endl
;
1055 cout
<< " upgrade - Perform an upgrade" << endl
;
1056 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
1057 cout
<< " remove - Remove packages" << endl
;
1058 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
1059 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
1060 cout
<< " clean - Erase downloaded archive files" << endl
;
1061 cout
<< " autoclean - Erase old downloaded archive files" << endl
;
1062 cout
<< " check - Verify that there are no broken dependencies" << endl
;
1064 cout
<< "Options:" << endl
;
1065 cout
<< " -h This help text." << endl
;
1066 cout
<< " -q Loggable output - no progress indicator" << endl
;
1067 cout
<< " -qq No output except for errors" << endl
;
1068 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
1069 cout
<< " -s No-act. Perform ordering simulation" << endl
;
1070 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
1071 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
1072 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
1073 cout
<< " -u Show a list of upgraded packages as well" << endl
;
1074 cout
<< " -c=? Read this configuration file" << endl
;
1075 cout
<< " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl
;
1076 cout
<< "See the apt-get(8), sources.list(5) and apt.conf(5) manual" << endl
;
1077 cout
<< "pages for more information." << endl
;
1081 // GetInitialize - Initialize things for apt-get /*{{{*/
1082 // ---------------------------------------------------------------------
1084 void GetInitialize()
1086 _config
->Set("quiet",0);
1087 _config
->Set("help",false);
1088 _config
->Set("APT::Get::Download-Only",false);
1089 _config
->Set("APT::Get::Simulate",false);
1090 _config
->Set("APT::Get::Assume-Yes",false);
1091 _config
->Set("APT::Get::Fix-Broken",false);
1092 _config
->Set("APT::Get::Force-Yes",false);
1095 // SigWinch - Window size change signal handler /*{{{*/
1096 // ---------------------------------------------------------------------
1100 // Riped from GNU ls
1104 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
1105 ScreenWidth
= ws
.ws_col
- 1;
1110 int main(int argc
,const char *argv
[])
1112 CommandLine::Args Args
[] = {
1113 {'h',"help","help",0},
1114 {'v',"version","version",0},
1115 {'q',"quiet","quiet",CommandLine::IntLevel
},
1116 {'q',"silent","quiet",CommandLine::IntLevel
},
1117 {'d',"download-only","APT::Get::Download-Only",0},
1118 {'s',"simulate","APT::Get::Simulate",0},
1119 {'s',"just-print","APT::Get::Simulate",0},
1120 {'s',"recon","APT::Get::Simulate",0},
1121 {'s',"no-act","APT::Get::Simulate",0},
1122 {'y',"yes","APT::Get::Assume-Yes",0},
1123 {'y',"assume-yes","APT::Get::Assume-Yes",0},
1124 {'f',"fix-broken","APT::Get::Fix-Broken",0},
1125 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
1126 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
1127 {0,"fix-missing","APT::Get::Fix-Missing",0},
1128 {0,"ignore-hold","APT::Ingore-Hold",0},
1129 {0,"no-upgrade","APT::Get::no-upgrade",0},
1130 {0,"force-yes","APT::Get::force-yes",0},
1131 {0,"print-uris","APT::Get::Print-URIs",0},
1132 {'c',"config-file",0,CommandLine::ConfigFile
},
1133 {'o',"option",0,CommandLine::ArbItem
},
1135 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
1136 {"upgrade",&DoUpgrade
},
1137 {"install",&DoInstall
},
1138 {"remove",&DoInstall
},
1139 {"dist-upgrade",&DoDistUpgrade
},
1140 {"dselect-upgrade",&DoDSelectUpgrade
},
1142 {"autoclean",&DoAutoClean
},
1147 // Parse the command line and initialize the package library
1148 CommandLine
CmdL(Args
,_config
);
1149 if (pkgInitialize(*_config
) == false ||
1150 CmdL
.Parse(argc
,argv
) == false)
1152 _error
->DumpErrors();
1156 // See if the help should be shown
1157 if (_config
->FindB("help") == true ||
1158 _config
->FindB("version") == true ||
1159 CmdL
.FileSize() == 0)
1160 return ShowHelp(CmdL
);
1162 // Setup the output streams
1163 c0out
.rdbuf(cout
.rdbuf());
1164 c1out
.rdbuf(cout
.rdbuf());
1165 c2out
.rdbuf(cout
.rdbuf());
1166 if (_config
->FindI("quiet",0) > 0)
1167 c0out
.rdbuf(devnull
.rdbuf());
1168 if (_config
->FindI("quiet",0) > 1)
1169 c1out
.rdbuf(devnull
.rdbuf());
1171 // Setup the signals
1172 signal(SIGPIPE
,SIG_IGN
);
1173 signal(SIGWINCH
,SigWinch
);
1176 // Match the operation
1177 CmdL
.DispatchArg(Cmds
);
1179 // Print any errors or warnings found during parsing
1180 if (_error
->empty() == false)
1182 bool Errors
= _error
->PendingError();
1183 _error
->DumpErrors();
1184 return Errors
== true?100:0;