]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
da364e03c238f6ed673e8c2212b4df67ce216d72
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.43 1999/02/21 08:38:53 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>
58 ofstream
devnull("/dev/null");
59 unsigned int ScreenWidth
= 80;
61 // YnPrompt - Yes No Prompt. /*{{{*/
62 // ---------------------------------------------------------------------
63 /* Returns true on a Yes.*/
66 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
74 read(STDIN_FILENO
,&C
,1);
75 while (C
!= '\n' && Jnk
!= '\n') read(STDIN_FILENO
,&Jnk
,1);
77 if (!(C
== 'Y' || C
== 'y' || C
== '\n' || C
== '\r'))
82 // ShowList - Show a list /*{{{*/
83 // ---------------------------------------------------------------------
84 /* This prints out a string of space seperated words with a title and
85 a two space indent line wraped to the current screen width. */
86 bool ShowList(ostream
&out
,string Title
,string List
)
88 if (List
.empty() == true)
91 // Acount for the leading space
92 int ScreenWidth
= ::ScreenWidth
- 3;
95 string::size_type Start
= 0;
96 while (Start
< List
.size())
98 string::size_type End
;
99 if (Start
+ ScreenWidth
>= List
.size())
102 End
= List
.rfind(' ',Start
+ScreenWidth
);
104 if (End
== string::npos
|| End
< Start
)
105 End
= Start
+ ScreenWidth
;
106 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
112 // ShowBroken - Debugging aide /*{{{*/
113 // ---------------------------------------------------------------------
114 /* This prints out the names of all the packages that are broken along
115 with the name of each each broken dependency and a quite version
117 void ShowBroken(ostream
&out
,pkgDepCache
&Cache
)
119 out
<< "Sorry, but the following packages have unmet dependencies:" << endl
;
120 pkgCache::PkgIterator I
= Cache
.PkgBegin();
121 for (;I
.end() != true; I
++)
123 if (Cache
[I
].InstBroken() == false)
126 // Print out each package and the failed dependencies
127 out
<<" " << I
.Name() << ":";
128 int Indent
= strlen(I
.Name()) + 3;
130 if (Cache
[I
].InstVerIter(Cache
).end() == true)
136 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
138 // Compute a single dependency element (glob or)
139 pkgCache::DepIterator Start
;
140 pkgCache::DepIterator End
;
143 if (Cache
.IsImportantDep(End
) == false ||
144 (Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
148 for (int J
= 0; J
!= Indent
; J
++)
152 cout
<< ' ' << End
.DepType() << ": " << End
.TargetPkg().Name();
154 // Show a quick summary of the version requirements
155 if (End
.TargetVer() != 0)
156 out
<< " (" << End
.CompType() << " " << End
.TargetVer() <<
159 /* Show a summary of the target package if possible. In the case
160 of virtual packages we show nothing */
162 pkgCache::PkgIterator Targ
= End
.TargetPkg();
163 if (Targ
->ProvidesList
== 0)
166 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
167 if (Ver
.end() == false)
168 out
<< Ver
.VerStr() << " is installed";
171 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
173 if (Targ
->ProvidesList
== 0)
174 out
<< "it is not installable";
176 out
<< "it is a virtual package";
179 out
<< "it is not installed";
188 // ShowNew - Show packages to newly install /*{{{*/
189 // ---------------------------------------------------------------------
191 void ShowNew(ostream
&out
,pkgDepCache
&Dep
)
193 /* Print out a list of packages that are going to be removed extra
194 to what the user asked */
195 pkgCache::PkgIterator I
= Dep
.PkgBegin();
197 for (;I
.end() != true; I
++)
198 if (Dep
[I
].NewInstall() == true)
199 List
+= string(I
.Name()) + " ";
200 ShowList(out
,"The following NEW packages will be installed:",List
);
203 // ShowDel - Show packages to delete /*{{{*/
204 // ---------------------------------------------------------------------
206 void ShowDel(ostream
&out
,pkgDepCache
&Dep
)
208 /* Print out a list of packages that are going to be removed extra
209 to what the user asked */
210 pkgCache::PkgIterator I
= Dep
.PkgBegin();
212 for (;I
.end() != true; I
++)
213 if (Dep
[I
].Delete() == true)
214 List
+= string(I
.Name()) + " ";
216 ShowList(out
,"The following packages will be REMOVED:",List
);
219 // ShowKept - Show kept packages /*{{{*/
220 // ---------------------------------------------------------------------
222 void ShowKept(ostream
&out
,pkgDepCache
&Dep
)
224 pkgCache::PkgIterator I
= Dep
.PkgBegin();
226 for (;I
.end() != true; I
++)
229 if (Dep
[I
].Upgrade() == true || Dep
[I
].Upgradable() == false ||
230 I
->CurrentVer
== 0 || Dep
[I
].Delete() == true)
233 List
+= string(I
.Name()) + " ";
235 ShowList(out
,"The following packages have been kept back",List
);
238 // ShowUpgraded - Show upgraded packages /*{{{*/
239 // ---------------------------------------------------------------------
241 void ShowUpgraded(ostream
&out
,pkgDepCache
&Dep
)
243 pkgCache::PkgIterator I
= Dep
.PkgBegin();
245 for (;I
.end() != true; I
++)
248 if (Dep
[I
].Upgrade() == false || Dep
[I
].NewInstall() == true)
251 List
+= string(I
.Name()) + " ";
253 ShowList(out
,"The following packages will be upgraded",List
);
256 // ShowHold - Show held but changed packages /*{{{*/
257 // ---------------------------------------------------------------------
259 bool ShowHold(ostream
&out
,pkgDepCache
&Dep
)
261 pkgCache::PkgIterator I
= Dep
.PkgBegin();
263 for (;I
.end() != true; I
++)
265 if (Dep
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
266 I
->SelectedState
== pkgCache::State::Hold
)
267 List
+= string(I
.Name()) + " ";
270 return ShowList(out
,"The following held packages will be changed:",List
);
273 // ShowEssential - Show an essential package warning /*{{{*/
274 // ---------------------------------------------------------------------
275 /* This prints out a warning message that is not to be ignored. It shows
276 all essential packages and their dependents that are to be removed.
277 It is insanely risky to remove the dependents of an essential package! */
278 bool ShowEssential(ostream
&out
,pkgDepCache
&Dep
)
280 pkgCache::PkgIterator I
= Dep
.PkgBegin();
282 bool *Added
= new bool[Dep
.HeaderP
->PackageCount
];
283 for (unsigned int I
= 0; I
!= Dep
.HeaderP
->PackageCount
; I
++)
286 for (;I
.end() != true; I
++)
288 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
291 // The essential package is being removed
292 if (Dep
[I
].Delete() == true)
294 if (Added
[I
->ID
] == false)
297 List
+= string(I
.Name()) + " ";
301 if (I
->CurrentVer
== 0)
304 // Print out any essential package depenendents that are to be removed
305 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
307 // Skip everything but depends
308 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
309 D
->Type
!= pkgCache::Dep::Depends
)
312 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
313 if (Dep
[P
].Delete() == true)
315 if (Added
[P
->ID
] == true)
320 sprintf(S
,"%s (due to %s) ",P
.Name(),I
.Name());
327 if (List
.empty() == false)
328 out
<< "WARNING: The following essential packages will be removed" << endl
;
329 return ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
332 // Stats - Show some statistics /*{{{*/
333 // ---------------------------------------------------------------------
335 void Stats(ostream
&out
,pkgDepCache
&Dep
)
337 unsigned long Upgrade
= 0;
338 unsigned long Install
= 0;
339 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
341 if (Dep
[I
].NewInstall() == true)
344 if (Dep
[I
].Upgrade() == true)
348 out
<< Upgrade
<< " packages upgraded, " <<
349 Install
<< " newly installed, " <<
350 Dep
.DelCount() << " to remove and " <<
351 Dep
.KeepCount() << " not upgraded." << endl
;
353 if (Dep
.BadCount() != 0)
354 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
358 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
359 // ---------------------------------------------------------------------
370 inline operator pkgDepCache
&() {return *Cache
;};
371 inline pkgDepCache
*operator ->() {return Cache
;};
372 inline pkgDepCache
&operator *() {return *Cache
;};
374 bool Open(bool AllowBroken
= false);
375 CacheFile() : File(0), Map(0), Cache(0) {};
384 // CacheFile::Open - Open the cache file /*{{{*/
385 // ---------------------------------------------------------------------
386 /* This routine generates the caches and then opens the dependency cache
387 and verifies that the system is OK. */
388 bool CacheFile::Open(bool AllowBroken
)
390 if (_error
->PendingError() == true)
393 // Create a progress class
394 OpTextProgress
Progress(*_config
);
396 // Read the source list
398 if (List
.ReadMainList() == false)
399 return _error
->Error("The list of sources could not be read.");
401 // Build all of the caches
402 pkgMakeStatusCache(List
,Progress
);
403 if (_error
->PendingError() == true)
404 return _error
->Error("The package lists or status file could not be parsed or opened.");
405 if (_error
->empty() == false)
406 _error
->Warning("You may want to run apt-get update to correct theses missing files");
410 // Open the cache file
411 File
= new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly
);
412 if (_error
->PendingError() == true)
415 Map
= new MMap(*File
,MMap::Public
| MMap::ReadOnly
);
416 if (_error
->PendingError() == true)
419 Cache
= new pkgDepCache(*Map
,Progress
);
420 if (_error
->PendingError() == true)
425 // Check that the system is OK
426 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
427 return _error
->Error("Internal Error, non-zero counts");
429 // Apply corrections for half-installed packages
430 if (pkgApplyStatus(*Cache
) == false)
434 if (Cache
->BrokenCount() == 0 || AllowBroken
== true)
437 // Attempt to fix broken things
438 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
440 c1out
<< "Correcting dependencies..." << flush
;
441 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
443 c1out
<< " failed." << endl
;
444 ShowBroken(c1out
,*this);
446 return _error
->Error("Unable to correct dependencies");
448 if (pkgMinimizeUpgrade(*Cache
) == false)
449 return _error
->Error("Unable to minimize the upgrade set");
451 c1out
<< " Done" << endl
;
455 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
456 ShowBroken(c1out
,*this);
458 return _error
->Error("Unmet dependencies. Try using -f.");
465 // InstallPackages - Actually download and install the packages /*{{{*/
466 // ---------------------------------------------------------------------
467 /* This displays the informative messages describing what is going to
468 happen and then calls the download routines */
469 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true)
473 // Show all the various warning indicators
474 ShowDel(c1out
,Cache
);
475 ShowNew(c1out
,Cache
);
477 ShowKept(c1out
,Cache
);
478 Fail
|= !ShowHold(c1out
,Cache
);
479 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
480 ShowUpgraded(c1out
,Cache
);
481 Fail
|= !ShowEssential(c1out
,Cache
);
485 if (Cache
->BrokenCount() != 0)
487 ShowBroken(c1out
,Cache
);
488 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
491 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
492 Cache
->BadCount() == 0)
495 // Run the simulator ..
496 if (_config
->FindB("APT::Get::Simulate") == true)
498 pkgSimulate
PM(Cache
);
499 return PM
.DoInstall();
502 // Create the text record parser
503 pkgRecords
Recs(Cache
);
504 if (_error
->PendingError() == true)
507 // Lock the archive directory
508 if (_config
->FindB("Debug::NoLocking",false) == false)
510 FileFd
Lock(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
511 if (_error
->PendingError() == true)
512 return _error
->Error("Unable to lock the download directory");
515 // Create the download object
516 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
517 pkgAcquire
Fetcher(&Stat
);
519 // Read the source list
521 if (List
.ReadMainList() == false)
522 return _error
->Error("The list of sources could not be read.");
524 // Create the package manager and prepare to download
526 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false ||
527 _error
->PendingError() == true)
530 // Display statistics
531 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
532 unsigned long DebBytes
= Fetcher
.TotalNeeded();
533 if (DebBytes
!= Cache
->DebSize())
535 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
536 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
539 // Check for enough free space
541 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
542 if (statfs(OutputDir
.c_str(),&Buf
) != 0)
543 return _error
->Errno("statfs","Couldn't determine free space in %s",
545 if (unsigned(Buf
.f_bfree
) < FetchBytes
/Buf
.f_bsize
)
546 return _error
->Error("Sorry, you don't have enough free space in %s",
550 c1out
<< "Need to get ";
551 if (DebBytes
!= FetchBytes
)
552 c1out
<< SizeToStr(FetchBytes
) << "b/" << SizeToStr(DebBytes
) << 'b';
554 c1out
<< SizeToStr(DebBytes
) << 'b';
556 c1out
<< " of archives. After unpacking ";
559 if (Cache
->UsrSize() >= 0)
560 c1out
<< SizeToStr(Cache
->UsrSize()) << "b will be used." << endl
;
562 c1out
<< SizeToStr(-1*Cache
->UsrSize()) << "b will be freed." << endl
;
564 if (_error
->PendingError() == true)
568 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
570 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
571 return _error
->Error("There are problems and -y was used without --force-yes");
574 // Prompt to continue
577 if (_config
->FindI("quiet",0) < 2 ||
578 _config
->FindB("APT::Get::Assume-Yes",false) == false)
579 c2out
<< "Do you want to continue? [Y/n] " << flush
;
581 if (YnPrompt() == false)
585 if (_config
->FindB("APT::Get::Print-URIs") == true)
587 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
588 for (; I
!= Fetcher
.UriEnd(); I
++)
589 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
590 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
595 if (Fetcher
.Run() == false)
600 bool Transient
= false;
601 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
603 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
604 (*I
)->Complete
== true)
607 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
614 cerr
<< "Failed to fetch " << (*I
)->Describe() << endl
;
615 cerr
<< " " << (*I
)->ErrorText
<< endl
;
619 if (_config
->FindB("APT::Get::Download-Only",false) == true)
622 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
624 if (Transient
== true)
626 c2out
<< "Upgrading with disk swapping is not supported in this version." << endl
;
627 c2out
<< "Try running multiple times with --fix-missing" << endl
;
630 return _error
->Error("Unable to fetch some archives, maybe try with --fix-missing?");
633 // Try to deal with missing package files
634 if (PM
.FixMissing() == false)
636 cerr
<< "Unable to correct missing packages." << endl
;
637 return _error
->Error("Aborting Install.");
641 return PM
.DoInstall();
645 // DoUpdate - Update the package lists /*{{{*/
646 // ---------------------------------------------------------------------
648 bool DoUpdate(CommandLine
&)
650 // Get the source list
652 if (List
.ReadMainList() == false)
655 // Lock the list directory
656 if (_config
->FindB("Debug::NoLocking",false) == false)
658 FileFd
Lock(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
659 if (_error
->PendingError() == true)
660 return _error
->Error("Unable to lock the list directory");
663 // Create the download object
664 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
665 pkgAcquire
Fetcher(&Stat
);
667 // Populate it with the source selection
668 pkgSourceList::const_iterator I
;
669 for (I
= List
.begin(); I
!= List
.end(); I
++)
671 new pkgAcqIndex(&Fetcher
,I
);
672 if (_error
->PendingError() == true)
677 if (Fetcher
.Run() == false)
680 // Clean out any old list files
681 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
682 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
685 // Prepare the cache.
687 if (Cache
.Open() == false)
693 // DoUpgrade - Upgrade all packages /*{{{*/
694 // ---------------------------------------------------------------------
695 /* Upgrade all packages without installing new packages or erasing old
697 bool DoUpgrade(CommandLine
&CmdL
)
700 if (Cache
.Open() == false)
704 if (pkgAllUpgrade(Cache
) == false)
706 ShowBroken(c1out
,Cache
);
707 return _error
->Error("Internal Error, AllUpgrade broke stuff");
710 return InstallPackages(Cache
,true);
713 // DoInstall - Install packages from the command line /*{{{*/
714 // ---------------------------------------------------------------------
715 /* Install named packages */
716 bool DoInstall(CommandLine
&CmdL
)
719 if (Cache
.Open(CmdL
.FileSize() != 1) == false)
722 // Enter the special broken fixing mode if the user specified arguments
723 bool BrokenFix
= false;
724 if (Cache
->BrokenCount() != 0)
727 unsigned int ExpectedInst
= 0;
728 unsigned int Packages
= 0;
729 pkgProblemResolver
Fix(Cache
);
731 bool DefRemove
= false;
732 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
735 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
737 // Duplicate the string
738 unsigned int Length
= strlen(*I
);
740 if (Length
>= sizeof(S
))
744 // See if we are removing the package
745 bool Remove
= DefRemove
;
746 if (Cache
->FindPkg(S
).end() == true)
748 // Handle an optional end tag indicating what to do
749 if (S
[Length
- 1] == '-')
754 if (S
[Length
- 1] == '+')
761 // Locate the package
762 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
764 if (Pkg
.end() == true)
765 return _error
->Error("Couldn't find package %s",S
);
767 // Handle the no-upgrade case
768 if (_config
->FindB("APT::Get::no-upgrade",false) == true &&
769 Pkg
->CurrentVer
!= 0)
771 c1out
<< "Skipping " << Pkg
.Name() << ", it is already installed and no-upgrade is set." << endl
;
775 // Check if there is something new to install
776 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
777 if (State
.CandidateVer
== 0)
779 if (Pkg
->ProvidesList
!= 0)
781 c1out
<< "Package " << S
<< " is a virtual package provided by:" << endl
;
783 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
784 for (; I
.end() == false; I
++)
786 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
788 if ((*Cache
)[Pkg
].CandidateVerIter(*Cache
) == I
.OwnerVer())
790 if ((*Cache
)[Pkg
].Install() == true && (*Cache
)[Pkg
].NewInstall() == false)
791 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
792 " [Installed]"<< endl
;
794 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
797 c1out
<< "You should explicly select one to install." << endl
;
801 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
802 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
803 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
806 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
807 for (; Dep
.end() == false; Dep
++)
809 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
811 List
+= string(Dep
.ParentPkg().Name()) + " ";
813 ShowList(c1out
,"However the following packages replace it:",List
);
816 return _error
->Error("Package %s has no installation candidate",S
);
823 Cache
->MarkDelete(Pkg
);
828 Cache
->MarkInstall(Pkg
,false);
829 if (State
.Install() == false)
830 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
834 // Install it with autoinstalling enabled.
835 if (State
.InstBroken() == true && BrokenFix
== false)
836 Cache
->MarkInstall(Pkg
,true);
839 /* If we are in the Broken fixing mode we do not attempt to fix the
840 problems. This is if the user invoked install without -f and gave
842 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
844 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
845 ShowBroken(c1out
,Cache
);
847 return _error
->Error("Unmet dependencies. Try using -f.");
850 // Call the scored problem resolver
851 Fix
.InstallProtect();
852 if (Fix
.Resolve(true) == false)
855 // Now we check the state of the packages,
856 if (Cache
->BrokenCount() != 0)
858 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
859 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
860 c1out
<< "distribution that some required packages have not yet been created" << endl
;
861 c1out
<< "or been moved out of Incoming." << endl
;
865 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
866 c1out
<< "the package is simply not installable and a bug report against" << endl
;
867 c1out
<< "that package should be filed." << endl
;
870 c1out
<< "The following information may help to resolve the situation:" << endl
;
872 ShowBroken(c1out
,Cache
);
873 return _error
->Error("Sorry, broken packages");
876 /* Print out a list of packages that are going to be installed extra
877 to what the user asked */
878 if (Cache
->InstCount() != ExpectedInst
)
881 pkgCache::PkgIterator I
= Cache
->PkgBegin();
882 for (;I
.end() != true; I
++)
884 if ((*Cache
)[I
].Install() == false)
888 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
889 if (strcmp(*J
,I
.Name()) == 0)
893 List
+= string(I
.Name()) + " ";
896 ShowList(c1out
,"The following extra packages will be installed:",List
);
899 // See if we need to prompt
900 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
901 return InstallPackages(Cache
,false,false);
903 return InstallPackages(Cache
,false);
906 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
907 // ---------------------------------------------------------------------
908 /* Intelligent upgrader that will install and remove packages at will */
909 bool DoDistUpgrade(CommandLine
&CmdL
)
912 if (Cache
.Open() == false)
915 c0out
<< "Calculating Upgrade... " << flush
;
916 if (pkgDistUpgrade(*Cache
) == false)
918 c0out
<< "Failed" << endl
;
919 ShowBroken(c1out
,Cache
);
923 c0out
<< "Done" << endl
;
925 return InstallPackages(Cache
,true);
928 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
929 // ---------------------------------------------------------------------
930 /* Follows dselect's selections */
931 bool DoDSelectUpgrade(CommandLine
&CmdL
)
934 if (Cache
.Open() == false)
937 // Install everything with the install flag set
938 pkgCache::PkgIterator I
= Cache
->PkgBegin();
939 for (;I
.end() != true; I
++)
941 /* Install the package only if it is a new install, the autoupgrader
942 will deal with the rest */
943 if (I
->SelectedState
== pkgCache::State::Install
)
944 Cache
->MarkInstall(I
,false);
947 /* Now install their deps too, if we do this above then order of
948 the status file is significant for | groups */
949 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
951 /* Install the package only if it is a new install, the autoupgrader
952 will deal with the rest */
953 if (I
->SelectedState
== pkgCache::State::Install
)
954 Cache
->MarkInstall(I
,true);
957 // Apply erasures now, they override everything else.
958 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
961 if (I
->SelectedState
== pkgCache::State::DeInstall
||
962 I
->SelectedState
== pkgCache::State::Purge
)
963 Cache
->MarkDelete(I
);
966 /* Resolve any problems that dselect created, allupgrade cannot handle
967 such things. We do so quite agressively too.. */
968 if (Cache
->BrokenCount() != 0)
970 pkgProblemResolver
Fix(Cache
);
972 // Hold back held packages.
973 if (_config
->FindB("APT::Ingore-Hold",false) == false)
975 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
977 if (I
->SelectedState
== pkgCache::State::Hold
)
985 if (Fix
.Resolve() == false)
987 ShowBroken(c1out
,Cache
);
988 return _error
->Error("Internal Error, problem resolver broke stuff");
992 // Now upgrade everything
993 if (pkgAllUpgrade(Cache
) == false)
995 ShowBroken(c1out
,Cache
);
996 return _error
->Error("Internal Error, problem resolver broke stuff");
999 return InstallPackages(Cache
,false);
1002 // DoClean - Remove download archives /*{{{*/
1003 // ---------------------------------------------------------------------
1005 bool DoClean(CommandLine
&CmdL
)
1008 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
1009 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1013 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1014 // ---------------------------------------------------------------------
1015 /* This is similar to clean but it only purges things that cannot be
1016 downloaded, that is old versions of cached packages. */
1017 class LogCleaner
: public pkgArchiveCleaner
1020 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1022 cout
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "b]" << endl
;
1026 bool DoAutoClean(CommandLine
&CmdL
)
1029 if (Cache
.Open(true) == false)
1034 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1035 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1038 // DoCheck - Perform the check operation /*{{{*/
1039 // ---------------------------------------------------------------------
1040 /* Opening automatically checks the system, this command is mostly used
1042 bool DoCheck(CommandLine
&CmdL
)
1051 // ShowHelp - Show a help screen /*{{{*/
1052 // ---------------------------------------------------------------------
1054 bool ShowHelp(CommandLine
&CmdL
)
1056 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
1057 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
1058 if (_config
->FindB("version") == true)
1061 cout
<< "Usage: apt-get [options] command" << endl
;
1062 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
1064 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
1065 cout
<< "installing packages. The most frequently used commands are update" << endl
;
1066 cout
<< "and install." << endl
;
1068 cout
<< "Commands:" << endl
;
1069 cout
<< " update - Retrieve new lists of packages" << endl
;
1070 cout
<< " upgrade - Perform an upgrade" << endl
;
1071 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
1072 cout
<< " remove - Remove packages" << endl
;
1073 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
1074 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
1075 cout
<< " clean - Erase downloaded archive files" << endl
;
1076 cout
<< " autoclean - Erase old downloaded archive files" << endl
;
1077 cout
<< " check - Verify that there are no broken dependencies" << endl
;
1079 cout
<< "Options:" << endl
;
1080 cout
<< " -h This help text." << endl
;
1081 cout
<< " -q Loggable output - no progress indicator" << endl
;
1082 cout
<< " -qq No output except for errors" << endl
;
1083 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
1084 cout
<< " -s No-act. Perform ordering simulation" << endl
;
1085 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
1086 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
1087 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
1088 cout
<< " -u Show a list of upgraded packages as well" << endl
;
1089 cout
<< " -c=? Read this configuration file" << endl
;
1090 cout
<< " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl
;
1091 cout
<< "See the apt-get(8), sources.list(5) and apt.conf(5) manual" << endl
;
1092 cout
<< "pages for more information." << endl
;
1096 // GetInitialize - Initialize things for apt-get /*{{{*/
1097 // ---------------------------------------------------------------------
1099 void GetInitialize()
1101 _config
->Set("quiet",0);
1102 _config
->Set("help",false);
1103 _config
->Set("APT::Get::Download-Only",false);
1104 _config
->Set("APT::Get::Simulate",false);
1105 _config
->Set("APT::Get::Assume-Yes",false);
1106 _config
->Set("APT::Get::Fix-Broken",false);
1107 _config
->Set("APT::Get::Force-Yes",false);
1110 // SigWinch - Window size change signal handler /*{{{*/
1111 // ---------------------------------------------------------------------
1115 // Riped from GNU ls
1119 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
1120 ScreenWidth
= ws
.ws_col
- 1;
1125 int main(int argc
,const char *argv
[])
1127 CommandLine::Args Args
[] = {
1128 {'h',"help","help",0},
1129 {'v',"version","version",0},
1130 {'q',"quiet","quiet",CommandLine::IntLevel
},
1131 {'q',"silent","quiet",CommandLine::IntLevel
},
1132 {'d',"download-only","APT::Get::Download-Only",0},
1133 {'s',"simulate","APT::Get::Simulate",0},
1134 {'s',"just-print","APT::Get::Simulate",0},
1135 {'s',"recon","APT::Get::Simulate",0},
1136 {'s',"no-act","APT::Get::Simulate",0},
1137 {'y',"yes","APT::Get::Assume-Yes",0},
1138 {'y',"assume-yes","APT::Get::Assume-Yes",0},
1139 {'f',"fix-broken","APT::Get::Fix-Broken",0},
1140 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
1141 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
1142 {0,"fix-missing","APT::Get::Fix-Missing",0},
1143 {0,"ignore-hold","APT::Ingore-Hold",0},
1144 {0,"no-upgrade","APT::Get::no-upgrade",0},
1145 {0,"force-yes","APT::Get::force-yes",0},
1146 {0,"print-uris","APT::Get::Print-URIs",0},
1147 {'c',"config-file",0,CommandLine::ConfigFile
},
1148 {'o',"option",0,CommandLine::ArbItem
},
1150 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
1151 {"upgrade",&DoUpgrade
},
1152 {"install",&DoInstall
},
1153 {"remove",&DoInstall
},
1154 {"dist-upgrade",&DoDistUpgrade
},
1155 {"dselect-upgrade",&DoDSelectUpgrade
},
1157 {"autoclean",&DoAutoClean
},
1162 // Parse the command line and initialize the package library
1163 CommandLine
CmdL(Args
,_config
);
1164 if (pkgInitialize(*_config
) == false ||
1165 CmdL
.Parse(argc
,argv
) == false)
1167 _error
->DumpErrors();
1171 // See if the help should be shown
1172 if (_config
->FindB("help") == true ||
1173 _config
->FindB("version") == true ||
1174 CmdL
.FileSize() == 0)
1175 return ShowHelp(CmdL
);
1177 // Setup the output streams
1178 c0out
.rdbuf(cout
.rdbuf());
1179 c1out
.rdbuf(cout
.rdbuf());
1180 c2out
.rdbuf(cout
.rdbuf());
1181 if (_config
->FindI("quiet",0) > 0)
1182 c0out
.rdbuf(devnull
.rdbuf());
1183 if (_config
->FindI("quiet",0) > 1)
1184 c1out
.rdbuf(devnull
.rdbuf());
1186 // Setup the signals
1187 signal(SIGPIPE
,SIG_IGN
);
1188 signal(SIGWINCH
,SigWinch
);
1191 // Match the operation
1192 CmdL
.DispatchArg(Cmds
);
1194 // Print any errors or warnings found during parsing
1195 if (_error
->empty() == false)
1197 bool Errors
= _error
->PendingError();
1198 _error
->DumpErrors();
1199 return Errors
== true?100:0;