]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.38 1999/02/01 08:11:57 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())
776 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
778 if ((*Cache
)[Pkg
].InstVerIter(*Cache
) == I
.OwnerVer())
779 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
780 " [Installed]"<< endl
;
782 c1out
<< "You should explicly select one to install." << endl
;
786 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
787 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
788 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
791 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
792 for (; Dep
.end() == false; Dep
++)
794 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
796 List
+= string(Dep
.ParentPkg().Name()) + " ";
798 ShowList(c1out
,"However the following packages replace it:",List
);
801 return _error
->Error("Package %s has no installation candidate",S
);
808 Cache
->MarkDelete(Pkg
);
813 Cache
->MarkInstall(Pkg
,false);
814 if (State
.Install() == false)
815 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
819 // Install it with autoinstalling enabled.
820 if (State
.InstBroken() == true && BrokenFix
== false)
821 Cache
->MarkInstall(Pkg
,true);
824 /* If we are in the Broken fixing mode we do not attempt to fix the
825 problems. This is if the user invoked install without -f and gave
827 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
829 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
830 ShowBroken(c1out
,Cache
);
832 return _error
->Error("Unmet dependencies. Try using -f.");
835 // Call the scored problem resolver
836 Fix
.InstallProtect();
837 if (Fix
.Resolve(true) == false)
840 // Now we check the state of the packages,
841 if (Cache
->BrokenCount() != 0)
843 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
844 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
845 c1out
<< "distribution that some required packages have not yet been created" << endl
;
846 c1out
<< "or been moved out of Incoming." << endl
;
850 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
851 c1out
<< "the package is simply not installable and a bug report against" << endl
;
852 c1out
<< "that package should be filed." << endl
;
855 c1out
<< "The following information may help to resolve the situation:" << endl
;
857 ShowBroken(c1out
,Cache
);
858 return _error
->Error("Sorry, broken packages");
861 /* Print out a list of packages that are going to be installed extra
862 to what the user asked */
863 if (Cache
->InstCount() != ExpectedInst
)
866 pkgCache::PkgIterator I
= Cache
->PkgBegin();
867 for (;I
.end() != true; I
++)
869 if ((*Cache
)[I
].Install() == false)
873 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
874 if (strcmp(*J
,I
.Name()) == 0)
878 List
+= string(I
.Name()) + " ";
881 ShowList(c1out
,"The following extra packages will be installed:",List
);
884 // See if we need to prompt
885 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
886 return InstallPackages(Cache
,false,false);
888 return InstallPackages(Cache
,false);
891 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
892 // ---------------------------------------------------------------------
893 /* Intelligent upgrader that will install and remove packages at will */
894 bool DoDistUpgrade(CommandLine
&CmdL
)
897 if (Cache
.Open() == false)
900 c0out
<< "Calculating Upgrade... " << flush
;
901 if (pkgDistUpgrade(*Cache
) == false)
903 c0out
<< "Failed" << endl
;
904 ShowBroken(c1out
,Cache
);
908 c0out
<< "Done" << endl
;
910 return InstallPackages(Cache
,true);
913 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
914 // ---------------------------------------------------------------------
915 /* Follows dselect's selections */
916 bool DoDSelectUpgrade(CommandLine
&CmdL
)
919 if (Cache
.Open() == false)
922 // Install everything with the install flag set
923 pkgCache::PkgIterator I
= Cache
->PkgBegin();
924 for (;I
.end() != true; I
++)
926 /* Install the package only if it is a new install, the autoupgrader
927 will deal with the rest */
928 if (I
->SelectedState
== pkgCache::State::Install
)
929 Cache
->MarkInstall(I
,false);
932 /* Now install their deps too, if we do this above then order of
933 the status file is significant for | groups */
934 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
936 /* Install the package only if it is a new install, the autoupgrader
937 will deal with the rest */
938 if (I
->SelectedState
== pkgCache::State::Install
)
939 Cache
->MarkInstall(I
,true);
942 // Apply erasures now, they override everything else.
943 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
946 if (I
->SelectedState
== pkgCache::State::DeInstall
||
947 I
->SelectedState
== pkgCache::State::Purge
)
948 Cache
->MarkDelete(I
);
951 /* Resolve any problems that dselect created, allupgrade cannot handle
952 such things. We do so quite agressively too.. */
953 if (Cache
->BrokenCount() != 0)
955 pkgProblemResolver
Fix(Cache
);
957 // Hold back held packages.
958 if (_config
->FindB("APT::Ingore-Hold",false) == false)
960 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
962 if (I
->SelectedState
== pkgCache::State::Hold
)
970 if (Fix
.Resolve() == false)
972 ShowBroken(c1out
,Cache
);
973 return _error
->Error("Internal Error, problem resolver broke stuff");
977 // Now upgrade everything
978 if (pkgAllUpgrade(Cache
) == false)
980 ShowBroken(c1out
,Cache
);
981 return _error
->Error("Internal Error, problem resolver broke stuff");
984 return InstallPackages(Cache
,false);
987 // DoClean - Remove download archives /*{{{*/
988 // ---------------------------------------------------------------------
990 bool DoClean(CommandLine
&CmdL
)
993 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
994 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
998 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
999 // ---------------------------------------------------------------------
1000 /* This is similar to clean but it only purges things that cannot be
1001 downloaded, that is old versions of cached packages. */
1002 bool DoAutoClean(CommandLine
&CmdL
)
1005 if (Cache
.Open(true) == false)
1008 class LogCleaner
: public pkgArchiveCleaner
1011 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1013 cout
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "b]" << endl
;
1017 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1018 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1021 // DoCheck - Perform the check operation /*{{{*/
1022 // ---------------------------------------------------------------------
1023 /* Opening automatically checks the system, this command is mostly used
1025 bool DoCheck(CommandLine
&CmdL
)
1034 // ShowHelp - Show a help screen /*{{{*/
1035 // ---------------------------------------------------------------------
1037 bool ShowHelp(CommandLine
&CmdL
)
1039 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
1040 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
1041 if (_config
->FindB("version") == true)
1044 cout
<< "Usage: apt-get [options] command" << endl
;
1045 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
1047 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
1048 cout
<< "installing packages. The most frequently used commands are update" << endl
;
1049 cout
<< "and install." << endl
;
1051 cout
<< "Commands:" << endl
;
1052 cout
<< " update - Retrieve new lists of packages" << endl
;
1053 cout
<< " upgrade - Perform an upgrade" << endl
;
1054 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
1055 cout
<< " remove - Remove packages" << endl
;
1056 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
1057 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
1058 cout
<< " clean - Erase downloaded archive files" << endl
;
1059 cout
<< " autoclean - Erase old downloaded archive files" << endl
;
1060 cout
<< " check - Verify that there are no broken dependencies" << endl
;
1062 cout
<< "Options:" << endl
;
1063 cout
<< " -h This help text." << endl
;
1064 cout
<< " -q Loggable output - no progress indicator" << endl
;
1065 cout
<< " -qq No output except for errors" << endl
;
1066 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
1067 cout
<< " -s No-act. Perform ordering simulation" << endl
;
1068 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
1069 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
1070 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
1071 cout
<< " -u Show a list of upgraded packages as well" << endl
;
1072 cout
<< " -c=? Read this configuration file" << endl
;
1073 cout
<< " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl
;
1074 cout
<< "See the apt-get(8), sources.list(5) and apt.conf(5) manual" << endl
;
1075 cout
<< "pages for more information." << endl
;
1079 // GetInitialize - Initialize things for apt-get /*{{{*/
1080 // ---------------------------------------------------------------------
1082 void GetInitialize()
1084 _config
->Set("quiet",0);
1085 _config
->Set("help",false);
1086 _config
->Set("APT::Get::Download-Only",false);
1087 _config
->Set("APT::Get::Simulate",false);
1088 _config
->Set("APT::Get::Assume-Yes",false);
1089 _config
->Set("APT::Get::Fix-Broken",false);
1090 _config
->Set("APT::Get::Force-Yes",false);
1093 // SigWinch - Window size change signal handler /*{{{*/
1094 // ---------------------------------------------------------------------
1098 // Riped from GNU ls
1102 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
1103 ScreenWidth
= ws
.ws_col
- 1;
1108 int main(int argc
,const char *argv
[])
1110 CommandLine::Args Args
[] = {
1111 {'h',"help","help",0},
1112 {'v',"version","version",0},
1113 {'q',"quiet","quiet",CommandLine::IntLevel
},
1114 {'q',"silent","quiet",CommandLine::IntLevel
},
1115 {'d',"download-only","APT::Get::Download-Only",0},
1116 {'s',"simulate","APT::Get::Simulate",0},
1117 {'s',"just-print","APT::Get::Simulate",0},
1118 {'s',"recon","APT::Get::Simulate",0},
1119 {'s',"no-act","APT::Get::Simulate",0},
1120 {'y',"yes","APT::Get::Assume-Yes",0},
1121 {'y',"assume-yes","APT::Get::Assume-Yes",0},
1122 {'f',"fix-broken","APT::Get::Fix-Broken",0},
1123 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
1124 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
1125 {0,"fix-missing","APT::Get::Fix-Missing",0},
1126 {0,"ignore-hold","APT::Ingore-Hold",0},
1127 {0,"no-upgrade","APT::Get::no-upgrade",0},
1128 {0,"force-yes","APT::Get::force-yes",0},
1129 {0,"print-uris","APT::Get::Print-URIs",0},
1130 {'c',"config-file",0,CommandLine::ConfigFile
},
1131 {'o',"option",0,CommandLine::ArbItem
},
1133 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
1134 {"upgrade",&DoUpgrade
},
1135 {"install",&DoInstall
},
1136 {"remove",&DoInstall
},
1137 {"dist-upgrade",&DoDistUpgrade
},
1138 {"dselect-upgrade",&DoDSelectUpgrade
},
1140 {"autoclean",&DoAutoClean
},
1145 // Parse the command line and initialize the package library
1146 CommandLine
CmdL(Args
,_config
);
1147 if (pkgInitialize(*_config
) == false ||
1148 CmdL
.Parse(argc
,argv
) == false)
1150 _error
->DumpErrors();
1154 // See if the help should be shown
1155 if (_config
->FindB("help") == true ||
1156 _config
->FindB("version") == true ||
1157 CmdL
.FileSize() == 0)
1158 return ShowHelp(CmdL
);
1160 // Setup the output streams
1161 c0out
.rdbuf(cout
.rdbuf());
1162 c1out
.rdbuf(cout
.rdbuf());
1163 c2out
.rdbuf(cout
.rdbuf());
1164 if (_config
->FindI("quiet",0) > 0)
1165 c0out
.rdbuf(devnull
.rdbuf());
1166 if (_config
->FindI("quiet",0) > 1)
1167 c1out
.rdbuf(devnull
.rdbuf());
1169 // Setup the signals
1170 signal(SIGPIPE
,SIG_IGN
);
1171 signal(SIGWINCH
,SigWinch
);
1174 // Match the operation
1175 CmdL
.DispatchArg(Cmds
);
1177 // Print any errors or warnings found during parsing
1178 if (_error
->empty() == false)
1180 bool Errors
= _error
->PendingError();
1181 _error
->DumpErrors();
1182 return Errors
== true?100:0;