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