]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.80 1999/10/18 00:37:35 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>
61 ofstream
devnull("/dev/null");
62 unsigned int ScreenWidth
= 80;
64 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
65 // ---------------------------------------------------------------------
67 class CacheFile
: public pkgCacheFile
69 static pkgCache
*SortCache
;
70 static int NameComp(const void *a
,const void *b
);
73 pkgCache::Package
**List
;
76 bool CheckDeps(bool AllowBroken
= false);
77 bool Open(bool WithLock
= true)
79 OpTextProgress
Prog(*_config
);
80 if (pkgCacheFile::Open(Prog
,WithLock
) == false)
85 CacheFile() : List(0) {};
89 // YnPrompt - Yes No Prompt. /*{{{*/
90 // ---------------------------------------------------------------------
91 /* Returns true on a Yes.*/
94 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
102 read(STDIN_FILENO
,&C
,1);
103 while (C
!= '\n' && Jnk
!= '\n') read(STDIN_FILENO
,&Jnk
,1);
105 if (!(C
== 'Y' || C
== 'y' || C
== '\n' || C
== '\r'))
110 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
111 // ---------------------------------------------------------------------
112 /* Returns true on a Yes.*/
113 bool AnalPrompt(const char *Text
)
116 cin
.getline(Buf
,sizeof(Buf
));
117 if (strcmp(Buf
,Text
) == 0)
122 // ShowList - Show a list /*{{{*/
123 // ---------------------------------------------------------------------
124 /* This prints out a string of space seperated words with a title and
125 a two space indent line wraped to the current screen width. */
126 bool ShowList(ostream
&out
,string Title
,string List
)
128 if (List
.empty() == true)
131 // Acount for the leading space
132 int ScreenWidth
= ::ScreenWidth
- 3;
134 out
<< Title
<< endl
;
135 string::size_type Start
= 0;
136 while (Start
< List
.size())
138 string::size_type End
;
139 if (Start
+ ScreenWidth
>= List
.size())
142 End
= List
.rfind(' ',Start
+ScreenWidth
);
144 if (End
== string::npos
|| End
< Start
)
145 End
= Start
+ ScreenWidth
;
146 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
152 // ShowBroken - Debugging aide /*{{{*/
153 // ---------------------------------------------------------------------
154 /* This prints out the names of all the packages that are broken along
155 with the name of each each broken dependency and a quite version
157 void ShowBroken(ostream
&out
,CacheFile
&Cache
,bool Now
)
159 out
<< "Sorry, but the following packages have unmet dependencies:" << endl
;
160 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
162 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
164 if (Cache
[I
].InstBroken() == false)
167 // Print out each package and the failed dependencies
168 out
<<" " << I
.Name() << ":";
169 int Indent
= strlen(I
.Name()) + 3;
171 if (Cache
[I
].InstVerIter(Cache
).end() == true)
177 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
179 // Compute a single dependency element (glob or)
180 pkgCache::DepIterator Start
;
181 pkgCache::DepIterator End
;
184 if (Cache
->IsImportantDep(End
) == false ||
185 (Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
189 for (int J
= 0; J
!= Indent
; J
++)
193 out
<< ' ' << End
.DepType() << ": " << End
.TargetPkg().Name();
195 // Show a quick summary of the version requirements
196 if (End
.TargetVer() != 0)
197 out
<< " (" << End
.CompType() << " " << End
.TargetVer() <<
200 /* Show a summary of the target package if possible. In the case
201 of virtual packages we show nothing */
202 pkgCache::PkgIterator Targ
= End
.TargetPkg();
203 if (Targ
->ProvidesList
== 0)
206 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
207 if (Ver
.end() == false)
208 out
<< Ver
.VerStr() << (Now
?" is installed":" is to be installed");
211 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
213 if (Targ
->ProvidesList
== 0)
214 out
<< "it is not installable";
216 out
<< "it is a virtual package";
219 out
<< (Now
?"it is not installed":"it is not going to be installed");
228 // ShowNew - Show packages to newly install /*{{{*/
229 // ---------------------------------------------------------------------
231 void ShowNew(ostream
&out
,CacheFile
&Cache
)
233 /* Print out a list of packages that are going to be removed extra
234 to what the user asked */
236 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
238 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
239 if (Cache
[I
].NewInstall() == true)
240 List
+= string(I
.Name()) + " ";
243 ShowList(out
,"The following NEW packages will be installed:",List
);
246 // ShowDel - Show packages to delete /*{{{*/
247 // ---------------------------------------------------------------------
249 void ShowDel(ostream
&out
,CacheFile
&Cache
)
251 /* Print out a list of packages that are going to be removed extra
252 to what the user asked */
254 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
256 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
257 if (Cache
[I
].Delete() == true)
259 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
260 List
+= string(I
.Name()) + "* ";
262 List
+= string(I
.Name()) + " ";
266 ShowList(out
,"The following packages will be REMOVED:",List
);
269 // ShowKept - Show kept packages /*{{{*/
270 // ---------------------------------------------------------------------
272 void ShowKept(ostream
&out
,CacheFile
&Cache
)
275 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
277 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
280 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
281 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
284 List
+= string(I
.Name()) + " ";
286 ShowList(out
,"The following packages have been kept back",List
);
289 // ShowUpgraded - Show upgraded packages /*{{{*/
290 // ---------------------------------------------------------------------
292 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
295 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
297 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
300 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
303 List
+= string(I
.Name()) + " ";
305 ShowList(out
,"The following packages will be upgraded",List
);
308 // ShowHold - Show held but changed packages /*{{{*/
309 // ---------------------------------------------------------------------
311 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
314 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
316 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
317 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
318 I
->SelectedState
== pkgCache::State::Hold
)
319 List
+= string(I
.Name()) + " ";
322 return ShowList(out
,"The following held packages will be changed:",List
);
325 // ShowEssential - Show an essential package warning /*{{{*/
326 // ---------------------------------------------------------------------
327 /* This prints out a warning message that is not to be ignored. It shows
328 all essential packages and their dependents that are to be removed.
329 It is insanely risky to remove the dependents of an essential package! */
330 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
333 bool *Added
= new bool[Cache
->HeaderP
->PackageCount
];
334 for (unsigned int I
= 0; I
!= Cache
->HeaderP
->PackageCount
; I
++)
337 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
339 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
340 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
343 // The essential package is being removed
344 if (Cache
[I
].Delete() == true)
346 if (Added
[I
->ID
] == false)
349 List
+= string(I
.Name()) + " ";
353 if (I
->CurrentVer
== 0)
356 // Print out any essential package depenendents that are to be removed
357 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
359 // Skip everything but depends
360 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
361 D
->Type
!= pkgCache::Dep::Depends
)
364 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
365 if (Cache
[P
].Delete() == true)
367 if (Added
[P
->ID
] == true)
372 sprintf(S
,"%s (due to %s) ",P
.Name(),I
.Name());
379 if (List
.empty() == false)
380 out
<< "WARNING: The following essential packages will be removed" << endl
;
381 return ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
384 // Stats - Show some statistics /*{{{*/
385 // ---------------------------------------------------------------------
387 void Stats(ostream
&out
,pkgDepCache
&Dep
)
389 unsigned long Upgrade
= 0;
390 unsigned long Install
= 0;
391 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
393 if (Dep
[I
].NewInstall() == true)
396 if (Dep
[I
].Upgrade() == true)
400 out
<< Upgrade
<< " packages upgraded, " <<
401 Install
<< " newly installed, " <<
402 Dep
.DelCount() << " to remove and " <<
403 Dep
.KeepCount() << " not upgraded." << endl
;
405 if (Dep
.BadCount() != 0)
406 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
410 // CacheFile::NameComp - QSort compare by name /*{{{*/
411 // ---------------------------------------------------------------------
413 pkgCache
*CacheFile::SortCache
= 0;
414 int CacheFile::NameComp(const void *a
,const void *b
)
416 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
417 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
419 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
420 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
422 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
425 // CacheFile::Sort - Sort by name /*{{{*/
426 // ---------------------------------------------------------------------
428 void CacheFile::Sort()
431 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
432 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
433 pkgCache::PkgIterator I
= Cache
->PkgBegin();
434 for (;I
.end() != true; I
++)
438 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
441 // CacheFile::Open - Open the cache file /*{{{*/
442 // ---------------------------------------------------------------------
443 /* This routine generates the caches and then opens the dependency cache
444 and verifies that the system is OK. */
445 bool CacheFile::CheckDeps(bool AllowBroken
)
447 if (_error
->PendingError() == true)
450 // Check that the system is OK
451 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
452 return _error
->Error("Internal Error, non-zero counts");
454 // Apply corrections for half-installed packages
455 if (pkgApplyStatus(*Cache
) == false)
459 if (Cache
->BrokenCount() == 0 || AllowBroken
== true)
462 // Attempt to fix broken things
463 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
465 c1out
<< "Correcting dependencies..." << flush
;
466 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
468 c1out
<< " failed." << endl
;
469 ShowBroken(c1out
,*this,true);
471 return _error
->Error("Unable to correct dependencies");
473 if (pkgMinimizeUpgrade(*Cache
) == false)
474 return _error
->Error("Unable to minimize the upgrade set");
476 c1out
<< " Done" << endl
;
480 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
481 ShowBroken(c1out
,*this,true);
483 return _error
->Error("Unmet dependencies. Try using -f.");
490 // InstallPackages - Actually download and install the packages /*{{{*/
491 // ---------------------------------------------------------------------
492 /* This displays the informative messages describing what is going to
493 happen and then calls the download routines */
494 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,bool Saftey
= true)
496 if (_config
->FindB("APT::Get::Purge",false) == true)
498 pkgCache::PkgIterator I
= Cache
->PkgBegin();
499 for (; I
.end() == false; I
++)
501 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
502 Cache
->MarkDelete(I
,true);
507 bool Essential
= false;
509 // Show all the various warning indicators
510 ShowDel(c1out
,Cache
);
511 ShowNew(c1out
,Cache
);
513 ShowKept(c1out
,Cache
);
514 Fail
|= !ShowHold(c1out
,Cache
);
515 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
516 ShowUpgraded(c1out
,Cache
);
517 Essential
= !ShowEssential(c1out
,Cache
);
522 if (Cache
->BrokenCount() != 0)
524 ShowBroken(c1out
,Cache
,false);
525 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
528 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
529 Cache
->BadCount() == 0)
532 // Run the simulator ..
533 if (_config
->FindB("APT::Get::Simulate") == true)
535 pkgSimulate
PM(Cache
);
536 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
537 if (Res
== pkgPackageManager::Failed
)
539 if (Res
!= pkgPackageManager::Completed
)
540 return _error
->Error("Internal Error, Ordering didn't finish");
544 // Create the text record parser
545 pkgRecords
Recs(Cache
);
546 if (_error
->PendingError() == true)
549 // Lock the archive directory
551 if (_config
->FindB("Debug::NoLocking",false) == false)
553 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
554 if (_error
->PendingError() == true)
555 return _error
->Error("Unable to lock the download directory");
558 // Create the download object
559 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
560 pkgAcquire
Fetcher(&Stat
);
562 // Read the source list
564 if (List
.ReadMainList() == false)
565 return _error
->Error("The list of sources could not be read.");
567 // Create the package manager and prepare to download
569 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false ||
570 _error
->PendingError() == true)
573 // Display statistics
574 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
575 unsigned long FetchPBytes
= Fetcher
.PartialPresent();
576 unsigned long DebBytes
= Fetcher
.TotalNeeded();
577 if (DebBytes
!= Cache
->DebSize())
579 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
580 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
584 c1out
<< "Need to get ";
585 if (DebBytes
!= FetchBytes
)
586 c1out
<< SizeToStr(FetchBytes
) << "B/" << SizeToStr(DebBytes
) << 'B';
588 c1out
<< SizeToStr(DebBytes
) << 'B';
590 c1out
<< " of archives. After unpacking ";
592 // Check for enough free space
594 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
595 if (statfs(OutputDir
.c_str(),&Buf
) != 0)
596 return _error
->Errno("statfs","Couldn't determine free space in %s",
598 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
599 return _error
->Error("Sorry, you don't have enough free space in %s to hold all the .debs.",
603 if (Cache
->UsrSize() >= 0)
604 c1out
<< SizeToStr(Cache
->UsrSize()) << "B will be used." << endl
;
606 c1out
<< SizeToStr(-1*Cache
->UsrSize()) << "B will be freed." << endl
;
608 if (_error
->PendingError() == true)
612 if (_config
->FindI("quiet",0) >= 2 ||
613 _config
->FindB("APT::Get::Assume-Yes",false) == true)
615 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
616 return _error
->Error("There are problems and -y was used without --force-yes");
619 if (Essential
== true && Saftey
== true)
621 c2out
<< "You are about to do something potentially harmful" << endl
;
622 c2out
<< "To continue type in the phrase 'Yes, I understand this may be bad'" << endl
;
623 c2out
<< " ?] " << flush
;
624 if (AnalPrompt("Yes, I understand this may be bad") == false)
626 c2out
<< "Abort." << endl
;
632 // Prompt to continue
633 if (Ask
== true || Fail
== true)
635 if (_config
->FindI("quiet",0) < 2 &&
636 _config
->FindB("APT::Get::Assume-Yes",false) == false)
638 c2out
<< "Do you want to continue? [Y/n] " << flush
;
640 if (YnPrompt() == false)
642 c2out
<< "Abort." << endl
;
649 // Just print out the uris an exit if the --print-uris flag was used
650 if (_config
->FindB("APT::Get::Print-URIs") == true)
652 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
653 for (; I
!= Fetcher
.UriEnd(); I
++)
654 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
655 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
662 if (_config
->FindB("APT::Get::No-Download",false) == false)
663 if (Fetcher
.Run() == pkgAcquire::Failed
)
668 bool Transient
= false;
669 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
671 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
672 (*I
)->Complete
== true)
675 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
682 cerr
<< "Failed to fetch " << (*I
)->DescURI() << endl
;
683 cerr
<< " " << (*I
)->ErrorText
<< endl
;
687 /* If we are in no download mode and missing files then there were
688 'failures' then the user must specify -m. Furthermore, there
689 is no such thing as a transient error in no-download mode! */
690 if (Transient
== true &&
691 _config
->FindB("APT::Get::No-Download",false) == true)
697 if (_config
->FindB("APT::Get::Download-Only",false) == true)
699 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
700 return _error
->Error("Some files failed to download");
704 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
706 return _error
->Error("Unable to fetch some archives, maybe try with --fix-missing?");
709 if (Transient
== true && Failed
== true)
710 return _error
->Error("--fix-missing and media swapping is not currently supported");
712 // Try to deal with missing package files
713 if (Failed
== true && PM
.FixMissing() == false)
715 cerr
<< "Unable to correct missing packages." << endl
;
716 return _error
->Error("Aborting Install.");
720 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
721 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
723 if (Res
== pkgPackageManager::Completed
)
726 // Reload the fetcher object and loop again for media swapping
728 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false)
734 // DoUpdate - Update the package lists /*{{{*/
735 // ---------------------------------------------------------------------
737 bool DoUpdate(CommandLine
&)
739 // Get the source list
741 if (List
.ReadMainList() == false)
744 // Lock the list directory
746 if (_config
->FindB("Debug::NoLocking",false) == false)
748 Lock
.Fd(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
749 if (_error
->PendingError() == true)
750 return _error
->Error("Unable to lock the list directory");
753 // Create the download object
754 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
755 pkgAcquire
Fetcher(&Stat
);
757 // Populate it with the source selection
758 pkgSourceList::const_iterator I
;
759 for (I
= List
.begin(); I
!= List
.end(); I
++)
761 new pkgAcqIndex(&Fetcher
,I
);
762 if (_error
->PendingError() == true)
767 if (Fetcher
.Run() == pkgAcquire::Failed
)
771 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
773 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
778 cerr
<< "Failed to fetch " << (*I
)->DescURI() << endl
;
779 cerr
<< " " << (*I
)->ErrorText
<< endl
;
783 // Clean out any old list files
784 if (_config
->FindB("APT::Get::List-Cleanup",false) == false)
786 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
787 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
791 // Prepare the cache.
793 if (Cache
.Open() == false)
797 return _error
->Error("Some index files failed to download, they have been ignored, or old ones used instead.");
801 // DoUpgrade - Upgrade all packages /*{{{*/
802 // ---------------------------------------------------------------------
803 /* Upgrade all packages without installing new packages or erasing old
805 bool DoUpgrade(CommandLine
&CmdL
)
808 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
812 if (pkgAllUpgrade(Cache
) == false)
814 ShowBroken(c1out
,Cache
,false);
815 return _error
->Error("Internal Error, AllUpgrade broke stuff");
818 return InstallPackages(Cache
,true);
821 // DoInstall - Install packages from the command line /*{{{*/
822 // ---------------------------------------------------------------------
823 /* Install named packages */
824 bool DoInstall(CommandLine
&CmdL
)
827 if (Cache
.Open() == false || Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
830 // Enter the special broken fixing mode if the user specified arguments
831 bool BrokenFix
= false;
832 if (Cache
->BrokenCount() != 0)
835 unsigned int ExpectedInst
= 0;
836 unsigned int Packages
= 0;
837 pkgProblemResolver
Fix(Cache
);
839 bool DefRemove
= false;
840 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
843 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
845 // Duplicate the string
846 unsigned int Length
= strlen(*I
);
848 if (Length
>= sizeof(S
))
852 // See if we are removing the package
853 bool Remove
= DefRemove
;
854 while (Cache
->FindPkg(S
).end() == true)
856 // Handle an optional end tag indicating what to do
857 if (S
[Length
- 1] == '-')
864 if (S
[Length
- 1] == '+')
873 // Locate the package
874 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
876 if (Pkg
.end() == true)
877 return _error
->Error("Couldn't find package %s",S
);
879 // Handle the no-upgrade case
880 if (_config
->FindB("APT::Get::no-upgrade",false) == true &&
881 Pkg
->CurrentVer
!= 0)
883 c1out
<< "Skipping " << Pkg
.Name() << ", it is already installed and no-upgrade is set." << endl
;
887 // Check if there is something new to install
888 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
889 if (State
.CandidateVer
== 0)
891 if (Pkg
->ProvidesList
!= 0)
893 c1out
<< "Package " << S
<< " is a virtual package provided by:" << endl
;
895 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
896 for (; I
.end() == false; I
++)
898 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
900 if ((*Cache
)[Pkg
].CandidateVerIter(*Cache
) == I
.OwnerVer())
902 if ((*Cache
)[Pkg
].Install() == true && (*Cache
)[Pkg
].NewInstall() == false)
903 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
904 " [Installed]"<< endl
;
906 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
909 c1out
<< "You should explicly select one to install." << endl
;
913 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
914 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
915 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
918 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
919 for (; Dep
.end() == false; Dep
++)
921 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
923 List
+= string(Dep
.ParentPkg().Name()) + " ";
925 ShowList(c1out
,"However the following packages replace it:",List
);
928 return _error
->Error("Package %s has no installation candidate",S
);
935 Cache
->MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
940 Cache
->MarkInstall(Pkg
,false);
941 if (State
.Install() == false)
942 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
946 // Install it with autoinstalling enabled.
947 if (State
.InstBroken() == true && BrokenFix
== false)
948 Cache
->MarkInstall(Pkg
,true);
951 /* If we are in the Broken fixing mode we do not attempt to fix the
952 problems. This is if the user invoked install without -f and gave
954 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
956 c1out
<< "You might want to run `apt-get -f install' to correct these:" << endl
;
957 ShowBroken(c1out
,Cache
,false);
959 return _error
->Error("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).");
962 // Call the scored problem resolver
963 Fix
.InstallProtect();
964 if (Fix
.Resolve(true) == false)
967 // Now we check the state of the packages,
968 if (Cache
->BrokenCount() != 0)
970 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
971 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
972 c1out
<< "distribution that some required packages have not yet been created" << endl
;
973 c1out
<< "or been moved out of Incoming." << endl
;
977 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
978 c1out
<< "the package is simply not installable and a bug report against" << endl
;
979 c1out
<< "that package should be filed." << endl
;
982 c1out
<< "The following information may help to resolve the situation:" << endl
;
984 ShowBroken(c1out
,Cache
,false);
985 return _error
->Error("Sorry, broken packages");
988 /* Print out a list of packages that are going to be installed extra
989 to what the user asked */
990 if (Cache
->InstCount() != ExpectedInst
)
993 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
995 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
996 if ((*Cache
)[I
].Install() == false)
1000 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1001 if (strcmp(*J
,I
.Name()) == 0)
1005 List
+= string(I
.Name()) + " ";
1008 ShowList(c1out
,"The following extra packages will be installed:",List
);
1011 // See if we need to prompt
1012 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
1013 return InstallPackages(Cache
,false,false);
1015 return InstallPackages(Cache
,false);
1018 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1019 // ---------------------------------------------------------------------
1020 /* Intelligent upgrader that will install and remove packages at will */
1021 bool DoDistUpgrade(CommandLine
&CmdL
)
1024 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1027 c0out
<< "Calculating Upgrade... " << flush
;
1028 if (pkgDistUpgrade(*Cache
) == false)
1030 c0out
<< "Failed" << endl
;
1031 ShowBroken(c1out
,Cache
,false);
1035 c0out
<< "Done" << endl
;
1037 return InstallPackages(Cache
,true);
1040 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1041 // ---------------------------------------------------------------------
1042 /* Follows dselect's selections */
1043 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1046 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1049 // Install everything with the install flag set
1050 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1051 for (;I
.end() != true; I
++)
1053 /* Install the package only if it is a new install, the autoupgrader
1054 will deal with the rest */
1055 if (I
->SelectedState
== pkgCache::State::Install
)
1056 Cache
->MarkInstall(I
,false);
1059 /* Now install their deps too, if we do this above then order of
1060 the status file is significant for | groups */
1061 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1063 /* Install the package only if it is a new install, the autoupgrader
1064 will deal with the rest */
1065 if (I
->SelectedState
== pkgCache::State::Install
)
1066 Cache
->MarkInstall(I
,true);
1069 // Apply erasures now, they override everything else.
1070 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1073 if (I
->SelectedState
== pkgCache::State::DeInstall
||
1074 I
->SelectedState
== pkgCache::State::Purge
)
1075 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
1078 /* Resolve any problems that dselect created, allupgrade cannot handle
1079 such things. We do so quite agressively too.. */
1080 if (Cache
->BrokenCount() != 0)
1082 pkgProblemResolver
Fix(Cache
);
1084 // Hold back held packages.
1085 if (_config
->FindB("APT::Ingore-Hold",false) == false)
1087 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
1089 if (I
->SelectedState
== pkgCache::State::Hold
)
1097 if (Fix
.Resolve() == false)
1099 ShowBroken(c1out
,Cache
,false);
1100 return _error
->Error("Internal Error, problem resolver broke stuff");
1104 // Now upgrade everything
1105 if (pkgAllUpgrade(Cache
) == false)
1107 ShowBroken(c1out
,Cache
,false);
1108 return _error
->Error("Internal Error, problem resolver broke stuff");
1111 return InstallPackages(Cache
,false);
1114 // DoClean - Remove download archives /*{{{*/
1115 // ---------------------------------------------------------------------
1117 bool DoClean(CommandLine
&CmdL
)
1120 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
1121 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1125 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1126 // ---------------------------------------------------------------------
1127 /* This is similar to clean but it only purges things that cannot be
1128 downloaded, that is old versions of cached packages. */
1129 class LogCleaner
: public pkgArchiveCleaner
1132 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1134 cout
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
1136 if (_config
->FindB("APT::Get::Simulate") == false)
1141 bool DoAutoClean(CommandLine
&CmdL
)
1144 if (Cache
.Open() == false)
1149 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1150 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1153 // DoCheck - Perform the check operation /*{{{*/
1154 // ---------------------------------------------------------------------
1155 /* Opening automatically checks the system, this command is mostly used
1157 bool DoCheck(CommandLine
&CmdL
)
1166 // DoSource - Fetch a source archive /*{{{*/
1167 // ---------------------------------------------------------------------
1168 /* Fetch souce packages */
1176 bool DoSource(CommandLine
&CmdL
)
1179 if (Cache
.Open(false) == false)
1182 if (CmdL
.FileSize() <= 1)
1183 return _error
->Error("Must specify at least one package to fetch source for");
1185 // Read the source list
1187 if (List
.ReadMainList() == false)
1188 return _error
->Error("The list of sources could not be read.");
1190 // Create the text record parsers
1191 pkgRecords
Recs(Cache
);
1192 pkgSrcRecords
SrcRecs(List
);
1193 if (_error
->PendingError() == true)
1196 // Create the download object
1197 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1198 pkgAcquire
Fetcher(&Stat
);
1200 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
1202 // Load the requestd sources into the fetcher
1204 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1208 /* Lookup the version of the package we would install if we were to
1209 install a version and determine the source package name, then look
1210 in the archive for a source package of the same name. In theory
1211 we could stash the version string as well and match that too but
1212 today there aren't multi source versions in the archive. */
1213 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(*I
);
1214 if (Pkg
.end() == false)
1216 pkgCache::VerIterator Ver
= Cache
->GetCandidateVer(Pkg
);
1217 if (Ver
.end() == false)
1219 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1220 Src
= Parse
.SourcePkg();
1224 // No source package name..
1225 if (Src
.empty() == true)
1229 pkgSrcRecords::Parser
*Last
= 0;
1230 unsigned long Offset
= 0;
1232 bool IsMatch
= false;
1234 // Iterate over all of the hits
1235 pkgSrcRecords::Parser
*Parse
;
1237 while ((Parse
= SrcRecs
.Find(Src
.c_str(),false)) != 0)
1239 string Ver
= Parse
->Version();
1241 // Skip name mismatches
1242 if (IsMatch
== true && Parse
->Package() != Src
)
1245 // Newer version or an exact match
1246 if (Last
== 0 || pkgVersionCompare(Version
,Ver
) < 0 ||
1247 (Parse
->Package() == Src
&& IsMatch
== false))
1249 IsMatch
= Parse
->Package() == Src
;
1251 Offset
= Parse
->Offset();
1257 return _error
->Error("Unable to find a source package for %s",Src
.c_str());
1260 vector
<pkgSrcRecords::File
> Lst
;
1261 if (Last
->Jump(Offset
) == false || Last
->Files(Lst
) == false)
1264 // Load them into the fetcher
1265 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
1266 I
!= Lst
.end(); I
++)
1268 // Try to guess what sort of file it is we are getting.
1270 if (I
->Path
.find(".dsc") != string::npos
)
1273 Dsc
[J
].Package
= Last
->Package();
1274 Dsc
[J
].Version
= Last
->Version();
1275 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
1278 if (I
->Path
.find(".tar.gz") != string::npos
)
1280 if (I
->Path
.find(".diff.gz") != string::npos
)
1283 // Diff only mode only fetches .diff files
1284 if (_config
->FindB("APT::Get::Diff-Only",false) == true &&
1288 // Tar only mode only fetches .tar files
1289 if (_config
->FindB("APT::Get::Tar-Only",false) == true &&
1293 new pkgAcqFile(&Fetcher
,Last
->Source()->ArchiveURI(I
->Path
),
1294 I
->MD5Hash
,I
->Size
,Last
->Source()->SourceInfo(Src
,
1295 Last
->Version(),Comp
),Src
);
1299 // Display statistics
1300 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
1301 unsigned long FetchPBytes
= Fetcher
.PartialPresent();
1302 unsigned long DebBytes
= Fetcher
.TotalNeeded();
1304 // Check for enough free space
1306 string OutputDir
= ".";
1307 if (statfs(OutputDir
.c_str(),&Buf
) != 0)
1308 return _error
->Errno("statfs","Couldn't determine free space in %s",
1310 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1311 return _error
->Error("Sorry, you don't have enough free space in %s",
1315 c1out
<< "Need to get ";
1316 if (DebBytes
!= FetchBytes
)
1317 c1out
<< SizeToStr(FetchBytes
) << "B/" << SizeToStr(DebBytes
) << 'B';
1319 c1out
<< SizeToStr(DebBytes
) << 'B';
1320 c1out
<< " of source archives." << endl
;
1322 if (_config
->FindB("APT::Get::Simulate",false) == true)
1324 for (unsigned I
= 0; I
!= J
; I
++)
1325 cout
<< "Fetch Source " << Dsc
[I
].Package
<< endl
;
1329 // Just print out the uris an exit if the --print-uris flag was used
1330 if (_config
->FindB("APT::Get::Print-URIs") == true)
1332 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1333 for (; I
!= Fetcher
.UriEnd(); I
++)
1334 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1335 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1340 if (Fetcher
.Run() == pkgAcquire::Failed
)
1343 // Print error messages
1344 bool Failed
= false;
1345 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1347 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1348 (*I
)->Complete
== true)
1351 cerr
<< "Failed to fetch " << (*I
)->DescURI() << endl
;
1352 cerr
<< " " << (*I
)->ErrorText
<< endl
;
1356 return _error
->Error("Failed to fetch some archives.");
1358 if (_config
->FindB("APT::Get::Download-only",false) == true)
1361 // Unpack the sources
1362 pid_t Process
= ExecFork();
1366 for (unsigned I
= 0; I
!= J
; I
++)
1368 string Dir
= Dsc
[I
].Package
+ '-' + pkgBaseVersion(Dsc
[I
].Version
.c_str());
1370 // Diff only mode only fetches .diff files
1371 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
1372 _config
->FindB("APT::Get::Tar-Only",false) == true)
1375 // See if the package is already unpacked
1377 if (stat(Dir
.c_str(),&Stat
) == 0 &&
1378 S_ISDIR(Stat
.st_mode
) != 0)
1380 c0out
<< "Skipping unpack of already unpacked source in " << Dir
<< endl
;
1386 snprintf(S
,sizeof(S
),"%s -x %s",
1387 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
1388 Dsc
[I
].Dsc
.c_str());
1391 cerr
<< "Unpack command '" << S
<< "' failed." << endl
;
1396 // Try to compile it with dpkg-buildpackage
1397 if (_config
->FindB("APT::Get::Compile",false) == true)
1399 // Call dpkg-buildpackage
1401 snprintf(S
,sizeof(S
),"cd %s && %s %s",
1403 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
1404 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
1408 cerr
<< "Build command '" << S
<< "' failed." << endl
;
1417 // Wait for the subprocess
1419 while (waitpid(Process
,&Status
,0) != Process
)
1423 return _error
->Errno("waitpid","Couldn't wait for subprocess");
1426 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
1427 return _error
->Error("Child process failed");
1433 // ShowHelp - Show a help screen /*{{{*/
1434 // ---------------------------------------------------------------------
1436 bool ShowHelp(CommandLine
&CmdL
)
1438 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
1439 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
1440 if (_config
->FindB("version") == true)
1443 cout
<< "Usage: apt-get [options] command" << endl
;
1444 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
1446 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
1447 cout
<< "installing packages. The most frequently used commands are update" << endl
;
1448 cout
<< "and install." << endl
;
1450 cout
<< "Commands:" << endl
;
1451 cout
<< " update - Retrieve new lists of packages" << endl
;
1452 cout
<< " upgrade - Perform an upgrade" << endl
;
1453 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
1454 cout
<< " remove - Remove packages" << endl
;
1455 cout
<< " source - Download source archives" << endl
;
1456 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
1457 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
1458 cout
<< " clean - Erase downloaded archive files" << endl
;
1459 cout
<< " autoclean - Erase old downloaded archive files" << endl
;
1460 cout
<< " check - Verify that there are no broken dependencies" << endl
;
1462 cout
<< "Options:" << endl
;
1463 cout
<< " -h This help text." << endl
;
1464 cout
<< " -q Loggable output - no progress indicator" << endl
;
1465 cout
<< " -qq No output except for errors" << endl
;
1466 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
1467 cout
<< " -s No-act. Perform ordering simulation" << endl
;
1468 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
1469 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
1470 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
1471 cout
<< " -u Show a list of upgraded packages as well" << endl
;
1472 cout
<< " -b Build the source package after fetching it" << endl
;
1473 cout
<< " -c=? Read this configuration file" << endl
;
1474 cout
<< " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl
;
1475 cout
<< "See the apt-get(8), sources.list(5) and apt.conf(5) manual" << endl
;
1476 cout
<< "pages for more information and options." << endl
;
1480 // GetInitialize - Initialize things for apt-get /*{{{*/
1481 // ---------------------------------------------------------------------
1483 void GetInitialize()
1485 _config
->Set("quiet",0);
1486 _config
->Set("help",false);
1487 _config
->Set("APT::Get::Download-Only",false);
1488 _config
->Set("APT::Get::Simulate",false);
1489 _config
->Set("APT::Get::Assume-Yes",false);
1490 _config
->Set("APT::Get::Fix-Broken",false);
1491 _config
->Set("APT::Get::Force-Yes",false);
1492 _config
->Set("APT::Get::APT::Get::No-List-Cleanup",true);
1495 // SigWinch - Window size change signal handler /*{{{*/
1496 // ---------------------------------------------------------------------
1500 // Riped from GNU ls
1504 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
1505 ScreenWidth
= ws
.ws_col
- 1;
1510 int main(int argc
,const char *argv
[])
1512 CommandLine::Args Args
[] = {
1513 {'h',"help","help",0},
1514 {'v',"version","version",0},
1515 {'q',"quiet","quiet",CommandLine::IntLevel
},
1516 {'q',"silent","quiet",CommandLine::IntLevel
},
1517 {'d',"download-only","APT::Get::Download-Only",0},
1518 {'b',"compile","APT::Get::Compile",0},
1519 {'b',"build","APT::Get::Compile",0},
1520 {'s',"simulate","APT::Get::Simulate",0},
1521 {'s',"just-print","APT::Get::Simulate",0},
1522 {'s',"recon","APT::Get::Simulate",0},
1523 {'s',"no-act","APT::Get::Simulate",0},
1524 {'y',"yes","APT::Get::Assume-Yes",0},
1525 {'y',"assume-yes","APT::Get::Assume-Yes",0},
1526 {'f',"fix-broken","APT::Get::Fix-Broken",0},
1527 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
1528 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
1529 {0,"no-download","APT::Get::No-Download",0},
1530 {0,"fix-missing","APT::Get::Fix-Missing",0},
1531 {0,"ignore-hold","APT::Ingore-Hold",0},
1532 {0,"no-upgrade","APT::Get::no-upgrade",0},
1533 {0,"force-yes","APT::Get::force-yes",0},
1534 {0,"print-uris","APT::Get::Print-URIs",0},
1535 {0,"diff-only","APT::Get::Diff-Only",0},
1536 {0,"tar-only","APT::Get::tar-Only",0},
1537 {0,"purge","APT::Get::Purge",0},
1538 {0,"list-cleanup","APT::Get::List-Cleanup",0},
1539 {'c',"config-file",0,CommandLine::ConfigFile
},
1540 {'o',"option",0,CommandLine::ArbItem
},
1542 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
1543 {"upgrade",&DoUpgrade
},
1544 {"install",&DoInstall
},
1545 {"remove",&DoInstall
},
1546 {"dist-upgrade",&DoDistUpgrade
},
1547 {"dselect-upgrade",&DoDSelectUpgrade
},
1549 {"autoclean",&DoAutoClean
},
1551 {"source",&DoSource
},
1555 // Parse the command line and initialize the package library
1556 CommandLine
CmdL(Args
,_config
);
1557 if (pkgInitialize(*_config
) == false ||
1558 CmdL
.Parse(argc
,argv
) == false)
1560 _error
->DumpErrors();
1564 // See if the help should be shown
1565 if (_config
->FindB("help") == true ||
1566 _config
->FindB("version") == true ||
1567 CmdL
.FileSize() == 0)
1568 return ShowHelp(CmdL
);
1570 // Deal with stdout not being a tty
1571 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
1572 _config
->Set("quiet","1");
1574 // Setup the output streams
1575 c0out
.rdbuf(cout
.rdbuf());
1576 c1out
.rdbuf(cout
.rdbuf());
1577 c2out
.rdbuf(cout
.rdbuf());
1578 if (_config
->FindI("quiet",0) > 0)
1579 c0out
.rdbuf(devnull
.rdbuf());
1580 if (_config
->FindI("quiet",0) > 1)
1581 c1out
.rdbuf(devnull
.rdbuf());
1583 // Setup the signals
1584 signal(SIGPIPE
,SIG_IGN
);
1585 signal(SIGWINCH
,SigWinch
);
1588 // Match the operation
1589 CmdL
.DispatchArg(Cmds
);
1591 // Print any errors or warnings found during parsing
1592 if (_error
->empty() == false)
1594 bool Errors
= _error
->PendingError();
1595 _error
->DumpErrors();
1596 return Errors
== true?100:0;