1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.81 1999/10/21 06:35:00 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/algorithms.h>
34 #include <apt-pkg/acquire-item.h>
35 #include <apt-pkg/dpkgpm.h>
36 #include <apt-pkg/strutl.h>
37 #include <apt-pkg/clean.h>
38 #include <apt-pkg/srcrecords.h>
39 #include <apt-pkg/version.h>
40 #include <apt-pkg/cachefile.h>
44 #include "acqprogress.h"
48 #include <sys/ioctl.h>
62 ofstream
devnull("/dev/null");
63 unsigned int ScreenWidth
= 80;
65 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
66 // ---------------------------------------------------------------------
68 class CacheFile
: public pkgCacheFile
70 static pkgCache
*SortCache
;
71 static int NameComp(const void *a
,const void *b
);
74 pkgCache::Package
**List
;
77 bool CheckDeps(bool AllowBroken
= false);
78 bool Open(bool WithLock
= true)
80 OpTextProgress
Prog(*_config
);
81 if (pkgCacheFile::Open(Prog
,WithLock
) == false)
86 CacheFile() : List(0) {};
90 // YnPrompt - Yes No Prompt. /*{{{*/
91 // ---------------------------------------------------------------------
92 /* Returns true on a Yes.*/
95 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
103 read(STDIN_FILENO
,&C
,1);
104 while (C
!= '\n' && Jnk
!= '\n') read(STDIN_FILENO
,&Jnk
,1);
106 if (!(C
== 'Y' || C
== 'y' || C
== '\n' || C
== '\r'))
111 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
112 // ---------------------------------------------------------------------
113 /* Returns true on a Yes.*/
114 bool AnalPrompt(const char *Text
)
117 cin
.getline(Buf
,sizeof(Buf
));
118 if (strcmp(Buf
,Text
) == 0)
123 // ShowList - Show a list /*{{{*/
124 // ---------------------------------------------------------------------
125 /* This prints out a string of space seperated words with a title and
126 a two space indent line wraped to the current screen width. */
127 bool ShowList(ostream
&out
,string Title
,string List
)
129 if (List
.empty() == true)
132 // Acount for the leading space
133 int ScreenWidth
= ::ScreenWidth
- 3;
135 out
<< Title
<< endl
;
136 string::size_type Start
= 0;
137 while (Start
< List
.size())
139 string::size_type End
;
140 if (Start
+ ScreenWidth
>= List
.size())
143 End
= List
.rfind(' ',Start
+ScreenWidth
);
145 if (End
== string::npos
|| End
< Start
)
146 End
= Start
+ ScreenWidth
;
147 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
153 // ShowBroken - Debugging aide /*{{{*/
154 // ---------------------------------------------------------------------
155 /* This prints out the names of all the packages that are broken along
156 with the name of each each broken dependency and a quite version
158 void ShowBroken(ostream
&out
,CacheFile
&Cache
,bool Now
)
160 out
<< "Sorry, but the following packages have unmet dependencies:" << endl
;
161 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
163 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
165 if (Cache
[I
].InstBroken() == false)
168 // Print out each package and the failed dependencies
169 out
<<" " << I
.Name() << ":";
170 int Indent
= strlen(I
.Name()) + 3;
172 if (Cache
[I
].InstVerIter(Cache
).end() == true)
178 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
180 // Compute a single dependency element (glob or)
181 pkgCache::DepIterator Start
;
182 pkgCache::DepIterator End
;
185 if (Cache
->IsImportantDep(End
) == false ||
186 (Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
190 for (int J
= 0; J
!= Indent
; J
++)
194 out
<< ' ' << End
.DepType() << ": " << End
.TargetPkg().Name();
196 // Show a quick summary of the version requirements
197 if (End
.TargetVer() != 0)
198 out
<< " (" << End
.CompType() << " " << End
.TargetVer() <<
201 /* Show a summary of the target package if possible. In the case
202 of virtual packages we show nothing */
203 pkgCache::PkgIterator Targ
= End
.TargetPkg();
204 if (Targ
->ProvidesList
== 0)
207 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
208 if (Ver
.end() == false)
209 out
<< Ver
.VerStr() << (Now
?" is installed":" is to be installed");
212 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
214 if (Targ
->ProvidesList
== 0)
215 out
<< "it is not installable";
217 out
<< "it is a virtual package";
220 out
<< (Now
?"it is not installed":"it is not going to be installed");
229 // ShowNew - Show packages to newly install /*{{{*/
230 // ---------------------------------------------------------------------
232 void ShowNew(ostream
&out
,CacheFile
&Cache
)
234 /* Print out a list of packages that are going to be removed extra
235 to what the user asked */
237 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
239 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
240 if (Cache
[I
].NewInstall() == true)
241 List
+= string(I
.Name()) + " ";
244 ShowList(out
,"The following NEW packages will be installed:",List
);
247 // ShowDel - Show packages to delete /*{{{*/
248 // ---------------------------------------------------------------------
250 void ShowDel(ostream
&out
,CacheFile
&Cache
)
252 /* Print out a list of packages that are going to be removed extra
253 to what the user asked */
255 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
257 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
258 if (Cache
[I
].Delete() == true)
260 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
261 List
+= string(I
.Name()) + "* ";
263 List
+= string(I
.Name()) + " ";
267 ShowList(out
,"The following packages will be REMOVED:",List
);
270 // ShowKept - Show kept packages /*{{{*/
271 // ---------------------------------------------------------------------
273 void ShowKept(ostream
&out
,CacheFile
&Cache
)
276 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
278 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
281 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
282 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
285 List
+= string(I
.Name()) + " ";
287 ShowList(out
,"The following packages have been kept back",List
);
290 // ShowUpgraded - Show upgraded packages /*{{{*/
291 // ---------------------------------------------------------------------
293 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
296 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
298 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
301 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
304 List
+= string(I
.Name()) + " ";
306 ShowList(out
,"The following packages will be upgraded",List
);
309 // ShowHold - Show held but changed packages /*{{{*/
310 // ---------------------------------------------------------------------
312 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
315 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
317 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
318 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
319 I
->SelectedState
== pkgCache::State::Hold
)
320 List
+= string(I
.Name()) + " ";
323 return ShowList(out
,"The following held packages will be changed:",List
);
326 // ShowEssential - Show an essential package warning /*{{{*/
327 // ---------------------------------------------------------------------
328 /* This prints out a warning message that is not to be ignored. It shows
329 all essential packages and their dependents that are to be removed.
330 It is insanely risky to remove the dependents of an essential package! */
331 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
334 bool *Added
= new bool[Cache
->HeaderP
->PackageCount
];
335 for (unsigned int I
= 0; I
!= Cache
->HeaderP
->PackageCount
; I
++)
338 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
340 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
341 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
344 // The essential package is being removed
345 if (Cache
[I
].Delete() == true)
347 if (Added
[I
->ID
] == false)
350 List
+= string(I
.Name()) + " ";
354 if (I
->CurrentVer
== 0)
357 // Print out any essential package depenendents that are to be removed
358 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
360 // Skip everything but depends
361 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
362 D
->Type
!= pkgCache::Dep::Depends
)
365 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
366 if (Cache
[P
].Delete() == true)
368 if (Added
[P
->ID
] == true)
373 sprintf(S
,"%s (due to %s) ",P
.Name(),I
.Name());
380 if (List
.empty() == false)
381 out
<< "WARNING: The following essential packages will be removed" << endl
;
382 return ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
385 // Stats - Show some statistics /*{{{*/
386 // ---------------------------------------------------------------------
388 void Stats(ostream
&out
,pkgDepCache
&Dep
)
390 unsigned long Upgrade
= 0;
391 unsigned long Install
= 0;
392 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
394 if (Dep
[I
].NewInstall() == true)
397 if (Dep
[I
].Upgrade() == true)
401 out
<< Upgrade
<< " packages upgraded, " <<
402 Install
<< " newly installed, " <<
403 Dep
.DelCount() << " to remove and " <<
404 Dep
.KeepCount() << " not upgraded." << endl
;
406 if (Dep
.BadCount() != 0)
407 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
411 // CacheFile::NameComp - QSort compare by name /*{{{*/
412 // ---------------------------------------------------------------------
414 pkgCache
*CacheFile::SortCache
= 0;
415 int CacheFile::NameComp(const void *a
,const void *b
)
417 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
418 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
420 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
421 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
423 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
426 // CacheFile::Sort - Sort by name /*{{{*/
427 // ---------------------------------------------------------------------
429 void CacheFile::Sort()
432 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
433 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
434 pkgCache::PkgIterator I
= Cache
->PkgBegin();
435 for (;I
.end() != true; I
++)
439 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
442 // CacheFile::Open - Open the cache file /*{{{*/
443 // ---------------------------------------------------------------------
444 /* This routine generates the caches and then opens the dependency cache
445 and verifies that the system is OK. */
446 bool CacheFile::CheckDeps(bool AllowBroken
)
448 if (_error
->PendingError() == true)
451 // Check that the system is OK
452 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
453 return _error
->Error("Internal Error, non-zero counts");
455 // Apply corrections for half-installed packages
456 if (pkgApplyStatus(*Cache
) == false)
460 if (Cache
->BrokenCount() == 0 || AllowBroken
== true)
463 // Attempt to fix broken things
464 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
466 c1out
<< "Correcting dependencies..." << flush
;
467 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
469 c1out
<< " failed." << endl
;
470 ShowBroken(c1out
,*this,true);
472 return _error
->Error("Unable to correct dependencies");
474 if (pkgMinimizeUpgrade(*Cache
) == false)
475 return _error
->Error("Unable to minimize the upgrade set");
477 c1out
<< " Done" << endl
;
481 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
482 ShowBroken(c1out
,*this,true);
484 return _error
->Error("Unmet dependencies. Try using -f.");
491 // InstallPackages - Actually download and install the packages /*{{{*/
492 // ---------------------------------------------------------------------
493 /* This displays the informative messages describing what is going to
494 happen and then calls the download routines */
495 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,bool Saftey
= true)
497 if (_config
->FindB("APT::Get::Purge",false) == true)
499 pkgCache::PkgIterator I
= Cache
->PkgBegin();
500 for (; I
.end() == false; I
++)
502 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
503 Cache
->MarkDelete(I
,true);
508 bool Essential
= false;
510 // Show all the various warning indicators
511 ShowDel(c1out
,Cache
);
512 ShowNew(c1out
,Cache
);
514 ShowKept(c1out
,Cache
);
515 Fail
|= !ShowHold(c1out
,Cache
);
516 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
517 ShowUpgraded(c1out
,Cache
);
518 Essential
= !ShowEssential(c1out
,Cache
);
523 if (Cache
->BrokenCount() != 0)
525 ShowBroken(c1out
,Cache
,false);
526 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
529 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
530 Cache
->BadCount() == 0)
533 // Run the simulator ..
534 if (_config
->FindB("APT::Get::Simulate") == true)
536 pkgSimulate
PM(Cache
);
537 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
538 if (Res
== pkgPackageManager::Failed
)
540 if (Res
!= pkgPackageManager::Completed
)
541 return _error
->Error("Internal Error, Ordering didn't finish");
545 // Create the text record parser
546 pkgRecords
Recs(Cache
);
547 if (_error
->PendingError() == true)
550 // Lock the archive directory
552 if (_config
->FindB("Debug::NoLocking",false) == false)
554 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
555 if (_error
->PendingError() == true)
556 return _error
->Error("Unable to lock the download directory");
559 // Create the download object
560 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
561 pkgAcquire
Fetcher(&Stat
);
563 // Read the source list
565 if (List
.ReadMainList() == false)
566 return _error
->Error("The list of sources could not be read.");
568 // Create the package manager and prepare to download
570 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false ||
571 _error
->PendingError() == true)
574 // Display statistics
575 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
576 unsigned long FetchPBytes
= Fetcher
.PartialPresent();
577 unsigned long DebBytes
= Fetcher
.TotalNeeded();
578 if (DebBytes
!= Cache
->DebSize())
580 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
581 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
585 c1out
<< "Need to get ";
586 if (DebBytes
!= FetchBytes
)
587 c1out
<< SizeToStr(FetchBytes
) << "B/" << SizeToStr(DebBytes
) << 'B';
589 c1out
<< SizeToStr(DebBytes
) << 'B';
591 c1out
<< " of archives. After unpacking ";
593 // Check for enough free space
595 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
596 if (statfs(OutputDir
.c_str(),&Buf
) != 0)
597 return _error
->Errno("statfs","Couldn't determine free space in %s",
599 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
600 return _error
->Error("Sorry, you don't have enough free space in %s to hold all the .debs.",
604 if (Cache
->UsrSize() >= 0)
605 c1out
<< SizeToStr(Cache
->UsrSize()) << "B will be used." << endl
;
607 c1out
<< SizeToStr(-1*Cache
->UsrSize()) << "B will be freed." << endl
;
609 if (_error
->PendingError() == true)
613 if (_config
->FindI("quiet",0) >= 2 ||
614 _config
->FindB("APT::Get::Assume-Yes",false) == true)
616 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
617 return _error
->Error("There are problems and -y was used without --force-yes");
620 if (Essential
== true && Saftey
== true)
622 c2out
<< "You are about to do something potentially harmful" << endl
;
623 c2out
<< "To continue type in the phrase 'Yes, I understand this may be bad'" << endl
;
624 c2out
<< " ?] " << flush
;
625 if (AnalPrompt("Yes, I understand this may be bad") == false)
627 c2out
<< "Abort." << endl
;
633 // Prompt to continue
634 if (Ask
== true || Fail
== true)
636 if (_config
->FindI("quiet",0) < 2 &&
637 _config
->FindB("APT::Get::Assume-Yes",false) == false)
639 c2out
<< "Do you want to continue? [Y/n] " << flush
;
641 if (YnPrompt() == false)
643 c2out
<< "Abort." << endl
;
650 // Just print out the uris an exit if the --print-uris flag was used
651 if (_config
->FindB("APT::Get::Print-URIs") == true)
653 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
654 for (; I
!= Fetcher
.UriEnd(); I
++)
655 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
656 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
663 if (_config
->FindB("APT::Get::No-Download",false) == false)
664 if (Fetcher
.Run() == pkgAcquire::Failed
)
669 bool Transient
= false;
670 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
672 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
673 (*I
)->Complete
== true)
676 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
683 cerr
<< "Failed to fetch " << (*I
)->DescURI() << endl
;
684 cerr
<< " " << (*I
)->ErrorText
<< endl
;
688 /* If we are in no download mode and missing files then there were
689 'failures' then the user must specify -m. Furthermore, there
690 is no such thing as a transient error in no-download mode! */
691 if (Transient
== true &&
692 _config
->FindB("APT::Get::No-Download",false) == true)
698 if (_config
->FindB("APT::Get::Download-Only",false) == true)
700 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
701 return _error
->Error("Some files failed to download");
705 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
707 return _error
->Error("Unable to fetch some archives, maybe try with --fix-missing?");
710 if (Transient
== true && Failed
== true)
711 return _error
->Error("--fix-missing and media swapping is not currently supported");
713 // Try to deal with missing package files
714 if (Failed
== true && PM
.FixMissing() == false)
716 cerr
<< "Unable to correct missing packages." << endl
;
717 return _error
->Error("Aborting Install.");
721 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
722 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
724 if (Res
== pkgPackageManager::Completed
)
727 // Reload the fetcher object and loop again for media swapping
729 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false)
734 // TryToInstall - Try to install a single package /*{{{*/
735 // ---------------------------------------------------------------------
736 /* This used to be inlined in DoInstall, but with the advent of regex package
737 name matching it was split out.. */
738 bool TryToInstall(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
739 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
740 unsigned int &ExpectedInst
,bool AllowFail
= true)
742 /* This is a pure virtual package and there is a single available
744 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0 &&
745 Pkg
.ProvidesList()->NextProvides
== 0)
747 pkgCache::PkgIterator Tmp
= Pkg
.ProvidesList().OwnerPkg();
748 c1out
<< "Note, installing " << Tmp
.Name() << " instead of " << Pkg
.Name() << endl
;
752 // Handle the no-upgrade case
753 if (_config
->FindB("APT::Get::no-upgrade",false) == true &&
754 Pkg
->CurrentVer
!= 0)
756 if (AllowFail
== true)
757 c1out
<< "Skipping " << Pkg
.Name() << ", it is already installed and no-upgrade is set." << endl
;
761 // Check if there is something at all to install
762 pkgDepCache::StateCache
&State
= Cache
[Pkg
];
763 if (State
.CandidateVer
== 0)
765 if (AllowFail
== false)
768 if (Pkg
->ProvidesList
!= 0)
770 c1out
<< "Package " << Pkg
.Name() << " is a virtual package provided by:" << endl
;
772 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
773 for (; I
.end() == false; I
++)
775 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
777 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer())
779 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
780 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
781 " [Installed]"<< endl
;
783 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
786 c1out
<< "You should explicitly select one to install." << endl
;
790 c1out
<< "Package " << Pkg
.Name() << " has no available version, but exists in the database." << endl
;
791 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
792 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
795 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
796 for (; Dep
.end() == false; Dep
++)
798 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
800 List
+= string(Dep
.ParentPkg().Name()) + " ";
802 ShowList(c1out
,"However the following packages replace it:",List
);
805 _error
->Error("Package %s has no installation candidate",Pkg
.Name());
813 Cache
.MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
818 Cache
.MarkInstall(Pkg
,false);
819 if (State
.Install() == false)
821 if (AllowFail
== true)
822 c1out
<< "Sorry, " << Pkg
.Name() << " is already the newest version" << endl
;
827 // Install it with autoinstalling enabled.
828 if (State
.InstBroken() == true && BrokenFix
== false)
829 Cache
.MarkInstall(Pkg
,true);
834 // DoUpdate - Update the package lists /*{{{*/
835 // ---------------------------------------------------------------------
837 bool DoUpdate(CommandLine
&)
839 // Get the source list
841 if (List
.ReadMainList() == false)
844 // Lock the list directory
846 if (_config
->FindB("Debug::NoLocking",false) == false)
848 Lock
.Fd(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
849 if (_error
->PendingError() == true)
850 return _error
->Error("Unable to lock the list directory");
853 // Create the download object
854 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
855 pkgAcquire
Fetcher(&Stat
);
857 // Populate it with the source selection
858 pkgSourceList::const_iterator I
;
859 for (I
= List
.begin(); I
!= List
.end(); I
++)
861 new pkgAcqIndex(&Fetcher
,I
);
862 if (_error
->PendingError() == true)
867 if (Fetcher
.Run() == pkgAcquire::Failed
)
871 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
873 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
878 cerr
<< "Failed to fetch " << (*I
)->DescURI() << endl
;
879 cerr
<< " " << (*I
)->ErrorText
<< endl
;
883 // Clean out any old list files
884 if (_config
->FindB("APT::Get::List-Cleanup",false) == false)
886 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
887 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
891 // Prepare the cache.
893 if (Cache
.Open() == false)
897 return _error
->Error("Some index files failed to download, they have been ignored, or old ones used instead.");
901 // DoUpgrade - Upgrade all packages /*{{{*/
902 // ---------------------------------------------------------------------
903 /* Upgrade all packages without installing new packages or erasing old
905 bool DoUpgrade(CommandLine
&CmdL
)
908 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
912 if (pkgAllUpgrade(Cache
) == false)
914 ShowBroken(c1out
,Cache
,false);
915 return _error
->Error("Internal Error, AllUpgrade broke stuff");
918 return InstallPackages(Cache
,true);
921 // DoInstall - Install packages from the command line /*{{{*/
922 // ---------------------------------------------------------------------
923 /* Install named packages */
924 bool DoInstall(CommandLine
&CmdL
)
927 if (Cache
.Open() == false || Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
930 // Enter the special broken fixing mode if the user specified arguments
931 bool BrokenFix
= false;
932 if (Cache
->BrokenCount() != 0)
935 unsigned int ExpectedInst
= 0;
936 unsigned int Packages
= 0;
937 pkgProblemResolver
Fix(Cache
);
939 bool DefRemove
= false;
940 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
943 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
945 // Duplicate the string
946 unsigned int Length
= strlen(*I
);
948 if (Length
>= sizeof(S
))
952 // See if we are removing the package
953 bool Remove
= DefRemove
;
954 while (Cache
->FindPkg(S
).end() == true)
956 // Handle an optional end tag indicating what to do
957 if (S
[Length
- 1] == '-')
964 if (S
[Length
- 1] == '+')
973 // Locate the package
974 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
976 if (Pkg
.end() == true)
978 // Check if the name is a regex
980 for (I
= S
; *I
!= 0; I
++)
981 if (*I
== '.' || *I
== '?' || *I
== '*')
984 return _error
->Error("Couldn't find package %s",S
);
986 // Regexs must always be confirmed
987 ExpectedInst
+= 1000;
989 // Compile the regex pattern
991 if (regcomp(&Pattern
,S
,REG_EXTENDED
| REG_ICASE
|
993 return _error
->Error("Regex compilation error");
995 // Run over the matches
997 for (Pkg
= Cache
->PkgBegin(); Pkg
.end() == false; Pkg
++)
999 if (regexec(&Pattern
,Pkg
.Name(),0,0,0) != 0)
1002 Hit
|= TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,
1003 ExpectedInst
,false);
1008 return _error
->Error("Couldn't find package %s",S
);
1012 if (TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,ExpectedInst
) == false)
1017 /* If we are in the Broken fixing mode we do not attempt to fix the
1018 problems. This is if the user invoked install without -f and gave
1020 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1022 c1out
<< "You might want to run `apt-get -f install' to correct these:" << endl
;
1023 ShowBroken(c1out
,Cache
,false);
1025 return _error
->Error("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).");
1028 // Call the scored problem resolver
1029 Fix
.InstallProtect();
1030 if (Fix
.Resolve(true) == false)
1033 // Now we check the state of the packages,
1034 if (Cache
->BrokenCount() != 0)
1036 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
1037 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
1038 c1out
<< "distribution that some required packages have not yet been created" << endl
;
1039 c1out
<< "or been moved out of Incoming." << endl
;
1043 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
1044 c1out
<< "the package is simply not installable and a bug report against" << endl
;
1045 c1out
<< "that package should be filed." << endl
;
1048 c1out
<< "The following information may help to resolve the situation:" << endl
;
1050 ShowBroken(c1out
,Cache
,false);
1051 return _error
->Error("Sorry, broken packages");
1054 /* Print out a list of packages that are going to be installed extra
1055 to what the user asked */
1056 if (Cache
->InstCount() != ExpectedInst
)
1059 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1061 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1062 if ((*Cache
)[I
].Install() == false)
1066 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1067 if (strcmp(*J
,I
.Name()) == 0)
1071 List
+= string(I
.Name()) + " ";
1074 ShowList(c1out
,"The following extra packages will be installed:",List
);
1077 // See if we need to prompt
1078 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
1079 return InstallPackages(Cache
,false,false);
1081 return InstallPackages(Cache
,false);
1084 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1085 // ---------------------------------------------------------------------
1086 /* Intelligent upgrader that will install and remove packages at will */
1087 bool DoDistUpgrade(CommandLine
&CmdL
)
1090 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1093 c0out
<< "Calculating Upgrade... " << flush
;
1094 if (pkgDistUpgrade(*Cache
) == false)
1096 c0out
<< "Failed" << endl
;
1097 ShowBroken(c1out
,Cache
,false);
1101 c0out
<< "Done" << endl
;
1103 return InstallPackages(Cache
,true);
1106 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1107 // ---------------------------------------------------------------------
1108 /* Follows dselect's selections */
1109 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1112 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1115 // Install everything with the install flag set
1116 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1117 for (;I
.end() != true; I
++)
1119 /* Install the package only if it is a new install, the autoupgrader
1120 will deal with the rest */
1121 if (I
->SelectedState
== pkgCache::State::Install
)
1122 Cache
->MarkInstall(I
,false);
1125 /* Now install their deps too, if we do this above then order of
1126 the status file is significant for | groups */
1127 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1129 /* Install the package only if it is a new install, the autoupgrader
1130 will deal with the rest */
1131 if (I
->SelectedState
== pkgCache::State::Install
)
1132 Cache
->MarkInstall(I
,true);
1135 // Apply erasures now, they override everything else.
1136 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1139 if (I
->SelectedState
== pkgCache::State::DeInstall
||
1140 I
->SelectedState
== pkgCache::State::Purge
)
1141 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
1144 /* Resolve any problems that dselect created, allupgrade cannot handle
1145 such things. We do so quite agressively too.. */
1146 if (Cache
->BrokenCount() != 0)
1148 pkgProblemResolver
Fix(Cache
);
1150 // Hold back held packages.
1151 if (_config
->FindB("APT::Ingore-Hold",false) == false)
1153 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
1155 if (I
->SelectedState
== pkgCache::State::Hold
)
1163 if (Fix
.Resolve() == false)
1165 ShowBroken(c1out
,Cache
,false);
1166 return _error
->Error("Internal Error, problem resolver broke stuff");
1170 // Now upgrade everything
1171 if (pkgAllUpgrade(Cache
) == false)
1173 ShowBroken(c1out
,Cache
,false);
1174 return _error
->Error("Internal Error, problem resolver broke stuff");
1177 return InstallPackages(Cache
,false);
1180 // DoClean - Remove download archives /*{{{*/
1181 // ---------------------------------------------------------------------
1183 bool DoClean(CommandLine
&CmdL
)
1186 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
1187 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1191 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1192 // ---------------------------------------------------------------------
1193 /* This is similar to clean but it only purges things that cannot be
1194 downloaded, that is old versions of cached packages. */
1195 class LogCleaner
: public pkgArchiveCleaner
1198 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1200 cout
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
1202 if (_config
->FindB("APT::Get::Simulate") == false)
1207 bool DoAutoClean(CommandLine
&CmdL
)
1210 if (Cache
.Open() == false)
1215 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1216 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1219 // DoCheck - Perform the check operation /*{{{*/
1220 // ---------------------------------------------------------------------
1221 /* Opening automatically checks the system, this command is mostly used
1223 bool DoCheck(CommandLine
&CmdL
)
1232 // DoSource - Fetch a source archive /*{{{*/
1233 // ---------------------------------------------------------------------
1234 /* Fetch souce packages */
1242 bool DoSource(CommandLine
&CmdL
)
1245 if (Cache
.Open(false) == false)
1248 if (CmdL
.FileSize() <= 1)
1249 return _error
->Error("Must specify at least one package to fetch source for");
1251 // Read the source list
1253 if (List
.ReadMainList() == false)
1254 return _error
->Error("The list of sources could not be read.");
1256 // Create the text record parsers
1257 pkgRecords
Recs(Cache
);
1258 pkgSrcRecords
SrcRecs(List
);
1259 if (_error
->PendingError() == true)
1262 // Create the download object
1263 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1264 pkgAcquire
Fetcher(&Stat
);
1266 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
1268 // Load the requestd sources into the fetcher
1270 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1274 /* Lookup the version of the package we would install if we were to
1275 install a version and determine the source package name, then look
1276 in the archive for a source package of the same name. In theory
1277 we could stash the version string as well and match that too but
1278 today there aren't multi source versions in the archive. */
1279 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(*I
);
1280 if (Pkg
.end() == false)
1282 pkgCache::VerIterator Ver
= Cache
->GetCandidateVer(Pkg
);
1283 if (Ver
.end() == false)
1285 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1286 Src
= Parse
.SourcePkg();
1290 // No source package name..
1291 if (Src
.empty() == true)
1295 pkgSrcRecords::Parser
*Last
= 0;
1296 unsigned long Offset
= 0;
1298 bool IsMatch
= false;
1300 // Iterate over all of the hits
1301 pkgSrcRecords::Parser
*Parse
;
1303 while ((Parse
= SrcRecs
.Find(Src
.c_str(),false)) != 0)
1305 string Ver
= Parse
->Version();
1307 // Skip name mismatches
1308 if (IsMatch
== true && Parse
->Package() != Src
)
1311 // Newer version or an exact match
1312 if (Last
== 0 || pkgVersionCompare(Version
,Ver
) < 0 ||
1313 (Parse
->Package() == Src
&& IsMatch
== false))
1315 IsMatch
= Parse
->Package() == Src
;
1317 Offset
= Parse
->Offset();
1323 return _error
->Error("Unable to find a source package for %s",Src
.c_str());
1326 vector
<pkgSrcRecords::File
> Lst
;
1327 if (Last
->Jump(Offset
) == false || Last
->Files(Lst
) == false)
1330 // Load them into the fetcher
1331 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
1332 I
!= Lst
.end(); I
++)
1334 // Try to guess what sort of file it is we are getting.
1336 if (I
->Path
.find(".dsc") != string::npos
)
1339 Dsc
[J
].Package
= Last
->Package();
1340 Dsc
[J
].Version
= Last
->Version();
1341 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
1344 if (I
->Path
.find(".tar.gz") != string::npos
)
1346 if (I
->Path
.find(".diff.gz") != string::npos
)
1349 // Diff only mode only fetches .diff files
1350 if (_config
->FindB("APT::Get::Diff-Only",false) == true &&
1354 // Tar only mode only fetches .tar files
1355 if (_config
->FindB("APT::Get::Tar-Only",false) == true &&
1359 new pkgAcqFile(&Fetcher
,Last
->Source()->ArchiveURI(I
->Path
),
1360 I
->MD5Hash
,I
->Size
,Last
->Source()->SourceInfo(Src
,
1361 Last
->Version(),Comp
),Src
);
1365 // Display statistics
1366 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
1367 unsigned long FetchPBytes
= Fetcher
.PartialPresent();
1368 unsigned long DebBytes
= Fetcher
.TotalNeeded();
1370 // Check for enough free space
1372 string OutputDir
= ".";
1373 if (statfs(OutputDir
.c_str(),&Buf
) != 0)
1374 return _error
->Errno("statfs","Couldn't determine free space in %s",
1376 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1377 return _error
->Error("Sorry, you don't have enough free space in %s",
1381 c1out
<< "Need to get ";
1382 if (DebBytes
!= FetchBytes
)
1383 c1out
<< SizeToStr(FetchBytes
) << "B/" << SizeToStr(DebBytes
) << 'B';
1385 c1out
<< SizeToStr(DebBytes
) << 'B';
1386 c1out
<< " of source archives." << endl
;
1388 if (_config
->FindB("APT::Get::Simulate",false) == true)
1390 for (unsigned I
= 0; I
!= J
; I
++)
1391 cout
<< "Fetch Source " << Dsc
[I
].Package
<< endl
;
1395 // Just print out the uris an exit if the --print-uris flag was used
1396 if (_config
->FindB("APT::Get::Print-URIs") == true)
1398 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1399 for (; I
!= Fetcher
.UriEnd(); I
++)
1400 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1401 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1406 if (Fetcher
.Run() == pkgAcquire::Failed
)
1409 // Print error messages
1410 bool Failed
= false;
1411 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1413 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1414 (*I
)->Complete
== true)
1417 cerr
<< "Failed to fetch " << (*I
)->DescURI() << endl
;
1418 cerr
<< " " << (*I
)->ErrorText
<< endl
;
1422 return _error
->Error("Failed to fetch some archives.");
1424 if (_config
->FindB("APT::Get::Download-only",false) == true)
1427 // Unpack the sources
1428 pid_t Process
= ExecFork();
1432 for (unsigned I
= 0; I
!= J
; I
++)
1434 string Dir
= Dsc
[I
].Package
+ '-' + pkgBaseVersion(Dsc
[I
].Version
.c_str());
1436 // Diff only mode only fetches .diff files
1437 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
1438 _config
->FindB("APT::Get::Tar-Only",false) == true)
1441 // See if the package is already unpacked
1443 if (stat(Dir
.c_str(),&Stat
) == 0 &&
1444 S_ISDIR(Stat
.st_mode
) != 0)
1446 c0out
<< "Skipping unpack of already unpacked source in " << Dir
<< endl
;
1452 snprintf(S
,sizeof(S
),"%s -x %s",
1453 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
1454 Dsc
[I
].Dsc
.c_str());
1457 cerr
<< "Unpack command '" << S
<< "' failed." << endl
;
1462 // Try to compile it with dpkg-buildpackage
1463 if (_config
->FindB("APT::Get::Compile",false) == true)
1465 // Call dpkg-buildpackage
1467 snprintf(S
,sizeof(S
),"cd %s && %s %s",
1469 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
1470 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
1474 cerr
<< "Build command '" << S
<< "' failed." << endl
;
1483 // Wait for the subprocess
1485 while (waitpid(Process
,&Status
,0) != Process
)
1489 return _error
->Errno("waitpid","Couldn't wait for subprocess");
1492 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
1493 return _error
->Error("Child process failed");
1499 // ShowHelp - Show a help screen /*{{{*/
1500 // ---------------------------------------------------------------------
1502 bool ShowHelp(CommandLine
&CmdL
)
1504 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
1505 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
1506 if (_config
->FindB("version") == true)
1509 cout
<< "Usage: apt-get [options] command" << endl
;
1510 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
1512 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
1513 cout
<< "installing packages. The most frequently used commands are update" << endl
;
1514 cout
<< "and install." << endl
;
1516 cout
<< "Commands:" << endl
;
1517 cout
<< " update - Retrieve new lists of packages" << endl
;
1518 cout
<< " upgrade - Perform an upgrade" << endl
;
1519 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
1520 cout
<< " remove - Remove packages" << endl
;
1521 cout
<< " source - Download source archives" << endl
;
1522 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
1523 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
1524 cout
<< " clean - Erase downloaded archive files" << endl
;
1525 cout
<< " autoclean - Erase old downloaded archive files" << endl
;
1526 cout
<< " check - Verify that there are no broken dependencies" << endl
;
1528 cout
<< "Options:" << endl
;
1529 cout
<< " -h This help text." << endl
;
1530 cout
<< " -q Loggable output - no progress indicator" << endl
;
1531 cout
<< " -qq No output except for errors" << endl
;
1532 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
1533 cout
<< " -s No-act. Perform ordering simulation" << endl
;
1534 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
1535 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
1536 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
1537 cout
<< " -u Show a list of upgraded packages as well" << endl
;
1538 cout
<< " -b Build the source package after fetching it" << endl
;
1539 cout
<< " -c=? Read this configuration file" << endl
;
1540 cout
<< " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl
;
1541 cout
<< "See the apt-get(8), sources.list(5) and apt.conf(5) manual" << endl
;
1542 cout
<< "pages for more information and options." << endl
;
1546 // GetInitialize - Initialize things for apt-get /*{{{*/
1547 // ---------------------------------------------------------------------
1549 void GetInitialize()
1551 _config
->Set("quiet",0);
1552 _config
->Set("help",false);
1553 _config
->Set("APT::Get::Download-Only",false);
1554 _config
->Set("APT::Get::Simulate",false);
1555 _config
->Set("APT::Get::Assume-Yes",false);
1556 _config
->Set("APT::Get::Fix-Broken",false);
1557 _config
->Set("APT::Get::Force-Yes",false);
1558 _config
->Set("APT::Get::APT::Get::No-List-Cleanup",true);
1561 // SigWinch - Window size change signal handler /*{{{*/
1562 // ---------------------------------------------------------------------
1566 // Riped from GNU ls
1570 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
1571 ScreenWidth
= ws
.ws_col
- 1;
1576 int main(int argc
,const char *argv
[])
1578 CommandLine::Args Args
[] = {
1579 {'h',"help","help",0},
1580 {'v',"version","version",0},
1581 {'q',"quiet","quiet",CommandLine::IntLevel
},
1582 {'q',"silent","quiet",CommandLine::IntLevel
},
1583 {'d',"download-only","APT::Get::Download-Only",0},
1584 {'b',"compile","APT::Get::Compile",0},
1585 {'b',"build","APT::Get::Compile",0},
1586 {'s',"simulate","APT::Get::Simulate",0},
1587 {'s',"just-print","APT::Get::Simulate",0},
1588 {'s',"recon","APT::Get::Simulate",0},
1589 {'s',"no-act","APT::Get::Simulate",0},
1590 {'y',"yes","APT::Get::Assume-Yes",0},
1591 {'y',"assume-yes","APT::Get::Assume-Yes",0},
1592 {'f',"fix-broken","APT::Get::Fix-Broken",0},
1593 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
1594 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
1595 {0,"no-download","APT::Get::No-Download",0},
1596 {0,"fix-missing","APT::Get::Fix-Missing",0},
1597 {0,"ignore-hold","APT::Ingore-Hold",0},
1598 {0,"no-upgrade","APT::Get::no-upgrade",0},
1599 {0,"force-yes","APT::Get::force-yes",0},
1600 {0,"print-uris","APT::Get::Print-URIs",0},
1601 {0,"diff-only","APT::Get::Diff-Only",0},
1602 {0,"tar-only","APT::Get::tar-Only",0},
1603 {0,"purge","APT::Get::Purge",0},
1604 {0,"list-cleanup","APT::Get::List-Cleanup",0},
1605 {'c',"config-file",0,CommandLine::ConfigFile
},
1606 {'o',"option",0,CommandLine::ArbItem
},
1608 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
1609 {"upgrade",&DoUpgrade
},
1610 {"install",&DoInstall
},
1611 {"remove",&DoInstall
},
1612 {"dist-upgrade",&DoDistUpgrade
},
1613 {"dselect-upgrade",&DoDSelectUpgrade
},
1615 {"autoclean",&DoAutoClean
},
1617 {"source",&DoSource
},
1621 // Parse the command line and initialize the package library
1622 CommandLine
CmdL(Args
,_config
);
1623 if (pkgInitialize(*_config
) == false ||
1624 CmdL
.Parse(argc
,argv
) == false)
1626 _error
->DumpErrors();
1630 // See if the help should be shown
1631 if (_config
->FindB("help") == true ||
1632 _config
->FindB("version") == true ||
1633 CmdL
.FileSize() == 0)
1634 return ShowHelp(CmdL
);
1636 // Deal with stdout not being a tty
1637 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
1638 _config
->Set("quiet","1");
1640 // Setup the output streams
1641 c0out
.rdbuf(cout
.rdbuf());
1642 c1out
.rdbuf(cout
.rdbuf());
1643 c2out
.rdbuf(cout
.rdbuf());
1644 if (_config
->FindI("quiet",0) > 0)
1645 c0out
.rdbuf(devnull
.rdbuf());
1646 if (_config
->FindI("quiet",0) > 1)
1647 c1out
.rdbuf(devnull
.rdbuf());
1649 // Setup the signals
1650 signal(SIGPIPE
,SIG_IGN
);
1651 signal(SIGWINCH
,SigWinch
);
1654 // Match the operation
1655 CmdL
.DispatchArg(Cmds
);
1657 // Print any errors or warnings found during parsing
1658 if (_error
->empty() == false)
1660 bool Errors
= _error
->PendingError();
1661 _error
->DumpErrors();
1662 return Errors
== true?100:0;