]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
279a0c4ed2298a231b41fe951efc349d42581c98
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.16 1998/11/22 23:37:07 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>
41 #include "acqprogress.h"
45 #include <sys/ioctl.h>
53 ofstream
devnull("/dev/null");
54 unsigned int ScreenWidth
= 80;
56 // YnPrompt - Yes No Prompt. /*{{{*/
57 // ---------------------------------------------------------------------
58 /* Returns true on a Yes.*/
61 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
69 read(STDIN_FILENO
,&C
,1);
70 while (C
!= '\n' && Jnk
!= '\n') read(STDIN_FILENO
,&Jnk
,1);
72 if (!(C
== 'Y' || C
== 'y' || C
== '\n' || C
== '\r'))
77 // ShowList - Show a list /*{{{*/
78 // ---------------------------------------------------------------------
79 /* This prints out a string of space seperated words with a title and
80 a two space indent line wraped to the current screen width. */
81 void ShowList(ostream
&out
,string Title
,string List
)
83 if (List
.empty() == true)
86 // Acount for the leading space
87 int ScreenWidth
= ::ScreenWidth
- 3;
90 string::size_type Start
= 0;
91 while (Start
< List
.size())
93 string::size_type End
;
94 if (Start
+ ScreenWidth
>= List
.size())
97 End
= List
.rfind(' ',Start
+ScreenWidth
);
99 if (End
== string::npos
|| End
< Start
)
100 End
= Start
+ ScreenWidth
;
101 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
106 // ShowBroken - Debugging aide /*{{{*/
107 // ---------------------------------------------------------------------
108 /* This prints out the names of all the packages that are broken along
109 with the name of each each broken dependency and a quite version
111 void ShowBroken(ostream
&out
,pkgDepCache
&Cache
)
113 out
<< "Sorry, but the following packages have unmet dependencies:" << endl
;
114 pkgCache::PkgIterator I
= Cache
.PkgBegin();
115 for (;I
.end() != true; I
++)
117 if (Cache
[I
].InstBroken() == false)
120 // Print out each package and the failed dependencies
121 out
<<" " << I
.Name() << ":";
122 int Indent
= strlen(I
.Name()) + 3;
124 if (Cache
[I
].InstVerIter(Cache
).end() == true)
130 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
132 // Compute a single dependency element (glob or)
133 pkgCache::DepIterator Start
;
134 pkgCache::DepIterator End
;
137 if (Cache
.IsImportantDep(End
) == false ||
138 (Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
142 for (int J
= 0; J
!= Indent
; J
++)
146 cout
<< ' ' << End
.DepType() << ": " << End
.TargetPkg().Name();
148 // Show a quick summary of the version requirements
149 if (End
.TargetVer() != 0)
150 out
<< " (" << End
.CompType() << " " << End
.TargetVer() <<
153 /* Show a summary of the target package if possible. In the case
154 of virtual packages we show nothing */
156 pkgCache::PkgIterator Targ
= End
.TargetPkg();
157 if (Targ
->ProvidesList
== 0)
160 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
161 if (Ver
.end() == false)
162 out
<< Ver
.VerStr() << " is installed";
165 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
167 if (Targ
->ProvidesList
== 0)
168 out
<< "it is not installable";
170 out
<< "it is a virtual package";
173 out
<< "it is not installed";
182 // ShowNew - Show packages to newly install /*{{{*/
183 // ---------------------------------------------------------------------
185 void ShowNew(ostream
&out
,pkgDepCache
&Dep
)
187 /* Print out a list of packages that are going to be removed extra
188 to what the user asked */
189 pkgCache::PkgIterator I
= Dep
.PkgBegin();
191 for (;I
.end() != true; I
++)
192 if (Dep
[I
].NewInstall() == true)
193 List
+= string(I
.Name()) + " ";
194 ShowList(out
,"The following NEW packages will be installed:",List
);
197 // ShowDel - Show packages to delete /*{{{*/
198 // ---------------------------------------------------------------------
200 void ShowDel(ostream
&out
,pkgDepCache
&Dep
)
202 /* Print out a list of packages that are going to be removed extra
203 to what the user asked */
204 pkgCache::PkgIterator I
= Dep
.PkgBegin();
206 for (;I
.end() != true; I
++)
207 if (Dep
[I
].Delete() == true)
208 List
+= string(I
.Name()) + " ";
209 ShowList(out
,"The following packages will be REMOVED:",List
);
212 // ShowKept - Show kept packages /*{{{*/
213 // ---------------------------------------------------------------------
215 void ShowKept(ostream
&out
,pkgDepCache
&Dep
)
217 pkgCache::PkgIterator I
= Dep
.PkgBegin();
219 for (;I
.end() != true; I
++)
222 if (Dep
[I
].Upgrade() == true || Dep
[I
].Upgradable() == false ||
223 I
->CurrentVer
== 0 || Dep
[I
].Delete() == true)
226 List
+= string(I
.Name()) + " ";
228 ShowList(out
,"The following packages have been kept back",List
);
231 // ShowUpgraded - Show upgraded packages /*{{{*/
232 // ---------------------------------------------------------------------
234 void ShowUpgraded(ostream
&out
,pkgDepCache
&Dep
)
236 pkgCache::PkgIterator I
= Dep
.PkgBegin();
238 for (;I
.end() != true; I
++)
241 if (Dep
[I
].Upgrade() == false || Dep
[I
].NewInstall() == true)
244 List
+= string(I
.Name()) + " ";
246 ShowList(out
,"The following packages will be upgraded",List
);
249 // ShowHold - Show held but changed packages /*{{{*/
250 // ---------------------------------------------------------------------
252 void ShowHold(ostream
&out
,pkgDepCache
&Dep
)
254 pkgCache::PkgIterator I
= Dep
.PkgBegin();
256 for (;I
.end() != true; I
++)
258 if (Dep
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
259 I
->SelectedState
== pkgCache::State::Hold
)
260 List
+= string(I
.Name()) + " ";
263 ShowList(out
,"The following held packages will be changed:",List
);
266 // ShowEssential - Show an essential package warning /*{{{*/
267 // ---------------------------------------------------------------------
268 /* This prints out a warning message that is not to be ignored. It shows
269 all essential packages and their dependents that are to be removed.
270 It is insanely risky to remove the dependents of an essential package! */
271 void ShowEssential(ostream
&out
,pkgDepCache
&Dep
)
273 pkgCache::PkgIterator I
= Dep
.PkgBegin();
275 bool *Added
= new bool[Dep
.HeaderP
->PackageCount
];
276 for (unsigned int I
= 0; I
!= Dep
.HeaderP
->PackageCount
; I
++)
279 for (;I
.end() != true; I
++)
281 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
284 // The essential package is being removed
285 if (Dep
[I
].Delete() == true)
287 if (Added
[I
->ID
] == false)
290 List
+= string(I
.Name()) + " ";
294 if (I
->CurrentVer
== 0)
297 // Print out any essential package depenendents that are to be removed
298 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
300 // Skip everything but depends
301 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
302 D
->Type
!= pkgCache::Dep::Depends
)
305 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
306 if (Dep
[P
].Delete() == true)
308 if (Added
[P
->ID
] == true)
313 sprintf(S
,"%s (due to %s) ",P
.Name(),I
.Name());
319 if (List
.empty() == false)
320 out
<< "WARNING: The following essential packages will be removed" << endl
;
321 ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
326 // Stats - Show some statistics /*{{{*/
327 // ---------------------------------------------------------------------
329 void Stats(ostream
&out
,pkgDepCache
&Dep
)
331 unsigned long Upgrade
= 0;
332 unsigned long Install
= 0;
333 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
335 if (Dep
[I
].NewInstall() == true)
338 if (Dep
[I
].Upgrade() == true)
342 out
<< Upgrade
<< " packages upgraded, " <<
343 Install
<< " newly installed, " <<
344 Dep
.DelCount() << " to remove and " <<
345 Dep
.KeepCount() << " not upgraded." << endl
;
347 if (Dep
.BadCount() != 0)
348 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
352 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
353 // ---------------------------------------------------------------------
363 inline operator pkgDepCache
&() {return *Cache
;};
364 inline pkgDepCache
*operator ->() {return Cache
;};
365 inline pkgDepCache
&operator *() {return *Cache
;};
368 CacheFile() : File(0), Map(0), Cache(0) {};
377 // CacheFile::Open - Open the cache file /*{{{*/
378 // ---------------------------------------------------------------------
379 /* This routine generates the caches and then opens the dependency cache
380 and verifies that the system is OK. */
381 bool CacheFile::Open()
383 // Create a progress class
384 OpTextProgress
Progress(*_config
);
386 // Read the source list
388 if (List
.ReadMainList() == false)
389 return _error
->Error("The list of sources could not be read.");
391 // Build all of the caches
392 pkgMakeStatusCache(List
,Progress
);
393 if (_error
->PendingError() == true)
394 return _error
->Error("The package lists or status file could not be parsed or opened.");
398 // Open the cache file
399 File
= new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly
);
400 if (_error
->PendingError() == true)
403 Map
= new MMap(*File
,MMap::Public
| MMap::ReadOnly
);
404 if (_error
->PendingError() == true)
407 Cache
= new pkgDepCache(*Map
,Progress
);
408 if (_error
->PendingError() == true)
413 // Check that the system is OK
414 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
415 return _error
->Error("Internal Error, non-zero counts");
417 // Apply corrections for half-installed packages
418 if (pkgApplyStatus(*Cache
) == false)
422 if (Cache
->BrokenCount() == 0)
425 // Attempt to fix broken things
426 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
428 c1out
<< "Correcting dependencies..." << flush
;
429 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
431 c1out
<< " failed." << endl
;
432 ShowBroken(c1out
,*this);
434 return _error
->Error("Unable to correct dependencies");
436 if (pkgMinimizeUpgrade(*Cache
) == false)
437 return _error
->Error("Unable to minimize the upgrade set");
439 c1out
<< " Done" << endl
;
443 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
444 ShowBroken(c1out
,*this);
446 return _error
->Error("Unmet dependencies. Try using -f.");
453 // InstallPackages - Actually download and install the packages /*{{{*/
454 // ---------------------------------------------------------------------
455 /* This displays the informative messages describing what is going to
456 happen and then calls the download routines */
457 bool InstallPackages(pkgDepCache
&Cache
,bool ShwKept
,bool Ask
= true)
459 // Show all the various warning indicators
460 ShowDel(c1out
,Cache
);
461 ShowNew(c1out
,Cache
);
463 ShowKept(c1out
,Cache
);
464 ShowHold(c1out
,Cache
);
465 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
466 ShowUpgraded(c1out
,Cache
);
467 ShowEssential(c1out
,Cache
);
471 if (Cache
.BrokenCount() != 0)
473 ShowBroken(c1out
,Cache
);
474 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
477 if (Cache
.DelCount() == 0 && Cache
.InstCount() == 0 &&
478 Cache
.BadCount() == 0)
481 // Run the simulator ..
482 if (_config
->FindB("APT::Get::Simulate") == true)
484 pkgSimulate
PM(Cache
);
485 return PM
.DoInstall();
488 // Create the text record parser
489 pkgRecords
Recs(Cache
);
491 // Create the download object
492 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
493 pkgAcquire
Fetcher(&Stat
);
495 // Read the source list
497 if (List
.ReadMainList() == false)
498 return _error
->Error("The list of sources could not be read.");
500 // Create the package manager and prepare to download
502 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false)
505 // Display statistics
506 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
507 unsigned long DebBytes
= Fetcher
.TotalNeeded();
508 if (DebBytes
!= Cache
.DebSize())
509 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
512 c1out
<< "Need to get ";
513 if (DebBytes
!= FetchBytes
)
514 c1out
<< SizeToStr(FetchBytes
) << '/' << SizeToStr(DebBytes
);
516 c1out
<< SizeToStr(DebBytes
);
518 c1out
<< " of archives. After unpacking ";
521 if (Cache
.UsrSize() >= 0)
522 c1out
<< SizeToStr(Cache
.UsrSize()) << " will be used." << endl
;
524 c1out
<< SizeToStr(-1*Cache
.UsrSize()) << " will be freed." << endl
;
526 if (_error
->PendingError() == true)
529 // Prompt to continue
532 if (_config
->FindI("quiet",0) < 2 ||
533 _config
->FindB("APT::Get::Assume-Yes",false) == false)
534 c2out
<< "Do you want to continue? [Y/n] " << flush
;
535 if (YnPrompt() == false)
540 if (Fetcher
.Run() == false)
545 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
547 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
548 (*I
)->Complete
== true)
551 cerr
<< "Failed to fetch " << (*I
)->Describe() << endl
;
552 cerr
<< " " << (*I
)->ErrorText
<< endl
;
556 if (Failed
== true && _config
->FindB("APT::Fix-Missing",false) == false)
557 return _error
->Error("Unable to fetch some archives, maybe try with --fix-missing?");
559 // Try to deal with missing package files
560 /* if (PM.FixMissing() == false)
562 cerr << "Unable to correct missing packages." << endl;
563 return _error->Error("Aborting Install.");
566 return PM
.DoInstall();
570 // DoUpdate - Update the package lists /*{{{*/
571 // ---------------------------------------------------------------------
573 bool DoUpdate(CommandLine
&)
575 // Get the source list
577 if (List
.ReadMainList() == false)
580 // Create the download object
581 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
582 pkgAcquire
Fetcher(&Stat
);
584 // Populate it with the source selection
585 pkgSourceList::const_iterator I
;
586 for (I
= List
.begin(); I
!= List
.end(); I
++)
588 new pkgAcqIndex(&Fetcher
,I
);
589 if (_error
->PendingError() == true)
594 if (Fetcher
.Run() == false)
597 // Clean out any old list files
598 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
599 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
602 // Prepare the cache.
604 if (Cache
.Open() == false)
610 // DoUpgrade - Upgrade all packages /*{{{*/
611 // ---------------------------------------------------------------------
612 /* Upgrade all packages without installing new packages or erasing old
614 bool DoUpgrade(CommandLine
&CmdL
)
617 if (Cache
.Open() == false)
621 if (pkgAllUpgrade(Cache
) == false)
623 ShowBroken(c1out
,Cache
);
624 return _error
->Error("Internal Error, AllUpgrade broke stuff");
627 return InstallPackages(Cache
,true);
630 // DoInstall - Install packages from the command line /*{{{*/
631 // ---------------------------------------------------------------------
632 /* Install named packages */
633 bool DoInstall(CommandLine
&CmdL
)
636 if (Cache
.Open() == false)
639 unsigned int ExpectedInst
= 0;
640 unsigned int Packages
= 0;
641 pkgProblemResolver
Fix(Cache
);
643 bool DefRemove
= false;
644 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
647 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
649 // Duplicate the string
650 unsigned int Length
= strlen(*I
);
652 if (Length
>= sizeof(S
))
656 // See if we are removing the package
657 bool Remove
= DefRemove
;
658 if (Cache
->FindPkg(S
).end() == true)
660 // Handle an optional end tag indicating what to do
661 if (S
[Length
- 1] == '-')
666 if (S
[Length
- 1] == '+')
673 // Locate the package
674 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
676 if (Pkg
.end() == true)
677 return _error
->Error("Couldn't find package %s",S
);
679 // Handle the no-upgrade case
680 if (_config
->FindB("APT::Get::no-upgrade",false) == true &&
681 Pkg
->CurrentVer
!= 0)
683 c1out
<< "Skipping " << Pkg
.Name() << ", it is already installed and no-upgrade is set." << endl
;
687 // Check if there is something new to install
688 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
689 if (State
.CandidateVer
== 0)
691 if (Pkg
->ProvidesList
!= 0)
693 c1out
<< "Package " << S
<< " is a virtual package provided by:" << endl
;
695 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
696 for (; I
.end() == false; I
++)
698 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
700 if ((*Cache
)[Pkg
].CandidateVerIter(*Cache
) == I
.OwnerVer())
701 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
703 if ((*Cache
)[Pkg
].InstVerIter(*Cache
) == I
.OwnerVer())
704 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
705 " [Installed]"<< endl
;
707 c1out
<< "You should explicly select one to install." << endl
;
711 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
712 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
713 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
716 return _error
->Error("Package %s has no installation candidate",S
);
723 Cache
->MarkDelete(Pkg
);
728 Cache
->MarkInstall(Pkg
,false);
729 if (State
.Install() == false)
730 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
734 // Install it with autoinstalling enabled.
735 if (State
.InstBroken() == true)
736 Cache
->MarkInstall(Pkg
,true);
739 // Call the scored problem resolver
740 Fix
.InstallProtect();
741 if (Fix
.Resolve(true) == false)
744 // Now we check the state of the packages,
745 if (Cache
->BrokenCount() != 0)
747 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
748 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
749 c1out
<< "distribution that some required packages have not yet been created" << endl
;
750 c1out
<< "or been moved out of Incoming." << endl
;
754 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
755 c1out
<< "the package is simply not installable and a bug report against" << endl
;
756 c1out
<< "that package should be filed." << endl
;
759 c1out
<< "The following information may help to resolve the situation:" << endl
;
761 ShowBroken(c1out
,Cache
);
762 return _error
->Error("Sorry, broken packages");
765 /* Print out a list of packages that are going to be installed extra
766 to what the user asked */
767 if (Cache
->InstCount() != ExpectedInst
)
770 pkgCache::PkgIterator I
= Cache
->PkgBegin();
771 for (;I
.end() != true; I
++)
773 if ((*Cache
)[I
].Install() == false)
777 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
778 if (strcmp(*J
,I
.Name()) == 0)
782 List
+= string(I
.Name()) + " ";
785 ShowList(c1out
,"The following extra packages will be installed:",List
);
788 // See if we need to prompt
789 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
790 return InstallPackages(Cache
,false,false);
792 return InstallPackages(Cache
,false);
795 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
796 // ---------------------------------------------------------------------
797 /* Intelligent upgrader that will install and remove packages at will */
798 bool DoDistUpgrade(CommandLine
&CmdL
)
801 if (Cache
.Open() == false)
804 c0out
<< "Calculating Upgrade... " << flush
;
805 if (pkgDistUpgrade(*Cache
) == false)
807 c0out
<< "Failed" << endl
;
808 ShowBroken(c1out
,Cache
);
812 c0out
<< "Done" << endl
;
814 return InstallPackages(Cache
,true);
817 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
818 // ---------------------------------------------------------------------
819 /* Follows dselect's selections */
820 bool DoDSelectUpgrade(CommandLine
&CmdL
)
823 if (Cache
.Open() == false)
826 // Install everything with the install flag set
827 pkgCache::PkgIterator I
= Cache
->PkgBegin();
828 for (;I
.end() != true; I
++)
830 /* Install the package only if it is a new install, the autoupgrader
831 will deal with the rest */
832 if (I
->SelectedState
== pkgCache::State::Install
)
833 Cache
->MarkInstall(I
,false);
836 /* Now install their deps too, if we do this above then order of
837 the status file is significant for | groups */
838 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
840 /* Install the package only if it is a new install, the autoupgrader
841 will deal with the rest */
842 if (I
->SelectedState
== pkgCache::State::Install
)
843 Cache
->MarkInstall(I
);
846 // Apply erasures now, they override everything else.
847 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
850 if (I
->SelectedState
== pkgCache::State::DeInstall
||
851 I
->SelectedState
== pkgCache::State::Purge
)
852 Cache
->MarkDelete(I
);
855 /* Use updates smart upgrade to do the rest, it will automatically
857 if (pkgAllUpgrade(Cache
) == false)
859 ShowBroken(c1out
,Cache
);
860 return _error
->Error("Internal Error, AllUpgrade broke stuff");
863 return InstallPackages(Cache
,false);
866 // DoClean - Remove download archives /*{{{*/
867 // ---------------------------------------------------------------------
869 bool DoClean(CommandLine
&CmdL
)
872 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
873 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
877 // DoCheck - Perform the check operation /*{{{*/
878 // ---------------------------------------------------------------------
879 /* Opening automatically checks the system, this command is mostly used
881 bool DoCheck(CommandLine
&CmdL
)
890 // ShowHelp - Show a help screen /*{{{*/
891 // ---------------------------------------------------------------------
895 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
896 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
898 cout
<< "Usage: apt-get [options] command" << endl
;
899 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
901 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
902 cout
<< "installing packages. The most frequently used commands are update" << endl
;
903 cout
<< "and install." << endl
;
905 cout
<< "Commands:" << endl
;
906 cout
<< " update - Retrieve new lists of packages" << endl
;
907 cout
<< " upgrade - Perform an upgrade" << endl
;
908 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
909 cout
<< " remove - Remove packages" << endl
;
910 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
911 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
912 cout
<< " clean - Erase downloaded archive files" << endl
;
913 cout
<< " check - Verify that there are no broken dependencies" << endl
;
915 cout
<< "Options:" << endl
;
916 cout
<< " -h This help text." << endl
;
917 cout
<< " -q Loggable output - no progress indicator" << endl
;
918 cout
<< " -qq No output except for errors" << endl
;
919 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
920 cout
<< " -s No-act. Perform ordering simulation" << endl
;
921 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
922 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
923 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
924 cout
<< " -u Show a list of upgraded packages as well" << endl
;
925 cout
<< " -c=? Read this configuration file" << endl
;
926 cout
<< " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl
;
927 cout
<< "See the apt-get(8), sources.list(8) and apt.conf(8) manual" << endl
;
928 cout
<< "pages for more information." << endl
;
932 // GetInitialize - Initialize things for apt-get /*{{{*/
933 // ---------------------------------------------------------------------
937 _config
->Set("quiet",0);
938 _config
->Set("help",false);
939 _config
->Set("APT::Get::Download-Only",false);
940 _config
->Set("APT::Get::Simulate",false);
941 _config
->Set("APT::Get::Assume-Yes",false);
942 _config
->Set("APT::Get::Fix-Broken",false);
945 // SigWinch - Window size change signal handler /*{{{*/
946 // ---------------------------------------------------------------------
954 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
955 ScreenWidth
= ws
.ws_col
- 1;
960 int main(int argc
,const char *argv
[])
962 CommandLine::Args Args
[] = {
963 {'h',"help","help",0},
964 {'q',"quiet","quiet",CommandLine::IntLevel
},
965 {'q',"silent","quiet",CommandLine::IntLevel
},
966 {'d',"download-only","APT::Get::Download-Only",0},
967 {'s',"simulate","APT::Get::Simulate",0},
968 {'s',"just-print","APT::Get::Simulate",0},
969 {'s',"recon","APT::Get::Simulate",0},
970 {'s',"no-act","APT::Get::Simulate",0},
971 {'y',"yes","APT::Get::Assume-Yes",0},
972 {'y',"assume-yes","APT::Get::Assume-Yes",0},
973 {'f',"fix-broken","APT::Get::Fix-Broken",0},
974 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
975 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
976 {0,"fix-missing","APT::Get::Fix-Missing",0},
977 {0,"ignore-hold","APT::Ingore-Hold",0},
978 {0,"no-upgrade","APT::Get::no-upgrade",0},
979 {'c',"config-file",0,CommandLine::ConfigFile
},
980 {'o',"option",0,CommandLine::ArbItem
},
983 // Parse the command line and initialize the package library
984 CommandLine
CmdL(Args
,_config
);
985 if (pkgInitialize(*_config
) == false ||
986 CmdL
.Parse(argc
,argv
) == false)
988 _error
->DumpErrors();
992 // See if the help should be shown
993 if (_config
->FindB("help") == true ||
994 CmdL
.FileSize() == 0)
997 // Setup the output streams
998 c0out
.rdbuf(cout
.rdbuf());
999 c1out
.rdbuf(cout
.rdbuf());
1000 c2out
.rdbuf(cout
.rdbuf());
1001 if (_config
->FindI("quiet",0) > 0)
1002 c0out
.rdbuf(devnull
.rdbuf());
1003 if (_config
->FindI("quiet",0) > 1)
1004 c1out
.rdbuf(devnull
.rdbuf());
1006 // Setup the signals
1007 signal(SIGPIPE
,SIG_IGN
);
1008 signal(SIGWINCH
,SigWinch
);
1011 // Match the operation
1015 bool (*Handler
)(CommandLine
&);
1016 } Map
[] = {{"update",&DoUpdate
},
1017 {"upgrade",&DoUpgrade
},
1018 {"install",&DoInstall
},
1019 {"remove",&DoInstall
},
1020 {"dist-upgrade",&DoDistUpgrade
},
1021 {"dselect-upgrade",&DoDSelectUpgrade
},
1026 for (I
= 0; Map
[I
].Match
!= 0; I
++)
1028 if (strcmp(CmdL
.FileList
[0],Map
[I
].Match
) == 0)
1030 if (Map
[I
].Handler(CmdL
) == false && _error
->PendingError() == false)
1031 _error
->Error("Handler silently failed");
1037 if (Map
[I
].Match
== 0)
1038 _error
->Error("Invalid operation %s", CmdL
.FileList
[0]);
1040 // Print any errors or warnings found during parsing
1041 if (_error
->empty() == false)
1043 bool Errors
= _error
->PendingError();
1044 _error
->DumpErrors();
1046 cout
<< "Returning 100." << endl
;
1047 return Errors
== true?100:0;