]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.25 1998/12/06 06:22:01 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 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()) + " ";
211 ShowList(out
,"The following packages will be REMOVED:",List
);
214 // ShowKept - Show kept packages /*{{{*/
215 // ---------------------------------------------------------------------
217 void ShowKept(ostream
&out
,pkgDepCache
&Dep
)
219 pkgCache::PkgIterator I
= Dep
.PkgBegin();
221 for (;I
.end() != true; I
++)
224 if (Dep
[I
].Upgrade() == true || Dep
[I
].Upgradable() == false ||
225 I
->CurrentVer
== 0 || Dep
[I
].Delete() == true)
228 List
+= string(I
.Name()) + " ";
230 ShowList(out
,"The following packages have been kept back",List
);
233 // ShowUpgraded - Show upgraded packages /*{{{*/
234 // ---------------------------------------------------------------------
236 void ShowUpgraded(ostream
&out
,pkgDepCache
&Dep
)
238 pkgCache::PkgIterator I
= Dep
.PkgBegin();
240 for (;I
.end() != true; I
++)
243 if (Dep
[I
].Upgrade() == false || Dep
[I
].NewInstall() == true)
246 List
+= string(I
.Name()) + " ";
248 ShowList(out
,"The following packages will be upgraded",List
);
251 // ShowHold - Show held but changed packages /*{{{*/
252 // ---------------------------------------------------------------------
254 bool ShowHold(ostream
&out
,pkgDepCache
&Dep
)
256 pkgCache::PkgIterator I
= Dep
.PkgBegin();
258 for (;I
.end() != true; I
++)
260 if (Dep
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
261 I
->SelectedState
== pkgCache::State::Hold
)
262 List
+= string(I
.Name()) + " ";
265 return ShowList(out
,"The following held packages will be changed:",List
);
268 // ShowEssential - Show an essential package warning /*{{{*/
269 // ---------------------------------------------------------------------
270 /* This prints out a warning message that is not to be ignored. It shows
271 all essential packages and their dependents that are to be removed.
272 It is insanely risky to remove the dependents of an essential package! */
273 bool ShowEssential(ostream
&out
,pkgDepCache
&Dep
)
275 pkgCache::PkgIterator I
= Dep
.PkgBegin();
277 bool *Added
= new bool[Dep
.HeaderP
->PackageCount
];
278 for (unsigned int I
= 0; I
!= Dep
.HeaderP
->PackageCount
; I
++)
281 for (;I
.end() != true; I
++)
283 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
286 // The essential package is being removed
287 if (Dep
[I
].Delete() == true)
289 if (Added
[I
->ID
] == false)
292 List
+= string(I
.Name()) + " ";
296 if (I
->CurrentVer
== 0)
299 // Print out any essential package depenendents that are to be removed
300 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
302 // Skip everything but depends
303 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
304 D
->Type
!= pkgCache::Dep::Depends
)
307 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
308 if (Dep
[P
].Delete() == true)
310 if (Added
[P
->ID
] == true)
315 sprintf(S
,"%s (due to %s) ",P
.Name(),I
.Name());
322 if (List
.empty() == false)
323 out
<< "WARNING: The following essential packages will be removed" << endl
;
324 return 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)
466 // Show all the various warning indicators
467 ShowDel(c1out
,Cache
);
468 ShowNew(c1out
,Cache
);
470 ShowKept(c1out
,Cache
);
471 Fail
|= !ShowHold(c1out
,Cache
);
472 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
473 ShowUpgraded(c1out
,Cache
);
474 Fail
|= !ShowEssential(c1out
,Cache
);
478 if (Cache
->BrokenCount() != 0)
480 ShowBroken(c1out
,Cache
);
481 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
484 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
485 Cache
->BadCount() == 0)
488 // Run the simulator ..
489 if (_config
->FindB("APT::Get::Simulate") == true)
491 pkgSimulate
PM(Cache
);
492 return PM
.DoInstall();
495 // Create the text record parser
496 pkgRecords
Recs(Cache
);
497 if (_error
->PendingError() == true)
500 // Lock the archive directory
501 if (_config
->FindB("Debug::NoLocking",false) == false)
503 FileFd
Lock(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
504 if (_error
->PendingError() == true)
505 return _error
->Error("Unable to lock the download directory");
508 // Create the download object
509 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
510 pkgAcquire
Fetcher(&Stat
);
512 // Read the source list
514 if (List
.ReadMainList() == false)
515 return _error
->Error("The list of sources could not be read.");
517 // Create the package manager and prepare to download
519 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false)
522 // Display statistics
523 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
524 unsigned long DebBytes
= Fetcher
.TotalNeeded();
525 if (DebBytes
!= Cache
->DebSize())
527 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
528 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
532 c2out
<< "Need to get ";
533 if (DebBytes
!= FetchBytes
)
534 c2out
<< SizeToStr(FetchBytes
) << '/' << SizeToStr(DebBytes
);
536 c2out
<< SizeToStr(DebBytes
);
538 c1out
<< " of archives. After unpacking ";
541 if (Cache
->UsrSize() >= 0)
542 c2out
<< SizeToStr(Cache
->UsrSize()) << " will be used." << endl
;
544 c2out
<< SizeToStr(-1*Cache
->UsrSize()) << " will be freed." << endl
;
546 if (_error
->PendingError() == true)
550 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
552 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
553 return _error
->Error("There are problems and -y was used without --force-yes");
556 // Prompt to continue
559 if (_config
->FindI("quiet",0) < 2 ||
560 _config
->FindB("APT::Get::Assume-Yes",false) == false)
561 c2out
<< "Do you want to continue? [Y/n] " << flush
;
563 if (YnPrompt() == false)
568 if (Fetcher
.Run() == false)
573 bool Transient
= false;
574 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
576 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
577 (*I
)->Complete
== true)
580 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
587 cerr
<< "Failed to fetch " << (*I
)->Describe() << endl
;
588 cerr
<< " " << (*I
)->ErrorText
<< endl
;
592 if (_config
->FindB("APT::Get::Download-Only",false) == true)
595 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
597 if (Transient
== true)
599 c2out
<< "Upgrading with disk swapping is not supported in this version." << endl
;
600 c2out
<< "Try running multiple times with --fix-missing" << endl
;
603 return _error
->Error("Unable to fetch some archives, maybe try with --fix-missing?");
606 // Try to deal with missing package files
607 if (PM
.FixMissing() == false)
609 cerr
<< "Unable to correct missing packages." << endl
;
610 return _error
->Error("Aborting Install.");
614 return PM
.DoInstall();
618 // DoUpdate - Update the package lists /*{{{*/
619 // ---------------------------------------------------------------------
621 bool DoUpdate(CommandLine
&)
623 // Get the source list
625 if (List
.ReadMainList() == false)
628 // Lock the list directory
629 if (_config
->FindB("Debug::NoLocking",false) == false)
631 FileFd
Lock(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
632 if (_error
->PendingError() == true)
633 return _error
->Error("Unable to lock the list directory");
636 // Create the download object
637 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
638 pkgAcquire
Fetcher(&Stat
);
640 // Populate it with the source selection
641 pkgSourceList::const_iterator I
;
642 for (I
= List
.begin(); I
!= List
.end(); I
++)
644 new pkgAcqIndex(&Fetcher
,I
);
645 if (_error
->PendingError() == true)
650 if (Fetcher
.Run() == false)
653 // Clean out any old list files
654 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
655 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
658 // Prepare the cache.
660 if (Cache
.Open() == false)
666 // DoUpgrade - Upgrade all packages /*{{{*/
667 // ---------------------------------------------------------------------
668 /* Upgrade all packages without installing new packages or erasing old
670 bool DoUpgrade(CommandLine
&CmdL
)
673 if (Cache
.Open() == false)
677 if (pkgAllUpgrade(Cache
) == false)
679 ShowBroken(c1out
,Cache
);
680 return _error
->Error("Internal Error, AllUpgrade broke stuff");
683 return InstallPackages(Cache
,true);
686 // DoInstall - Install packages from the command line /*{{{*/
687 // ---------------------------------------------------------------------
688 /* Install named packages */
689 bool DoInstall(CommandLine
&CmdL
)
692 if (Cache
.Open() == false)
695 unsigned int ExpectedInst
= 0;
696 unsigned int Packages
= 0;
697 pkgProblemResolver
Fix(Cache
);
699 bool DefRemove
= false;
700 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
703 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
705 // Duplicate the string
706 unsigned int Length
= strlen(*I
);
708 if (Length
>= sizeof(S
))
712 // See if we are removing the package
713 bool Remove
= DefRemove
;
714 if (Cache
->FindPkg(S
).end() == true)
716 // Handle an optional end tag indicating what to do
717 if (S
[Length
- 1] == '-')
722 if (S
[Length
- 1] == '+')
729 // Locate the package
730 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
732 if (Pkg
.end() == true)
733 return _error
->Error("Couldn't find package %s",S
);
735 // Handle the no-upgrade case
736 if (_config
->FindB("APT::Get::no-upgrade",false) == true &&
737 Pkg
->CurrentVer
!= 0)
739 c1out
<< "Skipping " << Pkg
.Name() << ", it is already installed and no-upgrade is set." << endl
;
743 // Check if there is something new to install
744 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
745 if (State
.CandidateVer
== 0)
747 if (Pkg
->ProvidesList
!= 0)
749 c1out
<< "Package " << S
<< " is a virtual package provided by:" << endl
;
751 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
752 for (; I
.end() == false; I
++)
754 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
756 if ((*Cache
)[Pkg
].CandidateVerIter(*Cache
) == I
.OwnerVer())
757 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
759 if ((*Cache
)[Pkg
].InstVerIter(*Cache
) == I
.OwnerVer())
760 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
761 " [Installed]"<< endl
;
763 c1out
<< "You should explicly select one to install." << endl
;
767 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
768 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
769 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
772 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
773 for (; Dep
.end() == false; Dep
++)
775 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
777 List
+= string(Dep
.ParentPkg().Name()) + " ";
779 ShowList(c1out
,"However the following packages replace it:",List
);
782 return _error
->Error("Package %s has no installation candidate",S
);
789 Cache
->MarkDelete(Pkg
);
794 Cache
->MarkInstall(Pkg
,false);
795 if (State
.Install() == false)
796 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
800 // Install it with autoinstalling enabled.
801 if (State
.InstBroken() == true)
802 Cache
->MarkInstall(Pkg
,true);
805 // Call the scored problem resolver
806 Fix
.InstallProtect();
807 if (Fix
.Resolve(true) == false)
810 // Now we check the state of the packages,
811 if (Cache
->BrokenCount() != 0)
813 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
814 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
815 c1out
<< "distribution that some required packages have not yet been created" << endl
;
816 c1out
<< "or been moved out of Incoming." << endl
;
820 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
821 c1out
<< "the package is simply not installable and a bug report against" << endl
;
822 c1out
<< "that package should be filed." << endl
;
825 c1out
<< "The following information may help to resolve the situation:" << endl
;
827 ShowBroken(c1out
,Cache
);
828 return _error
->Error("Sorry, broken packages");
831 /* Print out a list of packages that are going to be installed extra
832 to what the user asked */
833 if (Cache
->InstCount() != ExpectedInst
)
836 pkgCache::PkgIterator I
= Cache
->PkgBegin();
837 for (;I
.end() != true; I
++)
839 if ((*Cache
)[I
].Install() == false)
843 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
844 if (strcmp(*J
,I
.Name()) == 0)
848 List
+= string(I
.Name()) + " ";
851 ShowList(c1out
,"The following extra packages will be installed:",List
);
854 // See if we need to prompt
855 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
856 return InstallPackages(Cache
,false,false);
858 return InstallPackages(Cache
,false);
861 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
862 // ---------------------------------------------------------------------
863 /* Intelligent upgrader that will install and remove packages at will */
864 bool DoDistUpgrade(CommandLine
&CmdL
)
867 if (Cache
.Open() == false)
870 c0out
<< "Calculating Upgrade... " << flush
;
871 if (pkgDistUpgrade(*Cache
) == false)
873 c0out
<< "Failed" << endl
;
874 ShowBroken(c1out
,Cache
);
878 c0out
<< "Done" << endl
;
880 return InstallPackages(Cache
,true);
883 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
884 // ---------------------------------------------------------------------
885 /* Follows dselect's selections */
886 bool DoDSelectUpgrade(CommandLine
&CmdL
)
889 if (Cache
.Open() == false)
892 // Install everything with the install flag set
893 pkgCache::PkgIterator I
= Cache
->PkgBegin();
894 for (;I
.end() != true; I
++)
896 /* Install the package only if it is a new install, the autoupgrader
897 will deal with the rest */
898 if (I
->SelectedState
== pkgCache::State::Install
)
899 Cache
->MarkInstall(I
,false);
902 /* Now install their deps too, if we do this above then order of
903 the status file is significant for | groups */
904 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
906 /* Install the package only if it is a new install, the autoupgrader
907 will deal with the rest */
908 if (I
->SelectedState
== pkgCache::State::Install
)
909 Cache
->MarkInstall(I
);
912 // Apply erasures now, they override everything else.
913 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
916 if (I
->SelectedState
== pkgCache::State::DeInstall
||
917 I
->SelectedState
== pkgCache::State::Purge
)
918 Cache
->MarkDelete(I
);
921 /* Use updates smart upgrade to do the rest, it will automatically
923 if (pkgAllUpgrade(Cache
) == false)
925 ShowBroken(c1out
,Cache
);
926 return _error
->Error("Internal Error, AllUpgrade broke stuff");
929 return InstallPackages(Cache
,false);
932 // DoClean - Remove download archives /*{{{*/
933 // ---------------------------------------------------------------------
935 bool DoClean(CommandLine
&CmdL
)
938 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
939 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
943 // DoCheck - Perform the check operation /*{{{*/
944 // ---------------------------------------------------------------------
945 /* Opening automatically checks the system, this command is mostly used
947 bool DoCheck(CommandLine
&CmdL
)
956 // ShowHelp - Show a help screen /*{{{*/
957 // ---------------------------------------------------------------------
961 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
962 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
964 cout
<< "Usage: apt-get [options] command" << endl
;
965 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
967 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
968 cout
<< "installing packages. The most frequently used commands are update" << endl
;
969 cout
<< "and install." << endl
;
971 cout
<< "Commands:" << endl
;
972 cout
<< " update - Retrieve new lists of packages" << endl
;
973 cout
<< " upgrade - Perform an upgrade" << endl
;
974 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
975 cout
<< " remove - Remove packages" << endl
;
976 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
977 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
978 cout
<< " clean - Erase downloaded archive files" << endl
;
979 cout
<< " check - Verify that there are no broken dependencies" << endl
;
981 cout
<< "Options:" << endl
;
982 cout
<< " -h This help text." << endl
;
983 cout
<< " -q Loggable output - no progress indicator" << endl
;
984 cout
<< " -qq No output except for errors" << endl
;
985 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
986 cout
<< " -s No-act. Perform ordering simulation" << endl
;
987 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
988 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
989 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
990 cout
<< " -u Show a list of upgraded packages as well" << endl
;
991 cout
<< " -c=? Read this configuration file" << endl
;
992 cout
<< " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl
;
993 cout
<< "See the apt-get(8), sources.list(8) and apt.conf(8) manual" << endl
;
994 cout
<< "pages for more information." << endl
;
998 // GetInitialize - Initialize things for apt-get /*{{{*/
999 // ---------------------------------------------------------------------
1001 void GetInitialize()
1003 _config
->Set("quiet",0);
1004 _config
->Set("help",false);
1005 _config
->Set("APT::Get::Download-Only",false);
1006 _config
->Set("APT::Get::Simulate",false);
1007 _config
->Set("APT::Get::Assume-Yes",false);
1008 _config
->Set("APT::Get::Fix-Broken",false);
1009 _config
->Set("APT::Get::Force-Yes",false);
1012 // SigWinch - Window size change signal handler /*{{{*/
1013 // ---------------------------------------------------------------------
1017 // Riped from GNU ls
1021 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
1022 ScreenWidth
= ws
.ws_col
- 1;
1027 int main(int argc
,const char *argv
[])
1029 CommandLine::Args Args
[] = {
1030 {'h',"help","help",0},
1031 {'q',"quiet","quiet",CommandLine::IntLevel
},
1032 {'q',"silent","quiet",CommandLine::IntLevel
},
1033 {'d',"download-only","APT::Get::Download-Only",0},
1034 {'s',"simulate","APT::Get::Simulate",0},
1035 {'s',"just-print","APT::Get::Simulate",0},
1036 {'s',"recon","APT::Get::Simulate",0},
1037 {'s',"no-act","APT::Get::Simulate",0},
1038 {'y',"yes","APT::Get::Assume-Yes",0},
1039 {'y',"assume-yes","APT::Get::Assume-Yes",0},
1040 {'f',"fix-broken","APT::Get::Fix-Broken",0},
1041 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
1042 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
1043 {0,"fix-missing","APT::Get::Fix-Missing",0},
1044 {0,"ignore-hold","APT::Ingore-Hold",0},
1045 {0,"no-upgrade","APT::Get::no-upgrade",0},
1046 {0,"force-yes","APT::Get::force-yes",0},
1047 {'c',"config-file",0,CommandLine::ConfigFile
},
1048 {'o',"option",0,CommandLine::ArbItem
},
1050 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
1051 {"upgrade",&DoUpgrade
},
1052 {"install",&DoInstall
},
1053 {"remove",&DoInstall
},
1054 {"dist-upgrade",&DoDistUpgrade
},
1055 {"dselect-upgrade",&DoDSelectUpgrade
},
1060 // Parse the command line and initialize the package library
1061 CommandLine
CmdL(Args
,_config
);
1062 if (pkgInitialize(*_config
) == false ||
1063 CmdL
.Parse(argc
,argv
) == false)
1065 _error
->DumpErrors();
1069 // See if the help should be shown
1070 if (_config
->FindB("help") == true ||
1071 CmdL
.FileSize() == 0)
1074 // Setup the output streams
1075 c0out
.rdbuf(cout
.rdbuf());
1076 c1out
.rdbuf(cout
.rdbuf());
1077 c2out
.rdbuf(cout
.rdbuf());
1078 if (_config
->FindI("quiet",0) > 0)
1079 c0out
.rdbuf(devnull
.rdbuf());
1080 if (_config
->FindI("quiet",0) > 1)
1081 c1out
.rdbuf(devnull
.rdbuf());
1083 // Setup the signals
1084 signal(SIGPIPE
,SIG_IGN
);
1085 signal(SIGWINCH
,SigWinch
);
1088 // Match the operation
1089 CmdL
.DispatchArg(Cmds
);
1091 // Print any errors or warnings found during parsing
1092 if (_error
->empty() == false)
1094 bool Errors
= _error
->PendingError();
1095 _error
->DumpErrors();
1097 cout
<< "Returning 100." << endl
;
1098 return Errors
== true?100:0;