]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.11 1998/11/14 01:39: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/pkgcachegen.h>
34 #include <apt-pkg/algorithms.h>
35 #include <apt-pkg/acquire-item.h>
36 #include <apt-pkg/dpkgpm.h>
41 #include "acqprogress.h"
45 #include <sys/ioctl.h>
52 ofstream
devnull("/dev/null");
53 unsigned int ScreenWidth
= 80;
55 // YnPrompt - Yes No Prompt. /*{{{*/
56 // ---------------------------------------------------------------------
57 /* Returns true on a Yes.*/
60 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
68 read(STDIN_FILENO
,&C
,1);
69 while (C
!= '\n' && Jnk
!= '\n') read(STDIN_FILENO
,&Jnk
,1);
71 if (!(C
== 'Y' || C
== 'y' || C
== '\n' || C
== '\r'))
76 // ShowList - Show a list /*{{{*/
77 // ---------------------------------------------------------------------
78 /* This prints out a string of space seperated words with a title and
79 a two space indent line wraped to the current screen width. */
80 void ShowList(ostream
&out
,string Title
,string List
)
82 if (List
.empty() == true)
85 // Acount for the leading space
86 int ScreenWidth
= ::ScreenWidth
- 3;
89 string::size_type Start
= 0;
90 while (Start
< List
.size())
92 string::size_type End
;
93 if (Start
+ ScreenWidth
>= List
.size())
96 End
= List
.rfind(' ',Start
+ScreenWidth
);
98 if (End
== string::npos
|| End
< Start
)
99 End
= Start
+ ScreenWidth
;
100 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
105 // ShowBroken - Debugging aide /*{{{*/
106 // ---------------------------------------------------------------------
107 /* This prints out the names of all the packages that are broken along
108 with the name of each each broken dependency and a quite version
110 void ShowBroken(ostream
&out
,pkgDepCache
&Cache
)
112 out
<< "Sorry, but the following packages are broken - this means they have unmet" << endl
;
113 out
<< "dependencies:" << endl
;
114 pkgCache::PkgIterator I
= Cache
.PkgBegin();
115 for (;I
.end() != true; I
++)
117 if (Cache
[I
].InstBroken() == false)
120 // Print out each package and the failed dependencies
121 out
<<" " << I
.Name() << ":";
122 int Indent
= strlen(I
.Name()) + 3;
124 if (Cache
[I
].InstVerIter(Cache
).end() == true)
130 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false; D
++)
132 if (Cache
.IsImportantDep(D
) == false || (Cache
[D
] &
133 pkgDepCache::DepInstall
) != 0)
137 for (int J
= 0; J
!= Indent
; J
++)
141 if (D
->Type
== pkgCache::Dep::Conflicts
)
142 out
<< " Conflicts:" << D
.TargetPkg().Name();
144 out
<< " Depends:" << D
.TargetPkg().Name();
146 // Show a quick summary of the version requirements
147 if (D
.TargetVer() != 0)
148 out
<< " (" << D
.CompType() << " " << D
.TargetVer() <<
151 /* Show a summary of the target package if possible. In the case
152 of virtual packages we show nothing */
154 pkgCache::PkgIterator Targ
= D
.TargetPkg();
155 if (Targ
->ProvidesList
== 0)
158 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
159 if (Ver
.end() == false)
160 out
<< Ver
.VerStr() << " is installed";
163 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
165 if (Targ
->ProvidesList
== 0)
166 out
<< "it is not installable";
168 out
<< "it is a virtual package";
171 out
<< "it is not installed";
180 // ShowNew - Show packages to newly install /*{{{*/
181 // ---------------------------------------------------------------------
183 void ShowNew(ostream
&out
,pkgDepCache
&Dep
)
185 /* Print out a list of packages that are going to be removed extra
186 to what the user asked */
187 pkgCache::PkgIterator I
= Dep
.PkgBegin();
189 for (;I
.end() != true; I
++)
190 if (Dep
[I
].NewInstall() == true)
191 List
+= string(I
.Name()) + " ";
192 ShowList(out
,"The following NEW packages will be installed:",List
);
195 // ShowDel - Show packages to delete /*{{{*/
196 // ---------------------------------------------------------------------
198 void ShowDel(ostream
&out
,pkgDepCache
&Dep
)
200 /* Print out a list of packages that are going to be removed extra
201 to what the user asked */
202 pkgCache::PkgIterator I
= Dep
.PkgBegin();
204 for (;I
.end() != true; I
++)
205 if (Dep
[I
].Delete() == true)
206 List
+= string(I
.Name()) + " ";
207 ShowList(out
,"The following packages will be REMOVED:",List
);
210 // ShowKept - Show kept packages /*{{{*/
211 // ---------------------------------------------------------------------
213 void ShowKept(ostream
&out
,pkgDepCache
&Dep
)
215 pkgCache::PkgIterator I
= Dep
.PkgBegin();
217 for (;I
.end() != true; I
++)
220 if (Dep
[I
].Upgrade() == true || Dep
[I
].Upgradable() == false ||
221 I
->CurrentVer
== 0 || Dep
[I
].Delete() == true)
224 List
+= string(I
.Name()) + " ";
226 ShowList(out
,"The following packages have been kept back",List
);
229 // ShowUpgraded - Show upgraded packages /*{{{*/
230 // ---------------------------------------------------------------------
232 void ShowUpgraded(ostream
&out
,pkgDepCache
&Dep
)
234 pkgCache::PkgIterator I
= Dep
.PkgBegin();
236 for (;I
.end() != true; I
++)
239 if (Dep
[I
].Upgrade() == false || Dep
[I
].NewInstall() == true)
242 List
+= string(I
.Name()) + " ";
244 ShowList(out
,"The following packages will be upgraded",List
);
247 // ShowHold - Show held but changed packages /*{{{*/
248 // ---------------------------------------------------------------------
250 void ShowHold(ostream
&out
,pkgDepCache
&Dep
)
252 pkgCache::PkgIterator I
= Dep
.PkgBegin();
254 for (;I
.end() != true; I
++)
256 if (Dep
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
257 I
->SelectedState
== pkgCache::State::Hold
)
258 List
+= string(I
.Name()) + " ";
261 ShowList(out
,"The following held packages will be changed:",List
);
264 // ShowEssential - Show an essential package warning /*{{{*/
265 // ---------------------------------------------------------------------
266 /* This prints out a warning message that is not to be ignored. It shows
267 all essential packages and their dependents that are to be removed.
268 It is insanely risky to remove the dependents of an essential package! */
269 void ShowEssential(ostream
&out
,pkgDepCache
&Dep
)
271 pkgCache::PkgIterator I
= Dep
.PkgBegin();
273 bool *Added
= new bool[Dep
.HeaderP
->PackageCount
];
274 for (unsigned int I
= 0; I
!= Dep
.HeaderP
->PackageCount
; I
++)
277 for (;I
.end() != true; I
++)
279 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
282 // The essential package is being removed
283 if (Dep
[I
].Delete() == true)
285 if (Added
[I
->ID
] == false)
288 List
+= string(I
.Name()) + " ";
292 if (I
->CurrentVer
== 0)
295 // Print out any essential package depenendents that are to be removed
296 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
298 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
299 if (Dep
[P
].Delete() == true)
301 if (Added
[P
->ID
] == true)
304 List
+= string(P
.Name()) + " ";
309 if (List
.empty() == false)
310 out
<< "WARNING: The following essential packages will be removed" << endl
;
311 ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
316 // Stats - Show some statistics /*{{{*/
317 // ---------------------------------------------------------------------
319 void Stats(ostream
&out
,pkgDepCache
&Dep
)
321 unsigned long Upgrade
= 0;
322 unsigned long Install
= 0;
323 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
325 if (Dep
[I
].NewInstall() == true)
328 if (Dep
[I
].Upgrade() == true)
332 out
<< Upgrade
<< " packages upgraded, " <<
333 Install
<< " newly installed, " <<
334 Dep
.DelCount() << " to remove and " <<
335 Dep
.KeepCount() << " not upgraded." << endl
;
337 if (Dep
.BadCount() != 0)
338 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
342 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
343 // ---------------------------------------------------------------------
353 inline operator pkgDepCache
&() {return *Cache
;};
354 inline pkgDepCache
*operator ->() {return Cache
;};
355 inline pkgDepCache
&operator *() {return *Cache
;};
358 CacheFile() : File(0), Map(0), Cache(0) {};
367 // CacheFile::Open - Open the cache file /*{{{*/
368 // ---------------------------------------------------------------------
369 /* This routine generates the caches and then opens the dependency cache
370 and verifies that the system is OK. */
371 bool CacheFile::Open()
373 // Create a progress class
374 OpTextProgress
Progress(*_config
);
376 // Read the source list
378 if (List
.ReadMainList() == false)
379 return _error
->Error("The list of sources could not be read.");
381 // Build all of the caches
382 pkgMakeStatusCache(List
,Progress
);
383 if (_error
->PendingError() == true)
384 return _error
->Error("The package lists or status file could not be parsed or opened.");
388 // Open the cache file
389 File
= new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly
);
390 if (_error
->PendingError() == true)
393 Map
= new MMap(*File
,MMap::Public
| MMap::ReadOnly
);
394 if (_error
->PendingError() == true)
397 Cache
= new pkgDepCache(*Map
,Progress
);
398 if (_error
->PendingError() == true)
403 // Check that the system is OK
404 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
405 return _error
->Error("Internal Error, non-zero counts");
407 // Apply corrections for half-installed packages
408 if (pkgApplyStatus(*Cache
) == false)
412 if (Cache
->BrokenCount() == 0)
415 // Attempt to fix broken things
416 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
418 c1out
<< "Correcting dependencies..." << flush
;
419 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
421 c1out
<< " failed." << endl
;
422 ShowBroken(c1out
,*this);
424 return _error
->Error("Unable to correct dependencies");
426 if (pkgMinimizeUpgrade(*Cache
) == false)
427 return _error
->Error("Unable to minimize the upgrade set");
429 c1out
<< " Done" << endl
;
433 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
434 ShowBroken(c1out
,*this);
436 return _error
->Error("Unmet dependencies. Try using -f.");
443 // InstallPackages - Actually download and install the packages /*{{{*/
444 // ---------------------------------------------------------------------
445 /* This displays the informative messages describing what is going to
446 happen and then calls the download routines */
447 bool InstallPackages(pkgDepCache
&Cache
,bool ShwKept
,bool Ask
= true)
449 // Show all the various warning indicators
450 ShowDel(c1out
,Cache
);
451 ShowNew(c1out
,Cache
);
453 ShowKept(c1out
,Cache
);
454 ShowHold(c1out
,Cache
);
455 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
456 ShowUpgraded(c1out
,Cache
);
457 ShowEssential(c1out
,Cache
);
461 if (Cache
.BrokenCount() != 0)
463 ShowBroken(c1out
,Cache
);
464 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
467 if (Cache
.DelCount() == 0 && Cache
.InstCount() == 0 &&
468 Cache
.BadCount() == 0)
471 // Run the simulator ..
472 if (_config
->FindB("APT::Get::Simulate") == true)
474 pkgSimulate
PM(Cache
);
475 return PM
.DoInstall();
478 // Create the text record parser
479 pkgRecords
Recs(Cache
);
481 // Create the download object
482 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
483 pkgAcquire
Fetcher(&Stat
);
485 // Read the source list
487 if (List
.ReadMainList() == false)
488 return _error
->Error("The list of sources could not be read.");
490 // Create the package manager and prepare to download
491 pkgPackageManager
PM(Cache
);
492 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false)
495 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
496 unsigned long DebBytes
= Fetcher
.TotalNeeded();
497 if (DebBytes
!= Cache
.DebSize())
498 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
500 c1out
<< "Need to get ";
501 if (DebBytes
!= FetchBytes
)
502 c1out
<< SizeToStr(FetchBytes
) << '/' << SizeToStr(DebBytes
);
504 c1out
<< SizeToStr(DebBytes
);
506 c1out
<< " of archives. After unpacking ";
508 if (Cache
.UsrSize() >= 0)
509 c1out
<< SizeToStr(Cache
.UsrSize()) << " will be used." << endl
;
511 c1out
<< SizeToStr(-1*Cache
.UsrSize()) << " will be freed." << endl
;
513 if (_error
->PendingError() == true)
518 if (_config
->FindI("quiet",0) < 2 ||
519 _config
->FindB("APT::Get::Assume-Yes",false) == false)
520 c2out
<< "Do you want to continue? [Y/n] " << flush
;
521 if (YnPrompt() == false)
526 if (Fetcher
.Run() == false)
533 // DoUpdate - Update the package lists /*{{{*/
534 // ---------------------------------------------------------------------
536 bool DoUpdate(CommandLine
&)
538 // Get the source list
540 if (List
.ReadMainList() == false)
543 // Create the download object
544 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
545 pkgAcquire
Fetcher(&Stat
);
547 // Populate it with the source selection
548 pkgSourceList::const_iterator I
;
549 for (I
= List
.begin(); I
!= List
.end(); I
++)
551 new pkgAcqIndex(&Fetcher
,I
);
552 if (_error
->PendingError() == true)
557 if (Fetcher
.Run() == false)
560 // Clean out any old list files
561 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
562 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
565 // Prepare the cache.
567 if (Cache
.Open() == false)
573 // DoUpgrade - Upgrade all packages /*{{{*/
574 // ---------------------------------------------------------------------
575 /* Upgrade all packages without installing new packages or erasing old
577 bool DoUpgrade(CommandLine
&CmdL
)
580 if (Cache
.Open() == false)
584 if (pkgAllUpgrade(Cache
) == false)
586 ShowBroken(c1out
,Cache
);
587 return _error
->Error("Internal Error, AllUpgrade broke stuff");
590 return InstallPackages(Cache
,true);
593 // DoInstall - Install packages from the command line /*{{{*/
594 // ---------------------------------------------------------------------
595 /* Install named packages */
596 bool DoInstall(CommandLine
&CmdL
)
599 if (Cache
.Open() == false)
602 unsigned int ExpectedInst
= 0;
603 unsigned int Packages
= 0;
604 pkgProblemResolver
Fix(Cache
);
606 bool DefRemove
= false;
607 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
610 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
612 // Duplicate the string
613 unsigned int Length
= strlen(*I
);
615 if (Length
>= sizeof(S
))
619 // See if we are removing the package
620 bool Remove
= DefRemove
;
621 if (S
[Length
- 1] == '-')
626 if (S
[Length
- 1] == '+')
632 // Locate the package
633 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
635 if (Pkg
.end() == true)
636 return _error
->Error("Couldn't find package %s",S
);
638 // Check if there is something new to install
639 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
640 if (State
.CandidateVer
== 0)
642 if (Pkg
->ProvidesList
!= 0)
644 c1out
<< "Package " << S
<< " is a virtual package provided by:" << endl
;
646 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
647 for (; I
.end() == false; I
++)
649 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
651 if ((*Cache
)[Pkg
].CandidateVerIter(*Cache
) == I
.OwnerVer())
652 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
654 if ((*Cache
)[Pkg
].InstVerIter(*Cache
) == I
.OwnerVer())
655 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
656 " [Installed]"<< endl
;
658 c1out
<< "You should explicly select one to install." << endl
;
662 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
663 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
664 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
667 return _error
->Error("Package %s has no installation candidate",S
);
674 Cache
->MarkDelete(Pkg
);
679 Cache
->MarkInstall(Pkg
,false);
680 if (State
.Install() == false)
681 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
685 // Install it with autoinstalling enabled.
686 if (State
.InstBroken() == true)
687 Cache
->MarkInstall(Pkg
,true);
690 // Call the scored problem resolver
691 Fix
.InstallProtect();
692 if (Fix
.Resolve(true) == false)
695 // Now we check the state of the packages,
696 if (Cache
->BrokenCount() != 0)
698 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
699 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
700 c1out
<< "distribution that some required packages have not yet been created" << endl
;
701 c1out
<< "or been moved out of Incoming." << endl
;
705 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
706 c1out
<< "the package is simply not installable and a bug report against" << endl
;
707 c1out
<< "that package should be filed." << endl
;
710 c1out
<< "The following information may help to resolve the situation:" << endl
;
712 ShowBroken(c1out
,Cache
);
713 return _error
->Error("Sorry, broken packages");
716 /* Print out a list of packages that are going to be installed extra
717 to what the user asked */
718 if (Cache
->InstCount() != ExpectedInst
)
721 pkgCache::PkgIterator I
= Cache
->PkgBegin();
722 for (;I
.end() != true; I
++)
724 if ((*Cache
)[I
].Install() == false)
728 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
729 if (strcmp(*J
,I
.Name()) == 0)
733 List
+= string(I
.Name()) + " ";
736 ShowList(c1out
,"The following extra packages will be installed:",List
);
739 // See if we need to prompt
740 if (Cache
->InstCount() != ExpectedInst
|| Cache
->DelCount() != 0)
741 return InstallPackages(Cache
,false,true);
742 return InstallPackages(Cache
,false);
745 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
746 // ---------------------------------------------------------------------
747 /* Intelligent upgrader that will install and remove packages at will */
748 bool DoDistUpgrade(CommandLine
&CmdL
)
751 if (Cache
.Open() == false)
754 c0out
<< "Calculating Upgrade... " << flush
;
755 if (pkgDistUpgrade(*Cache
) == false)
757 c0out
<< "Failed" << endl
;
758 ShowBroken(c1out
,Cache
);
762 c0out
<< "Done" << endl
;
764 return InstallPackages(Cache
,true);
767 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
768 // ---------------------------------------------------------------------
769 /* Follows dselect's selections */
770 bool DoDSelectUpgrade(CommandLine
&CmdL
)
773 if (Cache
.Open() == false)
776 // Install everything with the install flag set
777 pkgCache::PkgIterator I
= Cache
->PkgBegin();
778 for (;I
.end() != true; I
++)
780 /* Install the package only if it is a new install, the autoupgrader
781 will deal with the rest */
782 if (I
->SelectedState
== pkgCache::State::Install
)
783 Cache
->MarkInstall(I
,false);
786 /* Now install their deps too, if we do this above then order of
787 the status file is significant for | groups */
788 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
790 /* Install the package only if it is a new install, the autoupgrader
791 will deal with the rest */
792 if (I
->SelectedState
== pkgCache::State::Install
)
793 Cache
->MarkInstall(I
);
796 // Apply erasures now, they override everything else.
797 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
800 if (I
->SelectedState
== pkgCache::State::DeInstall
||
801 I
->SelectedState
== pkgCache::State::Purge
)
802 Cache
->MarkDelete(I
);
805 /* Use updates smart upgrade to do the rest, it will automatically
807 if (pkgAllUpgrade(Cache
) == false)
809 ShowBroken(c1out
,Cache
);
810 return _error
->Error("Internal Error, AllUpgrade broke stuff");
813 return InstallPackages(Cache
,false);
816 // DoClean - Remove download archives /*{{{*/
817 // ---------------------------------------------------------------------
819 bool DoClean(CommandLine
&CmdL
)
824 // DoCheck - Perform the check operation /*{{{*/
825 // ---------------------------------------------------------------------
826 /* Opening automatically checks the system, this command is mostly used
828 bool DoCheck(CommandLine
&CmdL
)
837 // ShowHelp - Show a help screen /*{{{*/
838 // ---------------------------------------------------------------------
842 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
843 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
845 cout
<< "Usage: apt-get [options] command" << endl
;
846 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
848 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
849 cout
<< "installing packages. The most frequently used commands are update" << endl
;
850 cout
<< "and install." << endl
;
852 cout
<< "Commands:" << endl
;
853 cout
<< " update - Retrieve new lists of packages" << endl
;
854 cout
<< " upgrade - Perform an upgrade" << endl
;
855 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
856 cout
<< " remove - Remove packages" << endl
;
857 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
858 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
859 cout
<< " clean - Erase downloaded archive files" << endl
;
860 cout
<< " check - Verify that there are no broken dependencies" << endl
;
862 cout
<< "Options:" << endl
;
863 cout
<< " -h This help text." << endl
;
864 cout
<< " -q Loggable output - no progress indicator" << endl
;
865 cout
<< " -qq No output except for errors" << endl
;
866 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
867 cout
<< " -s No-act. Perform ordering simulation" << endl
;
868 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
869 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
870 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
871 cout
<< " -u Show a list of upgraded packages as well" << endl
;
872 cout
<< " -c=? Read this configuration file" << endl
;
873 cout
<< " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl
;
874 cout
<< "See the apt-get(8), sources.list(8) and apt.conf(8) manual" << endl
;
875 cout
<< "pages for more information." << endl
;
879 // GetInitialize - Initialize things for apt-get /*{{{*/
880 // ---------------------------------------------------------------------
884 _config
->Set("quiet",0);
885 _config
->Set("help",false);
886 _config
->Set("APT::Get::Download-Only",false);
887 _config
->Set("APT::Get::Simulate",false);
888 _config
->Set("APT::Get::Assume-Yes",false);
889 _config
->Set("APT::Get::Fix-Broken",false);
892 // SigWinch - Window size change signal handler /*{{{*/
893 // ---------------------------------------------------------------------
901 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
902 ScreenWidth
= ws
.ws_col
- 1;
907 int main(int argc
,const char *argv
[])
909 CommandLine::Args Args
[] = {
910 {'h',"help","help",0},
911 {'q',"quiet","quiet",CommandLine::IntLevel
},
912 {'q',"silent","quiet",CommandLine::IntLevel
},
913 {'d',"download-only","APT::Get::Download-Only",0},
914 {'s',"simulate","APT::Get::Simulate",0},
915 {'s',"just-print","APT::Get::Simulate",0},
916 {'s',"recon","APT::Get::Simulate",0},
917 {'s',"no-act","APT::Get::Simulate",0},
918 {'y',"yes","APT::Get::Assume-Yes",0},
919 {'y',"assume-yes","APT::Get::Assume-Yes",0},
920 {'f',"fix-broken","APT::Get::Fix-Broken",0},
921 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
922 {'m',"ignore-missing","APT::Get::Fix-Broken",0},
923 {0,"ignore-hold","APT::Ingore-Hold",0},
924 {'c',"config-file",0,CommandLine::ConfigFile
},
925 {'o',"option",0,CommandLine::ArbItem
},
928 // Parse the command line and initialize the package library
929 CommandLine
CmdL(Args
,_config
);
930 if (pkgInitialize(*_config
) == false ||
931 CmdL
.Parse(argc
,argv
) == false)
933 _error
->DumpErrors();
937 // See if the help should be shown
938 if (_config
->FindB("help") == true ||
939 CmdL
.FileSize() == 0)
942 // Setup the output streams
943 c0out
.rdbuf(cout
.rdbuf());
944 c1out
.rdbuf(cout
.rdbuf());
945 c2out
.rdbuf(cout
.rdbuf());
946 if (_config
->FindI("quiet",0) > 0)
947 c0out
.rdbuf(devnull
.rdbuf());
948 if (_config
->FindI("quiet",0) > 1)
949 c1out
.rdbuf(devnull
.rdbuf());
952 signal(SIGPIPE
,SIG_IGN
);
953 signal(SIGWINCH
,SigWinch
);
956 // Match the operation
960 bool (*Handler
)(CommandLine
&);
961 } Map
[] = {{"update",&DoUpdate
},
962 {"upgrade",&DoUpgrade
},
963 {"install",&DoInstall
},
964 {"remove",&DoInstall
},
965 {"dist-upgrade",&DoDistUpgrade
},
966 {"dselect-upgrade",&DoDSelectUpgrade
},
971 for (I
= 0; Map
[I
].Match
!= 0; I
++)
973 if (strcmp(CmdL
.FileList
[0],Map
[I
].Match
) == 0)
975 if (Map
[I
].Handler(CmdL
) == false && _error
->PendingError() == false)
976 _error
->Error("Handler silently failed");
982 if (Map
[I
].Match
== 0)
983 _error
->Error("Invalid operation %s", CmdL
.FileList
[0]);
985 // Print any errors or warnings found during parsing
986 if (_error
->empty() == false)
988 bool Errors
= _error
->PendingError();
989 _error
->DumpErrors();
991 cout
<< "Returning 100." << endl
;
992 return Errors
== true?100:0;