]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1cc983e47544e31b75d809ceb9699e7ab0050d73
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.36 1999/01/30 03:35:28 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>
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 bool 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
;
108 // ShowBroken - Debugging aide /*{{{*/
109 // ---------------------------------------------------------------------
110 /* This prints out the names of all the packages that are broken along
111 with the name of each each broken dependency and a quite version
113 void ShowBroken(ostream
&out
,pkgDepCache
&Cache
)
115 out
<< "Sorry, but the following packages have unmet dependencies:" << endl
;
116 pkgCache::PkgIterator I
= Cache
.PkgBegin();
117 for (;I
.end() != true; I
++)
119 if (Cache
[I
].InstBroken() == false)
122 // Print out each package and the failed dependencies
123 out
<<" " << I
.Name() << ":";
124 int Indent
= strlen(I
.Name()) + 3;
126 if (Cache
[I
].InstVerIter(Cache
).end() == true)
132 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
134 // Compute a single dependency element (glob or)
135 pkgCache::DepIterator Start
;
136 pkgCache::DepIterator End
;
139 if (Cache
.IsImportantDep(End
) == false ||
140 (Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
144 for (int J
= 0; J
!= Indent
; J
++)
148 cout
<< ' ' << End
.DepType() << ": " << End
.TargetPkg().Name();
150 // Show a quick summary of the version requirements
151 if (End
.TargetVer() != 0)
152 out
<< " (" << End
.CompType() << " " << End
.TargetVer() <<
155 /* Show a summary of the target package if possible. In the case
156 of virtual packages we show nothing */
158 pkgCache::PkgIterator Targ
= End
.TargetPkg();
159 if (Targ
->ProvidesList
== 0)
162 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
163 if (Ver
.end() == false)
164 out
<< Ver
.VerStr() << " is installed";
167 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
169 if (Targ
->ProvidesList
== 0)
170 out
<< "it is not installable";
172 out
<< "it is a virtual package";
175 out
<< "it is not installed";
184 // ShowNew - Show packages to newly install /*{{{*/
185 // ---------------------------------------------------------------------
187 void ShowNew(ostream
&out
,pkgDepCache
&Dep
)
189 /* Print out a list of packages that are going to be removed extra
190 to what the user asked */
191 pkgCache::PkgIterator I
= Dep
.PkgBegin();
193 for (;I
.end() != true; I
++)
194 if (Dep
[I
].NewInstall() == true)
195 List
+= string(I
.Name()) + " ";
196 ShowList(out
,"The following NEW packages will be installed:",List
);
199 // ShowDel - Show packages to delete /*{{{*/
200 // ---------------------------------------------------------------------
202 void ShowDel(ostream
&out
,pkgDepCache
&Dep
)
204 /* Print out a list of packages that are going to be removed extra
205 to what the user asked */
206 pkgCache::PkgIterator I
= Dep
.PkgBegin();
208 for (;I
.end() != true; I
++)
209 if (Dep
[I
].Delete() == true)
210 List
+= string(I
.Name()) + " ";
212 ShowList(out
,"The following packages will be REMOVED:",List
);
215 // ShowKept - Show kept packages /*{{{*/
216 // ---------------------------------------------------------------------
218 void ShowKept(ostream
&out
,pkgDepCache
&Dep
)
220 pkgCache::PkgIterator I
= Dep
.PkgBegin();
222 for (;I
.end() != true; I
++)
225 if (Dep
[I
].Upgrade() == true || Dep
[I
].Upgradable() == false ||
226 I
->CurrentVer
== 0 || Dep
[I
].Delete() == true)
229 List
+= string(I
.Name()) + " ";
231 ShowList(out
,"The following packages have been kept back",List
);
234 // ShowUpgraded - Show upgraded packages /*{{{*/
235 // ---------------------------------------------------------------------
237 void ShowUpgraded(ostream
&out
,pkgDepCache
&Dep
)
239 pkgCache::PkgIterator I
= Dep
.PkgBegin();
241 for (;I
.end() != true; I
++)
244 if (Dep
[I
].Upgrade() == false || Dep
[I
].NewInstall() == true)
247 List
+= string(I
.Name()) + " ";
249 ShowList(out
,"The following packages will be upgraded",List
);
252 // ShowHold - Show held but changed packages /*{{{*/
253 // ---------------------------------------------------------------------
255 bool ShowHold(ostream
&out
,pkgDepCache
&Dep
)
257 pkgCache::PkgIterator I
= Dep
.PkgBegin();
259 for (;I
.end() != true; I
++)
261 if (Dep
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
262 I
->SelectedState
== pkgCache::State::Hold
)
263 List
+= string(I
.Name()) + " ";
266 return ShowList(out
,"The following held packages will be changed:",List
);
269 // ShowEssential - Show an essential package warning /*{{{*/
270 // ---------------------------------------------------------------------
271 /* This prints out a warning message that is not to be ignored. It shows
272 all essential packages and their dependents that are to be removed.
273 It is insanely risky to remove the dependents of an essential package! */
274 bool ShowEssential(ostream
&out
,pkgDepCache
&Dep
)
276 pkgCache::PkgIterator I
= Dep
.PkgBegin();
278 bool *Added
= new bool[Dep
.HeaderP
->PackageCount
];
279 for (unsigned int I
= 0; I
!= Dep
.HeaderP
->PackageCount
; I
++)
282 for (;I
.end() != true; I
++)
284 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
287 // The essential package is being removed
288 if (Dep
[I
].Delete() == true)
290 if (Added
[I
->ID
] == false)
293 List
+= string(I
.Name()) + " ";
297 if (I
->CurrentVer
== 0)
300 // Print out any essential package depenendents that are to be removed
301 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
303 // Skip everything but depends
304 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
305 D
->Type
!= pkgCache::Dep::Depends
)
308 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
309 if (Dep
[P
].Delete() == true)
311 if (Added
[P
->ID
] == true)
316 sprintf(S
,"%s (due to %s) ",P
.Name(),I
.Name());
323 if (List
.empty() == false)
324 out
<< "WARNING: The following essential packages will be removed" << endl
;
325 return ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
328 // Stats - Show some statistics /*{{{*/
329 // ---------------------------------------------------------------------
331 void Stats(ostream
&out
,pkgDepCache
&Dep
)
333 unsigned long Upgrade
= 0;
334 unsigned long Install
= 0;
335 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
337 if (Dep
[I
].NewInstall() == true)
340 if (Dep
[I
].Upgrade() == true)
344 out
<< Upgrade
<< " packages upgraded, " <<
345 Install
<< " newly installed, " <<
346 Dep
.DelCount() << " to remove and " <<
347 Dep
.KeepCount() << " not upgraded." << endl
;
349 if (Dep
.BadCount() != 0)
350 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
354 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
355 // ---------------------------------------------------------------------
366 inline operator pkgDepCache
&() {return *Cache
;};
367 inline pkgDepCache
*operator ->() {return Cache
;};
368 inline pkgDepCache
&operator *() {return *Cache
;};
370 bool Open(bool AllowBroken
= false);
371 CacheFile() : File(0), Map(0), Cache(0) {};
380 // CacheFile::Open - Open the cache file /*{{{*/
381 // ---------------------------------------------------------------------
382 /* This routine generates the caches and then opens the dependency cache
383 and verifies that the system is OK. */
384 bool CacheFile::Open(bool AllowBroken
)
386 if (_error
->PendingError() == true)
389 // Create a progress class
390 OpTextProgress
Progress(*_config
);
392 // Read the source list
394 if (List
.ReadMainList() == false)
395 return _error
->Error("The list of sources could not be read.");
397 // Build all of the caches
398 pkgMakeStatusCache(List
,Progress
);
399 if (_error
->PendingError() == true)
400 return _error
->Error("The package lists or status file could not be parsed or opened.");
401 if (_error
->empty() == false)
402 _error
->Warning("You may want to run apt-get update to correct theses missing files");
406 // Open the cache file
407 File
= new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly
);
408 if (_error
->PendingError() == true)
411 Map
= new MMap(*File
,MMap::Public
| MMap::ReadOnly
);
412 if (_error
->PendingError() == true)
415 Cache
= new pkgDepCache(*Map
,Progress
);
416 if (_error
->PendingError() == true)
421 // Check that the system is OK
422 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
423 return _error
->Error("Internal Error, non-zero counts");
425 // Apply corrections for half-installed packages
426 if (pkgApplyStatus(*Cache
) == false)
430 if (Cache
->BrokenCount() == 0 || AllowBroken
== true)
433 // Attempt to fix broken things
434 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
436 c1out
<< "Correcting dependencies..." << flush
;
437 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
439 c1out
<< " failed." << endl
;
440 ShowBroken(c1out
,*this);
442 return _error
->Error("Unable to correct dependencies");
444 if (pkgMinimizeUpgrade(*Cache
) == false)
445 return _error
->Error("Unable to minimize the upgrade set");
447 c1out
<< " Done" << endl
;
451 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
452 ShowBroken(c1out
,*this);
454 return _error
->Error("Unmet dependencies. Try using -f.");
461 // InstallPackages - Actually download and install the packages /*{{{*/
462 // ---------------------------------------------------------------------
463 /* This displays the informative messages describing what is going to
464 happen and then calls the download routines */
465 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true)
469 // Show all the various warning indicators
470 ShowDel(c1out
,Cache
);
471 ShowNew(c1out
,Cache
);
473 ShowKept(c1out
,Cache
);
474 Fail
|= !ShowHold(c1out
,Cache
);
475 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
476 ShowUpgraded(c1out
,Cache
);
477 Fail
|= !ShowEssential(c1out
,Cache
);
481 if (Cache
->BrokenCount() != 0)
483 ShowBroken(c1out
,Cache
);
484 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
487 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
488 Cache
->BadCount() == 0)
491 // Run the simulator ..
492 if (_config
->FindB("APT::Get::Simulate") == true)
494 pkgSimulate
PM(Cache
);
495 return PM
.DoInstall();
498 // Create the text record parser
499 pkgRecords
Recs(Cache
);
500 if (_error
->PendingError() == true)
503 // Lock the archive directory
504 if (_config
->FindB("Debug::NoLocking",false) == false)
506 FileFd
Lock(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
507 if (_error
->PendingError() == true)
508 return _error
->Error("Unable to lock the download directory");
511 // Create the download object
512 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
513 pkgAcquire
Fetcher(&Stat
);
515 // Read the source list
517 if (List
.ReadMainList() == false)
518 return _error
->Error("The list of sources could not be read.");
520 // Create the package manager and prepare to download
522 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false)
525 // Display statistics
526 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
527 unsigned long DebBytes
= Fetcher
.TotalNeeded();
528 if (DebBytes
!= Cache
->DebSize())
530 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
531 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
535 c2out
<< "Need to get ";
536 if (DebBytes
!= FetchBytes
)
537 c2out
<< SizeToStr(FetchBytes
) << '/' << SizeToStr(DebBytes
);
539 c2out
<< SizeToStr(DebBytes
);
541 c1out
<< " of archives. After unpacking ";
544 if (Cache
->UsrSize() >= 0)
545 c2out
<< SizeToStr(Cache
->UsrSize()) << " will be used." << endl
;
547 c2out
<< SizeToStr(-1*Cache
->UsrSize()) << " will be freed." << endl
;
549 if (_error
->PendingError() == true)
553 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
555 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
556 return _error
->Error("There are problems and -y was used without --force-yes");
559 // Prompt to continue
562 if (_config
->FindI("quiet",0) < 2 ||
563 _config
->FindB("APT::Get::Assume-Yes",false) == false)
564 c2out
<< "Do you want to continue? [Y/n] " << flush
;
566 if (YnPrompt() == false)
571 if (Fetcher
.Run() == false)
576 bool Transient
= false;
577 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
579 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
580 (*I
)->Complete
== true)
583 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
590 cerr
<< "Failed to fetch " << (*I
)->Describe() << endl
;
591 cerr
<< " " << (*I
)->ErrorText
<< endl
;
595 if (_config
->FindB("APT::Get::Download-Only",false) == true)
598 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
600 if (Transient
== true)
602 c2out
<< "Upgrading with disk swapping is not supported in this version." << endl
;
603 c2out
<< "Try running multiple times with --fix-missing" << endl
;
606 return _error
->Error("Unable to fetch some archives, maybe try with --fix-missing?");
609 // Try to deal with missing package files
610 if (PM
.FixMissing() == false)
612 cerr
<< "Unable to correct missing packages." << endl
;
613 return _error
->Error("Aborting Install.");
617 return PM
.DoInstall();
621 // DoUpdate - Update the package lists /*{{{*/
622 // ---------------------------------------------------------------------
624 bool DoUpdate(CommandLine
&)
626 // Get the source list
628 if (List
.ReadMainList() == false)
631 // Lock the list directory
632 if (_config
->FindB("Debug::NoLocking",false) == false)
634 FileFd
Lock(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
635 if (_error
->PendingError() == true)
636 return _error
->Error("Unable to lock the list directory");
639 // Create the download object
640 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
641 pkgAcquire
Fetcher(&Stat
);
643 // Populate it with the source selection
644 pkgSourceList::const_iterator I
;
645 for (I
= List
.begin(); I
!= List
.end(); I
++)
647 new pkgAcqIndex(&Fetcher
,I
);
648 if (_error
->PendingError() == true)
653 if (Fetcher
.Run() == false)
656 // Clean out any old list files
657 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
658 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
661 // Prepare the cache.
663 if (Cache
.Open() == false)
669 // DoUpgrade - Upgrade all packages /*{{{*/
670 // ---------------------------------------------------------------------
671 /* Upgrade all packages without installing new packages or erasing old
673 bool DoUpgrade(CommandLine
&CmdL
)
676 if (Cache
.Open() == false)
680 if (pkgAllUpgrade(Cache
) == false)
682 ShowBroken(c1out
,Cache
);
683 return _error
->Error("Internal Error, AllUpgrade broke stuff");
686 return InstallPackages(Cache
,true);
689 // DoInstall - Install packages from the command line /*{{{*/
690 // ---------------------------------------------------------------------
691 /* Install named packages */
692 bool DoInstall(CommandLine
&CmdL
)
695 if (Cache
.Open(CmdL
.FileSize() != 1) == false)
698 // Enter the special broken fixing mode if the user specified arguments
699 bool BrokenFix
= false;
700 if (Cache
->BrokenCount() != 0)
703 unsigned int ExpectedInst
= 0;
704 unsigned int Packages
= 0;
705 pkgProblemResolver
Fix(Cache
);
707 bool DefRemove
= false;
708 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
711 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
713 // Duplicate the string
714 unsigned int Length
= strlen(*I
);
716 if (Length
>= sizeof(S
))
720 // See if we are removing the package
721 bool Remove
= DefRemove
;
722 if (Cache
->FindPkg(S
).end() == true)
724 // Handle an optional end tag indicating what to do
725 if (S
[Length
- 1] == '-')
730 if (S
[Length
- 1] == '+')
737 // Locate the package
738 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
740 if (Pkg
.end() == true)
741 return _error
->Error("Couldn't find package %s",S
);
743 // Handle the no-upgrade case
744 if (_config
->FindB("APT::Get::no-upgrade",false) == true &&
745 Pkg
->CurrentVer
!= 0)
747 c1out
<< "Skipping " << Pkg
.Name() << ", it is already installed and no-upgrade is set." << endl
;
751 // Check if there is something new to install
752 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
753 if (State
.CandidateVer
== 0)
755 if (Pkg
->ProvidesList
!= 0)
757 c1out
<< "Package " << S
<< " is a virtual package provided by:" << endl
;
759 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
760 for (; I
.end() == false; I
++)
762 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
764 if ((*Cache
)[Pkg
].CandidateVerIter(*Cache
) == I
.OwnerVer())
765 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
767 if ((*Cache
)[Pkg
].InstVerIter(*Cache
) == I
.OwnerVer())
768 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
769 " [Installed]"<< endl
;
771 c1out
<< "You should explicly select one to install." << endl
;
775 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
776 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
777 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
780 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
781 for (; Dep
.end() == false; Dep
++)
783 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
785 List
+= string(Dep
.ParentPkg().Name()) + " ";
787 ShowList(c1out
,"However the following packages replace it:",List
);
790 return _error
->Error("Package %s has no installation candidate",S
);
797 Cache
->MarkDelete(Pkg
);
802 Cache
->MarkInstall(Pkg
,false);
803 if (State
.Install() == false)
804 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
808 // Install it with autoinstalling enabled.
809 if (State
.InstBroken() == true && BrokenFix
== false)
810 Cache
->MarkInstall(Pkg
,true);
813 /* If we are in the Broken fixing mode we do not attempt to fix the
814 problems. This is if the user invoked install without -f and gave
816 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
818 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
819 ShowBroken(c1out
,Cache
);
821 return _error
->Error("Unmet dependencies. Try using -f.");
824 // Call the scored problem resolver
825 Fix
.InstallProtect();
826 if (Fix
.Resolve(true) == false)
829 // Now we check the state of the packages,
830 if (Cache
->BrokenCount() != 0)
832 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
833 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
834 c1out
<< "distribution that some required packages have not yet been created" << endl
;
835 c1out
<< "or been moved out of Incoming." << endl
;
839 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
840 c1out
<< "the package is simply not installable and a bug report against" << endl
;
841 c1out
<< "that package should be filed." << endl
;
844 c1out
<< "The following information may help to resolve the situation:" << endl
;
846 ShowBroken(c1out
,Cache
);
847 return _error
->Error("Sorry, broken packages");
850 /* Print out a list of packages that are going to be installed extra
851 to what the user asked */
852 if (Cache
->InstCount() != ExpectedInst
)
855 pkgCache::PkgIterator I
= Cache
->PkgBegin();
856 for (;I
.end() != true; I
++)
858 if ((*Cache
)[I
].Install() == false)
862 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
863 if (strcmp(*J
,I
.Name()) == 0)
867 List
+= string(I
.Name()) + " ";
870 ShowList(c1out
,"The following extra packages will be installed:",List
);
873 // See if we need to prompt
874 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
875 return InstallPackages(Cache
,false,false);
877 return InstallPackages(Cache
,false);
880 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
881 // ---------------------------------------------------------------------
882 /* Intelligent upgrader that will install and remove packages at will */
883 bool DoDistUpgrade(CommandLine
&CmdL
)
886 if (Cache
.Open() == false)
889 c0out
<< "Calculating Upgrade... " << flush
;
890 if (pkgDistUpgrade(*Cache
) == false)
892 c0out
<< "Failed" << endl
;
893 ShowBroken(c1out
,Cache
);
897 c0out
<< "Done" << endl
;
899 return InstallPackages(Cache
,true);
902 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
903 // ---------------------------------------------------------------------
904 /* Follows dselect's selections */
905 bool DoDSelectUpgrade(CommandLine
&CmdL
)
908 if (Cache
.Open() == false)
911 // Install everything with the install flag set
912 pkgCache::PkgIterator I
= Cache
->PkgBegin();
913 for (;I
.end() != true; I
++)
915 /* Install the package only if it is a new install, the autoupgrader
916 will deal with the rest */
917 if (I
->SelectedState
== pkgCache::State::Install
)
918 Cache
->MarkInstall(I
,false);
921 /* Now install their deps too, if we do this above then order of
922 the status file is significant for | groups */
923 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
925 /* Install the package only if it is a new install, the autoupgrader
926 will deal with the rest */
927 if (I
->SelectedState
== pkgCache::State::Install
)
928 Cache
->MarkInstall(I
,true);
931 // Apply erasures now, they override everything else.
932 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
935 if (I
->SelectedState
== pkgCache::State::DeInstall
||
936 I
->SelectedState
== pkgCache::State::Purge
)
937 Cache
->MarkDelete(I
);
940 /* Resolve any problems that dselect created, allupgrade cannot handle
941 such things. We do so quite agressively too.. */
942 if (Cache
->BrokenCount() != 0)
944 pkgProblemResolver
Fix(Cache
);
946 // Hold back held packages.
947 if (_config
->FindB("APT::Ingore-Hold",false) == false)
949 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
951 if (I
->SelectedState
== pkgCache::State::Hold
)
959 if (Fix
.Resolve() == false)
961 ShowBroken(c1out
,Cache
);
962 return _error
->Error("Internal Error, problem resolver broke stuff");
966 // Now upgrade everything
967 if (pkgAllUpgrade(Cache
) == false)
969 ShowBroken(c1out
,Cache
);
970 return _error
->Error("Internal Error, problem resolver broke stuff");
973 return InstallPackages(Cache
,false);
976 // DoClean - Remove download archives /*{{{*/
977 // ---------------------------------------------------------------------
979 bool DoClean(CommandLine
&CmdL
)
982 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
983 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
987 // DoCheck - Perform the check operation /*{{{*/
988 // ---------------------------------------------------------------------
989 /* Opening automatically checks the system, this command is mostly used
991 bool DoCheck(CommandLine
&CmdL
)
1000 // ShowHelp - Show a help screen /*{{{*/
1001 // ---------------------------------------------------------------------
1003 bool ShowHelp(CommandLine
&CmdL
)
1005 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
1006 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
1007 if (_config
->FindB("version") == true)
1010 cout
<< "Usage: apt-get [options] command" << endl
;
1011 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
1013 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
1014 cout
<< "installing packages. The most frequently used commands are update" << endl
;
1015 cout
<< "and install." << endl
;
1017 cout
<< "Commands:" << endl
;
1018 cout
<< " update - Retrieve new lists of packages" << endl
;
1019 cout
<< " upgrade - Perform an upgrade" << endl
;
1020 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
1021 cout
<< " remove - Remove packages" << endl
;
1022 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
1023 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
1024 cout
<< " clean - Erase downloaded archive files" << endl
;
1025 cout
<< " check - Verify that there are no broken dependencies" << endl
;
1027 cout
<< "Options:" << endl
;
1028 cout
<< " -h This help text." << endl
;
1029 cout
<< " -q Loggable output - no progress indicator" << endl
;
1030 cout
<< " -qq No output except for errors" << endl
;
1031 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
1032 cout
<< " -s No-act. Perform ordering simulation" << endl
;
1033 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
1034 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
1035 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
1036 cout
<< " -u Show a list of upgraded packages as well" << endl
;
1037 cout
<< " -c=? Read this configuration file" << endl
;
1038 cout
<< " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl
;
1039 cout
<< "See the apt-get(8), sources.list(5) and apt.conf(5) manual" << endl
;
1040 cout
<< "pages for more information." << endl
;
1044 // GetInitialize - Initialize things for apt-get /*{{{*/
1045 // ---------------------------------------------------------------------
1047 void GetInitialize()
1049 _config
->Set("quiet",0);
1050 _config
->Set("help",false);
1051 _config
->Set("APT::Get::Download-Only",false);
1052 _config
->Set("APT::Get::Simulate",false);
1053 _config
->Set("APT::Get::Assume-Yes",false);
1054 _config
->Set("APT::Get::Fix-Broken",false);
1055 _config
->Set("APT::Get::Force-Yes",false);
1058 // SigWinch - Window size change signal handler /*{{{*/
1059 // ---------------------------------------------------------------------
1063 // Riped from GNU ls
1067 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
1068 ScreenWidth
= ws
.ws_col
- 1;
1073 int main(int argc
,const char *argv
[])
1075 CommandLine::Args Args
[] = {
1076 {'h',"help","help",0},
1077 {'v',"version","version",0},
1078 {'q',"quiet","quiet",CommandLine::IntLevel
},
1079 {'q',"silent","quiet",CommandLine::IntLevel
},
1080 {'d',"download-only","APT::Get::Download-Only",0},
1081 {'s',"simulate","APT::Get::Simulate",0},
1082 {'s',"just-print","APT::Get::Simulate",0},
1083 {'s',"recon","APT::Get::Simulate",0},
1084 {'s',"no-act","APT::Get::Simulate",0},
1085 {'y',"yes","APT::Get::Assume-Yes",0},
1086 {'y',"assume-yes","APT::Get::Assume-Yes",0},
1087 {'f',"fix-broken","APT::Get::Fix-Broken",0},
1088 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
1089 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
1090 {0,"fix-missing","APT::Get::Fix-Missing",0},
1091 {0,"ignore-hold","APT::Ingore-Hold",0},
1092 {0,"no-upgrade","APT::Get::no-upgrade",0},
1093 {0,"force-yes","APT::Get::force-yes",0},
1094 {'c',"config-file",0,CommandLine::ConfigFile
},
1095 {'o',"option",0,CommandLine::ArbItem
},
1097 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
1098 {"upgrade",&DoUpgrade
},
1099 {"install",&DoInstall
},
1100 {"remove",&DoInstall
},
1101 {"dist-upgrade",&DoDistUpgrade
},
1102 {"dselect-upgrade",&DoDSelectUpgrade
},
1108 // Parse the command line and initialize the package library
1109 CommandLine
CmdL(Args
,_config
);
1110 if (pkgInitialize(*_config
) == false ||
1111 CmdL
.Parse(argc
,argv
) == false)
1113 _error
->DumpErrors();
1117 // See if the help should be shown
1118 if (_config
->FindB("help") == true ||
1119 _config
->FindB("version") == true ||
1120 CmdL
.FileSize() == 0)
1121 return ShowHelp(CmdL
);
1123 // Setup the output streams
1124 c0out
.rdbuf(cout
.rdbuf());
1125 c1out
.rdbuf(cout
.rdbuf());
1126 c2out
.rdbuf(cout
.rdbuf());
1127 if (_config
->FindI("quiet",0) > 0)
1128 c0out
.rdbuf(devnull
.rdbuf());
1129 if (_config
->FindI("quiet",0) > 1)
1130 c1out
.rdbuf(devnull
.rdbuf());
1132 // Setup the signals
1133 signal(SIGPIPE
,SIG_IGN
);
1134 signal(SIGWINCH
,SigWinch
);
1137 // Match the operation
1138 CmdL
.DispatchArg(Cmds
);
1140 // Print any errors or warnings found during parsing
1141 if (_error
->empty() == false)
1143 bool Errors
= _error
->PendingError();
1144 _error
->DumpErrors();
1145 return Errors
== true?100:0;