]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.84 1999/10/24 06:03:48 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)
557 // Run the simulator ..
558 if (_config
->FindB("APT::Get::Simulate") == true)
560 pkgSimulate
PM(Cache
);
561 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
562 if (Res
== pkgPackageManager::Failed
)
564 if (Res
!= pkgPackageManager::Completed
)
565 return _error
->Error("Internal Error, Ordering didn't finish");
569 // Create the text record parser
570 pkgRecords
Recs(Cache
);
571 if (_error
->PendingError() == true)
574 // Lock the archive directory
576 if (_config
->FindB("Debug::NoLocking",false) == false)
578 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
579 if (_error
->PendingError() == true)
580 return _error
->Error("Unable to lock the download directory");
583 // Create the download object
584 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
585 pkgAcquire
Fetcher(&Stat
);
587 // Read the source list
589 if (List
.ReadMainList() == false)
590 return _error
->Error("The list of sources could not be read.");
592 // Create the package manager and prepare to download
594 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false ||
595 _error
->PendingError() == true)
598 // Display statistics
599 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
600 unsigned long FetchPBytes
= Fetcher
.PartialPresent();
601 unsigned long DebBytes
= Fetcher
.TotalNeeded();
602 if (DebBytes
!= Cache
->DebSize())
604 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
605 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
609 c1out
<< "Need to get ";
610 if (DebBytes
!= FetchBytes
)
611 c1out
<< SizeToStr(FetchBytes
) << "B/" << SizeToStr(DebBytes
) << 'B';
613 c1out
<< SizeToStr(DebBytes
) << 'B';
615 c1out
<< " of archives. After unpacking ";
617 // Check for enough free space
619 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
620 if (statfs(OutputDir
.c_str(),&Buf
) != 0)
621 return _error
->Errno("statfs","Couldn't determine free space in %s",
623 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
624 return _error
->Error("Sorry, you don't have enough free space in %s to hold all the .debs.",
628 if (Cache
->UsrSize() >= 0)
629 c1out
<< SizeToStr(Cache
->UsrSize()) << "B will be used." << endl
;
631 c1out
<< SizeToStr(-1*Cache
->UsrSize()) << "B will be freed." << endl
;
633 if (_error
->PendingError() == true)
637 if (_config
->FindI("quiet",0) >= 2 ||
638 _config
->FindB("APT::Get::Assume-Yes",false) == true)
640 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
641 return _error
->Error("There are problems and -y was used without --force-yes");
644 if (Essential
== true && Saftey
== true)
646 c2out
<< "You are about to do something potentially harmful" << endl
;
647 c2out
<< "To continue type in the phrase 'Yes, I understand this may be bad'" << endl
;
648 c2out
<< " ?] " << flush
;
649 if (AnalPrompt("Yes, I understand this may be bad") == false)
651 c2out
<< "Abort." << endl
;
657 // Prompt to continue
658 if (Ask
== true || Fail
== true)
660 if (_config
->FindI("quiet",0) < 2 &&
661 _config
->FindB("APT::Get::Assume-Yes",false) == false)
663 c2out
<< "Do you want to continue? [Y/n] " << flush
;
665 if (YnPrompt() == false)
667 c2out
<< "Abort." << endl
;
674 // Just print out the uris an exit if the --print-uris flag was used
675 if (_config
->FindB("APT::Get::Print-URIs") == true)
677 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
678 for (; I
!= Fetcher
.UriEnd(); I
++)
679 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
680 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
687 if (_config
->FindB("APT::Get::No-Download",false) == false)
688 if (Fetcher
.Run() == pkgAcquire::Failed
)
693 bool Transient
= false;
694 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
696 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
697 (*I
)->Complete
== true)
700 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
707 cerr
<< "Failed to fetch " << (*I
)->DescURI() << endl
;
708 cerr
<< " " << (*I
)->ErrorText
<< endl
;
712 /* If we are in no download mode and missing files then there were
713 'failures' then the user must specify -m. Furthermore, there
714 is no such thing as a transient error in no-download mode! */
715 if (Transient
== true &&
716 _config
->FindB("APT::Get::No-Download",false) == true)
722 if (_config
->FindB("APT::Get::Download-Only",false) == true)
724 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
725 return _error
->Error("Some files failed to download");
729 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
731 return _error
->Error("Unable to fetch some archives, maybe try with --fix-missing?");
734 if (Transient
== true && Failed
== true)
735 return _error
->Error("--fix-missing and media swapping is not currently supported");
737 // Try to deal with missing package files
738 if (Failed
== true && PM
.FixMissing() == false)
740 cerr
<< "Unable to correct missing packages." << endl
;
741 return _error
->Error("Aborting Install.");
745 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
746 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
748 if (Res
== pkgPackageManager::Completed
)
751 // Reload the fetcher object and loop again for media swapping
753 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false)
758 // TryToInstall - Try to install a single package /*{{{*/
759 // ---------------------------------------------------------------------
760 /* This used to be inlined in DoInstall, but with the advent of regex package
761 name matching it was split out.. */
762 bool TryToInstall(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
763 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
764 unsigned int &ExpectedInst
,bool AllowFail
= true)
766 /* This is a pure virtual package and there is a single available
768 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0 &&
769 Pkg
.ProvidesList()->NextProvides
== 0)
771 pkgCache::PkgIterator Tmp
= Pkg
.ProvidesList().OwnerPkg();
772 c1out
<< "Note, installing " << Tmp
.Name() << " instead of " << Pkg
.Name() << endl
;
776 // Handle the no-upgrade case
777 if (_config
->FindB("APT::Get::no-upgrade",false) == true &&
778 Pkg
->CurrentVer
!= 0)
780 if (AllowFail
== true)
781 c1out
<< "Skipping " << Pkg
.Name() << ", it is already installed and no-upgrade is set." << endl
;
785 // Check if there is something at all to install
786 pkgDepCache::StateCache
&State
= Cache
[Pkg
];
787 if (State
.CandidateVer
== 0)
789 if (AllowFail
== false)
792 if (Pkg
->ProvidesList
!= 0)
794 c1out
<< "Package " << Pkg
.Name() << " is a virtual package provided by:" << endl
;
796 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
797 for (; I
.end() == false; I
++)
799 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
801 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer())
803 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
804 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
805 " [Installed]"<< endl
;
807 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
810 c1out
<< "You should explicitly select one to install." << endl
;
814 c1out
<< "Package " << Pkg
.Name() << " has no available version, but exists in the database." << endl
;
815 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
816 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
819 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
820 for (; Dep
.end() == false; Dep
++)
822 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
824 List
+= string(Dep
.ParentPkg().Name()) + " ";
826 ShowList(c1out
,"However the following packages replace it:",List
);
829 _error
->Error("Package %s has no installation candidate",Pkg
.Name());
837 Cache
.MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
842 Cache
.MarkInstall(Pkg
,false);
843 if (State
.Install() == false)
845 if (_config
->FindB("APT::Get::ReInstall",false) == true)
847 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
848 c1out
<< "Sorry, re-installation of " << Pkg
.Name() << " is not possible, it cannot be downloaded" << endl
;
850 Cache
.SetReInstall(Pkg
,true);
854 if (AllowFail
== true)
855 c1out
<< "Sorry, " << Pkg
.Name() << " is already the newest version" << endl
;
861 // Install it with autoinstalling enabled.
862 if (State
.InstBroken() == true && BrokenFix
== false)
863 Cache
.MarkInstall(Pkg
,true);
868 // DoUpdate - Update the package lists /*{{{*/
869 // ---------------------------------------------------------------------
871 bool DoUpdate(CommandLine
&)
873 // Get the source list
875 if (List
.ReadMainList() == false)
878 // Lock the list directory
880 if (_config
->FindB("Debug::NoLocking",false) == false)
882 Lock
.Fd(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
883 if (_error
->PendingError() == true)
884 return _error
->Error("Unable to lock the list directory");
887 // Create the download object
888 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
889 pkgAcquire
Fetcher(&Stat
);
891 // Populate it with the source selection
892 pkgSourceList::const_iterator I
;
893 for (I
= List
.begin(); I
!= List
.end(); I
++)
895 new pkgAcqIndex(&Fetcher
,I
);
896 if (_error
->PendingError() == true)
901 if (Fetcher
.Run() == pkgAcquire::Failed
)
905 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
907 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
912 cerr
<< "Failed to fetch " << (*I
)->DescURI() << endl
;
913 cerr
<< " " << (*I
)->ErrorText
<< endl
;
917 // Clean out any old list files
918 if (_config
->FindB("APT::Get::List-Cleanup",false) == false)
920 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
921 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
925 // Prepare the cache.
927 if (Cache
.Open() == false)
931 return _error
->Error("Some index files failed to download, they have been ignored, or old ones used instead.");
935 // DoUpgrade - Upgrade all packages /*{{{*/
936 // ---------------------------------------------------------------------
937 /* Upgrade all packages without installing new packages or erasing old
939 bool DoUpgrade(CommandLine
&CmdL
)
942 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
946 if (pkgAllUpgrade(Cache
) == false)
948 ShowBroken(c1out
,Cache
,false);
949 return _error
->Error("Internal Error, AllUpgrade broke stuff");
952 return InstallPackages(Cache
,true);
955 // DoInstall - Install packages from the command line /*{{{*/
956 // ---------------------------------------------------------------------
957 /* Install named packages */
958 bool DoInstall(CommandLine
&CmdL
)
961 if (Cache
.Open() == false || Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
964 // Enter the special broken fixing mode if the user specified arguments
965 bool BrokenFix
= false;
966 if (Cache
->BrokenCount() != 0)
969 unsigned int ExpectedInst
= 0;
970 unsigned int Packages
= 0;
971 pkgProblemResolver
Fix(Cache
);
973 bool DefRemove
= false;
974 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
977 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
979 // Duplicate the string
980 unsigned int Length
= strlen(*I
);
982 if (Length
>= sizeof(S
))
986 // See if we are removing the package
987 bool Remove
= DefRemove
;
988 while (Cache
->FindPkg(S
).end() == true)
990 // Handle an optional end tag indicating what to do
991 if (S
[Length
- 1] == '-')
998 if (S
[Length
- 1] == '+')
1007 // Locate the package
1008 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1010 if (Pkg
.end() == true)
1012 // Check if the name is a regex
1014 for (I
= S
; *I
!= 0; I
++)
1015 if (*I
== '.' || *I
== '?' || *I
== '*')
1018 return _error
->Error("Couldn't find package %s",S
);
1020 // Regexs must always be confirmed
1021 ExpectedInst
+= 1000;
1023 // Compile the regex pattern
1025 if (regcomp(&Pattern
,S
,REG_EXTENDED
| REG_ICASE
|
1027 return _error
->Error("Regex compilation error");
1029 // Run over the matches
1031 for (Pkg
= Cache
->PkgBegin(); Pkg
.end() == false; Pkg
++)
1033 if (regexec(&Pattern
,Pkg
.Name(),0,0,0) != 0)
1036 Hit
|= TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,
1037 ExpectedInst
,false);
1042 return _error
->Error("Couldn't find package %s",S
);
1046 if (TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,ExpectedInst
) == false)
1051 /* If we are in the Broken fixing mode we do not attempt to fix the
1052 problems. This is if the user invoked install without -f and gave
1054 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1056 c1out
<< "You might want to run `apt-get -f install' to correct these:" << endl
;
1057 ShowBroken(c1out
,Cache
,false);
1059 return _error
->Error("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).");
1062 // Call the scored problem resolver
1063 Fix
.InstallProtect();
1064 if (Fix
.Resolve(true) == false)
1067 // Now we check the state of the packages,
1068 if (Cache
->BrokenCount() != 0)
1070 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
1071 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
1072 c1out
<< "distribution that some required packages have not yet been created" << endl
;
1073 c1out
<< "or been moved out of Incoming." << endl
;
1077 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
1078 c1out
<< "the package is simply not installable and a bug report against" << endl
;
1079 c1out
<< "that package should be filed." << endl
;
1082 c1out
<< "The following information may help to resolve the situation:" << endl
;
1084 ShowBroken(c1out
,Cache
,false);
1085 return _error
->Error("Sorry, broken packages");
1088 /* Print out a list of packages that are going to be installed extra
1089 to what the user asked */
1090 if (Cache
->InstCount() != ExpectedInst
)
1093 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1095 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1096 if ((*Cache
)[I
].Install() == false)
1100 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1101 if (strcmp(*J
,I
.Name()) == 0)
1105 List
+= string(I
.Name()) + " ";
1108 ShowList(c1out
,"The following extra packages will be installed:",List
);
1111 // See if we need to prompt
1112 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
1113 return InstallPackages(Cache
,false,false);
1115 return InstallPackages(Cache
,false);
1118 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1119 // ---------------------------------------------------------------------
1120 /* Intelligent upgrader that will install and remove packages at will */
1121 bool DoDistUpgrade(CommandLine
&CmdL
)
1124 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1127 c0out
<< "Calculating Upgrade... " << flush
;
1128 if (pkgDistUpgrade(*Cache
) == false)
1130 c0out
<< "Failed" << endl
;
1131 ShowBroken(c1out
,Cache
,false);
1135 c0out
<< "Done" << endl
;
1137 return InstallPackages(Cache
,true);
1140 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1141 // ---------------------------------------------------------------------
1142 /* Follows dselect's selections */
1143 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1146 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1149 // Install everything with the install flag set
1150 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1151 for (;I
.end() != true; I
++)
1153 /* Install the package only if it is a new install, the autoupgrader
1154 will deal with the rest */
1155 if (I
->SelectedState
== pkgCache::State::Install
)
1156 Cache
->MarkInstall(I
,false);
1159 /* Now install their deps too, if we do this above then order of
1160 the status file is significant for | groups */
1161 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1163 /* Install the package only if it is a new install, the autoupgrader
1164 will deal with the rest */
1165 if (I
->SelectedState
== pkgCache::State::Install
)
1166 Cache
->MarkInstall(I
,true);
1169 // Apply erasures now, they override everything else.
1170 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1173 if (I
->SelectedState
== pkgCache::State::DeInstall
||
1174 I
->SelectedState
== pkgCache::State::Purge
)
1175 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
1178 /* Resolve any problems that dselect created, allupgrade cannot handle
1179 such things. We do so quite agressively too.. */
1180 if (Cache
->BrokenCount() != 0)
1182 pkgProblemResolver
Fix(Cache
);
1184 // Hold back held packages.
1185 if (_config
->FindB("APT::Ingore-Hold",false) == false)
1187 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
1189 if (I
->SelectedState
== pkgCache::State::Hold
)
1197 if (Fix
.Resolve() == false)
1199 ShowBroken(c1out
,Cache
,false);
1200 return _error
->Error("Internal Error, problem resolver broke stuff");
1204 // Now upgrade everything
1205 if (pkgAllUpgrade(Cache
) == false)
1207 ShowBroken(c1out
,Cache
,false);
1208 return _error
->Error("Internal Error, problem resolver broke stuff");
1211 return InstallPackages(Cache
,false);
1214 // DoClean - Remove download archives /*{{{*/
1215 // ---------------------------------------------------------------------
1217 bool DoClean(CommandLine
&CmdL
)
1219 // Lock the archive directory
1221 if (_config
->FindB("Debug::NoLocking",false) == false)
1223 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1224 if (_error
->PendingError() == true)
1225 return _error
->Error("Unable to lock the download directory");
1229 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
1230 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1234 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1235 // ---------------------------------------------------------------------
1236 /* This is similar to clean but it only purges things that cannot be
1237 downloaded, that is old versions of cached packages. */
1238 class LogCleaner
: public pkgArchiveCleaner
1241 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1243 cout
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
1245 if (_config
->FindB("APT::Get::Simulate") == false)
1250 bool DoAutoClean(CommandLine
&CmdL
)
1252 // Lock the archive directory
1254 if (_config
->FindB("Debug::NoLocking",false) == false)
1256 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1257 if (_error
->PendingError() == true)
1258 return _error
->Error("Unable to lock the download directory");
1262 if (Cache
.Open() == false)
1267 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1268 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1271 // DoCheck - Perform the check operation /*{{{*/
1272 // ---------------------------------------------------------------------
1273 /* Opening automatically checks the system, this command is mostly used
1275 bool DoCheck(CommandLine
&CmdL
)
1284 // DoSource - Fetch a source archive /*{{{*/
1285 // ---------------------------------------------------------------------
1286 /* Fetch souce packages */
1294 bool DoSource(CommandLine
&CmdL
)
1297 if (Cache
.Open(false) == false)
1300 if (CmdL
.FileSize() <= 1)
1301 return _error
->Error("Must specify at least one package to fetch source for");
1303 // Read the source list
1305 if (List
.ReadMainList() == false)
1306 return _error
->Error("The list of sources could not be read.");
1308 // Create the text record parsers
1309 pkgRecords
Recs(Cache
);
1310 pkgSrcRecords
SrcRecs(List
);
1311 if (_error
->PendingError() == true)
1314 // Create the download object
1315 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1316 pkgAcquire
Fetcher(&Stat
);
1318 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
1320 // Load the requestd sources into the fetcher
1322 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1326 /* Lookup the version of the package we would install if we were to
1327 install a version and determine the source package name, then look
1328 in the archive for a source package of the same name. In theory
1329 we could stash the version string as well and match that too but
1330 today there aren't multi source versions in the archive. */
1331 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(*I
);
1332 if (Pkg
.end() == false)
1334 pkgCache::VerIterator Ver
= Cache
->GetCandidateVer(Pkg
);
1335 if (Ver
.end() == false)
1337 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1338 Src
= Parse
.SourcePkg();
1342 // No source package name..
1343 if (Src
.empty() == true)
1347 pkgSrcRecords::Parser
*Last
= 0;
1348 unsigned long Offset
= 0;
1350 bool IsMatch
= false;
1352 // Iterate over all of the hits
1353 pkgSrcRecords::Parser
*Parse
;
1355 while ((Parse
= SrcRecs
.Find(Src
.c_str(),false)) != 0)
1357 string Ver
= Parse
->Version();
1359 // Skip name mismatches
1360 if (IsMatch
== true && Parse
->Package() != Src
)
1363 // Newer version or an exact match
1364 if (Last
== 0 || pkgVersionCompare(Version
,Ver
) < 0 ||
1365 (Parse
->Package() == Src
&& IsMatch
== false))
1367 IsMatch
= Parse
->Package() == Src
;
1369 Offset
= Parse
->Offset();
1375 return _error
->Error("Unable to find a source package for %s",Src
.c_str());
1378 vector
<pkgSrcRecords::File
> Lst
;
1379 if (Last
->Jump(Offset
) == false || Last
->Files(Lst
) == false)
1382 // Load them into the fetcher
1383 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
1384 I
!= Lst
.end(); I
++)
1386 // Try to guess what sort of file it is we are getting.
1388 if (I
->Path
.find(".dsc") != string::npos
)
1391 Dsc
[J
].Package
= Last
->Package();
1392 Dsc
[J
].Version
= Last
->Version();
1393 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
1396 if (I
->Path
.find(".tar.gz") != string::npos
)
1398 if (I
->Path
.find(".diff.gz") != string::npos
)
1401 // Diff only mode only fetches .diff files
1402 if (_config
->FindB("APT::Get::Diff-Only",false) == true &&
1406 // Tar only mode only fetches .tar files
1407 if (_config
->FindB("APT::Get::Tar-Only",false) == true &&
1411 new pkgAcqFile(&Fetcher
,Last
->Source()->ArchiveURI(I
->Path
),
1412 I
->MD5Hash
,I
->Size
,Last
->Source()->SourceInfo(Src
,
1413 Last
->Version(),Comp
),Src
);
1417 // Display statistics
1418 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
1419 unsigned long FetchPBytes
= Fetcher
.PartialPresent();
1420 unsigned long DebBytes
= Fetcher
.TotalNeeded();
1422 // Check for enough free space
1424 string OutputDir
= ".";
1425 if (statfs(OutputDir
.c_str(),&Buf
) != 0)
1426 return _error
->Errno("statfs","Couldn't determine free space in %s",
1428 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1429 return _error
->Error("Sorry, you don't have enough free space in %s",
1433 c1out
<< "Need to get ";
1434 if (DebBytes
!= FetchBytes
)
1435 c1out
<< SizeToStr(FetchBytes
) << "B/" << SizeToStr(DebBytes
) << 'B';
1437 c1out
<< SizeToStr(DebBytes
) << 'B';
1438 c1out
<< " of source archives." << endl
;
1440 if (_config
->FindB("APT::Get::Simulate",false) == true)
1442 for (unsigned I
= 0; I
!= J
; I
++)
1443 cout
<< "Fetch Source " << Dsc
[I
].Package
<< endl
;
1447 // Just print out the uris an exit if the --print-uris flag was used
1448 if (_config
->FindB("APT::Get::Print-URIs") == true)
1450 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1451 for (; I
!= Fetcher
.UriEnd(); I
++)
1452 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1453 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1458 if (Fetcher
.Run() == pkgAcquire::Failed
)
1461 // Print error messages
1462 bool Failed
= false;
1463 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1465 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1466 (*I
)->Complete
== true)
1469 cerr
<< "Failed to fetch " << (*I
)->DescURI() << endl
;
1470 cerr
<< " " << (*I
)->ErrorText
<< endl
;
1474 return _error
->Error("Failed to fetch some archives.");
1476 if (_config
->FindB("APT::Get::Download-only",false) == true)
1479 // Unpack the sources
1480 pid_t Process
= ExecFork();
1484 for (unsigned I
= 0; I
!= J
; I
++)
1486 string Dir
= Dsc
[I
].Package
+ '-' + pkgBaseVersion(Dsc
[I
].Version
.c_str());
1488 // Diff only mode only fetches .diff files
1489 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
1490 _config
->FindB("APT::Get::Tar-Only",false) == true)
1493 // See if the package is already unpacked
1495 if (stat(Dir
.c_str(),&Stat
) == 0 &&
1496 S_ISDIR(Stat
.st_mode
) != 0)
1498 c0out
<< "Skipping unpack of already unpacked source in " << Dir
<< endl
;
1504 snprintf(S
,sizeof(S
),"%s -x %s",
1505 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
1506 Dsc
[I
].Dsc
.c_str());
1509 cerr
<< "Unpack command '" << S
<< "' failed." << endl
;
1514 // Try to compile it with dpkg-buildpackage
1515 if (_config
->FindB("APT::Get::Compile",false) == true)
1517 // Call dpkg-buildpackage
1519 snprintf(S
,sizeof(S
),"cd %s && %s %s",
1521 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
1522 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
1526 cerr
<< "Build command '" << S
<< "' failed." << endl
;
1535 // Wait for the subprocess
1537 while (waitpid(Process
,&Status
,0) != Process
)
1541 return _error
->Errno("waitpid","Couldn't wait for subprocess");
1544 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
1545 return _error
->Error("Child process failed");
1551 // ShowHelp - Show a help screen /*{{{*/
1552 // ---------------------------------------------------------------------
1554 bool ShowHelp(CommandLine
&CmdL
)
1556 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
1557 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
1558 if (_config
->FindB("version") == true)
1561 cout
<< "Usage: apt-get [options] command" << endl
;
1562 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
1564 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
1565 cout
<< "installing packages. The most frequently used commands are update" << endl
;
1566 cout
<< "and install." << endl
;
1568 cout
<< "Commands:" << endl
;
1569 cout
<< " update - Retrieve new lists of packages" << endl
;
1570 cout
<< " upgrade - Perform an upgrade" << endl
;
1571 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
1572 cout
<< " remove - Remove packages" << endl
;
1573 cout
<< " source - Download source archives" << endl
;
1574 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
1575 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
1576 cout
<< " clean - Erase downloaded archive files" << endl
;
1577 cout
<< " autoclean - Erase old downloaded archive files" << endl
;
1578 cout
<< " check - Verify that there are no broken dependencies" << endl
;
1580 cout
<< "Options:" << endl
;
1581 cout
<< " -h This help text." << endl
;
1582 cout
<< " -q Loggable output - no progress indicator" << endl
;
1583 cout
<< " -qq No output except for errors" << endl
;
1584 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
1585 cout
<< " -s No-act. Perform ordering simulation" << endl
;
1586 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
1587 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
1588 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
1589 cout
<< " -u Show a list of upgraded packages as well" << endl
;
1590 cout
<< " -b Build the source package after fetching it" << endl
;
1591 cout
<< " -c=? Read this configuration file" << endl
;
1592 cout
<< " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl
;
1593 cout
<< "See the apt-get(8), sources.list(5) and apt.conf(5) manual" << endl
;
1594 cout
<< "pages for more information and options." << endl
;
1598 // GetInitialize - Initialize things for apt-get /*{{{*/
1599 // ---------------------------------------------------------------------
1601 void GetInitialize()
1603 _config
->Set("quiet",0);
1604 _config
->Set("help",false);
1605 _config
->Set("APT::Get::Download-Only",false);
1606 _config
->Set("APT::Get::Simulate",false);
1607 _config
->Set("APT::Get::Assume-Yes",false);
1608 _config
->Set("APT::Get::Fix-Broken",false);
1609 _config
->Set("APT::Get::Force-Yes",false);
1610 _config
->Set("APT::Get::APT::Get::No-List-Cleanup",true);
1613 // SigWinch - Window size change signal handler /*{{{*/
1614 // ---------------------------------------------------------------------
1618 // Riped from GNU ls
1622 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
1623 ScreenWidth
= ws
.ws_col
- 1;
1628 int main(int argc
,const char *argv
[])
1630 CommandLine::Args Args
[] = {
1631 {'h',"help","help",0},
1632 {'v',"version","version",0},
1633 {'q',"quiet","quiet",CommandLine::IntLevel
},
1634 {'q',"silent","quiet",CommandLine::IntLevel
},
1635 {'d',"download-only","APT::Get::Download-Only",0},
1636 {'b',"compile","APT::Get::Compile",0},
1637 {'b',"build","APT::Get::Compile",0},
1638 {'s',"simulate","APT::Get::Simulate",0},
1639 {'s',"just-print","APT::Get::Simulate",0},
1640 {'s',"recon","APT::Get::Simulate",0},
1641 {'s',"no-act","APT::Get::Simulate",0},
1642 {'y',"yes","APT::Get::Assume-Yes",0},
1643 {'y',"assume-yes","APT::Get::Assume-Yes",0},
1644 {'f',"fix-broken","APT::Get::Fix-Broken",0},
1645 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
1646 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
1647 {0,"no-download","APT::Get::No-Download",0},
1648 {0,"fix-missing","APT::Get::Fix-Missing",0},
1649 {0,"ignore-hold","APT::Ingore-Hold",0},
1650 {0,"no-upgrade","APT::Get::no-upgrade",0},
1651 {0,"force-yes","APT::Get::force-yes",0},
1652 {0,"print-uris","APT::Get::Print-URIs",0},
1653 {0,"diff-only","APT::Get::Diff-Only",0},
1654 {0,"tar-only","APT::Get::tar-Only",0},
1655 {0,"purge","APT::Get::Purge",0},
1656 {0,"list-cleanup","APT::Get::List-Cleanup",0},
1657 {0,"reinstall","APT::Get::ReInstall",0},
1658 {'c',"config-file",0,CommandLine::ConfigFile
},
1659 {'o',"option",0,CommandLine::ArbItem
},
1661 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
1662 {"upgrade",&DoUpgrade
},
1663 {"install",&DoInstall
},
1664 {"remove",&DoInstall
},
1665 {"dist-upgrade",&DoDistUpgrade
},
1666 {"dselect-upgrade",&DoDSelectUpgrade
},
1668 {"autoclean",&DoAutoClean
},
1670 {"source",&DoSource
},
1674 // Parse the command line and initialize the package library
1675 CommandLine
CmdL(Args
,_config
);
1676 if (pkgInitialize(*_config
) == false ||
1677 CmdL
.Parse(argc
,argv
) == false)
1679 _error
->DumpErrors();
1683 // See if the help should be shown
1684 if (_config
->FindB("help") == true ||
1685 _config
->FindB("version") == true ||
1686 CmdL
.FileSize() == 0)
1687 return ShowHelp(CmdL
);
1689 // Deal with stdout not being a tty
1690 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
1691 _config
->Set("quiet","1");
1693 // Setup the output streams
1694 c0out
.rdbuf(cout
.rdbuf());
1695 c1out
.rdbuf(cout
.rdbuf());
1696 c2out
.rdbuf(cout
.rdbuf());
1697 if (_config
->FindI("quiet",0) > 0)
1698 c0out
.rdbuf(devnull
.rdbuf());
1699 if (_config
->FindI("quiet",0) > 1)
1700 c1out
.rdbuf(devnull
.rdbuf());
1702 // Setup the signals
1703 signal(SIGPIPE
,SIG_IGN
);
1704 signal(SIGWINCH
,SigWinch
);
1707 // Match the operation
1708 CmdL
.DispatchArg(Cmds
);
1710 // Print any errors or warnings found during parsing
1711 if (_error
->empty() == false)
1713 bool Errors
= _error
->PendingError();
1714 _error
->DumpErrors();
1715 return Errors
== true?100:0;