You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

apt-get.cc 15 KiB

* merged from main Patches applied: * apt@packages.debian.org/apt--main--0--patch-100 Use debian.org address in mainline * apt@packages.debian.org/apt--main--0--patch-101 Update pot file * apt@packages.debian.org/apt--main--0--patch-102 Open 0.6.40 * apt@packages.debian.org/apt--main--0--patch-103 Patch from Jordi Mallach to mark some additional strings for translation * apt@packages.debian.org/apt--main--0--patch-104 Updated Catalan translation from Jordi Mallach * apt@packages.debian.org/apt--main--0--patch-105 Merge from bubulle@debian.org--2005/apt--main--0 * apt@packages.debian.org/apt--main--0--patch-106 Restore lost changelog entries * apt@packages.debian.org/apt--main--0--patch-107 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-108 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-109 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-110 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * bubulle@debian.org--2005/apt--main--0--patch-90 Merge with Matt * bubulle@debian.org--2005/apt--main--0--patch-91 Updated Slovak translation * bubulle@debian.org--2005/apt--main--0--patch-92 Add apt-key French man page * bubulle@debian.org--2005/apt--main--0--patch-93 Update Greek translations * bubulle@debian.org--2005/apt--main--0--patch-94 Merge with Matt * bubulle@debian.org--2005/apt--main--0--patch-95 Sync PO files with the POT file/French translation update * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--base-0 tag of apt@packages.debian.org/apt--main--0--patch-85 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-1 * inital proof of concept code, understands what dpkg tells it already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-2 * progress reporting works now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-3 * added "APT::Status-Fd" variable * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-4 * do i18n now too * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-5 * define N_(x) if it is not defined already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-6 * PackageManager::DoInstall(int status_fd) added (does not break the ABI) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-7 * merged with apt--fixes--0 to make it build again * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-8 * added support for "error" and "conffile-prompt" messages from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-9 merge with main * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-10 * use sizeof() for all snprintf() uses; fix a potential line break problem in the status reading code; changed the N_() to _() calls * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-11 * added APT::KeepFDs configuration list for file descriptors that apt should leave open (needed for various frontends like debconf, synaptic) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-12 * fixed a API breakage * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-13 * doc added, should be releasable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-14 * merged with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-15 * more source comments, added Debug::DpkgPM debug code to inspect the dpkg<->apt communication, broke the abi (ok with matt) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-16 * the progress reporting has it's own "Debug::pkgDPkgProgressReporting" debug variable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-17 * merged PackageOps and TranslatedPackageOps into a single Map with the new DpkgState struct * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-18 * clear the APT::Keep-Fds configuration when it's no longer needed * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-19 * rewrote the reading from dpkg so that it never blocks * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-20 * merged the two status arrays into one * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-21 * added support for download progress reporting too (for Kamion and base-config) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-22 * ABI break; added Configuration::Clear(string List, {int,string} value) added (to remove a single Value from a list); test/conf_clear.cc added * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-23 * remvoed a debug string * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-24 * soname changed, fixed a bug in the parsing code when dpkg send the same state more than once (at the end) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-25 * merged with apt@packages.debian.org/apt--main--0, added changelog entry for the 0.6.40.1 upload * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-26 * fix a bug when out-of-order states are send from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-27 * changelog update * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-28 * a real changelog entry now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-29 * changelog finalized * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-30 * propper (and sane) support for pmerror and pmconffile added
16 years ago
* merged from main Patches applied: * apt@packages.debian.org/apt--main--0--patch-100 Use debian.org address in mainline * apt@packages.debian.org/apt--main--0--patch-101 Update pot file * apt@packages.debian.org/apt--main--0--patch-102 Open 0.6.40 * apt@packages.debian.org/apt--main--0--patch-103 Patch from Jordi Mallach to mark some additional strings for translation * apt@packages.debian.org/apt--main--0--patch-104 Updated Catalan translation from Jordi Mallach * apt@packages.debian.org/apt--main--0--patch-105 Merge from bubulle@debian.org--2005/apt--main--0 * apt@packages.debian.org/apt--main--0--patch-106 Restore lost changelog entries * apt@packages.debian.org/apt--main--0--patch-107 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-108 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-109 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-110 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * bubulle@debian.org--2005/apt--main--0--patch-90 Merge with Matt * bubulle@debian.org--2005/apt--main--0--patch-91 Updated Slovak translation * bubulle@debian.org--2005/apt--main--0--patch-92 Add apt-key French man page * bubulle@debian.org--2005/apt--main--0--patch-93 Update Greek translations * bubulle@debian.org--2005/apt--main--0--patch-94 Merge with Matt * bubulle@debian.org--2005/apt--main--0--patch-95 Sync PO files with the POT file/French translation update * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--base-0 tag of apt@packages.debian.org/apt--main--0--patch-85 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-1 * inital proof of concept code, understands what dpkg tells it already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-2 * progress reporting works now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-3 * added "APT::Status-Fd" variable * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-4 * do i18n now too * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-5 * define N_(x) if it is not defined already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-6 * PackageManager::DoInstall(int status_fd) added (does not break the ABI) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-7 * merged with apt--fixes--0 to make it build again * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-8 * added support for "error" and "conffile-prompt" messages from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-9 merge with main * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-10 * use sizeof() for all snprintf() uses; fix a potential line break problem in the status reading code; changed the N_() to _() calls * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-11 * added APT::KeepFDs configuration list for file descriptors that apt should leave open (needed for various frontends like debconf, synaptic) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-12 * fixed a API breakage * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-13 * doc added, should be releasable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-14 * merged with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-15 * more source comments, added Debug::DpkgPM debug code to inspect the dpkg<->apt communication, broke the abi (ok with matt) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-16 * the progress reporting has it's own "Debug::pkgDPkgProgressReporting" debug variable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-17 * merged PackageOps and TranslatedPackageOps into a single Map with the new DpkgState struct * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-18 * clear the APT::Keep-Fds configuration when it's no longer needed * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-19 * rewrote the reading from dpkg so that it never blocks * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-20 * merged the two status arrays into one * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-21 * added support for download progress reporting too (for Kamion and base-config) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-22 * ABI break; added Configuration::Clear(string List, {int,string} value) added (to remove a single Value from a list); test/conf_clear.cc added * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-23 * remvoed a debug string * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-24 * soname changed, fixed a bug in the parsing code when dpkg send the same state more than once (at the end) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-25 * merged with apt@packages.debian.org/apt--main--0, added changelog entry for the 0.6.40.1 upload * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-26 * fix a bug when out-of-order states are send from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-27 * changelog update * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-28 * a real changelog entry now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-29 * changelog finalized * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-30 * propper (and sane) support for pmerror and pmconffile added
16 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. apt-get - Cover for dpkg
  5. This is an allout cover for dpkg implementing a safer front end. It is
  6. based largely on libapt-pkg.
  7. The syntax is different,
  8. apt-get [opt] command [things]
  9. Where command is:
  10. update - Resyncronize the package files from their sources
  11. upgrade - Smart-Download the newest versions of all packages
  12. dselect-upgrade - Follows dselect's changes to the Status: field
  13. and installs new and removes old packages
  14. dist-upgrade - Powerful upgrader designed to handle the issues with
  15. a new distribution.
  16. install - Download and install a given package (by name, not by .deb)
  17. check - Update the package cache and check for broken packages
  18. clean - Erase the .debs downloaded to /var/cache/apt/archives and
  19. the partial dir too
  20. ##################################################################### */
  21. /*}}}*/
  22. // Include Files /*{{{*/
  23. #include <config.h>
  24. #include <apt-pkg/acquire-item.h>
  25. #include <apt-pkg/acquire.h>
  26. #include <apt-pkg/algorithms.h>
  27. #include <apt-pkg/aptconfiguration.h>
  28. #include <apt-pkg/cachefile.h>
  29. #include <apt-pkg/cacheset.h>
  30. #include <apt-pkg/clean.h>
  31. #include <apt-pkg/cmndline.h>
  32. #include <apt-pkg/configuration.h>
  33. #include <apt-pkg/debmetaindex.h>
  34. #include <apt-pkg/depcache.h>
  35. #include <apt-pkg/error.h>
  36. #include <apt-pkg/fileutl.h>
  37. #include <apt-pkg/indexfile.h>
  38. #include <apt-pkg/init.h>
  39. #include <apt-pkg/macros.h>
  40. #include <apt-pkg/md5.h>
  41. #include <apt-pkg/metaindex.h>
  42. #include <apt-pkg/pkgcache.h>
  43. #include <apt-pkg/pkgrecords.h>
  44. #include <apt-pkg/pkgsystem.h>
  45. #include <apt-pkg/progress.h>
  46. #include <apt-pkg/sourcelist.h>
  47. #include <apt-pkg/sptr.h>
  48. #include <apt-pkg/srcrecords.h>
  49. #include <apt-pkg/strutl.h>
  50. #include <apt-pkg/upgrade.h>
  51. #include <apt-pkg/version.h>
  52. #include <apt-private/acqprogress.h>
  53. #include <apt-private/private-cachefile.h>
  54. #include <apt-private/private-cacheset.h>
  55. #include <apt-private/private-cmndline.h>
  56. #include <apt-private/private-download.h>
  57. #include <apt-private/private-install.h>
  58. #include <apt-private/private-main.h>
  59. #include <apt-private/private-moo.h>
  60. #include <apt-private/private-output.h>
  61. #include <apt-private/private-source.h>
  62. #include <apt-private/private-update.h>
  63. #include <apt-private/private-upgrade.h>
  64. #include <apt-private/private-utils.h>
  65. #include <errno.h>
  66. #include <grp.h>
  67. #include <pwd.h>
  68. #include <signal.h>
  69. #include <stddef.h>
  70. #include <stdio.h>
  71. #include <stdlib.h>
  72. #include <string.h>
  73. #include <sys/ioctl.h>
  74. #include <sys/stat.h>
  75. #include <unistd.h>
  76. #include <algorithm>
  77. #include <fstream>
  78. #include <iostream>
  79. #include <set>
  80. #include <sstream>
  81. #include <string>
  82. #include <vector>
  83. #include <apti18n.h>
  84. /*}}}*/
  85. using namespace std;
  86. /* mark packages as automatically/manually installed. {{{*/
  87. static bool DoMarkAuto(CommandLine &CmdL)
  88. {
  89. bool Action = true;
  90. int AutoMarkChanged = 0;
  91. OpTextProgress progress;
  92. CacheFile Cache;
  93. if (Cache.Open() == false)
  94. return false;
  95. if (strcasecmp(CmdL.FileList[0],"markauto") == 0)
  96. Action = true;
  97. else if (strcasecmp(CmdL.FileList[0],"unmarkauto") == 0)
  98. Action = false;
  99. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  100. {
  101. const char *S = *I;
  102. // Locate the package
  103. pkgCache::PkgIterator Pkg = Cache->FindPkg(S);
  104. if (Pkg.end() == true) {
  105. return _error->Error(_("Couldn't find package %s"),S);
  106. }
  107. else
  108. {
  109. if (!Action)
  110. ioprintf(c1out,_("%s set to manually installed.\n"), Pkg.Name());
  111. else
  112. ioprintf(c1out,_("%s set to automatically installed.\n"),
  113. Pkg.Name());
  114. Cache->MarkAuto(Pkg,Action);
  115. AutoMarkChanged++;
  116. }
  117. }
  118. _error->Notice(_("This command is deprecated. Please use 'apt-mark auto' and 'apt-mark manual' instead."));
  119. if (AutoMarkChanged && ! _config->FindB("APT::Get::Simulate",false))
  120. return Cache->writeStateFile(NULL);
  121. return false;
  122. }
  123. /*}}}*/
  124. // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
  125. // ---------------------------------------------------------------------
  126. /* Follows dselect's selections */
  127. static bool DoDSelectUpgrade(CommandLine &)
  128. {
  129. CacheFile Cache;
  130. if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
  131. return false;
  132. pkgDepCache::ActionGroup group(Cache);
  133. // Install everything with the install flag set
  134. pkgCache::PkgIterator I = Cache->PkgBegin();
  135. for (;I.end() != true; ++I)
  136. {
  137. /* Install the package only if it is a new install, the autoupgrader
  138. will deal with the rest */
  139. if (I->SelectedState == pkgCache::State::Install)
  140. Cache->MarkInstall(I,false);
  141. }
  142. /* Now install their deps too, if we do this above then order of
  143. the status file is significant for | groups */
  144. for (I = Cache->PkgBegin();I.end() != true; ++I)
  145. {
  146. /* Install the package only if it is a new install, the autoupgrader
  147. will deal with the rest */
  148. if (I->SelectedState == pkgCache::State::Install)
  149. Cache->MarkInstall(I,true);
  150. }
  151. // Apply erasures now, they override everything else.
  152. for (I = Cache->PkgBegin();I.end() != true; ++I)
  153. {
  154. // Remove packages
  155. if (I->SelectedState == pkgCache::State::DeInstall ||
  156. I->SelectedState == pkgCache::State::Purge)
  157. Cache->MarkDelete(I,I->SelectedState == pkgCache::State::Purge);
  158. }
  159. /* Resolve any problems that dselect created, allupgrade cannot handle
  160. such things. We do so quite aggressively too.. */
  161. if (Cache->BrokenCount() != 0)
  162. {
  163. pkgProblemResolver Fix(Cache);
  164. // Hold back held packages.
  165. if (_config->FindB("APT::Ignore-Hold",false) == false)
  166. {
  167. for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; ++I)
  168. {
  169. if (I->SelectedState == pkgCache::State::Hold)
  170. {
  171. Fix.Protect(I);
  172. Cache->MarkKeep(I);
  173. }
  174. }
  175. }
  176. if (Fix.Resolve() == false)
  177. {
  178. ShowBroken(c1out,Cache,false);
  179. return _error->Error(_("Internal error, problem resolver broke stuff"));
  180. }
  181. }
  182. // Now upgrade everything
  183. if (APT::Upgrade::Upgrade(Cache, APT::Upgrade::FORBID_REMOVE_PACKAGES | APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES) == false)
  184. {
  185. ShowBroken(c1out,Cache,false);
  186. return _error->Error(_("Internal error, problem resolver broke stuff"));
  187. }
  188. return InstallPackages(Cache,false);
  189. }
  190. /*}}}*/
  191. // DoCheck - Perform the check operation /*{{{*/
  192. // ---------------------------------------------------------------------
  193. /* Opening automatically checks the system, this command is mostly used
  194. for debugging */
  195. static bool DoCheck(CommandLine &)
  196. {
  197. CacheFile Cache;
  198. Cache.Open();
  199. Cache.CheckDeps();
  200. return true;
  201. }
  202. /*}}}*/
  203. // DoIndexTargets - Lists all IndexTargets /*{{{*/
  204. static std::string format_key(std::string key)
  205. {
  206. // deb822 is case-insensitive, but the human eye prefers candy
  207. std::transform(key.begin(), key.end(), key.begin(), ::tolower);
  208. key[0] = ::toupper(key[0]);
  209. size_t found = key.find("_uri");
  210. if (found != std::string::npos)
  211. key.replace(found, 4, "-URI");
  212. while ((found = key.find('_')) != std::string::npos)
  213. {
  214. key[found] = '-';
  215. key[found + 1] = ::toupper(key[found + 1]);
  216. }
  217. return key;
  218. }
  219. static bool DoIndexTargets(CommandLine &CmdL)
  220. {
  221. pkgCacheFile CacheFile;
  222. pkgSourceList *SrcList = CacheFile.GetSourceList();
  223. pkgCache *Cache = CacheFile.GetPkgCache();
  224. if (SrcList == nullptr || Cache == nullptr)
  225. return false;
  226. std::string const Format = _config->Find("APT::Get::IndexTargets::Format");
  227. bool const ReleaseInfo = _config->FindB("APT::Get::IndexTargets::ReleaseInfo", true);
  228. bool Filtered = CmdL.FileSize() > 1;
  229. for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); ++S)
  230. {
  231. std::vector<IndexTarget> const targets = (*S)->GetIndexTargets();
  232. std::map<std::string, string> AddOptions;
  233. if (ReleaseInfo)
  234. {
  235. AddOptions.insert(std::make_pair("TRUSTED", ((*S)->IsTrusted() ? "yes" : "no")));
  236. pkgCache::RlsFileIterator const RlsFile = (*S)->FindInCache(*Cache, false);
  237. if (RlsFile.end())
  238. continue;
  239. #define APT_RELEASE(X,Y) if (RlsFile.Y() != NULL) AddOptions.insert(std::make_pair(X, RlsFile.Y()))
  240. APT_RELEASE("CODENAME", Codename);
  241. APT_RELEASE("SUITE", Archive);
  242. APT_RELEASE("VERSION", Version);
  243. APT_RELEASE("ORIGIN", Origin);
  244. APT_RELEASE("LABEL", Label);
  245. #undef APT_RELEASE
  246. }
  247. for (std::vector<IndexTarget>::const_iterator T = targets.begin(); T != targets.end(); ++T)
  248. {
  249. std::string filename = T->Option(ReleaseInfo ? IndexTarget::EXISTING_FILENAME : IndexTarget::FILENAME);
  250. if (filename.empty())
  251. continue;
  252. std::ostringstream stanza;
  253. if (Filtered || Format.empty())
  254. {
  255. stanza << "MetaKey: " << T->MetaKey << "\n"
  256. << "ShortDesc: " << T->ShortDesc << "\n"
  257. << "Description: " << T->Description << "\n"
  258. << "URI: " << T->URI << "\n"
  259. << "Filename: " << filename << "\n"
  260. << "Optional: " << (T->IsOptional ? "yes" : "no") << "\n"
  261. << "KeepCompressed: " << (T->KeepCompressed ? "yes" : "no") << "\n";
  262. for (std::map<std::string,std::string>::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O)
  263. stanza << format_key(O->first) << ": " << O->second << "\n";
  264. for (std::map<std::string,std::string>::const_iterator O = T->Options.begin(); O != T->Options.end(); ++O)
  265. {
  266. if (O->first == "PDIFFS")
  267. stanza << "PDiffs: " << O->second << "\n";
  268. else if (O->first == "COMPRESSIONTYPES")
  269. stanza << "CompressionTypes: " << O->second << "\n";
  270. else if (O->first == "KEEPCOMPRESSEDAS")
  271. stanza << "KeepCompressedAs: " << O->second << "\n";
  272. else if (O->first == "DEFAULTENABLED")
  273. stanza << "DefaultEnabled: " << O->second << "\n";
  274. else
  275. stanza << format_key(O->first) << ": " << O->second << "\n";
  276. }
  277. stanza << "\n";
  278. if (Filtered)
  279. {
  280. // that is a bit crude, but good enough for now
  281. bool found = true;
  282. std::string haystack = std::string("\n") + stanza.str() + "\n";
  283. std::transform(haystack.begin(), haystack.end(), haystack.begin(), ::tolower);
  284. size_t const filesize = CmdL.FileSize() - 1;
  285. for (size_t i = 0; i != filesize; ++i)
  286. {
  287. std::string needle = std::string("\n") + CmdL.FileList[i + 1] + "\n";
  288. std::transform(needle.begin(), needle.end(), needle.begin(), ::tolower);
  289. if (haystack.find(needle) != std::string::npos)
  290. continue;
  291. found = false;
  292. break;
  293. }
  294. if (found == false)
  295. continue;
  296. }
  297. }
  298. if (Format.empty())
  299. cout << stanza.str();
  300. else
  301. {
  302. std::string out = SubstVar(Format, "$(FILENAME)", filename);
  303. out = T->Format(out);
  304. for (std::map<std::string,std::string>::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O)
  305. out = SubstVar(out, std::string("$(") + O->first + ")", O->second);
  306. cout << out << std::endl;
  307. }
  308. }
  309. }
  310. return true;
  311. }
  312. /*}}}*/
  313. static bool ShowHelp(CommandLine &) /*{{{*/
  314. {
  315. if (_config->FindB("version") == true)
  316. {
  317. cout << _("Supported modules:") << endl;
  318. for (unsigned I = 0; I != pkgVersioningSystem::GlobalListLen; I++)
  319. {
  320. pkgVersioningSystem *VS = pkgVersioningSystem::GlobalList[I];
  321. if (_system != 0 && _system->VS == VS)
  322. cout << '*';
  323. else
  324. cout << ' ';
  325. cout << "Ver: " << VS->Label << endl;
  326. /* Print out all the packaging systems that will work with
  327. this VS */
  328. for (unsigned J = 0; J != pkgSystem::GlobalListLen; J++)
  329. {
  330. pkgSystem *Sys = pkgSystem::GlobalList[J];
  331. if (_system == Sys)
  332. cout << '*';
  333. else
  334. cout << ' ';
  335. if (Sys->VS->TestCompatibility(*VS) == true)
  336. cout << "Pkg: " << Sys->Label << " (Priority " << Sys->Score(*_config) << ")" << endl;
  337. }
  338. }
  339. for (unsigned I = 0; I != pkgSourceList::Type::GlobalListLen; I++)
  340. {
  341. pkgSourceList::Type *Type = pkgSourceList::Type::GlobalList[I];
  342. cout << " S.L: '" << Type->Name << "' " << Type->Label << endl;
  343. }
  344. for (unsigned I = 0; I != pkgIndexFile::Type::GlobalListLen; I++)
  345. {
  346. pkgIndexFile::Type *Type = pkgIndexFile::Type::GlobalList[I];
  347. cout << " Idx: " << Type->Label << endl;
  348. }
  349. return true;
  350. }
  351. std::cout <<
  352. _("Usage: apt-get [options] command\n"
  353. " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
  354. " apt-get [options] source pkg1 [pkg2 ...]\n"
  355. "\n"
  356. "apt-get is a command line interface for retrieval of packages\n"
  357. "and information about them from authenticated sources and\n"
  358. "for installation, upgrade and removal of packages together\n"
  359. "with their dependencies.\n");
  360. return true;
  361. }
  362. /*}}}*/
  363. static std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/
  364. {
  365. return {
  366. {"update", &DoUpdate, _("Retrieve new lists of packages")},
  367. {"upgrade", &DoUpgrade, _("Perform an upgrade")},
  368. {"install", &DoInstall, _("Install new packages (pkg is libc6 not libc6.deb)")},
  369. {"remove", &DoInstall, _("Remove packages")},
  370. {"purge", &DoInstall, _("Remove packages and config files")},
  371. {"autoremove", &DoInstall, _("Remove automatically all unused packages")},
  372. {"auto-remove", &DoInstall, nullptr},
  373. {"autopurge",&DoInstall, nullptr},
  374. {"markauto", &DoMarkAuto, nullptr},
  375. {"unmarkauto", &DoMarkAuto, nullptr},
  376. {"dist-upgrade", &DoDistUpgrade, _("Distribution upgrade, see apt-get(8)")},
  377. {"full-upgrade", &DoDistUpgrade, nullptr},
  378. {"dselect-upgrade", &DoDSelectUpgrade, _("Follow dselect selections")},
  379. {"build-dep", &DoBuildDep, _("Configure build-dependencies for source packages")},
  380. {"clean", &DoClean, _("Erase downloaded archive files")},
  381. {"autoclean", &DoAutoClean, _("Erase old downloaded archive files")},
  382. {"auto-clean", &DoAutoClean, nullptr},
  383. {"check", &DoCheck, _("Verify that there are no broken dependencies")},
  384. {"source", &DoSource, _("Download source archives")},
  385. {"download", &DoDownload, _("Download the binary package into the current directory")},
  386. {"changelog", &DoChangelog, _("Download and display the changelog for the given package")},
  387. {"indextargets", &DoIndexTargets, nullptr},
  388. {"moo", &DoMoo, nullptr},
  389. {nullptr, nullptr, nullptr}
  390. };
  391. }
  392. /*}}}*/
  393. int main(int argc,const char *argv[]) /*{{{*/
  394. {
  395. // Parse the command line and initialize the package library
  396. CommandLine CmdL;
  397. auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_GET, &_config, &_system, argc, argv, &ShowHelp, &GetCommands);
  398. InitSignals();
  399. InitOutput();
  400. CheckIfSimulateMode(CmdL);
  401. return DispatchCommandLine(CmdL, Cmds);
  402. }
  403. /*}}}*/