]>
Commit | Line | Data |
---|---|---|
0a8e3465 AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
7a7fa5f0 | 3 | // $Id: apt-get.cc,v 1.7 1998/11/12 04:10:56 jgg Exp $ |
0a8e3465 AL |
4 | /* ###################################################################### |
5 | ||
6 | apt-get - Cover for dpkg | |
7 | ||
8 | This is an allout cover for dpkg implementing a safer front end. It is | |
9 | based largely on libapt-pkg. | |
10 | ||
11 | The syntax is different, | |
12 | apt-get [opt] command [things] | |
13 | Where command is: | |
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 | |
19 | a new distribution. | |
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 | |
23 | the partial dir too | |
24 | ||
25 | ##################################################################### */ | |
26 | /*}}}*/ | |
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> | |
0919e3f9 | 35 | #include <apt-pkg/acquire-item.h> |
0a8e3465 AL |
36 | |
37 | #include <config.h> | |
38 | ||
0919e3f9 AL |
39 | #include "acqprogress.h" |
40 | ||
0a8e3465 AL |
41 | #include <fstream.h> |
42 | /*}}}*/ | |
43 | ||
44 | ostream c0out; | |
45 | ostream c1out; | |
46 | ostream c2out; | |
47 | ofstream devnull("/dev/null"); | |
48 | unsigned int ScreenWidth = 80; | |
49 | ||
50 | // ShowList - Show a list /*{{{*/ | |
51 | // --------------------------------------------------------------------- | |
52 | /* This prints out a string of space seperated words with a title and | |
53 | a two space indent line wraped to the current screen width. */ | |
54 | void ShowList(ostream &out,string Title,string List) | |
55 | { | |
56 | if (List.empty() == true) | |
57 | return; | |
58 | ||
59 | // Acount for the leading space | |
60 | int ScreenWidth = ::ScreenWidth - 3; | |
61 | ||
62 | out << Title << endl; | |
63 | string::size_type Start = 0; | |
64 | while (Start < List.size()) | |
65 | { | |
66 | string::size_type End; | |
67 | if (Start + ScreenWidth >= List.size()) | |
68 | End = List.size(); | |
69 | else | |
70 | End = List.rfind(' ',Start+ScreenWidth); | |
71 | ||
72 | if (End == string::npos || End < Start) | |
73 | End = Start + ScreenWidth; | |
74 | out << " " << string(List,Start,End - Start) << endl; | |
75 | Start = End + 1; | |
76 | } | |
77 | } | |
78 | /*}}}*/ | |
79 | // ShowBroken - Debugging aide /*{{{*/ | |
80 | // --------------------------------------------------------------------- | |
81 | /* This prints out the names of all the packages that are broken along | |
82 | with the name of each each broken dependency and a quite version | |
83 | description. */ | |
84 | void ShowBroken(ostream &out,pkgDepCache &Cache) | |
85 | { | |
86 | out << "Sorry, but the following packages are broken - this means they have unmet" << endl; | |
87 | out << "dependencies:" << endl; | |
88 | pkgCache::PkgIterator I = Cache.PkgBegin(); | |
89 | for (;I.end() != true; I++) | |
90 | { | |
303a1703 AL |
91 | if (Cache[I].InstBroken() == false) |
92 | continue; | |
93 | ||
94 | // Print out each package and the failed dependencies | |
95 | out <<" " << I.Name() << ":"; | |
96 | int Indent = strlen(I.Name()) + 3; | |
97 | bool First = true; | |
98 | if (Cache[I].InstVerIter(Cache).end() == true) | |
0a8e3465 | 99 | { |
303a1703 AL |
100 | cout << endl; |
101 | continue; | |
102 | } | |
103 | ||
104 | for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; D++) | |
105 | { | |
106 | if (Cache.IsImportantDep(D) == false || (Cache[D] & | |
107 | pkgDepCache::DepInstall) != 0) | |
108 | continue; | |
109 | ||
110 | if (First == false) | |
111 | for (int J = 0; J != Indent; J++) | |
112 | out << ' '; | |
113 | First = false; | |
114 | ||
115 | if (D->Type == pkgCache::Dep::Conflicts) | |
116 | out << " Conflicts:" << D.TargetPkg().Name(); | |
117 | else | |
118 | out << " Depends:" << D.TargetPkg().Name(); | |
119 | ||
120 | // Show a quick summary of the version requirements | |
121 | if (D.TargetVer() != 0) | |
122 | out << " (" << D.CompType() << " " << D.TargetVer() << | |
123 | ")"; | |
124 | ||
125 | /* Show a summary of the target package if possible. In the case | |
126 | of virtual packages we show nothing */ | |
127 | ||
128 | pkgCache::PkgIterator Targ = D.TargetPkg(); | |
129 | if (Targ->ProvidesList == 0) | |
0a8e3465 | 130 | { |
303a1703 AL |
131 | out << " but "; |
132 | pkgCache::VerIterator Ver = Cache[Targ].InstVerIter(Cache); | |
133 | if (Ver.end() == false) | |
134 | out << Ver.VerStr() << " is installed"; | |
0a8e3465 | 135 | else |
7e798dd7 | 136 | { |
303a1703 AL |
137 | if (Cache[Targ].CandidateVerIter(Cache).end() == true) |
138 | { | |
139 | if (Targ->ProvidesList == 0) | |
140 | out << "it is not installable"; | |
141 | else | |
142 | out << "it is a virtual package"; | |
143 | } | |
7e798dd7 AL |
144 | else |
145 | out << "it is not installed"; | |
303a1703 AL |
146 | } |
147 | } | |
148 | ||
149 | out << endl; | |
150 | } | |
0a8e3465 AL |
151 | } |
152 | } | |
153 | /*}}}*/ | |
154 | // ShowNew - Show packages to newly install /*{{{*/ | |
155 | // --------------------------------------------------------------------- | |
156 | /* */ | |
157 | void ShowNew(ostream &out,pkgDepCache &Dep) | |
158 | { | |
159 | /* Print out a list of packages that are going to be removed extra | |
160 | to what the user asked */ | |
161 | pkgCache::PkgIterator I = Dep.PkgBegin(); | |
162 | string List; | |
163 | for (;I.end() != true; I++) | |
164 | if (Dep[I].NewInstall() == true) | |
165 | List += string(I.Name()) + " "; | |
166 | ShowList(out,"The following NEW packages will be installed:",List); | |
167 | } | |
168 | /*}}}*/ | |
169 | // ShowDel - Show packages to delete /*{{{*/ | |
170 | // --------------------------------------------------------------------- | |
171 | /* */ | |
172 | void ShowDel(ostream &out,pkgDepCache &Dep) | |
173 | { | |
174 | /* Print out a list of packages that are going to be removed extra | |
175 | to what the user asked */ | |
176 | pkgCache::PkgIterator I = Dep.PkgBegin(); | |
177 | string List; | |
178 | for (;I.end() != true; I++) | |
179 | if (Dep[I].Delete() == true) | |
180 | List += string(I.Name()) + " "; | |
181 | ShowList(out,"The following packages will be REMOVED:",List); | |
182 | } | |
183 | /*}}}*/ | |
184 | // ShowKept - Show kept packages /*{{{*/ | |
185 | // --------------------------------------------------------------------- | |
186 | /* */ | |
187 | void ShowKept(ostream &out,pkgDepCache &Dep) | |
188 | { | |
189 | pkgCache::PkgIterator I = Dep.PkgBegin(); | |
190 | string List; | |
191 | for (;I.end() != true; I++) | |
192 | { | |
193 | // Not interesting | |
194 | if (Dep[I].Upgrade() == true || Dep[I].Upgradable() == false || | |
195 | I->CurrentVer == 0 || Dep[I].Delete() == true) | |
196 | continue; | |
197 | ||
198 | List += string(I.Name()) + " "; | |
199 | } | |
200 | ShowList(out,"The following packages have been kept back",List); | |
201 | } | |
202 | /*}}}*/ | |
203 | // ShowUpgraded - Show upgraded packages /*{{{*/ | |
204 | // --------------------------------------------------------------------- | |
205 | /* */ | |
206 | void ShowUpgraded(ostream &out,pkgDepCache &Dep) | |
207 | { | |
208 | pkgCache::PkgIterator I = Dep.PkgBegin(); | |
209 | string List; | |
210 | for (;I.end() != true; I++) | |
211 | { | |
212 | // Not interesting | |
213 | if (Dep[I].Upgrade() == false || Dep[I].NewInstall() == true) | |
214 | continue; | |
215 | ||
216 | List += string(I.Name()) + " "; | |
217 | } | |
218 | ShowList(out,"The following packages will be upgraded",List); | |
219 | } | |
220 | /*}}}*/ | |
221 | // ShowHold - Show held but changed packages /*{{{*/ | |
222 | // --------------------------------------------------------------------- | |
223 | /* */ | |
224 | void ShowHold(ostream &out,pkgDepCache &Dep) | |
225 | { | |
226 | pkgCache::PkgIterator I = Dep.PkgBegin(); | |
227 | string List; | |
228 | for (;I.end() != true; I++) | |
229 | { | |
230 | if (Dep[I].InstallVer != (pkgCache::Version *)I.CurrentVer() && | |
231 | I->SelectedState == pkgCache::State::Hold) | |
232 | List += string(I.Name()) + " "; | |
233 | } | |
234 | ||
235 | ShowList(out,"The following held packages will be changed:",List); | |
236 | } | |
237 | /*}}}*/ | |
238 | // ShowEssential - Show an essential package warning /*{{{*/ | |
239 | // --------------------------------------------------------------------- | |
240 | /* This prints out a warning message that is not to be ignored. It shows | |
241 | all essential packages and their dependents that are to be removed. | |
242 | It is insanely risky to remove the dependents of an essential package! */ | |
243 | void ShowEssential(ostream &out,pkgDepCache &Dep) | |
244 | { | |
245 | pkgCache::PkgIterator I = Dep.PkgBegin(); | |
246 | string List; | |
247 | bool *Added = new bool[Dep.HeaderP->PackageCount]; | |
93641593 | 248 | for (unsigned int I = 0; I != Dep.HeaderP->PackageCount; I++) |
0a8e3465 AL |
249 | Added[I] = false; |
250 | ||
251 | for (;I.end() != true; I++) | |
252 | { | |
253 | if ((I->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential) | |
254 | continue; | |
255 | ||
256 | // The essential package is being removed | |
257 | if (Dep[I].Delete() == true) | |
258 | { | |
259 | if (Added[I->ID] == false) | |
260 | { | |
261 | Added[I->ID] = true; | |
262 | List += string(I.Name()) + " "; | |
263 | } | |
264 | } | |
265 | ||
266 | if (I->CurrentVer == 0) | |
267 | continue; | |
268 | ||
269 | // Print out any essential package depenendents that are to be removed | |
270 | for (pkgDepCache::DepIterator D = I.CurrentVer().DependsList(); D.end() == false; D++) | |
271 | { | |
272 | pkgCache::PkgIterator P = D.SmartTargetPkg(); | |
273 | if (Dep[P].Delete() == true) | |
274 | { | |
275 | if (Added[P->ID] == true) | |
276 | continue; | |
277 | Added[P->ID] = true; | |
278 | List += string(P.Name()) + " "; | |
279 | } | |
280 | } | |
281 | } | |
282 | ||
283 | if (List.empty() == false) | |
284 | out << "WARNING: The following essential packages will be removed" << endl; | |
285 | ShowList(out,"This should NOT be done unless you know exactly what you are doing!",List); | |
286 | ||
287 | delete [] Added; | |
288 | } | |
289 | /*}}}*/ | |
290 | // Stats - Show some statistics /*{{{*/ | |
291 | // --------------------------------------------------------------------- | |
292 | /* */ | |
293 | void Stats(ostream &out,pkgDepCache &Dep) | |
294 | { | |
295 | unsigned long Upgrade = 0; | |
296 | unsigned long Install = 0; | |
297 | for (pkgCache::PkgIterator I = Dep.PkgBegin(); I.end() == false; I++) | |
298 | { | |
299 | if (Dep[I].NewInstall() == true) | |
300 | Install++; | |
301 | else | |
302 | if (Dep[I].Upgrade() == true) | |
303 | Upgrade++; | |
304 | } | |
305 | ||
306 | out << Upgrade << " packages upgraded, " << | |
307 | Install << " newly installed, " << | |
308 | Dep.DelCount() << " to remove and " << | |
309 | Dep.KeepCount() << " not upgraded." << endl; | |
310 | ||
311 | if (Dep.BadCount() != 0) | |
312 | out << Dep.BadCount() << " packages not fully installed or removed." << endl; | |
313 | } | |
314 | /*}}}*/ | |
315 | ||
316 | // class CacheFile - Cover class for some dependency cache functions /*{{{*/ | |
317 | // --------------------------------------------------------------------- | |
318 | /* */ | |
319 | class CacheFile | |
320 | { | |
321 | public: | |
322 | ||
323 | FileFd *File; | |
324 | MMap *Map; | |
325 | pkgDepCache *Cache; | |
326 | ||
327 | inline operator pkgDepCache &() {return *Cache;}; | |
328 | inline pkgDepCache *operator ->() {return Cache;}; | |
329 | inline pkgDepCache &operator *() {return *Cache;}; | |
330 | ||
331 | bool Open(); | |
332 | CacheFile() : File(0), Map(0), Cache(0) {}; | |
333 | ~CacheFile() | |
334 | { | |
335 | delete Cache; | |
336 | delete Map; | |
337 | delete File; | |
338 | } | |
339 | }; | |
340 | /*}}}*/ | |
341 | // CacheFile::Open - Open the cache file /*{{{*/ | |
342 | // --------------------------------------------------------------------- | |
343 | /* This routine generates the caches and then opens the dependency cache | |
344 | and verifies that the system is OK. */ | |
345 | bool CacheFile::Open() | |
346 | { | |
347 | // Create a progress class | |
348 | OpTextProgress Progress(*_config); | |
349 | ||
350 | // Read the source list | |
351 | pkgSourceList List; | |
352 | if (List.ReadMainList() == false) | |
353 | return _error->Error("The list of sources could not be read."); | |
354 | ||
355 | // Build all of the caches | |
356 | pkgMakeStatusCache(List,Progress); | |
357 | if (_error->PendingError() == true) | |
358 | return _error->Error("The package lists or status file could not be parsed or opened."); | |
359 | ||
360 | Progress.Done(); | |
361 | ||
362 | // Open the cache file | |
303a1703 | 363 | File = new FileFd(_config->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly); |
0a8e3465 AL |
364 | if (_error->PendingError() == true) |
365 | return false; | |
366 | ||
367 | Map = new MMap(*File,MMap::Public | MMap::ReadOnly); | |
368 | if (_error->PendingError() == true) | |
369 | return false; | |
370 | ||
371 | Cache = new pkgDepCache(*Map,Progress); | |
372 | if (_error->PendingError() == true) | |
373 | return false; | |
374 | ||
375 | Progress.Done(); | |
376 | ||
377 | // Check that the system is OK | |
378 | if (Cache->DelCount() != 0 || Cache->InstCount() != 0) | |
379 | return _error->Error("Internal Error, non-zero counts"); | |
380 | ||
381 | // Apply corrections for half-installed packages | |
382 | if (pkgApplyStatus(*Cache) == false) | |
383 | return false; | |
384 | ||
385 | // Nothing is broken | |
386 | if (Cache->BrokenCount() == 0) | |
387 | return true; | |
388 | ||
389 | // Attempt to fix broken things | |
390 | if (_config->FindB("APT::Get::Fix-Broken",false) == true) | |
391 | { | |
392 | c1out << "Correcting dependencies..." << flush; | |
393 | if (pkgFixBroken(*Cache) == false || Cache->BrokenCount() != 0) | |
394 | { | |
395 | c1out << " failed." << endl; | |
396 | ShowBroken(c1out,*this); | |
397 | ||
398 | return _error->Error("Unable to correct dependencies"); | |
399 | } | |
7e798dd7 AL |
400 | if (pkgMinimizeUpgrade(*Cache) == false) |
401 | return _error->Error("Unable to minimize the upgrade set"); | |
0a8e3465 AL |
402 | |
403 | c1out << " Done" << endl; | |
404 | } | |
405 | else | |
406 | { | |
407 | c1out << "You might want to run `apt-get -f install' to correct these." << endl; | |
408 | ShowBroken(c1out,*this); | |
409 | ||
410 | return _error->Error("Unmet dependencies. Try using -f."); | |
411 | } | |
412 | ||
413 | return true; | |
414 | } | |
415 | /*}}}*/ | |
416 | ||
417 | // InstallPackages - Actually download and install the packages /*{{{*/ | |
418 | // --------------------------------------------------------------------- | |
419 | /* This displays the informative messages describing what is going to | |
420 | happen and then calls the download routines */ | |
421 | bool InstallPackages(pkgDepCache &Cache,bool ShwKept) | |
422 | { | |
423 | ShowDel(c1out,Cache); | |
424 | ShowNew(c1out,Cache); | |
425 | if (ShwKept == true) | |
426 | ShowKept(c1out,Cache); | |
427 | ShowHold(c1out,Cache); | |
428 | if (_config->FindB("APT::Get::Show-Upgraded",false) == true) | |
429 | ShowUpgraded(c1out,Cache); | |
430 | ShowEssential(c1out,Cache); | |
431 | Stats(c1out,Cache); | |
432 | ||
433 | // Sanity check | |
434 | if (Cache.BrokenCount() != 0) | |
435 | { | |
436 | ShowBroken(c1out,Cache); | |
437 | return _error->Error("Internal Error, InstallPackages was called with broken packages!"); | |
438 | } | |
439 | ||
440 | if (Cache.DelCount() == 0 && Cache.InstCount() == 0 && | |
441 | Cache.BadCount() == 0) | |
442 | return true; | |
443 | ||
444 | return true; | |
445 | } | |
446 | /*}}}*/ | |
447 | ||
448 | // DoUpdate - Update the package lists /*{{{*/ | |
449 | // --------------------------------------------------------------------- | |
450 | /* */ | |
0919e3f9 | 451 | bool DoUpdate(CommandLine &) |
0a8e3465 | 452 | { |
0919e3f9 AL |
453 | // Get the source list |
454 | pkgSourceList List; | |
455 | if (List.ReadMainList() == false) | |
456 | return false; | |
457 | ||
458 | // Create the download object | |
459 | AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); | |
460 | pkgAcquire Fetcher(&Stat); | |
461 | ||
462 | // Populate it with the source selection | |
463 | pkgSourceList::const_iterator I; | |
464 | for (I = List.begin(); I != List.end(); I++) | |
465 | { | |
466 | new pkgAcqIndex(&Fetcher,I); | |
467 | if (_error->PendingError() == true) | |
468 | return false; | |
469 | } | |
470 | ||
471 | // Run it | |
472 | if (Fetcher.Run() == false) | |
473 | return false; | |
474 | ||
7a7fa5f0 AL |
475 | // Clean out any old list files |
476 | if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false || | |
477 | Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false) | |
478 | return false; | |
479 | ||
0919e3f9 AL |
480 | // Prepare the cache. |
481 | CacheFile Cache; | |
482 | if (Cache.Open() == false) | |
483 | return false; | |
484 | ||
485 | return true; | |
0a8e3465 AL |
486 | } |
487 | /*}}}*/ | |
488 | // DoUpgrade - Upgrade all packages /*{{{*/ | |
489 | // --------------------------------------------------------------------- | |
490 | /* Upgrade all packages without installing new packages or erasing old | |
491 | packages */ | |
492 | bool DoUpgrade(CommandLine &CmdL) | |
493 | { | |
494 | CacheFile Cache; | |
495 | if (Cache.Open() == false) | |
496 | return false; | |
497 | ||
498 | // Do the upgrade | |
0a8e3465 AL |
499 | if (pkgAllUpgrade(Cache) == false) |
500 | { | |
501 | ShowBroken(c1out,Cache); | |
502 | return _error->Error("Internal Error, AllUpgrade broke stuff"); | |
503 | } | |
504 | ||
505 | return InstallPackages(Cache,true); | |
506 | } | |
507 | /*}}}*/ | |
508 | // DoInstall - Install packages from the command line /*{{{*/ | |
509 | // --------------------------------------------------------------------- | |
510 | /* Install named packages */ | |
511 | bool DoInstall(CommandLine &CmdL) | |
512 | { | |
513 | CacheFile Cache; | |
514 | if (Cache.Open() == false) | |
515 | return false; | |
516 | ||
517 | int ExpectedInst = 0; | |
303a1703 | 518 | int Packages = 0; |
0a8e3465 AL |
519 | pkgProblemResolver Fix(Cache); |
520 | ||
303a1703 AL |
521 | bool DefRemove = false; |
522 | if (strcasecmp(CmdL.FileList[0],"remove") == 0) | |
523 | DefRemove = true; | |
524 | ||
0a8e3465 AL |
525 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) |
526 | { | |
527 | // Duplicate the string | |
528 | unsigned int Length = strlen(*I); | |
529 | char S[300]; | |
530 | if (Length >= sizeof(S)) | |
531 | continue; | |
532 | strcpy(S,*I); | |
533 | ||
534 | // See if we are removing the package | |
303a1703 | 535 | bool Remove = DefRemove; |
0a8e3465 AL |
536 | if (S[Length - 1] == '-') |
537 | { | |
538 | Remove = true; | |
539 | S[--Length] = 0; | |
540 | } | |
303a1703 AL |
541 | if (S[Length - 1] == '+') |
542 | { | |
543 | Remove = false; | |
544 | S[--Length] = 0; | |
545 | } | |
0a8e3465 AL |
546 | |
547 | // Locate the package | |
548 | pkgCache::PkgIterator Pkg = Cache->FindPkg(S); | |
303a1703 | 549 | Packages++; |
0a8e3465 AL |
550 | if (Pkg.end() == true) |
551 | return _error->Error("Couldn't find package %s",S); | |
552 | ||
553 | // Check if there is something new to install | |
554 | pkgDepCache::StateCache &State = (*Cache)[Pkg]; | |
555 | if (State.CandidateVer == 0) | |
303a1703 AL |
556 | { |
557 | if (Pkg->ProvidesList != 0) | |
558 | { | |
559 | c1out << "Package " << S << " is a virtual package provided by:" << endl; | |
560 | ||
561 | pkgCache::PrvIterator I = Pkg.ProvidesList(); | |
562 | for (; I.end() == false; I++) | |
563 | { | |
564 | pkgCache::PkgIterator Pkg = I.OwnerPkg(); | |
565 | ||
566 | if ((*Cache)[Pkg].CandidateVerIter(*Cache) == I.OwnerVer()) | |
567 | c1out << " " << Pkg.Name() << " " << I.OwnerVer().VerStr() << endl; | |
568 | ||
569 | if ((*Cache)[Pkg].InstVerIter(*Cache) == I.OwnerVer()) | |
570 | c1out << " " << Pkg.Name() << " " << I.OwnerVer().VerStr() << | |
571 | " [Installed]"<< endl; | |
572 | } | |
573 | c1out << "You should explicly select one to install." << endl; | |
574 | } | |
575 | else | |
576 | { | |
577 | c1out << "Package " << S << " has no available version, but exists in the database." << endl; | |
578 | c1out << "This typically means that the package was mentioned in a dependency and " << endl; | |
579 | c1out << "never uploaded, or that it is an obsolete package." << endl; | |
580 | } | |
581 | ||
0a8e3465 | 582 | return _error->Error("Package %s has no installation candidate",S); |
303a1703 | 583 | } |
0a8e3465 AL |
584 | |
585 | Fix.Protect(Pkg); | |
586 | if (Remove == true) | |
587 | { | |
303a1703 | 588 | Fix.Remove(Pkg); |
0a8e3465 AL |
589 | Cache->MarkDelete(Pkg); |
590 | continue; | |
591 | } | |
592 | ||
593 | // Install it | |
594 | Cache->MarkInstall(Pkg,false); | |
595 | if (State.Install() == false) | |
596 | c1out << "Sorry, " << S << " is already the newest version" << endl; | |
597 | else | |
598 | ExpectedInst++; | |
599 | ||
600 | // Install it with autoinstalling enabled. | |
601 | if (State.InstBroken() == true) | |
602 | Cache->MarkInstall(Pkg,true); | |
603 | } | |
604 | ||
605 | // Call the scored problem resolver | |
303a1703 | 606 | Fix.InstallProtect(); |
0a8e3465 AL |
607 | if (Fix.Resolve(true) == false) |
608 | _error->Discard(); | |
609 | ||
610 | // Now we check the state of the packages, | |
611 | if (Cache->BrokenCount() != 0) | |
612 | { | |
303a1703 AL |
613 | c1out << "Some packages could not be installed. This may mean that you have" << endl; |
614 | c1out << "requested an impossible situation or if you are using the unstable" << endl; | |
615 | c1out << "distribution that some required packages have not yet been created" << endl; | |
616 | c1out << "or been moved out of Incoming." << endl; | |
617 | if (Packages == 1) | |
618 | { | |
619 | c1out << endl; | |
620 | c1out << "Since you only requested a single operation it is extremely likely that" << endl; | |
621 | c1out << "the package is simply not installable and a bug report against" << endl; | |
622 | c1out << "that package should be filed." << endl; | |
623 | } | |
624 | ||
625 | c1out << "The following information may help to resolve the situation:" << endl; | |
626 | c1out << endl; | |
0a8e3465 AL |
627 | ShowBroken(c1out,Cache); |
628 | return _error->Error("Sorry, broken packages"); | |
629 | } | |
630 | ||
631 | /* Print out a list of packages that are going to be installed extra | |
632 | to what the user asked */ | |
633 | if (Cache->InstCount() != ExpectedInst) | |
634 | { | |
635 | string List; | |
636 | pkgCache::PkgIterator I = Cache->PkgBegin(); | |
637 | for (;I.end() != true; I++) | |
638 | { | |
639 | if ((*Cache)[I].Install() == false) | |
640 | continue; | |
641 | ||
642 | const char **J; | |
643 | for (J = CmdL.FileList + 1; *J != 0; J++) | |
644 | if (strcmp(*J,I.Name()) == 0) | |
645 | break; | |
646 | ||
647 | if (*J == 0) | |
648 | List += string(I.Name()) + " "; | |
649 | } | |
650 | ||
651 | ShowList(c1out,"The following extra packages will be installed:",List); | |
652 | } | |
653 | ||
654 | return InstallPackages(Cache,false); | |
655 | } | |
656 | /*}}}*/ | |
657 | // DoDistUpgrade - Automatic smart upgrader /*{{{*/ | |
658 | // --------------------------------------------------------------------- | |
659 | /* Intelligent upgrader that will install and remove packages at will */ | |
660 | bool DoDistUpgrade(CommandLine &CmdL) | |
661 | { | |
662 | CacheFile Cache; | |
663 | if (Cache.Open() == false) | |
664 | return false; | |
665 | ||
666 | c0out << "Calculating Upgrade... " << flush; | |
667 | if (pkgDistUpgrade(*Cache) == false) | |
668 | { | |
669 | c0out << "Failed" << endl; | |
670 | ShowBroken(c1out,Cache); | |
671 | return false; | |
672 | } | |
673 | ||
674 | c0out << "Done" << endl; | |
675 | ||
676 | return InstallPackages(Cache,true); | |
677 | } | |
678 | /*}}}*/ | |
679 | // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/ | |
680 | // --------------------------------------------------------------------- | |
681 | /* Follows dselect's selections */ | |
682 | bool DoDSelectUpgrade(CommandLine &CmdL) | |
683 | { | |
684 | CacheFile Cache; | |
685 | if (Cache.Open() == false) | |
686 | return false; | |
687 | ||
688 | // Install everything with the install flag set | |
689 | pkgCache::PkgIterator I = Cache->PkgBegin(); | |
690 | for (;I.end() != true; I++) | |
691 | { | |
692 | /* Install the package only if it is a new install, the autoupgrader | |
693 | will deal with the rest */ | |
694 | if (I->SelectedState == pkgCache::State::Install) | |
695 | Cache->MarkInstall(I,false); | |
696 | } | |
697 | ||
698 | /* Now install their deps too, if we do this above then order of | |
699 | the status file is significant for | groups */ | |
700 | for (I = Cache->PkgBegin();I.end() != true; I++) | |
701 | { | |
702 | /* Install the package only if it is a new install, the autoupgrader | |
703 | will deal with the rest */ | |
704 | if (I->SelectedState == pkgCache::State::Install) | |
705 | Cache->MarkInstall(I); | |
706 | } | |
707 | ||
708 | // Apply erasures now, they override everything else. | |
709 | for (I = Cache->PkgBegin();I.end() != true; I++) | |
710 | { | |
711 | // Remove packages | |
712 | if (I->SelectedState == pkgCache::State::DeInstall || | |
713 | I->SelectedState == pkgCache::State::Purge) | |
714 | Cache->MarkDelete(I); | |
715 | } | |
716 | ||
717 | /* Use updates smart upgrade to do the rest, it will automatically | |
718 | ignore held items */ | |
719 | if (pkgAllUpgrade(Cache) == false) | |
720 | { | |
721 | ShowBroken(c1out,Cache); | |
722 | return _error->Error("Internal Error, AllUpgrade broke stuff"); | |
723 | } | |
724 | ||
725 | return InstallPackages(Cache,false); | |
726 | } | |
727 | /*}}}*/ | |
728 | // DoClean - Remove download archives /*{{{*/ | |
729 | // --------------------------------------------------------------------- | |
730 | /* */ | |
731 | bool DoClean(CommandLine &CmdL) | |
732 | { | |
733 | return true; | |
734 | } | |
735 | /*}}}*/ | |
736 | // DoCheck - Perform the check operation /*{{{*/ | |
737 | // --------------------------------------------------------------------- | |
738 | /* Opening automatically checks the system, this command is mostly used | |
739 | for debugging */ | |
740 | bool DoCheck(CommandLine &CmdL) | |
741 | { | |
742 | CacheFile Cache; | |
743 | Cache.Open(); | |
744 | ||
745 | return true; | |
746 | } | |
747 | /*}}}*/ | |
748 | ||
749 | // ShowHelp - Show a help screen /*{{{*/ | |
750 | // --------------------------------------------------------------------- | |
751 | /* */ | |
752 | int ShowHelp() | |
753 | { | |
754 | cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE << | |
755 | " compiled on " << __DATE__ << " " << __TIME__ << endl; | |
756 | ||
757 | cout << "Usage: apt-get [options] command" << endl; | |
758 | cout << " apt-get [options] install pkg1 [pkg2 ...]" << endl; | |
759 | cout << endl; | |
760 | cout << "apt-get is a simple command line interface for downloading and" << endl; | |
761 | cout << "installing packages. The most frequently used commands are update" << endl; | |
762 | cout << "and install." << endl; | |
763 | cout << endl; | |
764 | cout << "Commands:" << endl; | |
765 | cout << " update - Retrieve new lists of packages" << endl; | |
766 | cout << " upgrade - Perform an upgrade" << endl; | |
767 | cout << " install - Install new packages (pkg is libc6 not libc6.deb)" << endl; | |
303a1703 | 768 | cout << " remove - Remove packages" << endl; |
0a8e3465 AL |
769 | cout << " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl; |
770 | cout << " dselect-upgrade - Follow dselect selections" << endl; | |
771 | cout << " clean - Erase downloaded archive files" << endl; | |
772 | cout << " check - Verify that there are no broken dependencies" << endl; | |
773 | cout << endl; | |
774 | cout << "Options:" << endl; | |
775 | cout << " -h This help text." << endl; | |
776 | cout << " -q Loggable output - no progress indicator" << endl; | |
777 | cout << " -qq No output except for errors" << endl; | |
778 | cout << " -d Download only - do NOT install or unpack archives" << endl; | |
779 | cout << " -s No-act. Perform ordering simulation" << endl; | |
780 | cout << " -y Assume Yes to all queries and do not prompt" << endl; | |
781 | cout << " -f Attempt to continue if the integrity check fails" << endl; | |
782 | cout << " -m Attempt to continue if archives are unlocatable" << endl; | |
783 | cout << " -u Show a list of upgraded packages as well" << endl; | |
784 | cout << " -c=? Read this configuration file" << endl; | |
785 | cout << " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl; | |
786 | cout << "See the apt-get(8), sources.list(8) and apt.conf(8) manual" << endl; | |
787 | cout << "pages for more information." << endl; | |
788 | return 100; | |
789 | } | |
790 | /*}}}*/ | |
791 | // GetInitialize - Initialize things for apt-get /*{{{*/ | |
792 | // --------------------------------------------------------------------- | |
793 | /* */ | |
794 | void GetInitialize() | |
795 | { | |
796 | _config->Set("quiet",0); | |
797 | _config->Set("help",false); | |
798 | _config->Set("APT::Get::Download-Only",false); | |
799 | _config->Set("APT::Get::Simulate",false); | |
800 | _config->Set("APT::Get::Assume-Yes",false); | |
801 | _config->Set("APT::Get::Fix-Broken",false); | |
802 | } | |
803 | /*}}}*/ | |
804 | ||
805 | int main(int argc,const char *argv[]) | |
806 | { | |
807 | CommandLine::Args Args[] = { | |
808 | {'h',"help","help",0}, | |
809 | {'q',"quiet","quiet",CommandLine::IntLevel}, | |
810 | {'q',"silent","quiet",CommandLine::IntLevel}, | |
811 | {'d',"download-only","APT::Get::Download-Only",0}, | |
812 | {'s',"simulate","APT::Get::Simulate",0}, | |
813 | {'s',"just-print","APT::Get::Simulate",0}, | |
814 | {'s',"recon","APT::Get::Simulate",0}, | |
815 | {'s',"no-act","APT::Get::Simulate",0}, | |
816 | {'y',"yes","APT::Get::Assume-Yes",0}, | |
817 | {'y',"assume-yes","APT::Get::Assume-Yes",0}, | |
818 | {'f',"fix-broken","APT::Get::Fix-Broken",0}, | |
819 | {'u',"show-upgraded","APT::Get::Show-Upgraded",0}, | |
820 | {'m',"ignore-missing","APT::Get::Fix-Broken",0}, | |
c88edf1d | 821 | {0,"ignore-hold","APT::Ingore-Hold",0}, |
0a8e3465 AL |
822 | {'c',"config-file",0,CommandLine::ConfigFile}, |
823 | {'o',"option",0,CommandLine::ArbItem}, | |
824 | {0,0,0,0}}; | |
825 | ||
826 | // Parse the command line and initialize the package library | |
827 | CommandLine CmdL(Args,_config); | |
828 | if (pkgInitialize(*_config) == false || | |
829 | CmdL.Parse(argc,argv) == false) | |
830 | { | |
831 | _error->DumpErrors(); | |
832 | return 100; | |
833 | } | |
834 | ||
835 | // See if the help should be shown | |
836 | if (_config->FindB("help") == true || | |
837 | CmdL.FileSize() == 0) | |
838 | return ShowHelp(); | |
839 | ||
840 | // Setup the output streams | |
841 | c0out.rdbuf(cout.rdbuf()); | |
842 | c1out.rdbuf(cout.rdbuf()); | |
843 | c2out.rdbuf(cout.rdbuf()); | |
844 | if (_config->FindI("quiet",0) > 0) | |
845 | c0out.rdbuf(devnull.rdbuf()); | |
846 | if (_config->FindI("quiet",0) > 1) | |
847 | c1out.rdbuf(devnull.rdbuf()); | |
848 | ||
849 | // Match the operation | |
850 | struct | |
851 | { | |
852 | const char *Match; | |
853 | bool (*Handler)(CommandLine &); | |
854 | } Map[] = {{"update",&DoUpdate}, | |
855 | {"upgrade",&DoUpgrade}, | |
856 | {"install",&DoInstall}, | |
303a1703 | 857 | {"remove",&DoInstall}, |
0a8e3465 AL |
858 | {"dist-upgrade",&DoDistUpgrade}, |
859 | {"dselect-upgrade",&DoDSelectUpgrade}, | |
860 | {"clean",&DoClean}, | |
861 | {"check",&DoCheck}, | |
862 | {0,0}}; | |
863 | int I; | |
864 | for (I = 0; Map[I].Match != 0; I++) | |
865 | { | |
866 | if (strcmp(CmdL.FileList[0],Map[I].Match) == 0) | |
867 | { | |
0919e3f9 AL |
868 | if (Map[I].Handler(CmdL) == false && _error->PendingError() == false) |
869 | _error->Error("Handler silently failed"); | |
0a8e3465 AL |
870 | break; |
871 | } | |
872 | } | |
873 | ||
874 | // No matching name | |
875 | if (Map[I].Match == 0) | |
876 | _error->Error("Invalid operation %s", CmdL.FileList[0]); | |
877 | ||
878 | // Print any errors or warnings found during parsing | |
879 | if (_error->empty() == false) | |
880 | { | |
881 | bool Errors = _error->PendingError(); | |
882 | _error->DumpErrors(); | |
883 | if (Errors == true) | |
884 | cout << "Returning 100." << endl; | |
885 | return Errors == true?100:0; | |
886 | } | |
887 | ||
888 | return 0; | |
889 | } |