]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.87 1999/10/28 05:54:45 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 unsigned 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
)
193 for (unsigned J
= 0; J
!= Indent
; J
++)
197 if (FirstOr
== false)
199 for (unsigned J
= 0; J
!= strlen(End
.DepType()) + 3; J
++)
203 out
<< ' ' << End
.DepType() << ": ";
206 out
<< Start
.TargetPkg().Name();
208 // Show a quick summary of the version requirements
209 if (Start
.TargetVer() != 0)
210 out
<< " (" << Start
.CompType() << " " << Start
.TargetVer() <<
213 /* Show a summary of the target package if possible. In the case
214 of virtual packages we show nothing */
215 pkgCache::PkgIterator Targ
= Start
.TargetPkg();
216 if (Targ
->ProvidesList
== 0)
219 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
220 if (Ver
.end() == false)
221 out
<< Ver
.VerStr() << (Now
?" is installed":" is to be installed");
224 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
226 if (Targ
->ProvidesList
== 0)
227 out
<< "it is not installable";
229 out
<< "it is a virtual package";
232 out
<< (Now
?"it is not installed":"it is not going to be installed");
248 // ShowNew - Show packages to newly install /*{{{*/
249 // ---------------------------------------------------------------------
251 void ShowNew(ostream
&out
,CacheFile
&Cache
)
253 /* Print out a list of packages that are going to be removed extra
254 to what the user asked */
256 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
258 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
259 if (Cache
[I
].NewInstall() == true)
260 List
+= string(I
.Name()) + " ";
263 ShowList(out
,"The following NEW packages will be installed:",List
);
266 // ShowDel - Show packages to delete /*{{{*/
267 // ---------------------------------------------------------------------
269 void ShowDel(ostream
&out
,CacheFile
&Cache
)
271 /* Print out a list of packages that are going to be removed extra
272 to what the user asked */
274 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
276 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
277 if (Cache
[I
].Delete() == true)
279 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
280 List
+= string(I
.Name()) + "* ";
282 List
+= string(I
.Name()) + " ";
286 ShowList(out
,"The following packages will be REMOVED:",List
);
289 // ShowKept - Show kept packages /*{{{*/
290 // ---------------------------------------------------------------------
292 void ShowKept(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() == true || Cache
[I
].Upgradable() == false ||
301 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
304 List
+= string(I
.Name()) + " ";
306 ShowList(out
,"The following packages have been kept back",List
);
309 // ShowUpgraded - Show upgraded packages /*{{{*/
310 // ---------------------------------------------------------------------
312 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
315 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
317 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
320 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
323 List
+= string(I
.Name()) + " ";
325 ShowList(out
,"The following packages will be upgraded",List
);
328 // ShowHold - Show held but changed packages /*{{{*/
329 // ---------------------------------------------------------------------
331 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
334 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
336 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
337 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
338 I
->SelectedState
== pkgCache::State::Hold
)
339 List
+= string(I
.Name()) + " ";
342 return ShowList(out
,"The following held packages will be changed:",List
);
345 // ShowEssential - Show an essential package warning /*{{{*/
346 // ---------------------------------------------------------------------
347 /* This prints out a warning message that is not to be ignored. It shows
348 all essential packages and their dependents that are to be removed.
349 It is insanely risky to remove the dependents of an essential package! */
350 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
353 bool *Added
= new bool[Cache
->HeaderP
->PackageCount
];
354 for (unsigned int I
= 0; I
!= Cache
->HeaderP
->PackageCount
; I
++)
357 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
359 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
360 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
363 // The essential package is being removed
364 if (Cache
[I
].Delete() == true)
366 if (Added
[I
->ID
] == false)
369 List
+= string(I
.Name()) + " ";
373 if (I
->CurrentVer
== 0)
376 // Print out any essential package depenendents that are to be removed
377 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
379 // Skip everything but depends
380 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
381 D
->Type
!= pkgCache::Dep::Depends
)
384 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
385 if (Cache
[P
].Delete() == true)
387 if (Added
[P
->ID
] == true)
392 sprintf(S
,"%s (due to %s) ",P
.Name(),I
.Name());
399 if (List
.empty() == false)
400 out
<< "WARNING: The following essential packages will be removed" << endl
;
401 return ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
404 // Stats - Show some statistics /*{{{*/
405 // ---------------------------------------------------------------------
407 void Stats(ostream
&out
,pkgDepCache
&Dep
)
409 unsigned long Upgrade
= 0;
410 unsigned long Install
= 0;
411 unsigned long ReInstall
= 0;
412 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
414 if (Dep
[I
].NewInstall() == true)
417 if (Dep
[I
].Upgrade() == true)
419 if (Dep
[I
].Delete() == false && (Dep
[I
].iFlags
& pkgDepCache::ReInstall
) == pkgDepCache::ReInstall
)
423 out
<< Upgrade
<< " packages upgraded, " <<
424 Install
<< " newly installed, ";
426 out
<< ReInstall
<< " reinstalled, ";
427 out
<< Dep
.DelCount() << " to remove and " <<
428 Dep
.KeepCount() << " not upgraded." << endl
;
430 if (Dep
.BadCount() != 0)
431 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
435 // CacheFile::NameComp - QSort compare by name /*{{{*/
436 // ---------------------------------------------------------------------
438 pkgCache
*CacheFile::SortCache
= 0;
439 int CacheFile::NameComp(const void *a
,const void *b
)
441 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
442 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
444 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
445 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
447 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
450 // CacheFile::Sort - Sort by name /*{{{*/
451 // ---------------------------------------------------------------------
453 void CacheFile::Sort()
456 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
457 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
458 pkgCache::PkgIterator I
= Cache
->PkgBegin();
459 for (;I
.end() != true; I
++)
463 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
466 // CacheFile::Open - Open the cache file /*{{{*/
467 // ---------------------------------------------------------------------
468 /* This routine generates the caches and then opens the dependency cache
469 and verifies that the system is OK. */
470 bool CacheFile::CheckDeps(bool AllowBroken
)
472 if (_error
->PendingError() == true)
475 // Check that the system is OK
476 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
477 return _error
->Error("Internal Error, non-zero counts");
479 // Apply corrections for half-installed packages
480 if (pkgApplyStatus(*Cache
) == false)
484 if (Cache
->BrokenCount() == 0 || AllowBroken
== true)
487 // Attempt to fix broken things
488 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
490 c1out
<< "Correcting dependencies..." << flush
;
491 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
493 c1out
<< " failed." << endl
;
494 ShowBroken(c1out
,*this,true);
496 return _error
->Error("Unable to correct dependencies");
498 if (pkgMinimizeUpgrade(*Cache
) == false)
499 return _error
->Error("Unable to minimize the upgrade set");
501 c1out
<< " Done" << endl
;
505 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
506 ShowBroken(c1out
,*this,true);
508 return _error
->Error("Unmet dependencies. Try using -f.");
515 // InstallPackages - Actually download and install the packages /*{{{*/
516 // ---------------------------------------------------------------------
517 /* This displays the informative messages describing what is going to
518 happen and then calls the download routines */
519 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,bool Saftey
= true)
521 if (_config
->FindB("APT::Get::Purge",false) == true)
523 pkgCache::PkgIterator I
= Cache
->PkgBegin();
524 for (; I
.end() == false; I
++)
526 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
527 Cache
->MarkDelete(I
,true);
532 bool Essential
= false;
534 // Show all the various warning indicators
535 ShowDel(c1out
,Cache
);
536 ShowNew(c1out
,Cache
);
538 ShowKept(c1out
,Cache
);
539 Fail
|= !ShowHold(c1out
,Cache
);
540 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
541 ShowUpgraded(c1out
,Cache
);
542 Essential
= !ShowEssential(c1out
,Cache
);
547 if (Cache
->BrokenCount() != 0)
549 ShowBroken(c1out
,Cache
,false);
550 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
553 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
554 Cache
->BadCount() == 0)
558 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::No-Remove",false) == true)
559 return _error
->Error("Packages need to be removed but No Remove was specified.");
561 // Run the simulator ..
562 if (_config
->FindB("APT::Get::Simulate") == true)
564 pkgSimulate
PM(Cache
);
565 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
566 if (Res
== pkgPackageManager::Failed
)
568 if (Res
!= pkgPackageManager::Completed
)
569 return _error
->Error("Internal Error, Ordering didn't finish");
573 // Create the text record parser
574 pkgRecords
Recs(Cache
);
575 if (_error
->PendingError() == true)
578 // Lock the archive directory
580 if (_config
->FindB("Debug::NoLocking",false) == false)
582 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
583 if (_error
->PendingError() == true)
584 return _error
->Error("Unable to lock the download directory");
587 // Create the download object
588 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
589 pkgAcquire
Fetcher(&Stat
);
591 // Read the source list
593 if (List
.ReadMainList() == false)
594 return _error
->Error("The list of sources could not be read.");
596 // Create the package manager and prepare to download
598 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false ||
599 _error
->PendingError() == true)
602 // Display statistics
603 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
604 unsigned long FetchPBytes
= Fetcher
.PartialPresent();
605 unsigned long DebBytes
= Fetcher
.TotalNeeded();
606 if (DebBytes
!= Cache
->DebSize())
608 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
609 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
613 c1out
<< "Need to get ";
614 if (DebBytes
!= FetchBytes
)
615 c1out
<< SizeToStr(FetchBytes
) << "B/" << SizeToStr(DebBytes
) << 'B';
617 c1out
<< SizeToStr(DebBytes
) << 'B';
619 c1out
<< " of archives. After unpacking ";
621 // Check for enough free space
623 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
624 if (statfs(OutputDir
.c_str(),&Buf
) != 0)
625 return _error
->Errno("statfs","Couldn't determine free space in %s",
627 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
628 return _error
->Error("Sorry, you don't have enough free space in %s to hold all the .debs.",
632 if (Cache
->UsrSize() >= 0)
633 c1out
<< SizeToStr(Cache
->UsrSize()) << "B will be used." << endl
;
635 c1out
<< SizeToStr(-1*Cache
->UsrSize()) << "B will be freed." << endl
;
637 if (_error
->PendingError() == true)
641 if (_config
->FindI("quiet",0) >= 2 ||
642 _config
->FindB("APT::Get::Assume-Yes",false) == true)
644 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
645 return _error
->Error("There are problems and -y was used without --force-yes");
648 if (Essential
== true && Saftey
== true)
650 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
651 return _error
->Error("Trivial Only specified but this is not a trivial operation.");
653 c2out
<< "You are about to do something potentially harmful" << endl
;
654 c2out
<< "To continue type in the phrase 'Yes, I understand this may be bad'" << endl
;
655 c2out
<< " ?] " << flush
;
656 if (AnalPrompt("Yes, I understand this may be bad") == false)
658 c2out
<< "Abort." << endl
;
664 // Prompt to continue
665 if (Ask
== true || Fail
== true)
667 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
668 return _error
->Error("Trivial Only specified but this is not a trivial operation.");
670 if (_config
->FindI("quiet",0) < 2 &&
671 _config
->FindB("APT::Get::Assume-Yes",false) == false)
673 c2out
<< "Do you want to continue? [Y/n] " << flush
;
675 if (YnPrompt() == false)
677 c2out
<< "Abort." << endl
;
684 // Just print out the uris an exit if the --print-uris flag was used
685 if (_config
->FindB("APT::Get::Print-URIs") == true)
687 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
688 for (; I
!= Fetcher
.UriEnd(); I
++)
689 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
690 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
697 if (_config
->FindB("APT::Get::No-Download",false) == false)
698 if (Fetcher
.Run() == pkgAcquire::Failed
)
703 bool Transient
= false;
704 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
706 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
707 (*I
)->Complete
== true)
710 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
717 cerr
<< "Failed to fetch " << (*I
)->DescURI() << endl
;
718 cerr
<< " " << (*I
)->ErrorText
<< endl
;
722 /* If we are in no download mode and missing files then there were
723 'failures' then the user must specify -m. Furthermore, there
724 is no such thing as a transient error in no-download mode! */
725 if (Transient
== true &&
726 _config
->FindB("APT::Get::No-Download",false) == true)
732 if (_config
->FindB("APT::Get::Download-Only",false) == true)
734 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
735 return _error
->Error("Some files failed to download");
739 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
741 return _error
->Error("Unable to fetch some archives, maybe try with --fix-missing?");
744 if (Transient
== true && Failed
== true)
745 return _error
->Error("--fix-missing and media swapping is not currently supported");
747 // Try to deal with missing package files
748 if (Failed
== true && PM
.FixMissing() == false)
750 cerr
<< "Unable to correct missing packages." << endl
;
751 return _error
->Error("Aborting Install.");
755 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
756 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
758 if (Res
== pkgPackageManager::Completed
)
761 // Reload the fetcher object and loop again for media swapping
763 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false)
768 // TryToInstall - Try to install a single package /*{{{*/
769 // ---------------------------------------------------------------------
770 /* This used to be inlined in DoInstall, but with the advent of regex package
771 name matching it was split out.. */
772 bool TryToInstall(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
773 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
774 unsigned int &ExpectedInst
,bool AllowFail
= true)
776 /* This is a pure virtual package and there is a single available
778 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0 &&
779 Pkg
.ProvidesList()->NextProvides
== 0)
781 pkgCache::PkgIterator Tmp
= Pkg
.ProvidesList().OwnerPkg();
782 c1out
<< "Note, installing " << Tmp
.Name() << " instead of " << Pkg
.Name() << endl
;
786 // Handle the no-upgrade case
787 if (_config
->FindB("APT::Get::no-upgrade",false) == true &&
788 Pkg
->CurrentVer
!= 0)
790 if (AllowFail
== true)
791 c1out
<< "Skipping " << Pkg
.Name() << ", it is already installed and no-upgrade is set." << endl
;
795 // Check if there is something at all to install
796 pkgDepCache::StateCache
&State
= Cache
[Pkg
];
797 if (State
.CandidateVer
== 0)
799 if (AllowFail
== false)
802 if (Pkg
->ProvidesList
!= 0)
804 c1out
<< "Package " << Pkg
.Name() << " is a virtual package provided by:" << endl
;
806 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
807 for (; I
.end() == false; I
++)
809 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
811 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer())
813 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
814 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
815 " [Installed]"<< endl
;
817 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
820 c1out
<< "You should explicitly select one to install." << endl
;
824 c1out
<< "Package " << Pkg
.Name() << " has no available version, but exists in the database." << endl
;
825 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
826 c1out
<< "never uploaded, has been obsoleted or is not available with the contents " << endl
;
827 c1out
<< "of sources.list" << endl
;
830 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
831 for (; Dep
.end() == false; Dep
++)
833 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
835 List
+= string(Dep
.ParentPkg().Name()) + " ";
837 ShowList(c1out
,"However the following packages replace it:",List
);
840 _error
->Error("Package %s has no installation candidate",Pkg
.Name());
849 Cache
.MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
854 Cache
.MarkInstall(Pkg
,false);
855 if (State
.Install() == false)
857 if (_config
->FindB("APT::Get::ReInstall",false) == true)
859 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
860 c1out
<< "Sorry, re-installation of " << Pkg
.Name() << " is not possible, it cannot be downloaded" << endl
;
862 Cache
.SetReInstall(Pkg
,true);
866 if (AllowFail
== true)
867 c1out
<< "Sorry, " << Pkg
.Name() << " is already the newest version" << endl
;
873 // Install it with autoinstalling enabled.
874 if (State
.InstBroken() == true && BrokenFix
== false)
875 Cache
.MarkInstall(Pkg
,true);
880 // DoUpdate - Update the package lists /*{{{*/
881 // ---------------------------------------------------------------------
883 bool DoUpdate(CommandLine
&)
885 // Get the source list
887 if (List
.ReadMainList() == false)
890 // Lock the list directory
892 if (_config
->FindB("Debug::NoLocking",false) == false)
894 Lock
.Fd(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
895 if (_error
->PendingError() == true)
896 return _error
->Error("Unable to lock the list directory");
899 // Create the download object
900 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
901 pkgAcquire
Fetcher(&Stat
);
903 // Populate it with the source selection
904 pkgSourceList::const_iterator I
;
905 for (I
= List
.begin(); I
!= List
.end(); I
++)
907 new pkgAcqIndex(&Fetcher
,I
);
908 if (_error
->PendingError() == true)
913 if (Fetcher
.Run() == pkgAcquire::Failed
)
917 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
919 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
924 cerr
<< "Failed to fetch " << (*I
)->DescURI() << endl
;
925 cerr
<< " " << (*I
)->ErrorText
<< endl
;
929 // Clean out any old list files
930 if (_config
->FindB("APT::Get::List-Cleanup",false) == false)
932 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
933 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
937 // Prepare the cache.
939 if (Cache
.Open() == false)
943 return _error
->Error("Some index files failed to download, they have been ignored, or old ones used instead.");
947 // DoUpgrade - Upgrade all packages /*{{{*/
948 // ---------------------------------------------------------------------
949 /* Upgrade all packages without installing new packages or erasing old
951 bool DoUpgrade(CommandLine
&CmdL
)
954 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
958 if (pkgAllUpgrade(Cache
) == false)
960 ShowBroken(c1out
,Cache
,false);
961 return _error
->Error("Internal Error, AllUpgrade broke stuff");
964 return InstallPackages(Cache
,true);
967 // DoInstall - Install packages from the command line /*{{{*/
968 // ---------------------------------------------------------------------
969 /* Install named packages */
970 bool DoInstall(CommandLine
&CmdL
)
973 if (Cache
.Open() == false || Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
976 // Enter the special broken fixing mode if the user specified arguments
977 bool BrokenFix
= false;
978 if (Cache
->BrokenCount() != 0)
981 unsigned int ExpectedInst
= 0;
982 unsigned int Packages
= 0;
983 pkgProblemResolver
Fix(Cache
);
985 bool DefRemove
= false;
986 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
989 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
991 // Duplicate the string
992 unsigned int Length
= strlen(*I
);
994 if (Length
>= sizeof(S
))
998 // See if we are removing the package
999 bool Remove
= DefRemove
;
1000 while (Cache
->FindPkg(S
).end() == true)
1002 // Handle an optional end tag indicating what to do
1003 if (S
[Length
- 1] == '-')
1010 if (S
[Length
- 1] == '+')
1019 // Locate the package
1020 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1022 if (Pkg
.end() == true)
1024 // Check if the name is a regex
1026 for (I
= S
; *I
!= 0; I
++)
1027 if (*I
== '.' || *I
== '?' || *I
== '*')
1030 return _error
->Error("Couldn't find package %s",S
);
1032 // Regexs must always be confirmed
1033 ExpectedInst
+= 1000;
1035 // Compile the regex pattern
1037 if (regcomp(&Pattern
,S
,REG_EXTENDED
| REG_ICASE
|
1039 return _error
->Error("Regex compilation error");
1041 // Run over the matches
1043 for (Pkg
= Cache
->PkgBegin(); Pkg
.end() == false; Pkg
++)
1045 if (regexec(&Pattern
,Pkg
.Name(),0,0,0) != 0)
1048 Hit
|= TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,
1049 ExpectedInst
,false);
1054 return _error
->Error("Couldn't find package %s",S
);
1058 if (TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,ExpectedInst
) == false)
1063 /* If we are in the Broken fixing mode we do not attempt to fix the
1064 problems. This is if the user invoked install without -f and gave
1066 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1068 c1out
<< "You might want to run `apt-get -f install' to correct these:" << endl
;
1069 ShowBroken(c1out
,Cache
,false);
1071 return _error
->Error("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).");
1074 // Call the scored problem resolver
1075 Fix
.InstallProtect();
1076 if (Fix
.Resolve(true) == false)
1079 // Now we check the state of the packages,
1080 if (Cache
->BrokenCount() != 0)
1082 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
1083 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
1084 c1out
<< "distribution that some required packages have not yet been created" << endl
;
1085 c1out
<< "or been moved out of Incoming." << endl
;
1089 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
1090 c1out
<< "the package is simply not installable and a bug report against" << endl
;
1091 c1out
<< "that package should be filed." << endl
;
1094 c1out
<< "The following information may help to resolve the situation:" << endl
;
1096 ShowBroken(c1out
,Cache
,false);
1097 return _error
->Error("Sorry, broken packages");
1100 /* Print out a list of packages that are going to be installed extra
1101 to what the user asked */
1102 if (Cache
->InstCount() != ExpectedInst
)
1105 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1107 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1108 if ((*Cache
)[I
].Install() == false)
1112 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1113 if (strcmp(*J
,I
.Name()) == 0)
1117 List
+= string(I
.Name()) + " ";
1120 ShowList(c1out
,"The following extra packages will be installed:",List
);
1123 // See if we need to prompt
1124 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
1125 return InstallPackages(Cache
,false,false);
1127 return InstallPackages(Cache
,false);
1130 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1131 // ---------------------------------------------------------------------
1132 /* Intelligent upgrader that will install and remove packages at will */
1133 bool DoDistUpgrade(CommandLine
&CmdL
)
1136 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1139 c0out
<< "Calculating Upgrade... " << flush
;
1140 if (pkgDistUpgrade(*Cache
) == false)
1142 c0out
<< "Failed" << endl
;
1143 ShowBroken(c1out
,Cache
,false);
1147 c0out
<< "Done" << endl
;
1149 return InstallPackages(Cache
,true);
1152 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1153 // ---------------------------------------------------------------------
1154 /* Follows dselect's selections */
1155 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1158 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1161 // Install everything with the install flag set
1162 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1163 for (;I
.end() != true; I
++)
1165 /* Install the package only if it is a new install, the autoupgrader
1166 will deal with the rest */
1167 if (I
->SelectedState
== pkgCache::State::Install
)
1168 Cache
->MarkInstall(I
,false);
1171 /* Now install their deps too, if we do this above then order of
1172 the status file is significant for | groups */
1173 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1175 /* Install the package only if it is a new install, the autoupgrader
1176 will deal with the rest */
1177 if (I
->SelectedState
== pkgCache::State::Install
)
1178 Cache
->MarkInstall(I
,true);
1181 // Apply erasures now, they override everything else.
1182 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1185 if (I
->SelectedState
== pkgCache::State::DeInstall
||
1186 I
->SelectedState
== pkgCache::State::Purge
)
1187 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
1190 /* Resolve any problems that dselect created, allupgrade cannot handle
1191 such things. We do so quite agressively too.. */
1192 if (Cache
->BrokenCount() != 0)
1194 pkgProblemResolver
Fix(Cache
);
1196 // Hold back held packages.
1197 if (_config
->FindB("APT::Ingore-Hold",false) == false)
1199 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
1201 if (I
->SelectedState
== pkgCache::State::Hold
)
1209 if (Fix
.Resolve() == false)
1211 ShowBroken(c1out
,Cache
,false);
1212 return _error
->Error("Internal Error, problem resolver broke stuff");
1216 // Now upgrade everything
1217 if (pkgAllUpgrade(Cache
) == false)
1219 ShowBroken(c1out
,Cache
,false);
1220 return _error
->Error("Internal Error, problem resolver broke stuff");
1223 return InstallPackages(Cache
,false);
1226 // DoClean - Remove download archives /*{{{*/
1227 // ---------------------------------------------------------------------
1229 bool DoClean(CommandLine
&CmdL
)
1231 // Lock the archive directory
1233 if (_config
->FindB("Debug::NoLocking",false) == false)
1235 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1236 if (_error
->PendingError() == true)
1237 return _error
->Error("Unable to lock the download directory");
1241 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
1242 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1246 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1247 // ---------------------------------------------------------------------
1248 /* This is similar to clean but it only purges things that cannot be
1249 downloaded, that is old versions of cached packages. */
1250 class LogCleaner
: public pkgArchiveCleaner
1253 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1255 cout
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
1257 if (_config
->FindB("APT::Get::Simulate") == false)
1262 bool DoAutoClean(CommandLine
&CmdL
)
1264 // Lock the archive directory
1266 if (_config
->FindB("Debug::NoLocking",false) == false)
1268 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1269 if (_error
->PendingError() == true)
1270 return _error
->Error("Unable to lock the download directory");
1274 if (Cache
.Open() == false)
1279 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1280 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1283 // DoCheck - Perform the check operation /*{{{*/
1284 // ---------------------------------------------------------------------
1285 /* Opening automatically checks the system, this command is mostly used
1287 bool DoCheck(CommandLine
&CmdL
)
1296 // DoSource - Fetch a source archive /*{{{*/
1297 // ---------------------------------------------------------------------
1298 /* Fetch souce packages */
1306 bool DoSource(CommandLine
&CmdL
)
1309 if (Cache
.Open(false) == false)
1312 if (CmdL
.FileSize() <= 1)
1313 return _error
->Error("Must specify at least one package to fetch source for");
1315 // Read the source list
1317 if (List
.ReadMainList() == false)
1318 return _error
->Error("The list of sources could not be read.");
1320 // Create the text record parsers
1321 pkgRecords
Recs(Cache
);
1322 pkgSrcRecords
SrcRecs(List
);
1323 if (_error
->PendingError() == true)
1326 // Create the download object
1327 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1328 pkgAcquire
Fetcher(&Stat
);
1330 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
1332 // Load the requestd sources into the fetcher
1334 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1338 /* Lookup the version of the package we would install if we were to
1339 install a version and determine the source package name, then look
1340 in the archive for a source package of the same name. In theory
1341 we could stash the version string as well and match that too but
1342 today there aren't multi source versions in the archive. */
1343 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(*I
);
1344 if (Pkg
.end() == false)
1346 pkgCache::VerIterator Ver
= Cache
->GetCandidateVer(Pkg
);
1347 if (Ver
.end() == false)
1349 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1350 Src
= Parse
.SourcePkg();
1354 // No source package name..
1355 if (Src
.empty() == true)
1359 pkgSrcRecords::Parser
*Last
= 0;
1360 unsigned long Offset
= 0;
1362 bool IsMatch
= false;
1364 // Iterate over all of the hits
1365 pkgSrcRecords::Parser
*Parse
;
1367 while ((Parse
= SrcRecs
.Find(Src
.c_str(),false)) != 0)
1369 string Ver
= Parse
->Version();
1371 // Skip name mismatches
1372 if (IsMatch
== true && Parse
->Package() != Src
)
1375 // Newer version or an exact match
1376 if (Last
== 0 || pkgVersionCompare(Version
,Ver
) < 0 ||
1377 (Parse
->Package() == Src
&& IsMatch
== false))
1379 IsMatch
= Parse
->Package() == Src
;
1381 Offset
= Parse
->Offset();
1387 return _error
->Error("Unable to find a source package for %s",Src
.c_str());
1390 vector
<pkgSrcRecords::File
> Lst
;
1391 if (Last
->Jump(Offset
) == false || Last
->Files(Lst
) == false)
1394 // Load them into the fetcher
1395 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
1396 I
!= Lst
.end(); I
++)
1398 // Try to guess what sort of file it is we are getting.
1400 if (I
->Path
.find(".dsc") != string::npos
)
1403 Dsc
[J
].Package
= Last
->Package();
1404 Dsc
[J
].Version
= Last
->Version();
1405 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
1408 if (I
->Path
.find(".tar.gz") != string::npos
)
1410 if (I
->Path
.find(".diff.gz") != string::npos
)
1413 // Diff only mode only fetches .diff files
1414 if (_config
->FindB("APT::Get::Diff-Only",false) == true &&
1418 // Tar only mode only fetches .tar files
1419 if (_config
->FindB("APT::Get::Tar-Only",false) == true &&
1423 new pkgAcqFile(&Fetcher
,Last
->Source()->ArchiveURI(I
->Path
),
1424 I
->MD5Hash
,I
->Size
,Last
->Source()->SourceInfo(Src
,
1425 Last
->Version(),Comp
),Src
);
1429 // Display statistics
1430 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
1431 unsigned long FetchPBytes
= Fetcher
.PartialPresent();
1432 unsigned long DebBytes
= Fetcher
.TotalNeeded();
1434 // Check for enough free space
1436 string OutputDir
= ".";
1437 if (statfs(OutputDir
.c_str(),&Buf
) != 0)
1438 return _error
->Errno("statfs","Couldn't determine free space in %s",
1440 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1441 return _error
->Error("Sorry, you don't have enough free space in %s",
1445 c1out
<< "Need to get ";
1446 if (DebBytes
!= FetchBytes
)
1447 c1out
<< SizeToStr(FetchBytes
) << "B/" << SizeToStr(DebBytes
) << 'B';
1449 c1out
<< SizeToStr(DebBytes
) << 'B';
1450 c1out
<< " of source archives." << endl
;
1452 if (_config
->FindB("APT::Get::Simulate",false) == true)
1454 for (unsigned I
= 0; I
!= J
; I
++)
1455 cout
<< "Fetch Source " << Dsc
[I
].Package
<< endl
;
1459 // Just print out the uris an exit if the --print-uris flag was used
1460 if (_config
->FindB("APT::Get::Print-URIs") == true)
1462 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1463 for (; I
!= Fetcher
.UriEnd(); I
++)
1464 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1465 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1470 if (Fetcher
.Run() == pkgAcquire::Failed
)
1473 // Print error messages
1474 bool Failed
= false;
1475 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1477 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1478 (*I
)->Complete
== true)
1481 cerr
<< "Failed to fetch " << (*I
)->DescURI() << endl
;
1482 cerr
<< " " << (*I
)->ErrorText
<< endl
;
1486 return _error
->Error("Failed to fetch some archives.");
1488 if (_config
->FindB("APT::Get::Download-only",false) == true)
1491 // Unpack the sources
1492 pid_t Process
= ExecFork();
1496 for (unsigned I
= 0; I
!= J
; I
++)
1498 string Dir
= Dsc
[I
].Package
+ '-' + pkgBaseVersion(Dsc
[I
].Version
.c_str());
1500 // Diff only mode only fetches .diff files
1501 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
1502 _config
->FindB("APT::Get::Tar-Only",false) == true)
1505 // See if the package is already unpacked
1507 if (stat(Dir
.c_str(),&Stat
) == 0 &&
1508 S_ISDIR(Stat
.st_mode
) != 0)
1510 c0out
<< "Skipping unpack of already unpacked source in " << Dir
<< endl
;
1516 snprintf(S
,sizeof(S
),"%s -x %s",
1517 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
1518 Dsc
[I
].Dsc
.c_str());
1521 cerr
<< "Unpack command '" << S
<< "' failed." << endl
;
1526 // Try to compile it with dpkg-buildpackage
1527 if (_config
->FindB("APT::Get::Compile",false) == true)
1529 // Call dpkg-buildpackage
1531 snprintf(S
,sizeof(S
),"cd %s && %s %s",
1533 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
1534 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
1538 cerr
<< "Build command '" << S
<< "' failed." << endl
;
1547 // Wait for the subprocess
1549 while (waitpid(Process
,&Status
,0) != Process
)
1553 return _error
->Errno("waitpid","Couldn't wait for subprocess");
1556 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
1557 return _error
->Error("Child process failed");
1563 // ShowHelp - Show a help screen /*{{{*/
1564 // ---------------------------------------------------------------------
1566 bool ShowHelp(CommandLine
&CmdL
)
1568 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
1569 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
1570 if (_config
->FindB("version") == true)
1573 cout
<< "Usage: apt-get [options] command" << endl
;
1574 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
1576 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
1577 cout
<< "installing packages. The most frequently used commands are update" << endl
;
1578 cout
<< "and install." << endl
;
1580 cout
<< "Commands:" << endl
;
1581 cout
<< " update - Retrieve new lists of packages" << endl
;
1582 cout
<< " upgrade - Perform an upgrade" << endl
;
1583 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
1584 cout
<< " remove - Remove packages" << endl
;
1585 cout
<< " source - Download source archives" << endl
;
1586 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
1587 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
1588 cout
<< " clean - Erase downloaded archive files" << endl
;
1589 cout
<< " autoclean - Erase old downloaded archive files" << endl
;
1590 cout
<< " check - Verify that there are no broken dependencies" << endl
;
1592 cout
<< "Options:" << endl
;
1593 cout
<< " -h This help text." << endl
;
1594 cout
<< " -q Loggable output - no progress indicator" << endl
;
1595 cout
<< " -qq No output except for errors" << endl
;
1596 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
1597 cout
<< " -s No-act. Perform ordering simulation" << endl
;
1598 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
1599 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
1600 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
1601 cout
<< " -u Show a list of upgraded packages as well" << endl
;
1602 cout
<< " -b Build the source package after fetching it" << endl
;
1603 cout
<< " -c=? Read this configuration file" << endl
;
1604 cout
<< " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl
;
1605 cout
<< "See the apt-get(8), sources.list(5) and apt.conf(5) manual" << endl
;
1606 cout
<< "pages for more information and options." << endl
;
1610 // GetInitialize - Initialize things for apt-get /*{{{*/
1611 // ---------------------------------------------------------------------
1613 void GetInitialize()
1615 _config
->Set("quiet",0);
1616 _config
->Set("help",false);
1617 _config
->Set("APT::Get::Download-Only",false);
1618 _config
->Set("APT::Get::Simulate",false);
1619 _config
->Set("APT::Get::Assume-Yes",false);
1620 _config
->Set("APT::Get::Fix-Broken",false);
1621 _config
->Set("APT::Get::Force-Yes",false);
1622 _config
->Set("APT::Get::APT::Get::No-List-Cleanup",true);
1625 // SigWinch - Window size change signal handler /*{{{*/
1626 // ---------------------------------------------------------------------
1630 // Riped from GNU ls
1634 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
1635 ScreenWidth
= ws
.ws_col
- 1;
1640 int main(int argc
,const char *argv
[])
1642 CommandLine::Args Args
[] = {
1643 {'h',"help","help",0},
1644 {'v',"version","version",0},
1645 {'q',"quiet","quiet",CommandLine::IntLevel
},
1646 {'q',"silent","quiet",CommandLine::IntLevel
},
1647 {'d',"download-only","APT::Get::Download-Only",0},
1648 {'b',"compile","APT::Get::Compile",0},
1649 {'b',"build","APT::Get::Compile",0},
1650 {'s',"simulate","APT::Get::Simulate",0},
1651 {'s',"just-print","APT::Get::Simulate",0},
1652 {'s',"recon","APT::Get::Simulate",0},
1653 {'s',"no-act","APT::Get::Simulate",0},
1654 {'y',"yes","APT::Get::Assume-Yes",0},
1655 {'y',"assume-yes","APT::Get::Assume-Yes",0},
1656 {'f',"fix-broken","APT::Get::Fix-Broken",0},
1657 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
1658 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
1659 {0,"no-download","APT::Get::No-Download",0},
1660 {0,"fix-missing","APT::Get::Fix-Missing",0},
1661 {0,"ignore-hold","APT::Ingore-Hold",0},
1662 {0,"no-upgrade","APT::Get::no-upgrade",0},
1663 {0,"force-yes","APT::Get::force-yes",0},
1664 {0,"print-uris","APT::Get::Print-URIs",0},
1665 {0,"diff-only","APT::Get::Diff-Only",0},
1666 {0,"tar-only","APT::Get::tar-Only",0},
1667 {0,"purge","APT::Get::Purge",0},
1668 {0,"list-cleanup","APT::Get::List-Cleanup",0},
1669 {0,"reinstall","APT::Get::ReInstall",0},
1670 {0,"trivial-only","APT::Get::Trivial-Only",0},
1671 {0,"no-remove","APT::Get::No-Remove",0},
1672 {'c',"config-file",0,CommandLine::ConfigFile
},
1673 {'o',"option",0,CommandLine::ArbItem
},
1675 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
1676 {"upgrade",&DoUpgrade
},
1677 {"install",&DoInstall
},
1678 {"remove",&DoInstall
},
1679 {"dist-upgrade",&DoDistUpgrade
},
1680 {"dselect-upgrade",&DoDSelectUpgrade
},
1682 {"autoclean",&DoAutoClean
},
1684 {"source",&DoSource
},
1688 // Parse the command line and initialize the package library
1689 CommandLine
CmdL(Args
,_config
);
1690 if (pkgInitialize(*_config
) == false ||
1691 CmdL
.Parse(argc
,argv
) == false)
1693 _error
->DumpErrors();
1697 // See if the help should be shown
1698 if (_config
->FindB("help") == true ||
1699 _config
->FindB("version") == true ||
1700 CmdL
.FileSize() == 0)
1701 return ShowHelp(CmdL
);
1703 // Deal with stdout not being a tty
1704 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
1705 _config
->Set("quiet","1");
1707 // Setup the output streams
1708 c0out
.rdbuf(cout
.rdbuf());
1709 c1out
.rdbuf(cout
.rdbuf());
1710 c2out
.rdbuf(cout
.rdbuf());
1711 if (_config
->FindI("quiet",0) > 0)
1712 c0out
.rdbuf(devnull
.rdbuf());
1713 if (_config
->FindI("quiet",0) > 1)
1714 c1out
.rdbuf(devnull
.rdbuf());
1716 // Setup the signals
1717 signal(SIGPIPE
,SIG_IGN
);
1718 signal(SIGWINCH
,SigWinch
);
1721 // Match the operation
1722 CmdL
.DispatchArg(Cmds
);
1724 // Print any errors or warnings found during parsing
1725 if (_error
->empty() == false)
1727 bool Errors
= _error
->PendingError();
1728 _error
->DumpErrors();
1729 return Errors
== true?100:0;